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.24 by root, Wed Jan 25 00:42:21 2006 UTC vs.
Revision 1.26 by root, Wed Jan 25 21:03:04 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
139 177
140#endif 178#endif
141 179
142///////////////////////////////////////////////////////////////////////////// 180/////////////////////////////////////////////////////////////////////////////
143 181
182void
183rxvt_screen::set (rxvt_display *disp)
184{
185 display = disp;
186
187 xdisp = disp->display;
188
189 Screen *screen = ScreenOfDisplay (xdisp, disp->screen);
190
191 depth = DefaultDepthOfScreen (screen);
192 visual = DefaultVisualOfScreen (screen);
193 cmap = DefaultColormapOfScreen (screen);
194}
195
196void
197rxvt_screen::set (rxvt_display *disp, int depth)
198{
199 set (disp);
200
201 XVisualInfo vinfo;
202
203 if (XMatchVisualInfo (xdisp, display->screen, depth, TrueColor, &vinfo))
204 {
205 this->depth = depth;
206 this->visual = vinfo.visual;
207 this->cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone);
208 }
209}
210
211void
212rxvt_screen::clear ()
213{
214 if (cmap != DefaultColormapOfScreen (ScreenOfDisplay (xdisp, display->screen)))
215 XFreeColormap (xdisp, cmap);
216}
217
218/////////////////////////////////////////////////////////////////////////////
219
144rxvt_display::rxvt_display (const char *id) 220rxvt_display::rxvt_display (const char *id)
145: refcounted (id) 221: refcounted (id)
146, x_ev (this, &rxvt_display::x_cb) 222, x_ev (this, &rxvt_display::x_cb)
147, selection_owner (0) 223, selection_owner (0)
148{ 224{
249 if (!display) 325 if (!display)
250 return false; 326 return false;
251 327
252 screen = DefaultScreen (display); 328 screen = DefaultScreen (display);
253 root = DefaultRootWindow (display); 329 root = DefaultRootWindow (display);
254 visual = DefaultVisual (display, screen); 330
255 cmap = DefaultColormap (display, screen); 331 assert (sizeof (xa_names) / sizeof (char *) == NUM_XA);
256 depth = DefaultDepth (display, screen); 332 XInternAtoms (display, (char **)xa_names, NUM_XA, False, xa);
257 333
258 XrmSetDatabase (display, get_resources ()); 334 XrmSetDatabase (display, get_resources ());
259 335
260#ifdef POINTER_BLANK 336#ifdef POINTER_BLANK
261 XColor blackcolour; 337 XColor blackcolour;
266 blank_cursor = XCreateGlyphCursor (display, f, f, ' ', ' ', 342 blank_cursor = XCreateGlyphCursor (display, f, f, ' ', ' ',
267 &blackcolour, &blackcolour); 343 &blackcolour, &blackcolour);
268 XUnloadFont (display, f); 344 XUnloadFont (display, f);
269#endif 345#endif
270 346
271#ifdef PREFER_24BIT
272 /*
273 * If depth is not 24, look for a 24bit visual.
274 */
275 if (depth != 24)
276 {
277 XVisualInfo vinfo;
278
279 if (XMatchVisualInfo (display, screen, 24, TrueColor, &vinfo))
280 {
281 depth = 24;
282 visual = vinfo.visual;
283 cmap = XCreateColormap (display,
284 RootWindow (display, screen),
285 visual, AllocNone);
286 }
287 }
288#endif
289
290 int fd = XConnectionNumber (display); 347 int fd = XConnectionNumber (display);
291 348
292#ifndef NO_SLOW_LINK_SUPPORT 349#ifndef NO_SLOW_LINK_SUPPORT
293 // try to detect wether we have a local connection. 350 // try to detect wether we have a local connection.
294 // assume unix domains socket == local, everything else not 351 // assume unix domains socket == local, everything else not
303 360
304 x_ev.start (fd, EVENT_READ); 361 x_ev.start (fd, EVENT_READ);
305 fcntl (fd, F_SETFD, FD_CLOEXEC); 362 fcntl (fd, F_SETFD, FD_CLOEXEC);
306 363
307 XSelectInput (display, root, PropertyChangeMask); 364 XSelectInput (display, root, PropertyChangeMask);
308#ifdef USE_XIM
309 xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0);
310#endif
311 365
312 flush (); 366 flush ();
313 367
314 return true; 368 return true;
315} 369}
351 // registers, as xlib crashes due to a race otherwise. 405 // registers, as xlib crashes due to a race otherwise.
352 Atom actual_type, *atoms; 406 Atom actual_type, *atoms;
353 int actual_format; 407 int actual_format;
354 unsigned long nitems, bytes_after; 408 unsigned long nitems, bytes_after;
355 409
356 if (XGetWindowProperty (display, root, xa_xim_servers, 0L, 1000000L, 410 if (XGetWindowProperty (display, root, xa[XA_XIM_SERVERS], 0L, 1000000L,
357 False, XA_ATOM, &actual_type, &actual_format, 411 False, XA_ATOM, &actual_type, &actual_format,
358 &nitems, &bytes_after, (unsigned char **)&atoms) 412 &nitems, &bytes_after, (unsigned char **)&atoms)
359 != Success ) 413 != Success )
360 return; 414 return;
361 415
381#ifdef USE_XIM 435#ifdef USE_XIM
382 if (!XFilterEvent (&xev, None)) 436 if (!XFilterEvent (&xev, None))
383 { 437 {
384 if (xev.type == PropertyNotify 438 if (xev.type == PropertyNotify
385 && xev.xany.window == root 439 && xev.xany.window == root
386 && xev.xproperty.atom == xa_xim_servers) 440 && xev.xproperty.atom == xa[XA_XIM_SERVERS])
387 im_change_check (); 441 im_change_check ();
388#endif 442#endif
389 for (int i = xw.size (); i--; ) 443 for (int i = xw.size (); i--; )
390 { 444 {
391 if (!xw[i]) 445 if (!xw[i])
481refcache<rxvt_display> displays; 535refcache<rxvt_display> displays;
482 536
483///////////////////////////////////////////////////////////////////////////// 537/////////////////////////////////////////////////////////////////////////////
484 538
485bool 539bool
486rxvt_color::set (rxvt_display *display, Pixel p) 540rxvt_color::set (rxvt_screen *screen, Pixel p)
487{ 541{
488#if XFT 542#if XFT
489 XColor xc; 543 XColor xc;
490 544
491 xc.pixel = p; 545 xc.pixel = p;
492 if (!XQueryColor (display->display, display->cmap, &xc)) 546 if (!XQueryColor (screen->xdisp, screen->cmap, &xc))
493 return false; 547 return false;
494 548
495 XRenderColor d; 549 XRenderColor d;
496 550
497 d.red = xc.red; 551 d.red = xc.red;
498 d.green = xc.green; 552 d.green = xc.green;
499 d.blue = xc.blue; 553 d.blue = xc.blue;
500 d.alpha = 0xffff; 554 d.alpha = 0xffff;
501 555
502 return 556 return
503 XftColorAllocValue (display->display, 557 XftColorAllocValue (screen->xdisp,
504 display->visual, 558 screen->visual,
505 display->cmap, 559 screen->cmap,
506 &d, &c); 560 &d, &c);
507#else 561#else
508 this->p = p; 562 this->p = p;
509#endif 563#endif
510 564
511 return true; 565 return true;
512} 566}
513 567
514bool 568bool
515rxvt_color::set (rxvt_display *display, const char *name) 569rxvt_color::set (rxvt_screen *screen, const char *name)
516{ 570{
517#if XFT 571#if XFT
518 return XftColorAllocName (display->display, display->visual, display->cmap, 572 return XftColorAllocName (screen->xdisp, screen->visual, screen->cmap, name, &c);
519 name, &c);
520#else 573#else
521 XColor xc; 574 XColor xc;
522 575
523 if (XParseColor (display->display, display->cmap, name, &xc)) 576 if (XParseColor (screen->xdisp, screen->cmap, name, &xc))
524 return set (display, xc.red, xc.green, xc.blue); 577 return set (screen, xc.red, xc.green, xc.blue);
525 578
526 return false; 579 return false;
527#endif 580#endif
528} 581}
529 582
530bool 583bool
531rxvt_color::set (rxvt_display *display, unsigned short cr, unsigned short cg, unsigned short cb) 584rxvt_color::set (rxvt_screen *screen, unsigned short cr, unsigned short cg, unsigned short cb)
532{ 585{
533 XColor xc; 586 XColor xc;
534 587
535 xc.red = cr; 588 xc.red = cr;
536 xc.green = cg; 589 xc.green = cg;
537 xc.blue = cb; 590 xc.blue = cb;
538 xc.flags = DoRed | DoGreen | DoBlue; 591 xc.flags = DoRed | DoGreen | DoBlue;
539 592
540 if (XAllocColor (display->display, display->cmap, &xc)) 593 if (XAllocColor (screen->xdisp, screen->cmap, &xc))
541 return set (display, xc.pixel); 594 return set (screen, xc.pixel);
542 595
543 return false; 596 return false;
544} 597}
545 598
546void 599void
547rxvt_color::get (rxvt_display *display, unsigned short &cr, unsigned short &cg, unsigned short &cb) 600rxvt_color::get (rxvt_screen *screen, unsigned short &cr, unsigned short &cg, unsigned short &cb)
548{ 601{
549#if XFT 602#if XFT
550 cr = c.color.red; 603 cr = c.color.red;
551 cg = c.color.green; 604 cg = c.color.green;
552 cb = c.color.blue; 605 cb = c.color.blue;
553#else 606#else
554 XColor c; 607 XColor c;
555 608
556 c.pixel = p; 609 c.pixel = p;
557 XQueryColor (display->display, display->cmap, &c); 610 XQueryColor (screen->xdisp, screen->cmap, &c);
558 611
559 cr = c.red; 612 cr = c.red;
560 cg = c.green; 613 cg = c.green;
561 cb = c.blue; 614 cb = c.blue;
562#endif 615#endif
563} 616}
564 617
565void 618void
566rxvt_color::free (rxvt_display *display) 619rxvt_color::free (rxvt_screen *screen)
567{ 620{
568#if XFT 621#if XFT
569 XftColorFree (display->display, display->visual, display->cmap, &c); 622 XftColorFree (screen->xdisp, screen->visual, screen->cmap, &c);
570#else 623#else
571 XFreeColors (display->display, display->cmap, &p, 1, AllPlanes); 624 XFreeColors (screen->xdisp, screen->cmap, &p, 1, AllPlanes);
572#endif 625#endif
573} 626}
574 627
575rxvt_color 628rxvt_color
576rxvt_color::fade (rxvt_display *display, int percent) 629rxvt_color::fade (rxvt_screen *screen, int percent)
577{ 630{
578 percent = 100 - percent; 631 percent = 100 - percent;
579 632
580 unsigned short cr, cg, cb; 633 unsigned short cr, cg, cb;
581 rxvt_color faded; 634 rxvt_color faded;
582 635
583 get (display, cr, cg, cb); 636 get (screen, cr, cg, cb);
584 637
585 faded.set ( 638 faded.set (
586 display, 639 screen,
587 cr * percent / 100, 640 cr * percent / 100,
588 cg * percent / 100, 641 cg * percent / 100,
589 cb * percent / 100 642 cb * percent / 100
590 ); 643 );
591 644
593} 646}
594 647
595#define LERP(a,b,p) (a * p + b * (100 - p)) / 100 648#define LERP(a,b,p) (a * p + b * (100 - p)) / 100
596 649
597rxvt_color 650rxvt_color
598rxvt_color::fade (rxvt_display *display, int percent, rxvt_color &fadeto) 651rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &fadeto)
599{ 652{
600 percent = 100 - percent; 653 percent = 100 - percent;
601 654
602 unsigned short cr, cg, cb; 655 unsigned short cr, cg, cb;
603 unsigned short fcr, fcg, fcb; 656 unsigned short fcr, fcg, fcb;
604 rxvt_color faded; 657 rxvt_color faded;
605 658
606 get (display, cr, cg, cb); 659 get (screen, cr, cg, cb);
607 fadeto.get(display, fcr, fcg, fcb); 660 fadeto.get (screen, fcr, fcg, fcb);
608 661
609 faded.set ( 662 faded.set (
610 display, 663 screen,
611 LERP (cr, fcr, percent), 664 LERP (cr, fcr, percent),
612 LERP (cg, fcg, percent), 665 LERP (cg, fcg, percent),
613 LERP (cb, fcb, percent) 666 LERP (cb, fcb, percent)
614 ); 667 );
615 668

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines