~ubuntu-branches/ubuntu/precise/xterm/precise-updates

« back to all changes in this revision

Viewing changes to misc.c

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2008-05-05 14:55:59 UTC
  • mfrom: (1.1.9 upstream) (11.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080505145559-r5qly64gdxj32873
Tags: 235-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Enabled URL highlighting
  - Changed rm -f to rm -rf .pc patches, fixes a bug when .pc is a directory
  - Updated maintainer field
* Noteworthy changes since Hardy:
  - Correct initialization of bold- and wide-, wide-bold fonts, which may be
    set via the utf8Fonts subresource (Closes LP: #194078)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $XTermId: misc.c,v 1.370 2007/07/22 20:34:04 tom Exp $ */
 
1
/* $XTermId: misc.c,v 1.383 2008/04/14 00:05:43 tom Exp $ */
2
2
 
3
3
/*
4
4
 *
5
 
 * Copyright 1999-2006,2007 by Thomas E. Dickey
 
5
 * Copyright 1999-2007,2008 by Thomas E. Dickey
6
6
 *
7
7
 *                        All Rights Reserved
8
8
 *
63
63
#include <pwd.h>
64
64
#include <sys/wait.h>
65
65
 
 
66
#include <X11/keysym.h>
66
67
#include <X11/Xatom.h>
67
68
#include <X11/cursorfont.h>
68
69
#include <X11/Xlocale.h>
108
109
#if OPT_TEK4014
109
110
#define OUR_EVENT(event,Type) \
110
111
                (event.type == Type && \
111
 
                  (event.xcrossing.window == XtWindow(XtParent(term)) || \
 
112
                  (event.xcrossing.window == XtWindow(XtParent(xw)) || \
112
113
                    (tekWidget && \
113
114
                     event.xcrossing.window == XtWindow(XtParent(tekWidget)))))
114
115
#else
115
116
#define OUR_EVENT(event,Type) \
116
117
                (event.type == Type && \
117
 
                   (event.xcrossing.window == XtWindow(XtParent(term))))
 
118
                   (event.xcrossing.window == XtWindow(XtParent(xw))))
118
119
#endif
119
120
 
 
121
static Cursor make_hidden_cursor(XtermWidget);
 
122
 
120
123
#if OPT_EXEC_XTERM
121
124
/* Like readlink(2), but returns a malloc()ed buffer, or NULL on
122
125
   error; adapted from libc docs */
128
131
    int n;
129
132
 
130
133
    for (;;) {
131
 
        buf = realloc(buf, size);
 
134
        buf = TypeRealloc(char, size, buf);
132
135
        memset(buf, 0, size);
133
136
 
134
137
        n = readlink(filename, buf, size);
187
190
{
188
191
    TRACE(("unselectwindow(%d) flag=%d\n", screen->select, flag));
189
192
 
 
193
    if (screen->hide_pointer) {
 
194
        screen->hide_pointer = False;
 
195
        xtermDisplayCursor(term);
 
196
    }
 
197
 
190
198
    if (!screen->always_highlight) {
191
199
#if OPT_TEK4014
192
200
        if (TEK4014_ACTIVE(term)) {
277
285
}
278
286
 
279
287
void
 
288
xtermDisplayCursor(XtermWidget xw)
 
289
{
 
290
    TScreen *screen = TScreenOf(xw);
 
291
 
 
292
    if (screen->Vshow) {
 
293
        if (screen->hide_pointer) {
 
294
            TRACE(("Display hidden_cursor\n"));
 
295
            XDefineCursor(screen->display, VWindow(screen), screen->hidden_cursor);
 
296
        } else {
 
297
            TRACE(("Display pointer_cursor\n"));
 
298
            recolor_cursor(screen,
 
299
                           screen->pointer_cursor,
 
300
                           T_COLOR(screen, MOUSE_FG),
 
301
                           T_COLOR(screen, MOUSE_BG));
 
302
            XDefineCursor(screen->display, VWindow(screen), screen->pointer_cursor);
 
303
        }
 
304
    }
 
305
}
 
306
 
 
307
void
 
308
xtermShowPointer(XtermWidget xw, Bool enable)
 
309
{
 
310
    static int tried = -1;
 
311
    TScreen *screen = TScreenOf(xw);
 
312
 
 
313
#if OPT_TEK4014
 
314
    if (TEK4014_SHOWN(xw))
 
315
        enable = True;
 
316
#endif
 
317
 
 
318
    /*
 
319
     * Whether we actually hide the pointer depends on the pointer-mode and
 
320
     * the mouse-mode:
 
321
     */
 
322
    if (!enable) {
 
323
        switch (screen->pointer_mode) {
 
324
        case pNever:
 
325
            enable = True;
 
326
            break;
 
327
        case pNoMouse:
 
328
            if (screen->send_mouse_pos != MOUSE_OFF)
 
329
                enable = True;
 
330
            break;
 
331
        case pAlways:
 
332
            break;
 
333
        }
 
334
    }
 
335
 
 
336
    if (enable) {
 
337
        if (screen->hide_pointer) {
 
338
            screen->hide_pointer = False;
 
339
            xtermDisplayCursor(xw);
 
340
            switch (screen->send_mouse_pos) {
 
341
            case ANY_EVENT_MOUSE:
 
342
                break;
 
343
            default:
 
344
                MotionOff(screen, xw);
 
345
                break;
 
346
            }
 
347
        }
 
348
    } else if (!(screen->hide_pointer) && (tried <= 0)) {
 
349
        if (screen->hidden_cursor == 0) {
 
350
            screen->hidden_cursor = make_hidden_cursor(xw);
 
351
        }
 
352
        if (screen->hidden_cursor == 0) {
 
353
            tried = 1;
 
354
        } else {
 
355
            tried = 0;
 
356
            screen->hide_pointer = True;
 
357
            xtermDisplayCursor(xw);
 
358
            MotionOn(screen, xw);
 
359
        }
 
360
    }
 
361
}
 
362
 
 
363
void
280
364
xevents(void)
281
365
{
282
366
    XtermWidget xw = term;
348
432
            ((event.xany.type != KeyPress) &&
349
433
             (event.xany.type != KeyRelease) &&
350
434
             (event.xany.type != ButtonPress) &&
351
 
             (event.xany.type != ButtonRelease)))
 
435
             (event.xany.type != ButtonRelease))) {
 
436
 
 
437
            /*
 
438
             * If the event is interesting (and not a keyboard event), turn the
 
439
             * mouse pointer back on.
 
440
             */
 
441
            if (screen->hide_pointer) {
 
442
                switch (event.xany.type) {
 
443
                case KeyPress:
 
444
                case KeyRelease:
 
445
                case ButtonPress:
 
446
                case ButtonRelease:
 
447
                    /* also these... */
 
448
                case Expose:
 
449
                case NoExpose:
 
450
                case PropertyNotify:
 
451
                    break;
 
452
                default:
 
453
                    xtermShowPointer(xw, True);
 
454
                    break;
 
455
                }
 
456
            }
 
457
 
352
458
            XtDispatchEvent(&event);
 
459
        }
353
460
    } while ((input_mask = XtAppPending(app_con)) & XtIMXEvent);
354
461
}
355
462
 
 
463
static Cursor
 
464
make_hidden_cursor(XtermWidget xw)
 
465
{
 
466
    TScreen *screen = TScreenOf(xw);
 
467
    Cursor c;
 
468
    Display *dpy = screen->display;
 
469
    XFontStruct *fn;
 
470
 
 
471
    static XColor dummy;
 
472
 
 
473
    /*
 
474
     * Prefer nil2 (which is normally available) to "fixed" (which is supposed
 
475
     * to be "always" available), since it's a smaller glyph in case the
 
476
     * server insists on drawing _somethng_.
 
477
     */
 
478
    TRACE(("Ask for nil2 font\n"));
 
479
    if ((fn = XLoadQueryFont(dpy, "nil2")) == 0) {
 
480
        TRACE(("...Ask for fixed font\n"));
 
481
        fn = XLoadQueryFont(dpy, "fixed");
 
482
    }
 
483
 
 
484
    if (fn != 0) {
 
485
        /* a space character seems to work as a cursor (dots are not needed) */
 
486
        c = XCreateGlyphCursor(dpy, fn->fid, fn->fid, 'X', ' ', &dummy, &dummy);
 
487
        XFreeFont(dpy, fn);
 
488
    } else {
 
489
        c = 0;
 
490
    }
 
491
    TRACE(("XCreateGlyphCursor ->%#lx\n", c));
 
492
    return (c);
 
493
}
 
494
 
356
495
Cursor
357
496
make_colored_cursor(unsigned cursorindex,       /* index into font */
358
497
                    unsigned long fg,   /* pixel value */
453
592
    pid_t pid;
454
593
 
455
594
    /*
456
 
     * Try to find the actual program which is running in the child process. 
 
595
     * Try to find the actual program which is running in the child process.
457
596
     * This works for Linux.  If we cannot find the program, fall back to the
458
597
     * xterm program (which is usually adequate).  Give up if we are given only
459
598
     * a relative path to xterm, since that would not always match $PATH.
596
735
           event->mode,
597
736
           event->detail));
598
737
 
599
 
    if (event->type == FocusIn) {
 
738
    if (screen->quiet_grab
 
739
        && (event->mode == NotifyGrab || event->mode == NotifyUngrab)) {
 
740
        ;
 
741
    } else if (event->type == FocusIn) {
600
742
        setXUrgency(screen, False);
601
743
 
602
744
        /*
1106
1248
    TScreen *screen = TScreenOf(term);
1107
1249
    XExposeEvent event;
1108
1250
 
 
1251
    TRACE(("Redraw\n"));
 
1252
 
1109
1253
    event.type = Expose;
1110
1254
    event.display = screen->display;
1111
1255
    event.x = 0;
1604
1748
                    for (i = 0; i < cmap_size; i++) {
1605
1749
                        if (!tried[bestInx]) {
1606
1750
                            /*
1607
 
                             * Look for the best match based on luminance. 
 
1751
                             * Look for the best match based on luminance.
1608
1752
                             * Measure this by the least-squares difference of
1609
1753
                             * the weighted R/G/B components from the color map
1610
1754
                             * versus the requested color.  Use the Y (luma)
2718
2862
                        unparseputn(xw, NUM_ANSI_COLORS);
2719
2863
                    } else
2720
2864
#endif
 
2865
#if OPT_TCAP_FKEYS
 
2866
                        /*
 
2867
                         * First ensure that we handle the extended cursor- and
 
2868
                         * editing-keypad keys.
 
2869
                         */
 
2870
                        if ((code <= XK_Fn(MAX_FKEY))
 
2871
                            || xtermcapString(xw, CodeToXkey(code), 0) == 0)
 
2872
#endif
2721
2873
                    {
2722
2874
                        XKeyEvent event;
2723
2875
                        event.state = state;
2772
2924
#if OPT_WIDE_CHARS
2773
2925
    static Char *converted;     /* NO_LEAKS */
2774
2926
#endif
 
2927
    static char empty[1];
 
2928
 
2775
2929
    Arg args[1];
2776
 
    char *original = (value != 0) ? value : "";
 
2930
    char *original = (value != 0) ? value : empty;
2777
2931
    char *name = original;
2778
2932
    TScreen *screen = TScreenOf(term);
2779
2933
    Widget w = CURRENT_EMU();
2854
3008
        Display *dpy = XtDisplay(term);
2855
3009
        Atom my_atom;
2856
3010
 
2857
 
        char *propname = (!strcmp(attribute, XtNtitle)
2858
 
                          ? "_NET_WM_NAME"
2859
 
                          : "_NET_WM_ICON_NAME");
 
3011
        const char *propname = (!strcmp(attribute, XtNtitle)
 
3012
                                ? "_NET_WM_NAME"
 
3013
                                : "_NET_WM_ICON_NAME");
2860
3014
        if ((my_atom = XInternAtom(dpy, propname, False)) != None) {
2861
3015
            if (screen->utf8_title) {   /* FIXME - redundant? */
2862
3016
                TRACE(("...updating %s\n", propname));