ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvttoolkit.C
(Generate patch)

Comparing rxvt-unicode/src/rxvttoolkit.C (file contents):
Revision 1.116 by sf-exg, Fri Feb 11 11:26:30 2011 UTC vs.
Revision 1.128 by sf-exg, Fri Jul 1 19:06:51 2011 UTC

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
449 return false; 449 return false;
450 450
451 screen = DefaultScreen (dpy); 451 screen = DefaultScreen (dpy);
452 root = DefaultRootWindow (dpy); 452 root = DefaultRootWindow (dpy);
453 453
454 assert (ARRAY_LENGTH(xa_names) == NUM_XA); 454 assert (ecb_array_length (xa_names) == NUM_XA);
455 XInternAtoms (dpy, (char **)xa_names, NUM_XA, False, xa); 455 XInternAtoms (dpy, (char **)xa_names, NUM_XA, False, xa);
456 456
457 XrmSetDatabase (dpy, get_resources (false)); 457 XrmSetDatabase (dpy, get_resources (false));
458 458
459#ifdef POINTER_BLANK 459#ifdef POINTER_BLANK
703 c.color.red = color.r; 703 c.color.red = color.r;
704 c.color.green = color.g; 704 c.color.green = color.g;
705 c.color.blue = color.b; 705 c.color.blue = color.b;
706 c.color.alpha = alpha; 706 c.color.alpha = alpha;
707 707
708 // Xft wants premultiplied alpha, but abuses the alpha channel
709 // as blend factor, and doesn't allow us to set the alpha channel
710 c.color.red = c.color.red * alpha / 0xffff;
711 c.color.green = c.color.green * alpha / 0xffff;
712 c.color.blue = c.color.blue * alpha / 0xffff;
713
708 c.pixel = insert_component (color.r, format->direct.redMask , format->direct.red ) 714 c.pixel = insert_component (c.color.red , format->direct.redMask , format->direct.red )
709 | insert_component (color.g, format->direct.greenMask, format->direct.green) 715 | insert_component (c.color.green, format->direct.greenMask, format->direct.green)
710 | insert_component (color.b, format->direct.blueMask , format->direct.blue ) 716 | insert_component (c.color.blue , format->direct.blueMask , format->direct.blue )
711 | insert_component (alpha , format->direct.alphaMask, format->direct.alpha); 717 | insert_component (alpha , format->direct.alphaMask, format->direct.alpha);
712 718
713 return true; 719 return true;
714 } 720 }
715 else 721 else
716 { 722 {
728 c.green = color.g; 734 c.green = color.g;
729 c.blue = color.b; 735 c.blue = color.b;
730 736
731 if (screen->visual->c_class == TrueColor) 737 if (screen->visual->c_class == TrueColor)
732 { 738 {
733 c.pixel = (color.r >> (16 - rxvt_popcount (screen->visual->red_mask )) << rxvt_ctz (screen->visual->red_mask )) 739 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)) 740 | (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 )); 741 | (color.b >> (16 - ecb_popcount32 (screen->visual->blue_mask )) << ecb_ctz32 (screen->visual->blue_mask ));
736 742
737 return true; 743 return true;
738 } 744 }
739 else if (XAllocColor (screen->dpy, screen->cmap, &c)) 745 else if (XAllocColor (screen->dpy, screen->cmap, &c))
740 return true; 746 return true;
892 lerp (c.a, to.a, percent) 898 lerp (c.a, to.a, percent)
893 ) 899 )
894 ); 900 );
895} 901}
896 902
897rxvt_selection::rxvt_selection (rxvt_display *disp, int selnum, Time tm, Window win, Atom prop, sel_cb cb, void *ptr) 903rxvt_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) 904: display (disp), request_time (tm), request_win (win), request_prop (prop), term (term)
899{ 905{
900 assert (selnum >= Sel_Primary && selnum <= Sel_Clipboard); 906 assert (selnum >= Sel_Primary && selnum <= Sel_Clipboard);
901 907
902 timer_ev.set<rxvt_selection, &rxvt_selection::timer_cb> (this); 908 timer_ev.set<rxvt_selection, &rxvt_selection::timer_cb> (this);
903 timer_ev.repeat = 10.; 909 timer_ev.repeat = 10.;
904 x_ev.set<rxvt_selection, &rxvt_selection::x_cb> (this); 910 x_ev.set<rxvt_selection, &rxvt_selection::x_cb> (this);
905 911
906 incr_buf = 0; 912 incr_buf = 0;
907 incr_buf_size = incr_buf_fill = 0; 913 incr_buf_size = incr_buf_fill = 0;
908 selection_wait = Sel_normal; 914 selection_wait = Sel_normal;
915 selection_type = selnum;
916 cb_sv = 0;
917}
918
919void
920rxvt_selection::stop ()
921{
922 free (incr_buf);
923 incr_buf = 0;
924 timer_ev.stop ();
925 x_ev.stop (display);
926}
927
928rxvt_selection::~rxvt_selection ()
929{
930 stop ();
931}
932
933void
934rxvt_selection::run ()
935{
936 int selnum = selection_type;
937
938#if ENABLE_FRILLS
939 if (selnum == Sel_Primary && display->selection_owner)
940 {
941 /* internal selection */
942 char *str = rxvt_wcstombs (display->selection_owner->selection.text, display->selection_owner->selection.len);
943 finish (str, strlen (str));
944 free (str);
945 return;
946 }
947#endif
909 948
910#if X_HAVE_UTF8_STRING 949#if X_HAVE_UTF8_STRING
911 selection_type = Sel_UTF8String; 950 selection_type = Sel_UTF8String;
912 if (request (display->xa[XA_UTF8_STRING], selnum)) 951 if (request (display->xa[XA_UTF8_STRING], selnum))
913 return; 952 return;
919 958
920 // fallback to CUT_BUFFER0 if the requested property has no owner 959 // fallback to CUT_BUFFER0 if the requested property has no owner
921 handle_selection (display->root, XA_CUT_BUFFER0, false); 960 handle_selection (display->root, XA_CUT_BUFFER0, false);
922} 961}
923 962
924rxvt_selection::~rxvt_selection ()
925{
926 stop ();
927}
928
929void 963void
930rxvt_selection::stop () 964rxvt_selection::finish (char *data, unsigned int len)
931{ 965{
932 free (incr_buf); 966 if (!cb_sv)
933 incr_buf = 0; 967 {
934 timer_ev.stop (); 968 if (data)
935 x_ev.stop (display); 969 term->paste (data, len);
970
971 term->selection_req = 0;
972 delete this;
973 }
974#if ENABLE_PERL
975 else
976 {
977 stop (); // we do not really trust perl callbacks
978 rxvt_perl.selection_finish (this, data, len);
979 }
980#endif
936} 981}
937 982
938bool 983bool
939rxvt_selection::request (Atom target, int selnum) 984rxvt_selection::request (Atom target, int selnum)
940{ 985{
1105bailout: 1150bailout:
1106 XFree (ct.value); 1151 XFree (ct.value);
1107 1152
1108 if (selection_wait == Sel_normal) 1153 if (selection_wait == Sel_normal)
1109 { 1154 {
1110 stop (); 1155 finish (data, data_len);
1111 request_cb (data, data_len, this, user_data);
1112 free (data); 1156 free (data);
1113 } 1157 }
1114} 1158}
1115 1159
1116void 1160void
1117rxvt_selection::timer_cb (ev::timer &w, int revents) 1161rxvt_selection::timer_cb (ev::timer &w, int revents)
1118{ 1162{
1119 if (selection_wait == Sel_incr) 1163 if (selection_wait == Sel_incr)
1120 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); 1164 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n");
1121 1165
1122 stop (); 1166 finish ();
1123 request_cb (NULL, 0, this, user_data);
1124} 1167}
1125 1168
1126void 1169void
1127rxvt_selection::x_cb (XEvent &xev) 1170rxvt_selection::x_cb (XEvent &xev)
1128{ 1171{
1135 handle_selection (xev.xproperty.window, xev.xproperty.atom, true); 1178 handle_selection (xev.xproperty.window, xev.xproperty.atom, true);
1136 break; 1179 break;
1137 1180
1138 case SelectionNotify: 1181 case SelectionNotify:
1139 if (selection_wait == Sel_normal 1182 if (selection_wait == Sel_normal
1140 && xev.xselection.time == request_time 1183 && xev.xselection.time == request_time)
1141 && xev.xselection.property == request_prop)
1142 { 1184 {
1143 timer_ev.stop (); 1185 timer_ev.stop ();
1144 handle_selection (xev.xselection.requestor, xev.xselection.property, true); 1186 handle_selection (xev.xselection.requestor, xev.xselection.property, true);
1145 } 1187 }
1146 break; 1188 break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines