… | |
… | |
33 | |
33 | |
34 | #if XFT |
34 | #if XFT |
35 | # include <X11/extensions/Xrender.h> |
35 | # include <X11/extensions/Xrender.h> |
36 | #endif |
36 | #endif |
37 | |
37 | |
38 | const char *const xa_names[] = |
38 | static const char *const xa_names[] = |
39 | { |
39 | { |
40 | "TEXT", |
40 | "TEXT", |
41 | "COMPOUND_TEXT", |
41 | "COMPOUND_TEXT", |
42 | "UTF8_STRING", |
42 | "UTF8_STRING", |
43 | "MULTIPLE", |
43 | "MULTIPLE", |
… | |
… | |
297 | ///////////////////////////////////////////////////////////////////////////// |
297 | ///////////////////////////////////////////////////////////////////////////// |
298 | |
298 | |
299 | rxvt_display::rxvt_display (const char *id) |
299 | rxvt_display::rxvt_display (const char *id) |
300 | : refcounted (id) |
300 | : refcounted (id) |
301 | , selection_owner (0) |
301 | , selection_owner (0) |
|
|
302 | , clipboard_owner (0) |
302 | { |
303 | { |
303 | x_ev .set<rxvt_display, &rxvt_display::x_cb > (this); |
304 | x_ev .set<rxvt_display, &rxvt_display::x_cb > (this); |
304 | flush_ev.set<rxvt_display, &rxvt_display::flush_cb> (this); |
305 | flush_ev.set<rxvt_display, &rxvt_display::flush_cb> (this); |
305 | } |
306 | } |
306 | |
307 | |
… | |
… | |
361 | XA_STRING, &actual_type, &actual_format, |
362 | XA_STRING, &actual_type, &actual_format, |
362 | &nitems, &nremaining, |
363 | &nitems, &nremaining, |
363 | (unsigned char **)&val) == Success |
364 | (unsigned char **)&val) == Success |
364 | && actual_type == XA_STRING |
365 | && actual_type == XA_STRING |
365 | && actual_format == 8) |
366 | && actual_format == 8) |
366 | displayResource = val; |
367 | displayResource = val; |
367 | else |
368 | else |
368 | { |
369 | { |
369 | displayResource = 0; |
370 | displayResource = 0; |
370 | |
371 | |
371 | if (val) |
372 | if (val) |
372 | XFree(val); |
373 | XFree (val); |
373 | } |
374 | } |
374 | |
375 | |
375 | #if XLIB_ILLEGAL_ACCESS |
376 | #if XLIB_ILLEGAL_ACCESS |
376 | dpy->xdefaults = displayResource; |
377 | dpy->xdefaults = displayResource; |
377 | #endif |
378 | #endif |
378 | } |
379 | } |
… | |
… | |
426 | bool rxvt_display::ref_init () |
427 | bool rxvt_display::ref_init () |
427 | { |
428 | { |
428 | #ifdef LOCAL_X_IS_UNIX |
429 | #ifdef LOCAL_X_IS_UNIX |
429 | if (id[0] == ':') |
430 | if (id[0] == ':') |
430 | { |
431 | { |
431 | val = rxvt_malloc (5 + strlen (id) + 1); |
432 | if (!(val = rxvt_temp_buf<char> (5 + strlen (id) + 1))) |
|
|
433 | return false; |
432 | strcpy (val, "unix/"); |
434 | strcpy (val, "unix/"); |
433 | strcat (val, id); |
435 | strcat (val, id); |
434 | dpy = XOpenDisplay (val); |
436 | dpy = XOpenDisplay (val); |
435 | free (val); |
|
|
436 | } |
437 | } |
437 | else |
438 | else |
438 | #endif |
439 | #endif |
439 | dpy = 0; |
440 | dpy = 0; |
440 | |
441 | |
… | |
… | |
445 | return false; |
446 | return false; |
446 | |
447 | |
447 | screen = DefaultScreen (dpy); |
448 | screen = DefaultScreen (dpy); |
448 | root = DefaultRootWindow (dpy); |
449 | root = DefaultRootWindow (dpy); |
449 | |
450 | |
450 | assert (sizeof (xa_names) / sizeof (char *) == NUM_XA); |
451 | assert (ARRAY_LENGTH(xa_names) == NUM_XA); |
451 | XInternAtoms (dpy, (char **)xa_names, NUM_XA, False, xa); |
452 | XInternAtoms (dpy, (char **)xa_names, NUM_XA, False, xa); |
452 | |
453 | |
453 | XrmSetDatabase (dpy, get_resources (false)); |
454 | XrmSetDatabase (dpy, get_resources (false)); |
454 | |
455 | |
455 | #ifdef POINTER_BLANK |
456 | #ifdef POINTER_BLANK |
… | |
… | |
463 | XUnloadFont (dpy, f); |
464 | XUnloadFont (dpy, f); |
464 | #endif |
465 | #endif |
465 | |
466 | |
466 | int fd = XConnectionNumber (dpy); |
467 | int fd = XConnectionNumber (dpy); |
467 | |
468 | |
468 | // try to detect wether we have a local connection. |
469 | // try to detect whether we have a local connection. |
469 | // assume unix domain socket == local, everything else not |
470 | // assume unix domain socket == local, everything else not |
470 | // TODO: might want to check for inet/127.0.0.1 |
471 | // TODO: might want to check for inet/127.0.0.1 |
471 | is_local = 0; |
472 | is_local = 0; |
472 | sockaddr_un sa; |
473 | sockaddr_un sa; |
473 | socklen_t sl = sizeof (sa); |
474 | socklen_t sl = sizeof (sa); |
… | |
… | |
487 | } |
488 | } |
488 | |
489 | |
489 | void |
490 | void |
490 | rxvt_display::ref_next () |
491 | rxvt_display::ref_next () |
491 | { |
492 | { |
492 | // TODO: somehow check wether the database files/resources changed |
493 | // TODO: somehow check whether the database files/resources changed |
493 | // before affording re-loading/parsing |
494 | // before affording re-loading/parsing |
494 | XrmDestroyDatabase (XrmGetDatabase (dpy)); |
495 | XrmDestroyDatabase (XrmGetDatabase (dpy)); |
495 | XrmSetDatabase (dpy, get_resources (true)); |
496 | XrmSetDatabase (dpy, get_resources (true)); |
496 | } |
497 | } |
497 | |
498 | |
… | |
… | |
506 | x_ev.stop (); |
507 | x_ev.stop (); |
507 | flush_ev.stop (); |
508 | flush_ev.stop (); |
508 | #ifdef USE_XIM |
509 | #ifdef USE_XIM |
509 | xims.clear (); |
510 | xims.clear (); |
510 | #endif |
511 | #endif |
|
|
512 | XrmDestroyDatabase (XrmGetDatabase (dpy)); |
511 | XCloseDisplay (dpy); |
513 | XCloseDisplay (dpy); |
512 | } |
514 | } |
513 | |
515 | |
514 | #ifdef USE_XIM |
516 | #ifdef USE_XIM |
515 | void rxvt_display::im_change_cb () |
517 | void rxvt_display::im_change_cb () |
… | |
… | |
527 | unsigned long nitems, bytes_after; |
529 | unsigned long nitems, bytes_after; |
528 | |
530 | |
529 | if (XGetWindowProperty (dpy, root, xa[XA_XIM_SERVERS], 0L, 1000000L, |
531 | if (XGetWindowProperty (dpy, root, xa[XA_XIM_SERVERS], 0L, 1000000L, |
530 | False, XA_ATOM, &actual_type, &actual_format, |
532 | False, XA_ATOM, &actual_type, &actual_format, |
531 | &nitems, &bytes_after, (unsigned char **)&atoms) |
533 | &nitems, &bytes_after, (unsigned char **)&atoms) |
532 | != Success ) |
534 | != Success) |
533 | return; |
535 | return; |
534 | |
536 | |
535 | if (actual_type == XA_ATOM && actual_format == 32) |
537 | if (actual_type == XA_ATOM && actual_format == 32) |
536 | for (int i = 0; i < nitems; i++) |
538 | for (int i = 0; i < nitems; i++) |
537 | if (XGetSelectionOwner (dpy, atoms[i])) |
539 | if (XGetSelectionOwner (dpy, atoms[i])) |
538 | { |
540 | { |
539 | im_change_cb (); |
541 | im_change_cb (); |
540 | break; |
542 | break; |
… | |
… | |
600 | xw[w->active - 1] = 0; |
602 | xw[w->active - 1] = 0; |
601 | w->active = 0; |
603 | w->active = 0; |
602 | } |
604 | } |
603 | } |
605 | } |
604 | |
606 | |
605 | void rxvt_display::set_selection_owner (rxvt_term *owner) |
607 | void rxvt_display::set_selection_owner (rxvt_term *owner, bool clipboard) |
606 | { |
608 | { |
|
|
609 | rxvt_term * &cur_owner = !clipboard ? selection_owner : clipboard_owner; |
|
|
610 | |
607 | if (selection_owner && selection_owner != owner) |
611 | if (cur_owner && cur_owner != owner) |
608 | { |
612 | { |
609 | rxvt_term *owner = selection_owner; |
613 | rxvt_term *term = cur_owner; |
610 | |
|
|
611 | owner->selection_clear (); |
614 | term->selection_clear (clipboard); |
612 | owner->flush (); |
615 | term->flush (); |
613 | } |
616 | } |
614 | |
617 | |
615 | selection_owner = owner; |
618 | cur_owner = owner; |
616 | } |
619 | } |
617 | |
620 | |
618 | #ifdef USE_XIM |
621 | #ifdef USE_XIM |
619 | |
622 | |
620 | void rxvt_display::reg (im_watcher *w) |
623 | void rxvt_display::reg (im_watcher *w) |
… | |
… | |
633 | int l, m; |
636 | int l, m; |
634 | |
637 | |
635 | l = strlen (locale); |
638 | l = strlen (locale); |
636 | m = strlen (modifiers); |
639 | m = strlen (modifiers); |
637 | |
640 | |
638 | if (!(id = (char *)malloc (l + m + 2))) |
641 | if (!(id = rxvt_temp_buf<char> (l + m + 2))) |
639 | return 0; |
642 | return 0; |
640 | |
643 | |
641 | memcpy (id, locale, l); id[l] = '\n'; |
644 | memcpy (id, locale, l); id[l] = '\n'; |
642 | memcpy (id + l + 1, modifiers, m); id[l + m + 1] = 0; |
645 | memcpy (id + l + 1, modifiers, m); id[l + m + 1] = 0; |
643 | |
646 | |
644 | rxvt_xim *xim = xims.get (id); |
647 | rxvt_xim *xim = xims.get (id); |
645 | |
|
|
646 | free (id); |
|
|
647 | |
648 | |
648 | return xim; |
649 | return xim; |
649 | } |
650 | } |
650 | |
651 | |
651 | void rxvt_display::put_xim (rxvt_xim *xim) |
652 | void rxvt_display::put_xim (rxvt_xim *xim) |
… | |
… | |
884 | lerp (c.a, to.a, percent) |
885 | lerp (c.a, to.a, percent) |
885 | ) |
886 | ) |
886 | ); |
887 | ); |
887 | } |
888 | } |
888 | |
889 | |
889 | #if TRACE_PIXMAPS |
|
|
890 | # undef XCreatePixmap |
|
|
891 | # undef XFreePixmap |
|
|
892 | Pixmap trace_XCreatePixmap (const char *file, int line, Display *dpy, Window r, unsigned int w, unsigned int h, unsigned int d) |
|
|
893 | { |
|
|
894 | Pixmap res = XCreatePixmap (dpy, r, w, h, d); |
|
|
895 | fprintf (stderr, "%s:%d: XCreatePixmap (%p,%lX,%u,%u,%u) returned %lX\n", file, line, dpy, r, w, h, d, res); |
|
|
896 | return res; |
|
|
897 | } |
|
|
898 | |
|
|
899 | void trace_XFreePixmap (const char *file, int line, Display *dpy, Pixmap p) |
|
|
900 | { |
|
|
901 | fprintf (stderr, "%s:%d: XFreePixmap (%p,%lX)\n", file, line, dpy, p); |
|
|
902 | XFreePixmap (dpy,p); |
|
|
903 | } |
|
|
904 | #endif |
|
|