1 | /*----------------------------------------------------------------------* |
1 | /*----------------------------------------------------------------------* |
2 | * File: rxvttoolkit.C |
2 | * File: rxvttoolkit.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 2003-2007 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2003-2011 Marc Lehmann <schmorp@schmorp.de> |
7 | * Copyright (c) 2011 Emanuele Giaquinta <e.giaquinta@glauco.it> |
7 | * Copyright (c) 2011 Emanuele Giaquinta <e.giaquinta@glauco.it> |
8 | * |
8 | * |
9 | * This program is free software; you can redistribute it and/or modify |
9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by |
10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or |
11 | * the Free Software Foundation; either version 2 of the License, or |
… | |
… | |
66 | #endif |
66 | #endif |
67 | #if USE_XIM |
67 | #if USE_XIM |
68 | "WM_LOCALE_NAME", |
68 | "WM_LOCALE_NAME", |
69 | "XIM_SERVERS", |
69 | "XIM_SERVERS", |
70 | #endif |
70 | #endif |
71 | #ifdef ENABLE_TRANSPARENCY |
71 | #if ENABLE_TRANSPARENCY |
72 | "_XROOTPMAP_ID", |
72 | "_XROOTPMAP_ID", |
73 | "ESETROOT_PMAP_ID", |
73 | "ESETROOT_PMAP_ID", |
74 | #endif |
74 | #endif |
75 | #if ENABLE_XEMBED |
75 | #if ENABLE_XEMBED |
76 | "_XEMBED", |
76 | "_XEMBED", |
… | |
… | |
153 | put (*this->begin ()); |
153 | put (*this->begin ()); |
154 | } |
154 | } |
155 | |
155 | |
156 | ///////////////////////////////////////////////////////////////////////////// |
156 | ///////////////////////////////////////////////////////////////////////////// |
157 | |
157 | |
158 | #ifdef USE_XIM |
158 | #if USE_XIM |
159 | |
159 | |
160 | static void |
160 | static void |
161 | #if XIMCB_PROTO_BROKEN |
161 | #if XIMCB_PROTO_BROKEN |
162 | im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3) |
162 | im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3) |
163 | #else |
163 | #else |
… | |
… | |
260 | depth = DefaultDepthOfScreen (screen); |
260 | depth = DefaultDepthOfScreen (screen); |
261 | visual = DefaultVisualOfScreen (screen); |
261 | visual = DefaultVisualOfScreen (screen); |
262 | cmap = DefaultColormapOfScreen (screen); |
262 | cmap = DefaultColormapOfScreen (screen); |
263 | } |
263 | } |
264 | |
264 | |
|
|
265 | #if ENABLE_FRILLS |
|
|
266 | |
265 | void |
267 | void |
266 | rxvt_screen::select_visual (int bitdepth) |
268 | rxvt_screen::select_visual (int id) |
267 | { |
269 | { |
268 | #if XFT |
|
|
269 | XVisualInfo vinfo; |
270 | XVisualInfo vinfo; |
|
|
271 | vinfo.visualid = id; |
|
|
272 | int n; |
|
|
273 | |
|
|
274 | if (XVisualInfo *vi = XGetVisualInfo (dpy, VisualIDMask, &vinfo, &n)) |
|
|
275 | { |
|
|
276 | depth = vi->depth; |
|
|
277 | visual = vi->visual; |
|
|
278 | |
|
|
279 | XFree (vi); |
|
|
280 | |
|
|
281 | cmap = XCreateColormap (dpy, display->root, visual, AllocNone); |
|
|
282 | } |
|
|
283 | else |
|
|
284 | rxvt_warn ("cannot requested visual id 0x%02x, using default visual.\n", id); |
|
|
285 | } |
|
|
286 | |
|
|
287 | void |
|
|
288 | rxvt_screen::select_depth (int bitdepth) |
|
|
289 | { |
|
|
290 | XVisualInfo vinfo; |
270 | |
291 | |
271 | if (XMatchVisualInfo (dpy, display->screen, bitdepth, TrueColor, &vinfo)) |
292 | if (XMatchVisualInfo (dpy, display->screen, bitdepth, TrueColor, &vinfo)) |
272 | { |
|
|
273 | depth = bitdepth; |
|
|
274 | visual = vinfo.visual; |
293 | select_visual (vinfo.visualid); |
275 | cmap = XCreateColormap (dpy, display->root, visual, AllocNone); |
294 | else |
276 | } |
295 | rxvt_warn ("no visual found for requested depth %d, using default visual.\n", bitdepth); |
277 | #endif |
|
|
278 | } |
296 | } |
|
|
297 | |
|
|
298 | #endif |
279 | |
299 | |
280 | void |
300 | void |
281 | rxvt_screen::clear () |
301 | rxvt_screen::clear () |
282 | { |
302 | { |
283 | #if XFT |
303 | #if XFT |
… | |
… | |
430 | bool rxvt_display::ref_init () |
450 | bool rxvt_display::ref_init () |
431 | { |
451 | { |
432 | #ifdef LOCAL_X_IS_UNIX |
452 | #ifdef LOCAL_X_IS_UNIX |
433 | if (id[0] == ':') |
453 | if (id[0] == ':') |
434 | { |
454 | { |
435 | if (!(val = rxvt_temp_buf<char> (5 + strlen (id) + 1))) |
455 | char *val = rxvt_temp_buf<char> (5 + strlen (id) + 1); |
436 | return false; |
456 | |
437 | strcpy (val, "unix/"); |
457 | strcpy (val, "unix/"); |
438 | strcat (val, id); |
458 | strcat (val, id); |
|
|
459 | |
439 | dpy = XOpenDisplay (val); |
460 | dpy = XOpenDisplay (val); |
440 | } |
461 | } |
441 | else |
462 | else |
442 | #endif |
463 | #endif |
443 | dpy = 0; |
464 | dpy = 0; |
… | |
… | |
449 | return false; |
470 | return false; |
450 | |
471 | |
451 | screen = DefaultScreen (dpy); |
472 | screen = DefaultScreen (dpy); |
452 | root = DefaultRootWindow (dpy); |
473 | root = DefaultRootWindow (dpy); |
453 | |
474 | |
454 | assert (ARRAY_LENGTH(xa_names) == NUM_XA); |
475 | assert (ecb_array_length (xa_names) == NUM_XA); |
455 | XInternAtoms (dpy, (char **)xa_names, NUM_XA, False, xa); |
476 | XInternAtoms (dpy, (char **)xa_names, NUM_XA, False, xa); |
456 | |
477 | |
457 | XrmSetDatabase (dpy, get_resources (false)); |
478 | XrmSetDatabase (dpy, get_resources (false)); |
458 | |
479 | |
459 | #ifdef POINTER_BLANK |
480 | #ifdef POINTER_BLANK |
… | |
… | |
465 | blank_cursor = XCreateGlyphCursor (dpy, f, f, ' ', ' ', |
486 | blank_cursor = XCreateGlyphCursor (dpy, f, f, ' ', ' ', |
466 | &blackcolour, &blackcolour); |
487 | &blackcolour, &blackcolour); |
467 | XUnloadFont (dpy, f); |
488 | XUnloadFont (dpy, f); |
468 | #endif |
489 | #endif |
469 | |
490 | |
|
|
491 | flags = 0; |
|
|
492 | #if XRENDER |
|
|
493 | int major, minor; |
|
|
494 | if (XRenderQueryVersion (dpy, &major, &minor)) |
|
|
495 | { |
|
|
496 | flags |= DISPLAY_HAS_RENDER; |
|
|
497 | |
|
|
498 | if (major > 0 || (major == 0 && minor >= 10)) |
|
|
499 | flags |= DISPLAY_HAS_RENDER_10; |
|
|
500 | |
|
|
501 | if (major > 0 || (major == 0 && minor >= 11)) |
|
|
502 | flags |= DISPLAY_HAS_RENDER_MUL; |
|
|
503 | |
|
|
504 | XFilters *filters = XRenderQueryFilters (dpy, root); |
|
|
505 | if (filters) |
|
|
506 | { |
|
|
507 | for (int i = 0; i < filters->nfilter; i++) |
|
|
508 | if (!strcmp (filters->filter[i], FilterConvolution)) |
|
|
509 | flags |= DISPLAY_HAS_RENDER_CONV; |
|
|
510 | |
|
|
511 | XFree (filters); |
|
|
512 | } |
|
|
513 | } |
|
|
514 | #endif |
|
|
515 | |
470 | int fd = XConnectionNumber (dpy); |
516 | int fd = XConnectionNumber (dpy); |
471 | |
517 | |
472 | // try to detect whether we have a local connection. |
518 | // try to detect whether we have a local connection. |
473 | // assume unix domain socket == local, everything else not |
519 | // assume unix domain socket == local, everything else not |
474 | // TODO: might want to check for inet/127.0.0.1 |
520 | // TODO: might want to check for inet/127.0.0.1 |
… | |
… | |
511 | #ifdef POINTER_BLANK |
557 | #ifdef POINTER_BLANK |
512 | XFreeCursor (dpy, blank_cursor); |
558 | XFreeCursor (dpy, blank_cursor); |
513 | #endif |
559 | #endif |
514 | x_ev.stop (); |
560 | x_ev.stop (); |
515 | flush_ev.stop (); |
561 | flush_ev.stop (); |
516 | #ifdef USE_XIM |
562 | #if USE_XIM |
517 | xims.clear (); |
563 | xims.clear (); |
518 | #endif |
564 | #endif |
519 | XrmDestroyDatabase (XrmGetDatabase (dpy)); |
565 | XrmDestroyDatabase (XrmGetDatabase (dpy)); |
520 | XCloseDisplay (dpy); |
566 | XCloseDisplay (dpy); |
521 | } |
567 | } |
522 | |
568 | |
523 | #ifdef USE_XIM |
569 | #if USE_XIM |
524 | void rxvt_display::im_change_cb () |
570 | void rxvt_display::im_change_cb () |
525 | { |
571 | { |
526 | for (im_watcher **i = imw.begin (); i != imw.end (); ++i) |
572 | for (im_watcher **i = imw.begin (); i != imw.end (); ++i) |
527 | (*i)->call (); |
573 | (*i)->call (); |
528 | } |
574 | } |
… | |
… | |
564 | do |
610 | do |
565 | { |
611 | { |
566 | XEvent xev; |
612 | XEvent xev; |
567 | XNextEvent (dpy, &xev); |
613 | XNextEvent (dpy, &xev); |
568 | |
614 | |
569 | #ifdef USE_XIM |
615 | #if USE_XIM |
570 | if (!XFilterEvent (&xev, None)) |
616 | if (!XFilterEvent (&xev, None)) |
571 | { |
617 | { |
572 | if (xev.type == PropertyNotify |
618 | if (xev.type == PropertyNotify |
573 | && xev.xany.window == root |
619 | && xev.xany.window == root |
574 | && xev.xproperty.atom == xa[XA_XIM_SERVERS]) |
620 | && xev.xproperty.atom == xa[XA_XIM_SERVERS]) |
… | |
… | |
582 | if (!xw[i]) |
628 | if (!xw[i]) |
583 | xw.erase_unordered (i); |
629 | xw.erase_unordered (i); |
584 | else if (xw[i]->window == xev.xany.window) |
630 | else if (xw[i]->window == xev.xany.window) |
585 | xw[i]->call (xev); |
631 | xw[i]->call (xev); |
586 | } |
632 | } |
587 | #ifdef USE_XIM |
633 | #if USE_XIM |
588 | } |
634 | } |
589 | #endif |
635 | #endif |
590 | } |
636 | } |
591 | while (XEventsQueued (dpy, QueuedAlready)); |
637 | while (XEventsQueued (dpy, QueuedAlready)); |
592 | |
638 | |
… | |
… | |
623 | } |
669 | } |
624 | |
670 | |
625 | cur_owner = owner; |
671 | cur_owner = owner; |
626 | } |
672 | } |
627 | |
673 | |
628 | #ifdef USE_XIM |
674 | #if USE_XIM |
629 | |
675 | |
630 | void rxvt_display::reg (im_watcher *w) |
676 | void rxvt_display::reg (im_watcher *w) |
631 | { |
677 | { |
632 | imw.push_back (w); |
678 | imw.push_back (w); |
633 | } |
679 | } |
… | |
… | |
668 | Atom rxvt_display::atom (const char *name) |
714 | Atom rxvt_display::atom (const char *name) |
669 | { |
715 | { |
670 | return XInternAtom (dpy, name, False); |
716 | return XInternAtom (dpy, name, False); |
671 | } |
717 | } |
672 | |
718 | |
|
|
719 | Pixmap |
|
|
720 | rxvt_display::get_pixmap_property (Atom property) |
|
|
721 | { |
|
|
722 | Pixmap pixmap = None; |
|
|
723 | |
|
|
724 | int aformat; |
|
|
725 | unsigned long nitems, bytes_after; |
|
|
726 | Atom atype; |
|
|
727 | unsigned char *prop; |
|
|
728 | int result = XGetWindowProperty (dpy, root, property, |
|
|
729 | 0L, 1L, False, XA_PIXMAP, &atype, &aformat, |
|
|
730 | &nitems, &bytes_after, &prop); |
|
|
731 | if (result == Success) |
|
|
732 | { |
|
|
733 | if (atype == XA_PIXMAP) |
|
|
734 | pixmap = *(Pixmap *)prop; |
|
|
735 | XFree (prop); |
|
|
736 | } |
|
|
737 | |
|
|
738 | return pixmap; |
|
|
739 | } |
|
|
740 | |
673 | ///////////////////////////////////////////////////////////////////////////// |
741 | ///////////////////////////////////////////////////////////////////////////// |
674 | |
742 | |
675 | template class refcache<rxvt_display>; |
743 | template class refcache<rxvt_display>; |
676 | refcache<rxvt_display> displays; |
744 | refcache<rxvt_display> displays; |
677 | |
745 | |
… | |
… | |
686 | |
754 | |
687 | bool |
755 | bool |
688 | rxvt_color::alloc (rxvt_screen *screen, const rgba &color) |
756 | rxvt_color::alloc (rxvt_screen *screen, const rgba &color) |
689 | { |
757 | { |
690 | //TODO: only supports 24 bit |
758 | //TODO: only supports 24 bit |
691 | int alpha = color.a >= 0xff00 ? 0xffff : color.a; |
759 | unsigned int alpha = color.a >= 0xff00 ? 0xffff : color.a; |
692 | |
760 | |
693 | #if XFT |
761 | #if XFT |
694 | XRenderPictFormat *format; |
762 | XRenderPictFormat *format; |
695 | |
763 | |
696 | // FUCKING Xft gets it wrong, of course, so work around it. |
764 | // FUCKING Xft gets it wrong, of course, so work around it. |
… | |
… | |
703 | c.color.red = color.r; |
771 | c.color.red = color.r; |
704 | c.color.green = color.g; |
772 | c.color.green = color.g; |
705 | c.color.blue = color.b; |
773 | c.color.blue = color.b; |
706 | c.color.alpha = alpha; |
774 | c.color.alpha = alpha; |
707 | |
775 | |
|
|
776 | // Xft wants premultiplied alpha, but abuses the alpha channel |
|
|
777 | // as blend factor, and doesn't allow us to set the alpha channel |
|
|
778 | c.color.red = c.color.red * alpha / 0xffff; |
|
|
779 | c.color.green = c.color.green * alpha / 0xffff; |
|
|
780 | c.color.blue = c.color.blue * alpha / 0xffff; |
|
|
781 | |
708 | c.pixel = insert_component (color.r, format->direct.redMask , format->direct.red ) |
782 | c.pixel = insert_component (c.color.red , format->direct.redMask , format->direct.red ) |
709 | | insert_component (color.g, format->direct.greenMask, format->direct.green) |
783 | | insert_component (c.color.green, format->direct.greenMask, format->direct.green) |
710 | | insert_component (color.b, format->direct.blueMask , format->direct.blue ) |
784 | | insert_component (c.color.blue , format->direct.blueMask , format->direct.blue ) |
711 | | insert_component (alpha , format->direct.alphaMask, format->direct.alpha); |
785 | | insert_component (alpha , format->direct.alphaMask, format->direct.alpha); |
712 | |
786 | |
713 | return true; |
787 | return true; |
714 | } |
788 | } |
715 | else |
789 | else |
716 | { |
790 | { |
… | |
… | |
719 | d.red = color.r; |
793 | d.red = color.r; |
720 | d.green = color.g; |
794 | d.green = color.g; |
721 | d.blue = color.b; |
795 | d.blue = color.b; |
722 | d.alpha = alpha; |
796 | d.alpha = alpha; |
723 | |
797 | |
724 | return XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c); |
798 | if (XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c)) |
|
|
799 | return true; |
725 | } |
800 | } |
726 | #else |
801 | #else |
727 | c.red = color.r; |
802 | c.red = color.r; |
728 | c.green = color.g; |
803 | c.green = color.g; |
729 | c.blue = color.b; |
804 | c.blue = color.b; |
730 | |
805 | |
731 | if (screen->visual->c_class == TrueColor) |
806 | if (screen->visual->c_class == TrueColor) |
732 | { |
807 | { |
733 | c.pixel = (color.r >> (16 - rxvt_popcount (screen->visual->red_mask )) << rxvt_ctz (screen->visual->red_mask )) |
808 | c.pixel = (color.r >> (16 - ecb_popcount32 (screen->visual->red_mask )) << ecb_ctz32 (screen->visual->red_mask )) |
734 | | (color.g >> (16 - rxvt_popcount (screen->visual->green_mask)) << rxvt_ctz (screen->visual->green_mask)) |
809 | | (color.g >> (16 - ecb_popcount32 (screen->visual->green_mask)) << ecb_ctz32 (screen->visual->green_mask)) |
735 | | (color.b >> (16 - rxvt_popcount (screen->visual->blue_mask )) << rxvt_ctz (screen->visual->blue_mask )); |
810 | | (color.b >> (16 - ecb_popcount32 (screen->visual->blue_mask )) << ecb_ctz32 (screen->visual->blue_mask )); |
736 | |
811 | |
737 | return true; |
812 | return true; |
738 | } |
813 | } |
739 | else if (XAllocColor (screen->dpy, screen->cmap, &c)) |
814 | else if (XAllocColor (screen->dpy, screen->cmap, &c)) |
740 | return true; |
815 | return true; |
741 | else |
816 | #endif |
|
|
817 | |
742 | c.pixel = (color.r + color.g + color.b) > 128*3 |
818 | c.pixel = (color.r + color.g + color.b) > 128*3 |
743 | ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy)) |
819 | ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy)) |
744 | : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy)); |
820 | : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy)); |
745 | #endif |
|
|
746 | |
821 | |
747 | return false; |
822 | return false; |
748 | } |
823 | } |
749 | |
824 | |
750 | bool |
825 | bool |
… | |
… | |
835 | |
910 | |
836 | return got; |
911 | return got; |
837 | } |
912 | } |
838 | |
913 | |
839 | void |
914 | void |
840 | rxvt_color::get (rgba &color) |
915 | rxvt_color::get (rgba &color) const |
841 | { |
916 | { |
842 | #if XFT |
917 | #if XFT |
843 | color.r = c.color.red; |
918 | color.r = c.color.red; |
844 | color.g = c.color.green; |
919 | color.g = c.color.green; |
845 | color.b = c.color.blue; |
920 | color.b = c.color.blue; |
… | |
… | |
851 | color.a = rgba::MAX_CC; |
926 | color.a = rgba::MAX_CC; |
852 | #endif |
927 | #endif |
853 | } |
928 | } |
854 | |
929 | |
855 | void |
930 | void |
856 | rxvt_color::get (XColor &color) |
931 | rxvt_color::get (XColor &color) const |
857 | { |
932 | { |
858 | rgba c; |
933 | rgba c; |
859 | get (c); |
934 | get (c); |
860 | |
935 | |
861 | color.red = c.r; |
936 | color.red = c.r; |
… | |
… | |
892 | lerp (c.a, to.a, percent) |
967 | lerp (c.a, to.a, percent) |
893 | ) |
968 | ) |
894 | ); |
969 | ); |
895 | } |
970 | } |
896 | |
971 | |
897 | rxvt_selection::rxvt_selection (rxvt_display *disp, int selnum, Time tm, Window win, Atom prop, sel_cb cb, void *ptr) |
972 | rxvt_selection::rxvt_selection (rxvt_display *disp, int selnum, Time tm, Window win, Atom prop, rxvt_term *term) |
898 | : display (disp), request_time (tm), request_win (win), request_prop (prop), request_cb (cb), user_data (ptr) |
973 | : display (disp), request_time (tm), request_win (win), request_prop (prop), term (term) |
899 | { |
974 | { |
900 | assert (selnum >= Sel_Primary && selnum <= Sel_Clipboard); |
975 | assert (selnum >= Sel_Primary && selnum <= Sel_Clipboard); |
901 | |
976 | |
902 | timer_ev.set<rxvt_selection, &rxvt_selection::timer_cb> (this); |
977 | timer_ev.set<rxvt_selection, &rxvt_selection::timer_cb> (this); |
903 | timer_ev.repeat = 10.; |
978 | timer_ev.repeat = 10.; |
… | |
… | |
905 | |
980 | |
906 | incr_buf = 0; |
981 | incr_buf = 0; |
907 | incr_buf_size = incr_buf_fill = 0; |
982 | incr_buf_size = incr_buf_fill = 0; |
908 | selection_wait = Sel_normal; |
983 | selection_wait = Sel_normal; |
909 | selection_type = selnum; |
984 | selection_type = selnum; |
|
|
985 | cb_sv = 0; |
|
|
986 | } |
|
|
987 | |
|
|
988 | void |
|
|
989 | rxvt_selection::stop () |
|
|
990 | { |
|
|
991 | free (incr_buf); |
|
|
992 | incr_buf = 0; |
|
|
993 | timer_ev.stop (); |
|
|
994 | x_ev.stop (display); |
|
|
995 | } |
|
|
996 | |
|
|
997 | rxvt_selection::~rxvt_selection () |
|
|
998 | { |
|
|
999 | stop (); |
910 | } |
1000 | } |
911 | |
1001 | |
912 | void |
1002 | void |
913 | rxvt_selection::run () |
1003 | rxvt_selection::run () |
914 | { |
1004 | { |
915 | int selnum = selection_type; |
1005 | int selnum = selection_type; |
|
|
1006 | |
|
|
1007 | #if ENABLE_FRILLS |
|
|
1008 | if (selnum == Sel_Primary && display->selection_owner) |
|
|
1009 | { |
|
|
1010 | /* internal selection */ |
|
|
1011 | char *str = rxvt_wcstombs (display->selection_owner->selection.text, display->selection_owner->selection.len); |
|
|
1012 | finish (str, strlen (str)); |
|
|
1013 | free (str); |
|
|
1014 | return; |
|
|
1015 | } |
|
|
1016 | #endif |
916 | |
1017 | |
917 | #if X_HAVE_UTF8_STRING |
1018 | #if X_HAVE_UTF8_STRING |
918 | selection_type = Sel_UTF8String; |
1019 | selection_type = Sel_UTF8String; |
919 | if (request (display->xa[XA_UTF8_STRING], selnum)) |
1020 | if (request (display->xa[XA_UTF8_STRING], selnum)) |
920 | return; |
1021 | return; |
… | |
… | |
926 | |
1027 | |
927 | // fallback to CUT_BUFFER0 if the requested property has no owner |
1028 | // fallback to CUT_BUFFER0 if the requested property has no owner |
928 | handle_selection (display->root, XA_CUT_BUFFER0, false); |
1029 | handle_selection (display->root, XA_CUT_BUFFER0, false); |
929 | } |
1030 | } |
930 | |
1031 | |
931 | rxvt_selection::~rxvt_selection () |
|
|
932 | { |
|
|
933 | stop (); |
|
|
934 | } |
|
|
935 | |
|
|
936 | void |
1032 | void |
937 | rxvt_selection::stop () |
1033 | rxvt_selection::finish (char *data, unsigned int len) |
938 | { |
1034 | { |
939 | free (incr_buf); |
1035 | if (!cb_sv) |
940 | incr_buf = 0; |
1036 | { |
941 | timer_ev.stop (); |
1037 | if (data) |
942 | x_ev.stop (display); |
1038 | term->paste (data, len); |
|
|
1039 | |
|
|
1040 | term->selection_req = 0; |
|
|
1041 | delete this; |
|
|
1042 | } |
|
|
1043 | #if ENABLE_PERL |
|
|
1044 | else |
|
|
1045 | { |
|
|
1046 | stop (); // we do not really trust perl callbacks |
|
|
1047 | rxvt_perl.selection_finish (this, data, len); |
|
|
1048 | } |
|
|
1049 | #endif |
943 | } |
1050 | } |
944 | |
1051 | |
945 | bool |
1052 | bool |
946 | rxvt_selection::request (Atom target, int selnum) |
1053 | rxvt_selection::request (Atom target, int selnum) |
947 | { |
1054 | { |
… | |
… | |
1112 | bailout: |
1219 | bailout: |
1113 | XFree (ct.value); |
1220 | XFree (ct.value); |
1114 | |
1221 | |
1115 | if (selection_wait == Sel_normal) |
1222 | if (selection_wait == Sel_normal) |
1116 | { |
1223 | { |
1117 | stop (); |
1224 | finish (data, data_len); |
1118 | request_cb (data, data_len, this); |
|
|
1119 | free (data); |
1225 | free (data); |
1120 | } |
1226 | } |
1121 | } |
1227 | } |
1122 | |
1228 | |
1123 | void |
1229 | void |
1124 | rxvt_selection::timer_cb (ev::timer &w, int revents) |
1230 | rxvt_selection::timer_cb (ev::timer &w, int revents) |
1125 | { |
1231 | { |
1126 | if (selection_wait == Sel_incr) |
1232 | if (selection_wait == Sel_incr) |
1127 | rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); |
1233 | rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); |
1128 | |
1234 | |
1129 | stop (); |
1235 | finish (); |
1130 | request_cb (NULL, 0, this); |
|
|
1131 | } |
1236 | } |
1132 | |
1237 | |
1133 | void |
1238 | void |
1134 | rxvt_selection::x_cb (XEvent &xev) |
1239 | rxvt_selection::x_cb (XEvent &xev) |
1135 | { |
1240 | { |
… | |
… | |
1142 | handle_selection (xev.xproperty.window, xev.xproperty.atom, true); |
1247 | handle_selection (xev.xproperty.window, xev.xproperty.atom, true); |
1143 | break; |
1248 | break; |
1144 | |
1249 | |
1145 | case SelectionNotify: |
1250 | case SelectionNotify: |
1146 | if (selection_wait == Sel_normal |
1251 | if (selection_wait == Sel_normal |
1147 | && xev.xselection.time == request_time |
1252 | && xev.xselection.time == request_time) |
1148 | && xev.xselection.property == request_prop) |
|
|
1149 | { |
1253 | { |
1150 | timer_ev.stop (); |
1254 | timer_ev.stop (); |
1151 | handle_selection (xev.xselection.requestor, xev.xselection.property, true); |
1255 | handle_selection (xev.xselection.requestor, xev.xselection.property, true); |
1152 | } |
1256 | } |
1153 | break; |
1257 | break; |