… | |
… | |
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 | |
… | |
… | |
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 | |
… | |
… | |
527 | unsigned long nitems, bytes_after; |
528 | unsigned long nitems, bytes_after; |
528 | |
529 | |
529 | if (XGetWindowProperty (dpy, root, xa[XA_XIM_SERVERS], 0L, 1000000L, |
530 | if (XGetWindowProperty (dpy, root, xa[XA_XIM_SERVERS], 0L, 1000000L, |
530 | False, XA_ATOM, &actual_type, &actual_format, |
531 | False, XA_ATOM, &actual_type, &actual_format, |
531 | &nitems, &bytes_after, (unsigned char **)&atoms) |
532 | &nitems, &bytes_after, (unsigned char **)&atoms) |
532 | != Success ) |
533 | != Success) |
533 | return; |
534 | return; |
534 | |
535 | |
535 | if (actual_type == XA_ATOM && actual_format == 32) |
536 | if (actual_type == XA_ATOM && actual_format == 32) |
536 | for (int i = 0; i < nitems; i++) |
537 | for (int i = 0; i < nitems; i++) |
537 | if (XGetSelectionOwner (dpy, atoms[i])) |
538 | if (XGetSelectionOwner (dpy, atoms[i])) |
538 | { |
539 | { |
539 | im_change_cb (); |
540 | im_change_cb (); |
540 | break; |
541 | break; |
… | |
… | |
600 | xw[w->active - 1] = 0; |
601 | xw[w->active - 1] = 0; |
601 | w->active = 0; |
602 | w->active = 0; |
602 | } |
603 | } |
603 | } |
604 | } |
604 | |
605 | |
605 | void rxvt_display::set_selection_owner (rxvt_term *owner) |
606 | void rxvt_display::set_selection_owner (rxvt_term *owner, bool clipboard) |
606 | { |
607 | { |
|
|
608 | rxvt_term * &cur_owner = !clipboard ? selection_owner : clipboard_owner; |
|
|
609 | |
607 | if (selection_owner && selection_owner != owner) |
610 | if (cur_owner && cur_owner != owner) |
608 | { |
611 | { |
609 | rxvt_term *owner = selection_owner; |
612 | rxvt_term *term = cur_owner; |
610 | |
|
|
611 | owner->selection_clear (); |
613 | term->selection_clear (clipboard); |
612 | owner->flush (); |
614 | term->flush (); |
613 | } |
615 | } |
614 | |
616 | |
615 | selection_owner = owner; |
617 | cur_owner = owner; |
616 | } |
618 | } |
617 | |
619 | |
618 | #ifdef USE_XIM |
620 | #ifdef USE_XIM |
619 | |
621 | |
620 | void rxvt_display::reg (im_watcher *w) |
622 | void rxvt_display::reg (im_watcher *w) |
… | |
… | |
633 | int l, m; |
635 | int l, m; |
634 | |
636 | |
635 | l = strlen (locale); |
637 | l = strlen (locale); |
636 | m = strlen (modifiers); |
638 | m = strlen (modifiers); |
637 | |
639 | |
638 | if (!(id = (char *)malloc (l + m + 2))) |
640 | if (!(id = rxvt_temp_buf<char> (l + m + 2))) |
639 | return 0; |
641 | return 0; |
640 | |
642 | |
641 | memcpy (id, locale, l); id[l] = '\n'; |
643 | memcpy (id, locale, l); id[l] = '\n'; |
642 | memcpy (id + l + 1, modifiers, m); id[l + m + 1] = 0; |
644 | memcpy (id + l + 1, modifiers, m); id[l + m + 1] = 0; |
643 | |
645 | |
644 | rxvt_xim *xim = xims.get (id); |
646 | rxvt_xim *xim = xims.get (id); |
645 | |
|
|
646 | free (id); |
|
|
647 | |
647 | |
648 | return xim; |
648 | return xim; |
649 | } |
649 | } |
650 | |
650 | |
651 | void rxvt_display::put_xim (rxvt_xim *xim) |
651 | void rxvt_display::put_xim (rxvt_xim *xim) |
… | |
… | |
884 | lerp (c.a, to.a, percent) |
884 | lerp (c.a, to.a, percent) |
885 | ) |
885 | ) |
886 | ); |
886 | ); |
887 | } |
887 | } |
888 | |
888 | |
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 |
|
|