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.7 by root, Wed Dec 15 00:53:23 2004 UTC vs.
Revision 1.21 by root, Sun Jan 8 07:55:36 2006 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.
202 return true; 227 return true;
203} 228}
204 229
205rxvt_display::~rxvt_display () 230rxvt_display::~rxvt_display ()
206{ 231{
232#ifdef POINTER_BLANK
233 XFreeCursor (display, blank_cursor);
234#endif
207 x_ev.stop (); 235 x_ev.stop ();
236#ifdef USE_XIM
237 xims.clear ();
238#endif
208 239
209 if (display) 240 if (display)
210 XCloseDisplay (display); 241 XCloseDisplay (display);
211} 242}
212 243
217 (*i)->call (); 248 (*i)->call ();
218} 249}
219 250
220void rxvt_display::im_change_check () 251void rxvt_display::im_change_check ()
221{ 252{
222 // make sure we only call im_change_cb when a new input method 253 // try to only call im_change_cb when a new input method
223 // registers, as xlib crashes due to a race otherwise. 254 // registers, as xlib crashes due to a race otherwise.
224 Atom actual_type, *atoms; 255 Atom actual_type, *atoms;
225 int actual_format; 256 int actual_format;
226 unsigned long nitems, bytes_after; 257 unsigned long nitems, bytes_after;
227 258
251 XNextEvent (display, &xev); 282 XNextEvent (display, &xev);
252 283
253#ifdef USE_XIM 284#ifdef USE_XIM
254 if (!XFilterEvent (&xev, None)) 285 if (!XFilterEvent (&xev, None))
255 { 286 {
256
257 if (xev.type == PropertyNotify 287 if (xev.type == PropertyNotify
258 && xev.xany.window == root 288 && xev.xany.window == root
259 && xev.xproperty.atom == xa_xim_servers) 289 && xev.xproperty.atom == xa_xim_servers)
260 im_change_check (); 290 im_change_check ();
261#endif 291#endif
270 } 300 }
271#endif 301#endif
272 } 302 }
273 while (XEventsQueued (display, QueuedAlready)); 303 while (XEventsQueued (display, QueuedAlready));
274 304
275 flush (); 305 XFlush (display);
276} 306}
277 307
278void rxvt_display::flush () 308void rxvt_display::flush ()
279{ 309{
280 for (;;) 310 if (XEventsQueued (display, QueuedAlready))
281 { 311 x_cb (x_ev, EVENT_READ);
282 if (!XPending (display))
283 break;
284 312
285 x_cb (x_ev, 0); 313 XFlush (display);
286 }
287} 314}
288 315
289void rxvt_display::reg (xevent_watcher *w) 316void rxvt_display::reg (xevent_watcher *w)
290{ 317{
291 xw.push_back (w); 318 xw.push_back (w);
338 return xim; 365 return xim;
339} 366}
340 367
341void rxvt_display::put_xim (rxvt_xim *xim) 368void rxvt_display::put_xim (rxvt_xim *xim)
342{ 369{
370#if XLIB_IS_RACEFREE
343 xims.put (xim); 371 xims.put (xim);
372#endif
344} 373}
345#endif 374#endif
346 375
347Atom rxvt_display::atom (const char *name) 376Atom rxvt_display::atom (const char *name)
348{ 377{
447} 476}
448 477
449rxvt_color 478rxvt_color
450rxvt_color::fade (rxvt_display *display, int percent) 479rxvt_color::fade (rxvt_display *display, int percent)
451{ 480{
481 percent = 100 - percent;
482
452 unsigned short cr, cg, cb; 483 unsigned short cr, cg, cb;
453 rxvt_color faded; 484 rxvt_color faded;
454 485
455 get (display, cr, cg, cb); 486 get (display, cr, cg, cb);
487
456 faded.set (display, 488 faded.set (
489 display,
457 cr * percent / 100, 490 cr * percent / 100,
458 cg * percent / 100, 491 cg * percent / 100,
459 cb * percent / 100); 492 cb * percent / 100
493 );
460 494
461 return faded; 495 return faded;
462} 496}
463 497
498#define LERP(a,b,p) (a * p + b * (100 - p)) / 100
499
500rxvt_color
501rxvt_color::fade (rxvt_display *display, int percent, rxvt_color &fadeto)
502{
503 percent = 100 - percent;
504
505 unsigned short cr, cg, cb;
506 unsigned short fcr, fcg, fcb;
507 rxvt_color faded;
508
509 get (display, cr, cg, cb);
510 fadeto.get(display, fcr, fcg, fcb);
511
512 faded.set (
513 display,
514 LERP (cr, fcr, percent),
515 LERP (cg, fcg, percent),
516 LERP (cb, fcb, percent)
517 );
518
519 return faded;
520}
521

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines