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.6 by root, Sat Dec 11 17:18:29 2004 UTC vs.
Revision 1.34 by root, Mon Jan 30 02:21:20 2006 UTC

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
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)
107 164
108 display->xims.erase (find (display->xims.begin (), display->xims.end (), xim)); 165 display->xims.erase (find (display->xims.begin (), display->xims.end (), xim));
109 display->im_change_cb (); 166 display->im_change_cb ();
110} 167}
111 168
169bool
112bool rxvt_xim::init () 170rxvt_xim::ref_init ()
113{ 171{
114 display = GET_R->display; //HACK: TODO 172 display = GET_R->display; //HACK: TODO
115 173
116 xim = XOpenIM (display->display, NULL, NULL, NULL); 174 xim = XOpenIM (display->display, NULL, NULL, NULL);
117 175
130rxvt_xim::~rxvt_xim () 188rxvt_xim::~rxvt_xim ()
131{ 189{
132 if (xim) 190 if (xim)
133 XCloseIM (xim); 191 XCloseIM (xim);
134} 192}
193
135#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}
136 234
137///////////////////////////////////////////////////////////////////////////// 235/////////////////////////////////////////////////////////////////////////////
138 236
139rxvt_display::rxvt_display (const char *id) 237rxvt_display::rxvt_display (const char *id)
140: refcounted (id) 238: refcounted (id)
141, x_ev (this, &rxvt_display::x_cb) 239, x_ev (this, &rxvt_display::x_cb)
142, selection_owner (0) 240, selection_owner (0)
143{ 241{
144} 242}
145 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
146bool rxvt_display::init () 324bool rxvt_display::ref_init ()
147{ 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)
148 display = XOpenDisplay (id); 340 display = XOpenDisplay (id);
149 341
150 if (!display) 342 if (!display)
151 return false; 343 return false;
152 344
153 screen = DefaultScreen (display); 345 screen = DefaultScreen (display);
154 root = DefaultRootWindow (display); 346 root = DefaultRootWindow (display);
155 visual = DefaultVisual (display, screen); 347
156 cmap = DefaultColormap (display, screen); 348 assert (sizeof (xa_names) / sizeof (char *) == NUM_XA);
157 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
158 363
159 int fd = XConnectionNumber (display); 364 int fd = XConnectionNumber (display);
160 365
161#ifndef NO_SLOW_LINK_SUPPORT 366#ifndef NO_SLOW_LINK_SUPPORT
162 // try to detetc wether we have a local connection. 367 // try to detect wether we have a local connection.
163 // assume unix domains socket == local, everything else not 368 // assume unix domains socket == local, everything else not
164 // TODO: might want to check for inet/127.0.0.1 369 // TODO: might want to check for inet/127.0.0.1
165 is_local = 0; 370 is_local = 0;
166 sockaddr_un sa; 371 sockaddr_un sa;
167 socklen_t sl = sizeof (sa); 372 socklen_t sl = sizeof (sa);
168 373
169 if (!getsockname (fd, (sockaddr *)&sa, &sl)) 374 if (!getsockname (fd, (sockaddr *)&sa, &sl))
170 is_local = sa.sun_family == AF_LOCAL; 375 is_local = sa.sun_family == AF_LOCAL;
171#endif 376#endif
172 377
173#ifdef PREFER_24BIT
174 /*
175 * If depth is not 24, look for a 24bit visual.
176 */
177 if (depth != 24)
178 {
179 XVisualInfo vinfo;
180
181 if (XMatchVisualInfo (display, screen, 24, TrueColor, &vinfo))
182 {
183 depth = 24;
184 visual = vinfo.visual;
185 cmap = XCreateColormap (display,
186 RootWindow (display, screen),
187 visual, AllocNone);
188 }
189 }
190#endif
191
192 x_ev.start (fd, EVENT_READ); 378 x_ev.start (fd, EVENT_READ);
193 fcntl (fd, F_SETFD, FD_CLOEXEC); 379 fcntl (fd, F_SETFD, FD_CLOEXEC);
194 380
195 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 ();
196#ifdef USE_XIM 406#ifdef USE_XIM
197 xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0); 407 xims.clear ();
198#endif 408#endif
199
200 flush ();
201
202 return true;
203}
204
205rxvt_display::~rxvt_display ()
206{
207 x_ev.stop ();
208
209 if (display)
210 XCloseDisplay (display); 409 XCloseDisplay (display);
211} 410}
212 411
213#ifdef USE_XIM 412#ifdef USE_XIM
214void rxvt_display::im_change_cb () 413void rxvt_display::im_change_cb ()
215{ 414{
217 (*i)->call (); 416 (*i)->call ();
218} 417}
219 418
220void rxvt_display::im_change_check () 419void rxvt_display::im_change_check ()
221{ 420{
222 // make sure we only call im_change_cb when a new input method 421 // try to only call im_change_cb when a new input method
223 // registers, as xlib crashes due to a race otherwise. 422 // registers, as xlib crashes due to a race otherwise.
224 Atom actual_type, *atoms; 423 Atom actual_type, *atoms;
225 int actual_format; 424 int actual_format;
226 unsigned long nitems, bytes_after; 425 unsigned long nitems, bytes_after;
227 426
228 if (XGetWindowProperty (display, root, xa_xim_servers, 0L, 1000000L, 427 if (XGetWindowProperty (display, root, xa[XA_XIM_SERVERS], 0L, 1000000L,
229 False, XA_ATOM, &actual_type, &actual_format, 428 False, XA_ATOM, &actual_type, &actual_format,
230 &nitems, &bytes_after, (unsigned char **)&atoms) 429 &nitems, &bytes_after, (unsigned char **)&atoms)
231 != Success ) 430 != Success )
232 return; 431 return;
233 432
251 XNextEvent (display, &xev); 450 XNextEvent (display, &xev);
252 451
253#ifdef USE_XIM 452#ifdef USE_XIM
254 if (!XFilterEvent (&xev, None)) 453 if (!XFilterEvent (&xev, None))
255 { 454 {
256
257 if (xev.type == PropertyNotify 455 if (xev.type == PropertyNotify
258 && xev.xany.window == root 456 && xev.xany.window == root
259 && xev.xproperty.atom == xa_xim_servers) 457 && xev.xproperty.atom == xa[XA_XIM_SERVERS])
260 im_change_check (); 458 im_change_check ();
261#endif 459#endif
262 for (int i = xw.size (); i--; ) 460 for (int i = xw.size (); i--; )
263 { 461 {
264 if (!xw[i]) 462 if (!xw[i])
270 } 468 }
271#endif 469#endif
272 } 470 }
273 while (XEventsQueued (display, QueuedAlready)); 471 while (XEventsQueued (display, QueuedAlready));
274 472
275 flush (); 473 XFlush (display);
276} 474}
277 475
278void rxvt_display::flush () 476void rxvt_display::flush ()
279{ 477{
280 for (;;) 478 if (XEventsQueued (display, QueuedAlready))
281 { 479 x_cb (x_ev, EVENT_READ);
282 if (!XPending (display))
283 break;
284 480
285 x_cb (x_ev, 0); 481 XFlush (display);
286 }
287} 482}
288 483
289void rxvt_display::reg (xevent_watcher *w) 484void rxvt_display::reg (xevent_watcher *w)
290{ 485{
291 xw.push_back (w); 486 xw.push_back (w);
338 return xim; 533 return xim;
339} 534}
340 535
341void rxvt_display::put_xim (rxvt_xim *xim) 536void rxvt_display::put_xim (rxvt_xim *xim)
342{ 537{
538#if XLIB_IS_RACEFREE
343 xims.put (xim); 539 xims.put (xim);
540#endif
344} 541}
345#endif 542#endif
346 543
347Atom rxvt_display::atom (const char *name) 544Atom rxvt_display::atom (const char *name)
348{ 545{
355refcache<rxvt_display> displays; 552refcache<rxvt_display> displays;
356 553
357///////////////////////////////////////////////////////////////////////////// 554/////////////////////////////////////////////////////////////////////////////
358 555
359bool 556bool
360rxvt_color::set (rxvt_display *display, Pixel p) 557rxvt_color::set (rxvt_screen *screen, const char *name)
361{ 558{
362#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
363 XColor xc; 590 XColor xc;
364 591
365 xc.pixel = p; 592 if (XParseColor (screen->xdisp, screen->cmap, name, &xc))
366 if (!XQueryColor (display->display, display->cmap, &xc)) 593 return set (screen, rxvt_rgba (xc.red, xc.green, xc.blue));
594
367 return false; 595 return false;
596#endif
597}
368 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 {
369 XRenderColor d; 626 XRenderColor d;
370 627
371 d.red = xc.red; 628 d.red = rgba.r;
372 d.green = xc.green; 629 d.green = rgba.g;
373 d.blue = xc.blue; 630 d.blue = rgba.b;
374 d.alpha = 0xffff; 631 d.alpha = rgba.a;
375 632
376 return 633 return XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c);
377 XftColorAllocValue (display->display, 634 }
378 display->visual, 635
379 display->cmap, 636 return false;
380 &d, &c);
381#else 637#else
382 this->p = p;
383#endif
384
385 return true;
386}
387
388bool
389rxvt_color::set (rxvt_display *display, const char *name)
390{
391 XColor xc; 638 XColor xc;
392 639
393 if (XParseColor (display->display, display->cmap, name, &xc)) 640 xc.red = rgba.r;
394 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 }
395 650
396 return false; 651 return false;
397} 652#endif
398
399bool
400rxvt_color::set (rxvt_display *display, unsigned short cr, unsigned short cg, unsigned short cb)
401{
402 XColor xc;
403
404 xc.red = cr;
405 xc.green = cg;
406 xc.blue = cb;
407 xc.flags = DoRed | DoGreen | DoBlue;
408
409 if (XAllocColor (display->display, display->cmap, &xc))
410 return set (display, xc.pixel);
411
412 return false;
413} 653}
414 654
415void 655void
416rxvt_color::get (rxvt_display *display, unsigned short &cr, unsigned short &cg, unsigned short &cb) 656rxvt_color::get (rxvt_screen *screen, rxvt_rgba &rgba)
417{ 657{
418#if XFT 658#if XFT
419 cr = c.color.red; 659 rgba.r = c.color.red;
420 cg = c.color.green; 660 rgba.g = c.color.green;
421 cb = c.color.blue; 661 rgba.b = c.color.blue;
662 rgba.a = c.color.alpha;
422#else 663#else
423 XColor c; 664 XColor c;
424 665
425 c.pixel = p; 666 c.pixel = p;
426 XQueryColor (display->display, display->cmap, &c); 667 XQueryColor (screen->xdisp, screen->cmap, &c);
427 668
428 cr = c.red; 669 rgba.r = c.red;
429 cg = c.green; 670 rgba.g = c.green;
430 cb = c.blue; 671 rgba.b = c.blue;
672 rgba.a = rxvt_rgba::MAX_CC;
431#endif 673#endif
432} 674}
433 675
434void 676void
435rxvt_color::free (rxvt_display *display) 677rxvt_color::free (rxvt_screen *screen)
436{ 678{
437#if XFT 679#if XFT
438 XftColorFree (display->display, display->visual, display->cmap, &c); 680 XftColorFree (screen->xdisp, screen->visual, screen->cmap, &c);
439#else 681#else
440 XFreeColors (display->display, display->cmap, &p, 1, AllPlanes); 682 XFreeColors (screen->xdisp, screen->cmap, &p, 1, AllPlanes);
441#endif 683#endif
442} 684}
443 685
444rxvt_color 686rxvt_color
445rxvt_color::fade (rxvt_display *display, int percent) 687rxvt_color::fade (rxvt_screen *screen, int percent)
446{ 688{
447 unsigned short cr, cg, cb;
448 rxvt_color faded; 689 rxvt_color faded;
449 690
450 get (display, cr, cg, cb); 691 rxvt_rgba c;
451 faded.set (display, 692 get (screen, c);
452 cr * percent / 100, 693
453 cg * percent / 100, 694 c.r = lerp (0, c.r, percent);
454 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);
455 699
456 return faded; 700 return faded;
457} 701}
458 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