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.120 by root, Mon Feb 21 07:18:19 2011 UTC vs.
Revision 1.137 by root, Thu Jun 7 16:04:31 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
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
160static void 160static void
161#if XIMCB_PROTO_BROKEN 161#if XIMCB_PROTO_BROKEN
162im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3) 162im_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
265void 267void
266rxvt_screen::select_visual (int bitdepth) 268rxvt_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
287void
288rxvt_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
280void 300void
281rxvt_screen::clear () 301rxvt_screen::clear ()
282{ 302{
283#if XFT 303#if XFT
430bool rxvt_display::ref_init () 450bool 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
524void rxvt_display::im_change_cb () 570void 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
630void rxvt_display::reg (im_watcher *w) 676void rxvt_display::reg (im_watcher *w)
631{ 677{
632 imw.push_back (w); 678 imw.push_back (w);
633} 679}
668Atom rxvt_display::atom (const char *name) 714Atom rxvt_display::atom (const char *name)
669{ 715{
670 return XInternAtom (dpy, name, False); 716 return XInternAtom (dpy, name, False);
671} 717}
672 718
719Pixmap
720rxvt_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
675template class refcache<rxvt_display>; 743template class refcache<rxvt_display>;
676refcache<rxvt_display> displays; 744refcache<rxvt_display> displays;
677 745
686 754
687bool 755bool
688rxvt_color::alloc (rxvt_screen *screen, const rgba &color) 756rxvt_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
750bool 825bool
835 910
836 return got; 911 return got;
837} 912}
838 913
839void 914void
840rxvt_color::get (rgba &color) 915rxvt_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
855void 930void
856rxvt_color::get (XColor &color) 931rxvt_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
897rxvt_selection::rxvt_selection (rxvt_display *disp, int selnum, Time tm, Window win, Atom prop, rxvt_term *term, void *cb_sv) 972rxvt_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), term (term), cb_sv (cb_sv) 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;
910} 986}
911 987
912void 988void
913rxvt_selection::stop () 989rxvt_selection::stop ()
914{ 990{
925 1001
926void 1002void
927rxvt_selection::run () 1003rxvt_selection::run ()
928{ 1004{
929 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
930 1017
931#if X_HAVE_UTF8_STRING 1018#if X_HAVE_UTF8_STRING
932 selection_type = Sel_UTF8String; 1019 selection_type = Sel_UTF8String;
933 if (request (display->xa[XA_UTF8_STRING], selnum)) 1020 if (request (display->xa[XA_UTF8_STRING], selnum))
934 return; 1021 return;
943} 1030}
944 1031
945void 1032void
946rxvt_selection::finish (char *data, unsigned int len) 1033rxvt_selection::finish (char *data, unsigned int len)
947{ 1034{
948 if (term) 1035 if (!cb_sv)
949 { 1036 {
950 if (data) 1037 if (data)
951 term->paste (data, len); 1038 term->paste (data, len);
952 1039
953 term->selection_req = 0; 1040 term->selection_req = 0;
954 delete this; 1041 delete this;
955 } 1042 }
956#if ENABLE_PERL 1043#if ENABLE_PERL
957 else 1044 else
958 { 1045 {
959 stop (); 1046 stop (); // we do not really trust perl callbacks
960 abort (); //TODO 1047 rxvt_perl.selection_finish (this, data, len);
961 } 1048 }
962#endif 1049#endif
963} 1050}
964 1051
965bool 1052bool
1160 handle_selection (xev.xproperty.window, xev.xproperty.atom, true); 1247 handle_selection (xev.xproperty.window, xev.xproperty.atom, true);
1161 break; 1248 break;
1162 1249
1163 case SelectionNotify: 1250 case SelectionNotify:
1164 if (selection_wait == Sel_normal 1251 if (selection_wait == Sel_normal
1165 && xev.xselection.time == request_time 1252 && xev.xselection.time == request_time)
1166 && xev.xselection.property == request_prop)
1167 { 1253 {
1168 timer_ev.stop (); 1254 timer_ev.stop ();
1169 handle_selection (xev.xselection.requestor, xev.xselection.property, true); 1255 handle_selection (xev.xselection.requestor, xev.xselection.property, true);
1170 } 1256 }
1171 break; 1257 break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines