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 | * |
… | |
… | |
32 | # include <sys/un.h> |
32 | # include <sys/un.h> |
33 | #endif |
33 | #endif |
34 | |
34 | |
35 | refcounted::refcounted (const char *id) |
35 | refcounted::refcounted (const char *id) |
36 | { |
36 | { |
37 | this->id = STRDUP (id); |
37 | this->id = strdup (id); |
38 | } |
38 | } |
39 | |
39 | |
40 | refcounted::~refcounted () |
40 | refcounted::~refcounted () |
41 | { |
41 | { |
42 | free (id); |
42 | free (id); |
… | |
… | |
101 | #endif |
101 | #endif |
102 | { |
102 | { |
103 | rxvt_xim *xim = (rxvt_xim *)client_data; |
103 | rxvt_xim *xim = (rxvt_xim *)client_data; |
104 | rxvt_display *display = xim->display; |
104 | rxvt_display *display = xim->display; |
105 | |
105 | |
|
|
106 | xim->xim = 0; |
|
|
107 | |
106 | display->xims.erase (find (display->xims.begin (), display->xims.end (), xim)); |
108 | display->xims.erase (find (display->xims.begin (), display->xims.end (), xim)); |
107 | |
|
|
108 | display->im_change_cb (); |
109 | display->im_change_cb (); |
109 | } |
110 | } |
110 | |
111 | |
111 | bool rxvt_xim::init () |
112 | bool rxvt_xim::init () |
112 | { |
113 | { |
… | |
… | |
213 | void rxvt_display::im_change_cb () |
214 | void rxvt_display::im_change_cb () |
214 | { |
215 | { |
215 | for (im_watcher **i = imw.begin (); i != imw.end (); ++i) |
216 | for (im_watcher **i = imw.begin (); i != imw.end (); ++i) |
216 | (*i)->call (); |
217 | (*i)->call (); |
217 | } |
218 | } |
|
|
219 | |
|
|
220 | void rxvt_display::im_change_check () |
|
|
221 | { |
|
|
222 | // make sure we only call im_change_cb when a new input method |
|
|
223 | // registers, as xlib crashes due to a race otherwise. |
|
|
224 | Atom actual_type, *atoms; |
|
|
225 | int actual_format; |
|
|
226 | unsigned long nitems, bytes_after; |
|
|
227 | |
|
|
228 | if (XGetWindowProperty (display, root, xa_xim_servers, 0L, 1000000L, |
|
|
229 | False, XA_ATOM, &actual_type, &actual_format, |
|
|
230 | &nitems, &bytes_after, (unsigned char **)&atoms) |
|
|
231 | != Success ) |
|
|
232 | return; |
|
|
233 | |
|
|
234 | if (actual_type == XA_ATOM && actual_format == 32) |
|
|
235 | for (int i = 0; i < nitems; i++) |
|
|
236 | if (XGetSelectionOwner (display, atoms[i])) |
|
|
237 | { |
|
|
238 | im_change_cb (); |
|
|
239 | break; |
|
|
240 | } |
|
|
241 | |
|
|
242 | XFree (atoms); |
|
|
243 | } |
218 | #endif |
244 | #endif |
219 | |
245 | |
220 | void rxvt_display::x_cb (io_watcher &w, short revents) |
246 | void rxvt_display::x_cb (io_watcher &w, short revents) |
221 | { |
247 | { |
222 | do |
248 | do |
223 | { |
249 | { |
224 | XEvent xev; |
250 | XEvent xev; |
225 | XNextEvent (display, &xev); |
251 | XNextEvent (display, &xev); |
226 | |
252 | |
227 | //printf ("T %d w %lx\n", xev.type, xev.xany.window);//D |
|
|
228 | |
|
|
229 | #ifdef USE_XIM |
253 | #ifdef USE_XIM |
230 | if (xev.type == PropertyNotify |
254 | 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 | { |
255 | { |
|
|
256 | |
|
|
257 | if (xev.type == PropertyNotify |
|
|
258 | && xev.xany.window == root |
|
|
259 | && xev.xproperty.atom == xa_xim_servers) |
|
|
260 | im_change_check (); |
|
|
261 | #endif |
|
|
262 | for (int i = xw.size (); i--; ) |
|
|
263 | { |
238 | if (!xw[i]) |
264 | if (!xw[i]) |
239 | xw.erase_unordered (i); |
265 | xw.erase_unordered (i); |
240 | else if (xw[i]->window == xev.xany.window) |
266 | else if (xw[i]->window == xev.xany.window) |
241 | xw[i]->call (xev); |
267 | xw[i]->call (xev); |
|
|
268 | } |
|
|
269 | #ifdef USE_XIM |
242 | } |
270 | } |
|
|
271 | #endif |
243 | } |
272 | } |
244 | while (XPending (display)); |
273 | while (XEventsQueued (display, QueuedAlready)); |
245 | |
274 | |
246 | flush (); |
275 | flush (); |
247 | } |
276 | } |
248 | |
277 | |
249 | void rxvt_display::flush () |
278 | void rxvt_display::flush () |
… | |
… | |
357 | } |
386 | } |
358 | |
387 | |
359 | bool |
388 | bool |
360 | rxvt_color::set (rxvt_display *display, const char *name) |
389 | rxvt_color::set (rxvt_display *display, const char *name) |
361 | { |
390 | { |
|
|
391 | #if XFT |
|
|
392 | return XftColorAllocName (display->display, display->visual, display->cmap, |
|
|
393 | name, &c); |
|
|
394 | #else |
362 | XColor xc; |
395 | XColor xc; |
363 | |
396 | |
364 | if (XParseColor (display->display, display->cmap, name, &xc)) |
397 | if (XParseColor (display->display, display->cmap, name, &xc)) |
365 | return set (display, xc.red, xc.green, xc.blue); |
398 | return set (display, xc.red, xc.green, xc.blue); |
366 | |
399 | |
367 | return false; |
400 | return false; |
|
|
401 | #endif |
368 | } |
402 | } |
369 | |
403 | |
370 | bool |
404 | bool |
371 | rxvt_color::set (rxvt_display *display, unsigned short cr, unsigned short cg, unsigned short cb) |
405 | rxvt_color::set (rxvt_display *display, unsigned short cr, unsigned short cg, unsigned short cb) |
372 | { |
406 | { |