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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines