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.118 by sf-exg, Sat Feb 12 00:50:04 2011 UTC vs.
Revision 1.130 by sf-exg, Fri Jan 13 12:40:53 2012 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
686 686
687bool 687bool
688rxvt_color::alloc (rxvt_screen *screen, const rgba &color) 688rxvt_color::alloc (rxvt_screen *screen, const rgba &color)
689{ 689{
690 //TODO: only supports 24 bit 690 //TODO: only supports 24 bit
691 int alpha = color.a >= 0xff00 ? 0xffff : color.a; 691 unsigned int alpha = color.a >= 0xff00 ? 0xffff : color.a;
692 692
693#if XFT 693#if XFT
694 XRenderPictFormat *format; 694 XRenderPictFormat *format;
695 695
696 // FUCKING Xft gets it wrong, of course, so work around it. 696 // FUCKING Xft gets it wrong, of course, so work around it.
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 {
719 d.red = color.r; 725 d.red = color.r;
720 d.green = color.g; 726 d.green = color.g;
721 d.blue = color.b; 727 d.blue = color.b;
722 d.alpha = alpha; 728 d.alpha = alpha;
723 729
724 return XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c); 730 if (XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c))
731 return true;
725 } 732 }
726#else 733#else
727 c.red = color.r; 734 c.red = color.r;
728 c.green = color.g; 735 c.green = color.g;
729 c.blue = color.b; 736 c.blue = color.b;
730 737
731 if (screen->visual->c_class == TrueColor) 738 if (screen->visual->c_class == TrueColor)
732 { 739 {
733 c.pixel = (color.r >> (16 - rxvt_popcount (screen->visual->red_mask )) << rxvt_ctz (screen->visual->red_mask )) 740 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)) 741 | (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 )); 742 | (color.b >> (16 - ecb_popcount32 (screen->visual->blue_mask )) << ecb_ctz32 (screen->visual->blue_mask ));
736 743
737 return true; 744 return true;
738 } 745 }
739 else if (XAllocColor (screen->dpy, screen->cmap, &c)) 746 else if (XAllocColor (screen->dpy, screen->cmap, &c))
740 return true; 747 return true;
741 else 748#endif
749
742 c.pixel = (color.r + color.g + color.b) > 128*3 750 c.pixel = (color.r + color.g + color.b) > 128*3
743 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy)) 751 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy))
744 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy)); 752 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy));
745#endif
746 753
747 return false; 754 return false;
748} 755}
749 756
750bool 757bool
892 lerp (c.a, to.a, percent) 899 lerp (c.a, to.a, percent)
893 ) 900 )
894 ); 901 );
895} 902}
896 903
897rxvt_selection::rxvt_selection (rxvt_display *disp, int selnum, Time tm, Window win, Atom prop, sel_cb cb, void *ptr) 904rxvt_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) 905: display (disp), request_time (tm), request_win (win), request_prop (prop), term (term)
899{ 906{
900 assert (selnum >= Sel_Primary && selnum <= Sel_Clipboard); 907 assert (selnum >= Sel_Primary && selnum <= Sel_Clipboard);
901 908
902 timer_ev.set<rxvt_selection, &rxvt_selection::timer_cb> (this); 909 timer_ev.set<rxvt_selection, &rxvt_selection::timer_cb> (this);
903 timer_ev.repeat = 10.; 910 timer_ev.repeat = 10.;
905 912
906 incr_buf = 0; 913 incr_buf = 0;
907 incr_buf_size = incr_buf_fill = 0; 914 incr_buf_size = incr_buf_fill = 0;
908 selection_wait = Sel_normal; 915 selection_wait = Sel_normal;
909 selection_type = selnum; 916 selection_type = selnum;
917 cb_sv = 0;
918}
919
920void
921rxvt_selection::stop ()
922{
923 free (incr_buf);
924 incr_buf = 0;
925 timer_ev.stop ();
926 x_ev.stop (display);
927}
928
929rxvt_selection::~rxvt_selection ()
930{
931 stop ();
910} 932}
911 933
912void 934void
913rxvt_selection::run () 935rxvt_selection::run ()
914{ 936{
915 int selnum = selection_type; 937 int selnum = selection_type;
938
939#if ENABLE_FRILLS
940 if (selnum == Sel_Primary && display->selection_owner)
941 {
942 /* internal selection */
943 char *str = rxvt_wcstombs (display->selection_owner->selection.text, display->selection_owner->selection.len);
944 finish (str, strlen (str));
945 free (str);
946 return;
947 }
948#endif
916 949
917#if X_HAVE_UTF8_STRING 950#if X_HAVE_UTF8_STRING
918 selection_type = Sel_UTF8String; 951 selection_type = Sel_UTF8String;
919 if (request (display->xa[XA_UTF8_STRING], selnum)) 952 if (request (display->xa[XA_UTF8_STRING], selnum))
920 return; 953 return;
926 959
927 // fallback to CUT_BUFFER0 if the requested property has no owner 960 // fallback to CUT_BUFFER0 if the requested property has no owner
928 handle_selection (display->root, XA_CUT_BUFFER0, false); 961 handle_selection (display->root, XA_CUT_BUFFER0, false);
929} 962}
930 963
931rxvt_selection::~rxvt_selection ()
932{
933 stop ();
934}
935
936void 964void
937rxvt_selection::stop () 965rxvt_selection::finish (char *data, unsigned int len)
938{ 966{
939 free (incr_buf); 967 if (!cb_sv)
940 incr_buf = 0; 968 {
941 timer_ev.stop (); 969 if (data)
942 x_ev.stop (display); 970 term->paste (data, len);
971
972 term->selection_req = 0;
973 delete this;
974 }
975#if ENABLE_PERL
976 else
977 {
978 stop (); // we do not really trust perl callbacks
979 rxvt_perl.selection_finish (this, data, len);
980 }
981#endif
943} 982}
944 983
945bool 984bool
946rxvt_selection::request (Atom target, int selnum) 985rxvt_selection::request (Atom target, int selnum)
947{ 986{
1112bailout: 1151bailout:
1113 XFree (ct.value); 1152 XFree (ct.value);
1114 1153
1115 if (selection_wait == Sel_normal) 1154 if (selection_wait == Sel_normal)
1116 { 1155 {
1117 stop (); 1156 finish (data, data_len);
1118 request_cb (data, data_len, this);
1119 free (data); 1157 free (data);
1120 } 1158 }
1121} 1159}
1122 1160
1123void 1161void
1124rxvt_selection::timer_cb (ev::timer &w, int revents) 1162rxvt_selection::timer_cb (ev::timer &w, int revents)
1125{ 1163{
1126 if (selection_wait == Sel_incr) 1164 if (selection_wait == Sel_incr)
1127 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n"); 1165 rxvt_warn ("data loss: timeout on INCR selection paste, ignoring.\n");
1128 1166
1129 stop (); 1167 finish ();
1130 request_cb (NULL, 0, this);
1131} 1168}
1132 1169
1133void 1170void
1134rxvt_selection::x_cb (XEvent &xev) 1171rxvt_selection::x_cb (XEvent &xev)
1135{ 1172{
1142 handle_selection (xev.xproperty.window, xev.xproperty.atom, true); 1179 handle_selection (xev.xproperty.window, xev.xproperty.atom, true);
1143 break; 1180 break;
1144 1181
1145 case SelectionNotify: 1182 case SelectionNotify:
1146 if (selection_wait == Sel_normal 1183 if (selection_wait == Sel_normal
1147 && xev.xselection.time == request_time 1184 && xev.xselection.time == request_time)
1148 && xev.xselection.property == request_prop)
1149 { 1185 {
1150 timer_ev.stop (); 1186 timer_ev.stop ();
1151 handle_selection (xev.xselection.requestor, xev.xselection.property, true); 1187 handle_selection (xev.xselection.requestor, xev.xselection.property, true);
1152 } 1188 }
1153 break; 1189 break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines