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.23 by root, Wed Jan 11 00:59:58 2006 UTC vs.
Revision 1.28 by root, Sun Jan 29 20:51:28 2006 UTC

32#ifndef NO_SLOW_LINK_SUPPORT 32#ifndef NO_SLOW_LINK_SUPPORT
33# include <sys/socket.h> 33# include <sys/socket.h>
34# include <sys/un.h> 34# include <sys/un.h>
35#endif 35#endif
36 36
37const char *const xa_names[] =
38 {
39 "TEXT",
40 "COMPOUND_TEXT",
41 "UTF8_STRING",
42 "MULTIPLE",
43 "TARGETS",
44 "TIMESTAMP",
45 "VT_SELECTION",
46 "INCR",
47 "WM_PROTOCOLS",
48 "WM_DELETE_WINDOW",
49 "CLIPBOARD",
50#if ENABLE_FRILLS
51 "_MOTIF_WM_HINTS",
52#endif
53#if ENABLE_EWMH
54 "_NET_WM_PID",
55 "_NET_WM_NAME",
56 "_NET_WM_ICON_NAME",
57 "_NET_WM_PING",
58#endif
59#if USE_XIM
60 "WM_LOCALE_NAME",
61 "XIM_SERVERS",
62#endif
63#ifdef TRANSPARENT
64 "_XROOTPMAP_ID",
65 "ESETROOT_PMAP_ID",
66#endif
67#if ENABLE_XEMBED
68 "_XEMBED",
69 "_XEMBED_INFO",
70#endif
71 };
72
73/////////////////////////////////////////////////////////////////////////////
74
37refcounted::refcounted (const char *id) 75refcounted::refcounted (const char *id)
38{ 76{
39 this->id = strdup (id); 77 this->id = strdup (id);
40} 78}
41 79
93} 131}
94 132
95///////////////////////////////////////////////////////////////////////////// 133/////////////////////////////////////////////////////////////////////////////
96 134
97#ifdef USE_XIM 135#ifdef USE_XIM
136
98static void 137static void
99#if XIMCB_PROTO_BROKEN 138#if XIMCB_PROTO_BROKEN
100im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3) 139im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3)
101#else 140#else
102im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3) 141im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3)
133rxvt_xim::~rxvt_xim () 172rxvt_xim::~rxvt_xim ()
134{ 173{
135 if (xim) 174 if (xim)
136 XCloseIM (xim); 175 XCloseIM (xim);
137} 176}
177
138#endif 178#endif
179
180/////////////////////////////////////////////////////////////////////////////
181
182void
183rxvt_screen::set (rxvt_display *disp)
184{
185 display = disp;
186 xdisp = disp->display;
187
188 Screen *screen = ScreenOfDisplay (xdisp, disp->screen);
189
190 depth = DefaultDepthOfScreen (screen);
191 visual = DefaultVisualOfScreen (screen);
192 cmap = DefaultColormapOfScreen (screen);
193}
194
195void
196rxvt_screen::set (rxvt_display *disp, int bitdepth)
197{
198 set (disp);
199
200 XVisualInfo vinfo;
201
202 if (XMatchVisualInfo (xdisp, display->screen, bitdepth, TrueColor, &vinfo))
203 {
204 depth = bitdepth;
205 visual = vinfo.visual;
206 cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone);
207 }
208}
209
210void
211rxvt_screen::clear ()
212{
213 if (cmap != DefaultColormapOfScreen (ScreenOfDisplay (xdisp, display->screen)))
214 XFreeColormap (xdisp, cmap);
215}
139 216
140///////////////////////////////////////////////////////////////////////////// 217/////////////////////////////////////////////////////////////////////////////
141 218
142rxvt_display::rxvt_display (const char *id) 219rxvt_display::rxvt_display (const char *id)
143: refcounted (id) 220: refcounted (id)
247 if (!display) 324 if (!display)
248 return false; 325 return false;
249 326
250 screen = DefaultScreen (display); 327 screen = DefaultScreen (display);
251 root = DefaultRootWindow (display); 328 root = DefaultRootWindow (display);
252 visual = DefaultVisual (display, screen); 329
253 cmap = DefaultColormap (display, screen); 330 assert (sizeof (xa_names) / sizeof (char *) == NUM_XA);
254 depth = DefaultDepth (display, screen); 331 XInternAtoms (display, (char **)xa_names, NUM_XA, False, xa);
255 332
256 XrmSetDatabase (display, get_resources ()); 333 XrmSetDatabase (display, get_resources ());
257 334
258#ifdef POINTER_BLANK 335#ifdef POINTER_BLANK
259 XColor blackcolour; 336 XColor blackcolour;
264 blank_cursor = XCreateGlyphCursor (display, f, f, ' ', ' ', 341 blank_cursor = XCreateGlyphCursor (display, f, f, ' ', ' ',
265 &blackcolour, &blackcolour); 342 &blackcolour, &blackcolour);
266 XUnloadFont (display, f); 343 XUnloadFont (display, f);
267#endif 344#endif
268 345
269#ifdef PREFER_24BIT
270 /*
271 * If depth is not 24, look for a 24bit visual.
272 */
273 if (depth != 24)
274 {
275 XVisualInfo vinfo;
276
277 if (XMatchVisualInfo (display, screen, 24, TrueColor, &vinfo))
278 {
279 depth = 24;
280 visual = vinfo.visual;
281 cmap = XCreateColormap (display,
282 RootWindow (display, screen),
283 visual, AllocNone);
284 }
285 }
286#endif
287
288 int fd = XConnectionNumber (display); 346 int fd = XConnectionNumber (display);
289 347
290#ifndef NO_SLOW_LINK_SUPPORT 348#ifndef NO_SLOW_LINK_SUPPORT
291 // try to detect wether we have a local connection. 349 // try to detect wether we have a local connection.
292 // assume unix domains socket == local, everything else not 350 // assume unix domains socket == local, everything else not
301 359
302 x_ev.start (fd, EVENT_READ); 360 x_ev.start (fd, EVENT_READ);
303 fcntl (fd, F_SETFD, FD_CLOEXEC); 361 fcntl (fd, F_SETFD, FD_CLOEXEC);
304 362
305 XSelectInput (display, root, PropertyChangeMask); 363 XSelectInput (display, root, PropertyChangeMask);
306#ifdef USE_XIM
307 xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0);
308#endif
309 364
310 flush (); 365 flush ();
311 366
312 return true; 367 return true;
313} 368}
349 // registers, as xlib crashes due to a race otherwise. 404 // registers, as xlib crashes due to a race otherwise.
350 Atom actual_type, *atoms; 405 Atom actual_type, *atoms;
351 int actual_format; 406 int actual_format;
352 unsigned long nitems, bytes_after; 407 unsigned long nitems, bytes_after;
353 408
354 if (XGetWindowProperty (display, root, xa_xim_servers, 0L, 1000000L, 409 if (XGetWindowProperty (display, root, xa[XA_XIM_SERVERS], 0L, 1000000L,
355 False, XA_ATOM, &actual_type, &actual_format, 410 False, XA_ATOM, &actual_type, &actual_format,
356 &nitems, &bytes_after, (unsigned char **)&atoms) 411 &nitems, &bytes_after, (unsigned char **)&atoms)
357 != Success ) 412 != Success )
358 return; 413 return;
359 414
379#ifdef USE_XIM 434#ifdef USE_XIM
380 if (!XFilterEvent (&xev, None)) 435 if (!XFilterEvent (&xev, None))
381 { 436 {
382 if (xev.type == PropertyNotify 437 if (xev.type == PropertyNotify
383 && xev.xany.window == root 438 && xev.xany.window == root
384 && xev.xproperty.atom == xa_xim_servers) 439 && xev.xproperty.atom == xa[XA_XIM_SERVERS])
385 im_change_check (); 440 im_change_check ();
386#endif 441#endif
387 for (int i = xw.size (); i--; ) 442 for (int i = xw.size (); i--; )
388 { 443 {
389 if (!xw[i]) 444 if (!xw[i])
479refcache<rxvt_display> displays; 534refcache<rxvt_display> displays;
480 535
481///////////////////////////////////////////////////////////////////////////// 536/////////////////////////////////////////////////////////////////////////////
482 537
483bool 538bool
484rxvt_color::set (rxvt_display *display, Pixel p) 539rxvt_color::set (rxvt_screen *screen, const char *name)
485{ 540{
486#if XFT 541#if XFT
487 XColor xc; 542 int l = strlen (name);
543 rxvt_rgba r;
544 char eos;
545 int mult;
488 546
489 xc.pixel = p; 547 if ( l == 1+4*1 && 4 == sscanf (name, "#%1hx%1hx%1hx%1hx%c", &r.a, &r.r, &r.g, &r.b, &eos))
490 if (!XQueryColor (display->display, display->cmap, &xc)) 548 mult = 0x1111;
491 return false; 549 else if (l == 1+4*2 && 4 == sscanf (name, "#%2hx%2hx%2hx%2hx%c", &r.a, &r.r, &r.g, &r.b, &eos))
550 mult = 0x0101;
551 else if (l == 1+4*4 && 4 == sscanf (name, "#%4hx%4hx%4hx%4hx%c", &r.a, &r.r, &r.g, &r.b, &eos))
552 mult = 0x0001;
553 else
554 return XftColorAllocName (screen->xdisp, screen->visual, screen->cmap, name, &c);
492 555
493 XRenderColor d; 556 r.r *= mult; r.g *= mult; r.b *= mult; r.a *= mult;
494 557 return set (screen, r);
495 d.red = xc.red;
496 d.green = xc.green;
497 d.blue = xc.blue;
498 d.alpha = 0xffff;
499
500 return
501 XftColorAllocValue (display->display,
502 display->visual,
503 display->cmap,
504 &d, &c);
505#else
506 this->p = p;
507#endif
508
509 return true;
510}
511
512bool
513rxvt_color::set (rxvt_display *display, const char *name)
514{
515#if XFT
516 return XftColorAllocName (display->display, display->visual, display->cmap,
517 name, &c);
518#else 558#else
519 XColor xc; 559 XColor xc;
520 560
521 if (XParseColor (display->display, display->cmap, name, &xc)) 561 if (XParseColor (screen->xdisp, screen->cmap, name, &xc))
522 return set (display, xc.red, xc.green, xc.blue); 562 return set (screen, rxvt_rgba (xc.red, xc.green, xc.blue));
523 563
524 return false; 564 return false;
525#endif 565#endif
526} 566}
527 567
528bool 568bool
529rxvt_color::set (rxvt_display *display, unsigned short cr, unsigned short cg, unsigned short cb) 569rxvt_color::set (rxvt_screen *screen, rxvt_rgba rgba)
530{ 570{
571#if XFT
572 XRenderColor d;
573
574 d.red = rgba.r;
575 d.green = rgba.g;
576 d.blue = rgba.b;
577 d.alpha = rgba.a;
578
579 return XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c);
580#else
531 XColor xc; 581 XColor xc;
532 582
533 xc.red = cr; 583 xc.red = rgba.r;
534 xc.green = cg; 584 xc.green = rgba.g;
535 xc.blue = cb; 585 xc.blue = rgba.b;
536 xc.flags = DoRed | DoGreen | DoBlue; 586 xc.flags = DoRed | DoGreen | DoBlue;
537 587
538 if (XAllocColor (display->display, display->cmap, &xc)) 588 if (XAllocColor (screen->xdisp, screen->cmap, &xc))
539 return set (display, xc.pixel); 589 {
590 p = xc.pixel;
591 return true;
592 }
540 593
541 return false; 594 return false;
595#endif
542} 596}
543 597
544void 598void
545rxvt_color::get (rxvt_display *display, unsigned short &cr, unsigned short &cg, unsigned short &cb) 599rxvt_color::get (rxvt_screen *screen, rxvt_rgba &rgba)
546{ 600{
547#if XFT 601#if XFT
548 cr = c.color.red; 602 rgba.r = c.color.red;
549 cg = c.color.green; 603 rgba.g = c.color.green;
550 cb = c.color.blue; 604 rgba.b = c.color.blue;
605 rgba.a = c.color.alpha;
551#else 606#else
552 XColor c; 607 XColor c;
553 608
554 c.pixel = p; 609 c.pixel = p;
555 XQueryColor (display->display, display->cmap, &c); 610 XQueryColor (screen->xdisp, screen->cmap, &c);
556 611
557 cr = c.red; 612 rgba.r = c.red;
558 cg = c.green; 613 rgba.g = c.green;
559 cb = c.blue; 614 rgba.b = c.blue;
615 rgba.a = rxvt_rgba::MAX_CC;
560#endif 616#endif
561} 617}
562 618
563void 619void
564rxvt_color::free (rxvt_display *display) 620rxvt_color::free (rxvt_screen *screen)
565{ 621{
566#if XFT 622#if XFT
567 XftColorFree (display->display, display->visual, display->cmap, &c); 623 XftColorFree (screen->xdisp, screen->visual, screen->cmap, &c);
568#else 624#else
569 XFreeColors (display->display, display->cmap, &p, 1, AllPlanes); 625 XFreeColors (screen->xdisp, screen->cmap, &p, 1, AllPlanes);
570#endif 626#endif
571} 627}
572 628
573rxvt_color 629rxvt_color
574rxvt_color::fade (rxvt_display *display, int percent) 630rxvt_color::fade (rxvt_screen *screen, int percent)
575{ 631{
576 percent = 100 - percent;
577
578 unsigned short cr, cg, cb;
579 rxvt_color faded; 632 rxvt_color faded;
580 633
581 get (display, cr, cg, cb); 634 rxvt_rgba c;
635 get (screen, c);
582 636
583 faded.set ( 637 c.r = lerp (0, c.r, percent);
584 display, 638 c.g = lerp (0, c.g, percent);
585 cr * percent / 100, 639 c.b = lerp (0, c.b, percent);
586 cg * percent / 100, 640
587 cb * percent / 100 641 faded.set (screen, c);
588 );
589 642
590 return faded; 643 return faded;
591} 644}
592 645
593#define LERP(a,b,p) (a * p + b * (100 - p)) / 100
594
595rxvt_color 646rxvt_color
596rxvt_color::fade (rxvt_display *display, int percent, rxvt_color &fadeto) 647rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &fadeto)
597{ 648{
598 percent = 100 - percent; 649 rxvt_rgba c, fc;
599
600 unsigned short cr, cg, cb;
601 unsigned short fcr, fcg, fcb;
602 rxvt_color faded; 650 rxvt_color faded;
603 651
604 get (display, cr, cg, cb); 652 get (screen, c);
605 fadeto.get(display, fcr, fcg, fcb); 653 fadeto.get (screen, fc);
606 654
607 faded.set ( 655 faded.set (
608 display, 656 screen,
657 rxvt_rgba (
609 LERP (cr, fcr, percent), 658 lerp (fc.r, c.r, percent),
610 LERP (cg, fcg, percent), 659 lerp (fc.g, c.g, percent),
611 LERP (cb, fcb, percent) 660 lerp (fc.b, c.b, percent),
661 lerp (fc.a, c.a, percent)
662 )
612 ); 663 );
613 664
614 return faded; 665 return faded;
615} 666}
616 667

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines