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.126 by sf-exg, Wed May 25 08:55:52 2011 UTC vs.
Revision 1.137 by root, Thu Jun 7 16:04:31 2012 UTC

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.
725 d.red = color.r; 793 d.red = color.r;
726 d.green = color.g; 794 d.green = color.g;
727 d.blue = color.b; 795 d.blue = color.b;
728 d.alpha = alpha; 796 d.alpha = alpha;
729 797
730 return XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c); 798 if (XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c))
799 return true;
731 } 800 }
732#else 801#else
733 c.red = color.r; 802 c.red = color.r;
734 c.green = color.g; 803 c.green = color.g;
735 c.blue = color.b; 804 c.blue = color.b;
736 805
737 if (screen->visual->c_class == TrueColor) 806 if (screen->visual->c_class == TrueColor)
738 { 807 {
739 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 ))
740 | (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))
741 | (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 ));
742 811
743 return true; 812 return true;
744 } 813 }
745 else if (XAllocColor (screen->dpy, screen->cmap, &c)) 814 else if (XAllocColor (screen->dpy, screen->cmap, &c))
746 return true; 815 return true;
747 else 816#endif
817
748 c.pixel = (color.r + color.g + color.b) > 128*3 818 c.pixel = (color.r + color.g + color.b) > 128*3
749 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy)) 819 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy))
750 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy)); 820 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy));
751#endif
752 821
753 return false; 822 return false;
754} 823}
755 824
756bool 825bool
841 910
842 return got; 911 return got;
843} 912}
844 913
845void 914void
846rxvt_color::get (rgba &color) 915rxvt_color::get (rgba &color) const
847{ 916{
848#if XFT 917#if XFT
849 color.r = c.color.red; 918 color.r = c.color.red;
850 color.g = c.color.green; 919 color.g = c.color.green;
851 color.b = c.color.blue; 920 color.b = c.color.blue;
857 color.a = rgba::MAX_CC; 926 color.a = rgba::MAX_CC;
858#endif 927#endif
859} 928}
860 929
861void 930void
862rxvt_color::get (XColor &color) 931rxvt_color::get (XColor &color) const
863{ 932{
864 rgba c; 933 rgba c;
865 get (c); 934 get (c);
866 935
867 color.red = c.r; 936 color.red = c.r;
911 980
912 incr_buf = 0; 981 incr_buf = 0;
913 incr_buf_size = incr_buf_fill = 0; 982 incr_buf_size = incr_buf_fill = 0;
914 selection_wait = Sel_normal; 983 selection_wait = Sel_normal;
915 selection_type = selnum; 984 selection_type = selnum;
985 cb_sv = 0;
916} 986}
917 987
918void 988void
919rxvt_selection::stop () 989rxvt_selection::stop ()
920{ 990{
960} 1030}
961 1031
962void 1032void
963rxvt_selection::finish (char *data, unsigned int len) 1033rxvt_selection::finish (char *data, unsigned int len)
964{ 1034{
965 if (term) 1035 if (!cb_sv)
966 { 1036 {
967 if (data) 1037 if (data)
968 term->paste (data, len); 1038 term->paste (data, len);
969 1039
970 term->selection_req = 0; 1040 term->selection_req = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines