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.1 by root, Sun Aug 15 00:37:04 2004 UTC vs.
Revision 1.34 by root, Mon Jan 30 02:21:20 2006 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: rxvtcolor.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-2004 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com>
7 * 7 *
25#include <rxvttoolkit.h> 25#include <rxvttoolkit.h>
26 26
27#include <unistd.h> 27#include <unistd.h>
28#include <fcntl.h> 28#include <fcntl.h>
29 29
30#include <sys/utsname.h>
31
30#ifndef NO_SLOW_LINK_SUPPORT 32#ifndef NO_SLOW_LINK_SUPPORT
31# include <sys/socket.h> 33# include <sys/socket.h>
32# include <sys/un.h> 34# include <sys/un.h>
33#endif 35#endif
34 36
37#if XFT
38# include <X11/extensions/Xrender.h>
39#endif
40
41const char *const xa_names[] =
42{
43 "TEXT",
44 "COMPOUND_TEXT",
45 "UTF8_STRING",
46 "MULTIPLE",
47 "TARGETS",
48 "TIMESTAMP",
49 "VT_SELECTION",
50 "INCR",
51 "WM_PROTOCOLS",
52 "WM_DELETE_WINDOW",
53 "CLIPBOARD",
54 "AVERAGE_WIDTH",
55 "WEIGHT_NAME",
56 "SLANT",
57 "CHARSET_REGISTRY",
58 "CHARSET_ENCODING",
59#if ENABLE_FRILLS
60 "_MOTIF_WM_HINTS",
61#endif
62#if ENABLE_EWMH
63 "_NET_WM_PID",
64 "_NET_WM_NAME",
65 "_NET_WM_ICON_NAME",
66 "_NET_WM_PING",
67#endif
68#if USE_XIM
69 "WM_LOCALE_NAME",
70 "XIM_SERVERS",
71#endif
72#ifdef TRANSPARENT
73 "_XROOTPMAP_ID",
74 "ESETROOT_PMAP_ID",
75#endif
76#if ENABLE_XEMBED
77 "_XEMBED",
78 "_XEMBED_INFO",
79#endif
80#if !ENABLE_MINIMAL
81 "SCREEN_RESOURCES",
82 "XDCCC_LINEAR_RGB_CORRECTION",
83 "XDCCC_LINEAR_RGB_MATRICES",
84 "WM_COLORMAP_WINDOWS",
85 "WM_STATE",
86#endif
87};
88
89/////////////////////////////////////////////////////////////////////////////
90
35refcounted::refcounted (const char *id) 91refcounted::refcounted (const char *id)
36{ 92{
37 this->id = STRDUP (id); 93 this->id = strdup (id);
38} 94}
39 95
40refcounted::~refcounted () 96refcounted::~refcounted ()
41{ 97{
42 free (id); 98 free (id);
47{ 103{
48 for (T **i = this->begin (); i < this->end (); ++i) 104 for (T **i = this->begin (); i < this->end (); ++i)
49 { 105 {
50 if (!strcmp (id, (*i)->id)) 106 if (!strcmp (id, (*i)->id))
51 { 107 {
52 (*i)->referenced++; 108 ++(*i)->referenced;
109 (*i)->ref_next ();
53 return *i; 110 return *i;
54 } 111 }
55 } 112 }
56 113
57 T *obj = new T (id); 114 T *obj = new T (id);
58 115
59 obj->referenced = 1;
60
61 if (obj && obj->init ()) 116 if (obj && obj->ref_init ())
62 { 117 {
118 obj->referenced = 1;
63 this->push_back (obj); 119 this->push_back (obj);
64 return obj; 120 return obj;
65 } 121 }
66 else 122 else
67 { 123 {
82 delete obj; 138 delete obj;
83 } 139 }
84} 140}
85 141
86template<class T> 142template<class T>
87refcache<T>::~refcache () 143void refcache<T>::clear ()
88{ 144{
89 while (this->size ()) 145 while (this->size ())
90 put (*this->begin ()); 146 put (*this->begin ());
91} 147}
92 148
93///////////////////////////////////////////////////////////////////////////// 149/////////////////////////////////////////////////////////////////////////////
94 150
95#ifdef USE_XIM 151#ifdef USE_XIM
152
96static void 153static void
97#if XIMCB_PROTO_BROKEN 154#if XIMCB_PROTO_BROKEN
98im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3) 155im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3)
99#else 156#else
100im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3) 157im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3)
101#endif 158#endif
102{ 159{
103 rxvt_xim *xim = (rxvt_xim *)client_data; 160 rxvt_xim *xim = (rxvt_xim *)client_data;
104 rxvt_display *display = xim->display; 161 rxvt_display *display = xim->display;
105 162
163 xim->xim = 0;
164
106 display->xims.erase (find (display->xims.begin (), display->xims.end (), xim)); 165 display->xims.erase (find (display->xims.begin (), display->xims.end (), xim));
107
108 display->im_change_cb (); 166 display->im_change_cb ();
109} 167}
110 168
169bool
111bool rxvt_xim::init () 170rxvt_xim::ref_init ()
112{ 171{
113 display = GET_R->display; //HACK: TODO 172 display = GET_R->display; //HACK: TODO
114 173
115 xim = XOpenIM (display->display, NULL, NULL, NULL); 174 xim = XOpenIM (display->display, NULL, NULL, NULL);
116 175
129rxvt_xim::~rxvt_xim () 188rxvt_xim::~rxvt_xim ()
130{ 189{
131 if (xim) 190 if (xim)
132 XCloseIM (xim); 191 XCloseIM (xim);
133} 192}
193
134#endif 194#endif
195
196/////////////////////////////////////////////////////////////////////////////
197
198void
199rxvt_screen::set (rxvt_display *disp)
200{
201 display = disp;
202 xdisp = disp->display;
203
204 Screen *screen = ScreenOfDisplay (xdisp, disp->screen);
205
206 depth = DefaultDepthOfScreen (screen);
207 visual = DefaultVisualOfScreen (screen);
208 cmap = DefaultColormapOfScreen (screen);
209}
210
211void
212rxvt_screen::set (rxvt_display *disp, int bitdepth)
213{
214 set (disp);
215
216#if XFT
217 XVisualInfo vinfo;
218
219 if (XMatchVisualInfo (xdisp, display->screen, bitdepth, TrueColor, &vinfo))
220 {
221 depth = bitdepth;
222 visual = vinfo.visual;
223 cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone);
224 }
225#endif
226}
227
228void
229rxvt_screen::clear ()
230{
231 if (cmap != DefaultColormapOfScreen (ScreenOfDisplay (xdisp, display->screen)))
232 XFreeColormap (xdisp, cmap);
233}
135 234
136///////////////////////////////////////////////////////////////////////////// 235/////////////////////////////////////////////////////////////////////////////
137 236
138rxvt_display::rxvt_display (const char *id) 237rxvt_display::rxvt_display (const char *id)
139: refcounted (id) 238: refcounted (id)
140, x_ev (this, &rxvt_display::x_cb) 239, x_ev (this, &rxvt_display::x_cb)
141, selection_owner (0) 240, selection_owner (0)
142{ 241{
143} 242}
144 243
244XrmDatabase
245rxvt_display::get_resources ()
246{
247 char *homedir = (char *)getenv ("HOME");
248 char fname[1024];
249
250 /*
251 * get resources using the X library function
252 */
253 char *displayResource, *xe;
254 XrmDatabase database, rdb1;
255
256 database = NULL;
257
258 // for ordering, see for example http://www.faqs.org/faqs/Xt-FAQ/ Subject: 20
259
260 // 6. System wide per application default file.
261
262 /* Add in $XAPPLRESDIR/Rxvt only; not bothering with XUSERFILESEARCHPATH */
263 if ((xe = (char *)getenv ("XAPPLRESDIR")))
264 {
265 snprintf (fname, sizeof (fname), "%s/%s", xe, RESCLASS);
266
267 if ((rdb1 = XrmGetFileDatabase (fname)))
268 XrmMergeDatabases (rdb1, &database);
269 }
270
271 // 5. User's per application default file.
272 // none
273
274 // 4. User's defaults file.
275 /* Get any Xserver defaults */
276 displayResource = XResourceManagerString (display);
277
278 if (displayResource != NULL)
279 {
280 if ((rdb1 = XrmGetStringDatabase (displayResource)))
281 XrmMergeDatabases (rdb1, &database);
282 }
283 else if (homedir)
284 {
285 snprintf (fname, sizeof (fname), "%s/.Xdefaults", homedir);
286
287 if ((rdb1 = XrmGetFileDatabase (fname)))
288 XrmMergeDatabases (rdb1, &database);
289 }
290
291 /* Get screen specific resources */
292 displayResource = XScreenResourceString (ScreenOfDisplay (display, screen));
293
294 if (displayResource != NULL)
295 {
296 if ((rdb1 = XrmGetStringDatabase (displayResource)))
297 /* Merge with screen-independent resources */
298 XrmMergeDatabases (rdb1, &database);
299
300 XFree (displayResource);
301 }
302
303 // 3. User's per host defaults file
304 /* Add in XENVIRONMENT file */
305 if ((xe = (char *)getenv ("XENVIRONMENT"))
306 && (rdb1 = XrmGetFileDatabase (xe)))
307 XrmMergeDatabases (rdb1, &database);
308 else if (homedir)
309 {
310 struct utsname un;
311
312 if (!uname (&un))
313 {
314 snprintf (fname, sizeof (fname), "%s/.Xdefaults-%s", homedir, un.nodename);
315
316 if ((rdb1 = XrmGetFileDatabase (fname)))
317 XrmMergeDatabases (rdb1, &database);
318 }
319 }
320
321 return database;
322}
323
145bool rxvt_display::init () 324bool rxvt_display::ref_init ()
146{ 325{
326#ifdef LOCAL_X_IS_UNIX
327 if (id[0] == ':')
328 {
329 val = rxvt_malloc (5 + strlen (id) + 1);
330 strcpy (val, "unix/");
331 strcat (val, id);
332 display = XOpenDisplay (val);
333 free (val);
334 }
335 else
336#endif
337 display = 0;
338
339 if (!display)
147 display = XOpenDisplay (id); 340 display = XOpenDisplay (id);
148 341
149 if (!display) 342 if (!display)
150 return false; 343 return false;
151 344
152 screen = DefaultScreen (display); 345 screen = DefaultScreen (display);
153 root = DefaultRootWindow (display); 346 root = DefaultRootWindow (display);
154 visual = DefaultVisual (display, screen); 347
155 cmap = DefaultColormap (display, screen); 348 assert (sizeof (xa_names) / sizeof (char *) == NUM_XA);
156 depth = DefaultDepth (display, screen); 349 XInternAtoms (display, (char **)xa_names, NUM_XA, False, xa);
350
351 XrmSetDatabase (display, get_resources ());
352
353#ifdef POINTER_BLANK
354 XColor blackcolour;
355 blackcolour.red = 0;
356 blackcolour.green = 0;
357 blackcolour.blue = 0;
358 Font f = XLoadFont (display, "fixed");
359 blank_cursor = XCreateGlyphCursor (display, f, f, ' ', ' ',
360 &blackcolour, &blackcolour);
361 XUnloadFont (display, f);
362#endif
157 363
158 int fd = XConnectionNumber (display); 364 int fd = XConnectionNumber (display);
159 365
160#ifndef NO_SLOW_LINK_SUPPORT 366#ifndef NO_SLOW_LINK_SUPPORT
161 // try to detetc wether we have a local connection. 367 // try to detect wether we have a local connection.
162 // assume unix domains socket == local, everything else not 368 // assume unix domains socket == local, everything else not
163 // TODO: might want to check for inet/127.0.0.1 369 // TODO: might want to check for inet/127.0.0.1
164 is_local = 0; 370 is_local = 0;
165 sockaddr_un sa; 371 sockaddr_un sa;
166 socklen_t sl = sizeof (sa); 372 socklen_t sl = sizeof (sa);
167 373
168 if (!getsockname (fd, (sockaddr *)&sa, &sl)) 374 if (!getsockname (fd, (sockaddr *)&sa, &sl))
169 is_local = sa.sun_family == AF_LOCAL; 375 is_local = sa.sun_family == AF_LOCAL;
170#endif 376#endif
171 377
172#ifdef PREFER_24BIT
173 /*
174 * If depth is not 24, look for a 24bit visual.
175 */
176 if (depth != 24)
177 {
178 XVisualInfo vinfo;
179
180 if (XMatchVisualInfo (display, screen, 24, TrueColor, &vinfo))
181 {
182 depth = 24;
183 visual = vinfo.visual;
184 cmap = XCreateColormap (display,
185 RootWindow (display, screen),
186 visual, AllocNone);
187 }
188 }
189#endif
190
191 x_ev.start (fd, EVENT_READ); 378 x_ev.start (fd, EVENT_READ);
192 fcntl (fd, F_SETFD, FD_CLOEXEC); 379 fcntl (fd, F_SETFD, FD_CLOEXEC);
193 380
194 XSelectInput (display, root, PropertyChangeMask); 381 XSelectInput (display, root, PropertyChangeMask);
382
383 flush ();
384
385 return true;
386}
387
388void
389rxvt_display::ref_next ()
390{
391 // TODO: somehow check wether the database files/resources changed
392 // before re-loading/parsing
393 XrmDestroyDatabase (XrmGetDatabase (display));
394 XrmSetDatabase (display, get_resources ());
395}
396
397rxvt_display::~rxvt_display ()
398{
399 if (!display)
400 return;
401
402#ifdef POINTER_BLANK
403 XFreeCursor (display, blank_cursor);
404#endif
405 x_ev.stop ();
195#ifdef USE_XIM 406#ifdef USE_XIM
196 xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0); 407 xims.clear ();
197#endif 408#endif
198
199 flush ();
200
201 return true;
202}
203
204rxvt_display::~rxvt_display ()
205{
206 x_ev.stop ();
207
208 if (display)
209 XCloseDisplay (display); 409 XCloseDisplay (display);
210} 410}
211 411
212#ifdef USE_XIM 412#ifdef USE_XIM
213void rxvt_display::im_change_cb () 413void rxvt_display::im_change_cb ()
214{ 414{
215 for (im_watcher **i = imw.begin (); i != imw.end (); ++i) 415 for (im_watcher **i = imw.begin (); i != imw.end (); ++i)
216 (*i)->call (); 416 (*i)->call ();
217} 417}
418
419void rxvt_display::im_change_check ()
420{
421 // try to only call im_change_cb when a new input method
422 // registers, as xlib crashes due to a race otherwise.
423 Atom actual_type, *atoms;
424 int actual_format;
425 unsigned long nitems, bytes_after;
426
427 if (XGetWindowProperty (display, root, xa[XA_XIM_SERVERS], 0L, 1000000L,
428 False, XA_ATOM, &actual_type, &actual_format,
429 &nitems, &bytes_after, (unsigned char **)&atoms)
430 != Success )
431 return;
432
433 if (actual_type == XA_ATOM && actual_format == 32)
434 for (int i = 0; i < nitems; i++)
435 if (XGetSelectionOwner (display, atoms[i]))
436 {
437 im_change_cb ();
438 break;
439 }
440
441 XFree (atoms);
442}
218#endif 443#endif
219 444
220void rxvt_display::x_cb (io_watcher &w, short revents) 445void rxvt_display::x_cb (io_watcher &w, short revents)
221{ 446{
222 do 447 do
223 { 448 {
224 XEvent xev; 449 XEvent xev;
225 XNextEvent (display, &xev); 450 XNextEvent (display, &xev);
226 451
227 //printf ("T %d w %lx\n", xev.type, xev.xany.window);//D
228
229#ifdef USE_XIM 452#ifdef USE_XIM
230 if (xev.type == PropertyNotify 453 if (!XFilterEvent (&xev, None))
231 && xev.xany.window == root
232 && xev.xproperty.atom == xa_xim_servers)
233 im_change_cb ();
234#endif
235
236 for (int i = xw.size (); i--; )
237 { 454 {
455 if (xev.type == PropertyNotify
456 && xev.xany.window == root
457 && xev.xproperty.atom == xa[XA_XIM_SERVERS])
458 im_change_check ();
459#endif
460 for (int i = xw.size (); i--; )
461 {
238 if (!xw[i]) 462 if (!xw[i])
239 xw.erase_unordered (i); 463 xw.erase_unordered (i);
240 else if (xw[i]->window == xev.xany.window) 464 else if (xw[i]->window == xev.xany.window)
241 xw[i]->call (xev); 465 xw[i]->call (xev);
466 }
467#ifdef USE_XIM
242 } 468 }
469#endif
243 } 470 }
244 while (XPending (display)); 471 while (XEventsQueued (display, QueuedAlready));
245 472
246 flush (); 473 XFlush (display);
247} 474}
248 475
249void rxvt_display::flush () 476void rxvt_display::flush ()
250{ 477{
251 for (;;) 478 if (XEventsQueued (display, QueuedAlready))
252 { 479 x_cb (x_ev, EVENT_READ);
253 if (!XPending (display))
254 break;
255 480
256 x_cb (x_ev, 0); 481 XFlush (display);
257 }
258} 482}
259 483
260void rxvt_display::reg (xevent_watcher *w) 484void rxvt_display::reg (xevent_watcher *w)
261{ 485{
262 xw.push_back (w); 486 xw.push_back (w);
309 return xim; 533 return xim;
310} 534}
311 535
312void rxvt_display::put_xim (rxvt_xim *xim) 536void rxvt_display::put_xim (rxvt_xim *xim)
313{ 537{
538#if XLIB_IS_RACEFREE
314 xims.put (xim); 539 xims.put (xim);
540#endif
315} 541}
316#endif 542#endif
317 543
318Atom rxvt_display::atom (const char *name) 544Atom rxvt_display::atom (const char *name)
319{ 545{
326refcache<rxvt_display> displays; 552refcache<rxvt_display> displays;
327 553
328///////////////////////////////////////////////////////////////////////////// 554/////////////////////////////////////////////////////////////////////////////
329 555
330bool 556bool
331rxvt_color::set (rxvt_display *display, Pixel p) 557rxvt_color::set (rxvt_screen *screen, const char *name)
332{ 558{
333#if XFT 559#if XFT
560 int l = strlen (name);
561 rxvt_rgba r;
562 char eos;
563 int mult;
564
565 // shortcutting this saves countless server RTTs for the built-in colours
566 if (l == 3+3*3 && 3 == sscanf (name, "rgb:%hx/%hx/%hx/%hx%c", &r.r, &r.g, &r.b, &r.a, &eos))
567 {
568 r.a = rxvt_rgba::MAX_CC;
569 mult = rxvt_rgba::MAX_CC / 0x00ff;
570 }
571
572 // parse a number of non-standard ARGB colour specifications
573 else if ( l == 1+4*1 && 4 == sscanf (name, "#%1hx%1hx%1hx%1hx%c", &r.a, &r.r, &r.g, &r.b, &eos))
574 mult = rxvt_rgba::MAX_CC / 0x000f;
575 else if (l == 1+4*2 && 4 == sscanf (name, "#%2hx%2hx%2hx%2hx%c", &r.a, &r.r, &r.g, &r.b, &eos))
576 mult = rxvt_rgba::MAX_CC / 0x00ff;
577 else if (l == 1+4*4 && 4 == sscanf (name, "#%4hx%4hx%4hx%4hx%c", &r.a, &r.r, &r.g, &r.b, &eos))
578 mult = rxvt_rgba::MAX_CC / 0xffff;
579 else if (l == 4+5*4 && 4 == sscanf (name, "rgba:%hx/%hx/%hx/%hx%c", &r.r, &r.g, &r.b, &r.a, &eos))
580 mult = rxvt_rgba::MAX_CC / 0xffff;
581
582 // slow case: server round trip
583 else
584 return XftColorAllocName (screen->xdisp, screen->visual, screen->cmap, name, &c);
585
586 r.r *= mult; r.g *= mult; r.b *= mult; r.a *= mult;
587
588 return set (screen, r);
589#else
334 XColor xc; 590 XColor xc;
335 591
336 xc.pixel = p; 592 if (XParseColor (screen->xdisp, screen->cmap, name, &xc))
337 if (!XQueryColor (display->display, display->cmap, &xc)) 593 return set (screen, rxvt_rgba (xc.red, xc.green, xc.blue));
594
338 return false; 595 return false;
596#endif
597}
339 598
599bool
600rxvt_color::set (rxvt_screen *screen, rxvt_rgba rgba)
601{
602#if XFT
603 XRenderPictFormat *format;
604
605 // FUCKING Xft gets it wrong, of course, so work around it
606 // transparency users should eat shit and die, and then
607 // XRenderQueryPictIndexValues themselves plenty.
608 if (screen->visual->c_class == TrueColor
609 && (format = XRenderFindVisualFormat (screen->xdisp, screen->visual)))
610 {
611 // the fun lies in doing everything manually...
612 c.color.red = rgba.r;
613 c.color.green = rgba.g;
614 c.color.blue = rgba.b;
615 c.color.alpha = rgba.a;
616
617 c.pixel = ((rgba.r * format->direct.redMask / rxvt_rgba::MAX_CC) << format->direct.red )
618 | ((rgba.g * format->direct.greenMask / rxvt_rgba::MAX_CC) << format->direct.green)
619 | ((rgba.b * format->direct.blueMask / rxvt_rgba::MAX_CC) << format->direct.blue )
620 | ((rgba.a * format->direct.alphaMask / rxvt_rgba::MAX_CC) << format->direct.alpha);
621
622 return true;
623 }
624 else
625 {
340 XRenderColor d; 626 XRenderColor d;
341 627
342 d.red = xc.red; 628 d.red = rgba.r;
343 d.green = xc.green; 629 d.green = rgba.g;
344 d.blue = xc.blue; 630 d.blue = rgba.b;
345 d.alpha = 0xffff; 631 d.alpha = rgba.a;
346 632
347 return 633 return XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c);
348 XftColorAllocValue (display->display, 634 }
349 display->visual, 635
350 display->cmap, 636 return false;
351 &d, &c);
352#else 637#else
353 this->p = p;
354#endif
355
356 return true;
357}
358
359bool
360rxvt_color::set (rxvt_display *display, const char *name)
361{
362 XColor xc; 638 XColor xc;
363 639
364 if (XParseColor (display->display, display->cmap, name, &xc)) 640 xc.red = rgba.r;
365 return set (display, xc.red, xc.green, xc.blue); 641 xc.green = rgba.g;
642 xc.blue = rgba.b;
643 xc.flags = DoRed | DoGreen | DoBlue;
644
645 if (XAllocColor (screen->xdisp, screen->cmap, &xc))
646 {
647 p = xc.pixel;
648 return true;
649 }
366 650
367 return false; 651 return false;
368} 652#endif
369
370bool
371rxvt_color::set (rxvt_display *display, unsigned short cr, unsigned short cg, unsigned short cb)
372{
373 XColor xc;
374
375 xc.red = cr;
376 xc.green = cg;
377 xc.blue = cb;
378 xc.flags = DoRed | DoGreen | DoBlue;
379
380 if (XAllocColor (display->display, display->cmap, &xc))
381 return set (display, xc.pixel);
382
383 return false;
384} 653}
385 654
386void 655void
387rxvt_color::get (rxvt_display *display, unsigned short &cr, unsigned short &cg, unsigned short &cb) 656rxvt_color::get (rxvt_screen *screen, rxvt_rgba &rgba)
388{ 657{
389#if XFT 658#if XFT
390 cr = c.color.red; 659 rgba.r = c.color.red;
391 cg = c.color.green; 660 rgba.g = c.color.green;
392 cb = c.color.blue; 661 rgba.b = c.color.blue;
662 rgba.a = c.color.alpha;
393#else 663#else
394 XColor c; 664 XColor c;
395 665
396 c.pixel = p; 666 c.pixel = p;
397 XQueryColor (display->display, display->cmap, &c); 667 XQueryColor (screen->xdisp, screen->cmap, &c);
398 668
399 cr = c.red; 669 rgba.r = c.red;
400 cg = c.green; 670 rgba.g = c.green;
401 cb = c.blue; 671 rgba.b = c.blue;
672 rgba.a = rxvt_rgba::MAX_CC;
402#endif 673#endif
403} 674}
404 675
405void 676void
406rxvt_color::free (rxvt_display *display) 677rxvt_color::free (rxvt_screen *screen)
407{ 678{
408#if XFT 679#if XFT
409 XftColorFree (display->display, display->visual, display->cmap, &c); 680 XftColorFree (screen->xdisp, screen->visual, screen->cmap, &c);
410#else 681#else
411 XFreeColors (display->display, display->cmap, &p, 1, AllPlanes); 682 XFreeColors (screen->xdisp, screen->cmap, &p, 1, AllPlanes);
412#endif 683#endif
413} 684}
414 685
415rxvt_color 686rxvt_color
416rxvt_color::fade (rxvt_display *display, int percent) 687rxvt_color::fade (rxvt_screen *screen, int percent)
417{ 688{
418 unsigned short cr, cg, cb;
419 rxvt_color faded; 689 rxvt_color faded;
420 690
421 get (display, cr, cg, cb); 691 rxvt_rgba c;
422 faded.set (display, 692 get (screen, c);
423 cr * percent / 100, 693
424 cg * percent / 100, 694 c.r = lerp (0, c.r, percent);
425 cb * percent / 100); 695 c.g = lerp (0, c.g, percent);
696 c.b = lerp (0, c.b, percent);
697
698 faded.set (screen, c);
426 699
427 return faded; 700 return faded;
428} 701}
429 702
703rxvt_color
704rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &fadeto)
705{
706 rxvt_rgba c, fc;
707 rxvt_color faded;
708
709 get (screen, c);
710 fadeto.get (screen, fc);
711
712 faded.set (
713 screen,
714 rxvt_rgba (
715 lerp (fc.r, c.r, percent),
716 lerp (fc.g, c.g, percent),
717 lerp (fc.b, c.b, percent),
718 lerp (fc.a, c.a, percent)
719 )
720 );
721
722 return faded;
723}
724

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines