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.12 by root, Mon Jan 17 00:59:24 2005 UTC vs.
Revision 1.22 by root, Mon Jan 9 05:08:02 2006 UTC

143{ 143{
144} 144}
145 145
146bool rxvt_display::init () 146bool rxvt_display::init ()
147{ 147{
148#ifdef LOCAL_X_IS_UNIX
149 if (id[0] == ':')
150 {
151 val = rxvt_malloc (5 + strlen (id) + 1);
152 strcpy (val, "unix/");
153 strcat (val, id);
154 display = XOpenDisplay (val);
155 free (val);
156 }
157 else
158#endif
159 display = 0;
160
161 if (!display)
148 display = XOpenDisplay (id); 162 display = XOpenDisplay (id);
149 163
150 if (!display) 164 if (!display)
151 return false; 165 return false;
152 166
153 screen = DefaultScreen (display); 167 screen = DefaultScreen (display);
157 depth = DefaultDepth (display, screen); 171 depth = DefaultDepth (display, screen);
158 172
159 int fd = XConnectionNumber (display); 173 int fd = XConnectionNumber (display);
160 174
161#ifndef NO_SLOW_LINK_SUPPORT 175#ifndef NO_SLOW_LINK_SUPPORT
162 // try to detetc wether we have a local connection. 176 // try to detect wether we have a local connection.
163 // assume unix domains socket == local, everything else not 177 // assume unix domains socket == local, everything else not
164 // TODO: might want to check for inet/127.0.0.1 178 // TODO: might want to check for inet/127.0.0.1
165 is_local = 0; 179 is_local = 0;
166 sockaddr_un sa; 180 sockaddr_un sa;
167 socklen_t sl = sizeof (sa); 181 socklen_t sl = sizeof (sa);
213 return true; 227 return true;
214} 228}
215 229
216rxvt_display::~rxvt_display () 230rxvt_display::~rxvt_display ()
217{ 231{
232 if (!display)
233 return;
234
235#ifdef POINTER_BLANK
236 XFreeCursor (display, blank_cursor);
237#endif
218 x_ev.stop (); 238 x_ev.stop ();
219#ifdef USE_XIM 239#ifdef USE_XIM
220 xims.clear (); 240 xims.clear ();
221#endif 241#endif
222
223 if (display)
224 XCloseDisplay (display); 242 XCloseDisplay (display);
225} 243}
226 244
227#ifdef USE_XIM 245#ifdef USE_XIM
228void rxvt_display::im_change_cb () 246void rxvt_display::im_change_cb ()
229{ 247{
231 (*i)->call (); 249 (*i)->call ();
232} 250}
233 251
234void rxvt_display::im_change_check () 252void rxvt_display::im_change_check ()
235{ 253{
236 // make sure we only call im_change_cb when a new input method 254 // try to only call im_change_cb when a new input method
237 // registers, as xlib crashes due to a race otherwise. 255 // registers, as xlib crashes due to a race otherwise.
238 Atom actual_type, *atoms; 256 Atom actual_type, *atoms;
239 int actual_format; 257 int actual_format;
240 unsigned long nitems, bytes_after; 258 unsigned long nitems, bytes_after;
241 259
265 XNextEvent (display, &xev); 283 XNextEvent (display, &xev);
266 284
267#ifdef USE_XIM 285#ifdef USE_XIM
268 if (!XFilterEvent (&xev, None)) 286 if (!XFilterEvent (&xev, None))
269 { 287 {
270
271 if (xev.type == PropertyNotify 288 if (xev.type == PropertyNotify
272 && xev.xany.window == root 289 && xev.xany.window == root
273 && xev.xproperty.atom == xa_xim_servers) 290 && xev.xproperty.atom == xa_xim_servers)
274 im_change_check (); 291 im_change_check ();
275#endif 292#endif
460} 477}
461 478
462rxvt_color 479rxvt_color
463rxvt_color::fade (rxvt_display *display, int percent) 480rxvt_color::fade (rxvt_display *display, int percent)
464{ 481{
482 percent = 100 - percent;
483
465 unsigned short cr, cg, cb; 484 unsigned short cr, cg, cb;
466 rxvt_color faded; 485 rxvt_color faded;
467 486
468 get (display, cr, cg, cb); 487 get (display, cr, cg, cb);
488
469 faded.set (display, 489 faded.set (
490 display,
470 cr * percent / 100, 491 cr * percent / 100,
471 cg * percent / 100, 492 cg * percent / 100,
472 cb * percent / 100); 493 cb * percent / 100
494 );
473 495
474 return faded; 496 return faded;
475} 497}
476 498
499#define LERP(a,b,p) (a * p + b * (100 - p)) / 100
500
501rxvt_color
502rxvt_color::fade (rxvt_display *display, int percent, rxvt_color &fadeto)
503{
504 percent = 100 - percent;
505
506 unsigned short cr, cg, cb;
507 unsigned short fcr, fcg, fcb;
508 rxvt_color faded;
509
510 get (display, cr, cg, cb);
511 fadeto.get(display, fcr, fcg, fcb);
512
513 faded.set (
514 display,
515 LERP (cr, fcr, percent),
516 LERP (cg, fcg, percent),
517 LERP (cb, fcb, percent)
518 );
519
520 return faded;
521}
522

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines