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.19 by root, Mon Nov 28 19:04:39 2005 UTC

82 delete obj; 82 delete obj;
83 } 83 }
84} 84}
85 85
86template<class T> 86template<class T>
87refcache<T>::~refcache () 87void refcache<T>::clear ()
88{ 88{
89 while (this->size ()) 89 while (this->size ())
90 put (*this->begin ()); 90 put (*this->begin ());
91} 91}
92 92
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);
168 182
169 if (!getsockname (fd, (sockaddr *)&sa, &sl)) 183 if (!getsockname (fd, (sockaddr *)&sa, &sl))
170 is_local = sa.sun_family == AF_LOCAL; 184 is_local = sa.sun_family == AF_LOCAL;
185#endif
186
187#ifdef POINTER_BLANK
188 XColor blackcolour;
189 blackcolour.red = 0;
190 blackcolour.green = 0;
191 blackcolour.blue = 0;
192 Font f = XLoadFont (display, "fixed");
193 blank_cursor = XCreateGlyphCursor (display, f, f, ' ', ' ',
194 &blackcolour, &blackcolour);
195 XUnloadFont (display, f);
171#endif 196#endif
172 197
173#ifdef PREFER_24BIT 198#ifdef PREFER_24BIT
174 /* 199 /*
175 * If depth is not 24, look for a 24bit visual. 200 * If depth is not 24, look for a 24bit visual.
203} 228}
204 229
205rxvt_display::~rxvt_display () 230rxvt_display::~rxvt_display ()
206{ 231{
207 x_ev.stop (); 232 x_ev.stop ();
233#ifdef USE_XIM
234 xims.clear ();
235#endif
208 236
209 if (display) 237 if (display)
210 XCloseDisplay (display); 238 XCloseDisplay (display);
211} 239}
212 240
217 (*i)->call (); 245 (*i)->call ();
218} 246}
219 247
220void rxvt_display::im_change_check () 248void rxvt_display::im_change_check ()
221{ 249{
222 // make sure we only call im_change_cb when a new input method 250 // try to only call im_change_cb when a new input method
223 // registers, as xlib crashes due to a race otherwise. 251 // registers, as xlib crashes due to a race otherwise.
224 Atom actual_type, *atoms; 252 Atom actual_type, *atoms;
225 int actual_format; 253 int actual_format;
226 unsigned long nitems, bytes_after; 254 unsigned long nitems, bytes_after;
227 255
270 } 298 }
271#endif 299#endif
272 } 300 }
273 while (XEventsQueued (display, QueuedAlready)); 301 while (XEventsQueued (display, QueuedAlready));
274 302
275 flush (); 303 XFlush (display);
276} 304}
277 305
278void rxvt_display::flush () 306void rxvt_display::flush ()
279{ 307{
280 for (;;) 308 if (XEventsQueued (display, QueuedAlready))
281 { 309 x_cb (x_ev, EVENT_READ);
282 if (!XPending (display))
283 break;
284 310
285 x_cb (x_ev, 0); 311 XFlush (display);
286 }
287} 312}
288 313
289void rxvt_display::reg (xevent_watcher *w) 314void rxvt_display::reg (xevent_watcher *w)
290{ 315{
291 xw.push_back (w); 316 xw.push_back (w);
338 return xim; 363 return xim;
339} 364}
340 365
341void rxvt_display::put_xim (rxvt_xim *xim) 366void rxvt_display::put_xim (rxvt_xim *xim)
342{ 367{
368#if XLIB_IS_RACEFREE
343 xims.put (xim); 369 xims.put (xim);
370#endif
344} 371}
345#endif 372#endif
346 373
347Atom rxvt_display::atom (const char *name) 374Atom rxvt_display::atom (const char *name)
348{ 375{
386} 413}
387 414
388bool 415bool
389rxvt_color::set (rxvt_display *display, const char *name) 416rxvt_color::set (rxvt_display *display, const char *name)
390{ 417{
418#if XFT
419 return XftColorAllocName (display->display, display->visual, display->cmap,
420 name, &c);
421#else
391 XColor xc; 422 XColor xc;
392 423
393 if (XParseColor (display->display, display->cmap, name, &xc)) 424 if (XParseColor (display->display, display->cmap, name, &xc))
394 return set (display, xc.red, xc.green, xc.blue); 425 return set (display, xc.red, xc.green, xc.blue);
395 426
396 return false; 427 return false;
428#endif
397} 429}
398 430
399bool 431bool
400rxvt_color::set (rxvt_display *display, unsigned short cr, unsigned short cg, unsigned short cb) 432rxvt_color::set (rxvt_display *display, unsigned short cr, unsigned short cg, unsigned short cb)
401{ 433{
442} 474}
443 475
444rxvt_color 476rxvt_color
445rxvt_color::fade (rxvt_display *display, int percent) 477rxvt_color::fade (rxvt_display *display, int percent)
446{ 478{
479 percent = 100 - percent;
480
447 unsigned short cr, cg, cb; 481 unsigned short cr, cg, cb;
448 rxvt_color faded; 482 rxvt_color faded;
449 483
450 get (display, cr, cg, cb); 484 get (display, cr, cg, cb);
485
451 faded.set (display, 486 faded.set (
487 display,
452 cr * percent / 100, 488 cr * percent / 100,
453 cg * percent / 100, 489 cg * percent / 100,
454 cb * percent / 100); 490 cb * percent / 100
491 );
455 492
456 return faded; 493 return faded;
457} 494}
458 495
496#define LERP(a,b,p) (a * p + b * (100 - p)) / 100
497
498rxvt_color
499rxvt_color::fade (rxvt_display *display, int percent, rxvt_color &fadeto)
500{
501 percent = 100 - percent;
502
503 unsigned short cr, cg, cb;
504 unsigned short fcr, fcg, fcb;
505 rxvt_color faded;
506
507 get (display, cr, cg, cb);
508 fadeto.get(display, fcr, fcg, fcb);
509
510 faded.set (
511 display,
512 LERP (cr, fcr, percent),
513 LERP (cg, fcg, percent),
514 LERP (cb, fcb, percent)
515 );
516
517 return faded;
518}
519

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines