… | |
… | |
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 | const char *const xa_names[] = |
|
|
38 | { |
|
|
39 | "TEXT", |
|
|
40 | "COMPOUND_TEXT", |
|
|
41 | "UTF8_STRING", |
|
|
42 | "MULTIPLE", |
|
|
43 | "TARGETS", |
|
|
44 | "TIMESTAMP", |
|
|
45 | "VT_SELECTION", |
|
|
46 | "INCR", |
|
|
47 | "WM_PROTOCOLS", |
|
|
48 | "WM_DELETE_WINDOW", |
|
|
49 | "CLIPBOARD", |
|
|
50 | #if ENABLE_FRILLS |
|
|
51 | "_MOTIF_WM_HINTS", |
|
|
52 | #endif |
|
|
53 | #if ENABLE_EWMH |
|
|
54 | "_NET_WM_PID", |
|
|
55 | "_NET_WM_NAME", |
|
|
56 | "_NET_WM_ICON_NAME", |
|
|
57 | "_NET_WM_PING", |
|
|
58 | #endif |
|
|
59 | #if USE_XIM |
|
|
60 | "WM_LOCALE_NAME", |
|
|
61 | "XIM_SERVERS", |
|
|
62 | #endif |
|
|
63 | #ifdef TRANSPARENT |
|
|
64 | "_XROOTPMAP_ID", |
|
|
65 | "ESETROOT_PMAP_ID", |
|
|
66 | #endif |
|
|
67 | #if ENABLE_XEMBED |
|
|
68 | "_XEMBED", |
|
|
69 | "_XEMBED_INFO", |
|
|
70 | #endif |
|
|
71 | }; |
|
|
72 | |
|
|
73 | ///////////////////////////////////////////////////////////////////////////// |
|
|
74 | |
35 | refcounted::refcounted (const char *id) |
75 | refcounted::refcounted (const char *id) |
36 | { |
76 | { |
37 | this->id = strdup (id); |
77 | this->id = strdup (id); |
38 | } |
78 | } |
39 | |
79 | |
… | |
… | |
47 | { |
87 | { |
48 | for (T **i = this->begin (); i < this->end (); ++i) |
88 | for (T **i = this->begin (); i < this->end (); ++i) |
49 | { |
89 | { |
50 | if (!strcmp (id, (*i)->id)) |
90 | if (!strcmp (id, (*i)->id)) |
51 | { |
91 | { |
52 | (*i)->referenced++; |
92 | ++(*i)->referenced; |
|
|
93 | (*i)->ref_next (); |
53 | return *i; |
94 | return *i; |
54 | } |
95 | } |
55 | } |
96 | } |
56 | |
97 | |
57 | T *obj = new T (id); |
98 | T *obj = new T (id); |
58 | |
99 | |
59 | obj->referenced = 1; |
|
|
60 | |
|
|
61 | if (obj && obj->init ()) |
100 | if (obj && obj->ref_init ()) |
62 | { |
101 | { |
|
|
102 | obj->referenced = 1; |
63 | this->push_back (obj); |
103 | this->push_back (obj); |
64 | return obj; |
104 | return obj; |
65 | } |
105 | } |
66 | else |
106 | else |
67 | { |
107 | { |
… | |
… | |
91 | } |
131 | } |
92 | |
132 | |
93 | ///////////////////////////////////////////////////////////////////////////// |
133 | ///////////////////////////////////////////////////////////////////////////// |
94 | |
134 | |
95 | #ifdef USE_XIM |
135 | #ifdef USE_XIM |
|
|
136 | |
96 | static void |
137 | static void |
97 | #if XIMCB_PROTO_BROKEN |
138 | #if XIMCB_PROTO_BROKEN |
98 | im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3) |
139 | im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3) |
99 | #else |
140 | #else |
100 | im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3) |
141 | im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3) |
… | |
… | |
107 | |
148 | |
108 | display->xims.erase (find (display->xims.begin (), display->xims.end (), xim)); |
149 | display->xims.erase (find (display->xims.begin (), display->xims.end (), xim)); |
109 | display->im_change_cb (); |
150 | display->im_change_cb (); |
110 | } |
151 | } |
111 | |
152 | |
|
|
153 | bool |
112 | bool rxvt_xim::init () |
154 | rxvt_xim::ref_init () |
113 | { |
155 | { |
114 | display = GET_R->display; //HACK: TODO |
156 | display = GET_R->display; //HACK: TODO |
115 | |
157 | |
116 | xim = XOpenIM (display->display, NULL, NULL, NULL); |
158 | xim = XOpenIM (display->display, NULL, NULL, NULL); |
117 | |
159 | |
… | |
… | |
130 | rxvt_xim::~rxvt_xim () |
172 | rxvt_xim::~rxvt_xim () |
131 | { |
173 | { |
132 | if (xim) |
174 | if (xim) |
133 | XCloseIM (xim); |
175 | XCloseIM (xim); |
134 | } |
176 | } |
|
|
177 | |
135 | #endif |
178 | #endif |
|
|
179 | |
|
|
180 | ///////////////////////////////////////////////////////////////////////////// |
|
|
181 | |
|
|
182 | void |
|
|
183 | rxvt_screen::set (rxvt_display *disp) |
|
|
184 | { |
|
|
185 | display = disp; |
|
|
186 | |
|
|
187 | xdisp = disp->display; |
|
|
188 | |
|
|
189 | Screen *screen = ScreenOfDisplay (xdisp, disp->screen); |
|
|
190 | |
|
|
191 | depth = DefaultDepthOfScreen (screen); |
|
|
192 | visual = DefaultVisualOfScreen (screen); |
|
|
193 | cmap = DefaultColormapOfScreen (screen); |
|
|
194 | } |
|
|
195 | |
|
|
196 | void |
|
|
197 | rxvt_screen::set (rxvt_display *disp, int depth) |
|
|
198 | { |
|
|
199 | set (disp); |
|
|
200 | |
|
|
201 | XVisualInfo vinfo; |
|
|
202 | |
|
|
203 | if (XMatchVisualInfo (xdisp, display->screen, depth, TrueColor, &vinfo)) |
|
|
204 | { |
|
|
205 | this->depth = depth; |
|
|
206 | this->visual = vinfo.visual; |
|
|
207 | this->cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone); |
|
|
208 | } |
|
|
209 | } |
|
|
210 | |
|
|
211 | void |
|
|
212 | rxvt_screen::clear () |
|
|
213 | { |
|
|
214 | if (cmap != DefaultColormapOfScreen (ScreenOfDisplay (xdisp, display->screen))) |
|
|
215 | XFreeColormap (xdisp, cmap); |
|
|
216 | } |
136 | |
217 | |
137 | ///////////////////////////////////////////////////////////////////////////// |
218 | ///////////////////////////////////////////////////////////////////////////// |
138 | |
219 | |
139 | rxvt_display::rxvt_display (const char *id) |
220 | rxvt_display::rxvt_display (const char *id) |
140 | : refcounted (id) |
221 | : refcounted (id) |
141 | , x_ev (this, &rxvt_display::x_cb) |
222 | , x_ev (this, &rxvt_display::x_cb) |
142 | , selection_owner (0) |
223 | , selection_owner (0) |
143 | { |
224 | { |
144 | } |
225 | } |
145 | |
226 | |
|
|
227 | XrmDatabase |
|
|
228 | rxvt_display::get_resources () |
|
|
229 | { |
|
|
230 | char *homedir = (char *)getenv ("HOME"); |
|
|
231 | char fname[1024]; |
|
|
232 | |
|
|
233 | /* |
|
|
234 | * get resources using the X library function |
|
|
235 | */ |
|
|
236 | char *displayResource, *xe; |
|
|
237 | XrmDatabase database, rdb1; |
|
|
238 | |
|
|
239 | database = NULL; |
|
|
240 | |
|
|
241 | // for ordering, see for example http://www.faqs.org/faqs/Xt-FAQ/ Subject: 20 |
|
|
242 | |
|
|
243 | // 6. System wide per application default file. |
|
|
244 | |
|
|
245 | /* Add in $XAPPLRESDIR/Rxvt only; not bothering with XUSERFILESEARCHPATH */ |
|
|
246 | if ((xe = (char *)getenv ("XAPPLRESDIR"))) |
|
|
247 | { |
|
|
248 | snprintf (fname, sizeof (fname), "%s/%s", xe, RESCLASS); |
|
|
249 | |
|
|
250 | if ((rdb1 = XrmGetFileDatabase (fname))) |
|
|
251 | XrmMergeDatabases (rdb1, &database); |
|
|
252 | } |
|
|
253 | |
|
|
254 | // 5. User's per application default file. |
|
|
255 | // none |
|
|
256 | |
|
|
257 | // 4. User's defaults file. |
|
|
258 | /* Get any Xserver defaults */ |
|
|
259 | displayResource = XResourceManagerString (display); |
|
|
260 | |
|
|
261 | if (displayResource != NULL) |
|
|
262 | { |
|
|
263 | if ((rdb1 = XrmGetStringDatabase (displayResource))) |
|
|
264 | XrmMergeDatabases (rdb1, &database); |
|
|
265 | } |
|
|
266 | else if (homedir) |
|
|
267 | { |
|
|
268 | snprintf (fname, sizeof (fname), "%s/.Xdefaults", homedir); |
|
|
269 | |
|
|
270 | if ((rdb1 = XrmGetFileDatabase (fname))) |
|
|
271 | XrmMergeDatabases (rdb1, &database); |
|
|
272 | } |
|
|
273 | |
|
|
274 | /* Get screen specific resources */ |
|
|
275 | displayResource = XScreenResourceString (ScreenOfDisplay (display, screen)); |
|
|
276 | |
|
|
277 | if (displayResource != NULL) |
|
|
278 | { |
|
|
279 | if ((rdb1 = XrmGetStringDatabase (displayResource))) |
|
|
280 | /* Merge with screen-independent resources */ |
|
|
281 | XrmMergeDatabases (rdb1, &database); |
|
|
282 | |
|
|
283 | XFree (displayResource); |
|
|
284 | } |
|
|
285 | |
|
|
286 | // 3. User's per host defaults file |
|
|
287 | /* Add in XENVIRONMENT file */ |
|
|
288 | if ((xe = (char *)getenv ("XENVIRONMENT")) |
|
|
289 | && (rdb1 = XrmGetFileDatabase (xe))) |
|
|
290 | XrmMergeDatabases (rdb1, &database); |
|
|
291 | else if (homedir) |
|
|
292 | { |
|
|
293 | struct utsname un; |
|
|
294 | |
|
|
295 | if (!uname (&un)) |
|
|
296 | { |
|
|
297 | snprintf (fname, sizeof (fname), "%s/.Xdefaults-%s", homedir, un.nodename); |
|
|
298 | |
|
|
299 | if ((rdb1 = XrmGetFileDatabase (fname))) |
|
|
300 | XrmMergeDatabases (rdb1, &database); |
|
|
301 | } |
|
|
302 | } |
|
|
303 | |
|
|
304 | return database; |
|
|
305 | } |
|
|
306 | |
146 | bool rxvt_display::init () |
307 | bool rxvt_display::ref_init () |
147 | { |
308 | { |
|
|
309 | #ifdef LOCAL_X_IS_UNIX |
|
|
310 | if (id[0] == ':') |
|
|
311 | { |
|
|
312 | val = rxvt_malloc (5 + strlen (id) + 1); |
|
|
313 | strcpy (val, "unix/"); |
|
|
314 | strcat (val, id); |
|
|
315 | display = XOpenDisplay (val); |
|
|
316 | free (val); |
|
|
317 | } |
|
|
318 | else |
|
|
319 | #endif |
|
|
320 | display = 0; |
|
|
321 | |
|
|
322 | if (!display) |
148 | display = XOpenDisplay (id); |
323 | display = XOpenDisplay (id); |
149 | |
324 | |
150 | if (!display) |
325 | if (!display) |
151 | return false; |
326 | return false; |
152 | |
327 | |
153 | screen = DefaultScreen (display); |
328 | screen = DefaultScreen (display); |
154 | root = DefaultRootWindow (display); |
329 | root = DefaultRootWindow (display); |
155 | visual = DefaultVisual (display, screen); |
|
|
156 | cmap = DefaultColormap (display, screen); |
|
|
157 | depth = DefaultDepth (display, screen); |
|
|
158 | |
330 | |
159 | int fd = XConnectionNumber (display); |
331 | assert (sizeof (xa_names) / sizeof (char *) == NUM_XA); |
|
|
332 | XInternAtoms (display, (char **)xa_names, NUM_XA, False, xa); |
160 | |
333 | |
161 | #ifndef NO_SLOW_LINK_SUPPORT |
334 | XrmSetDatabase (display, get_resources ()); |
162 | // try to detetc wether we have a local connection. |
|
|
163 | // assume unix domains socket == local, everything else not |
|
|
164 | // TODO: might want to check for inet/127.0.0.1 |
|
|
165 | is_local = 0; |
|
|
166 | sockaddr_un sa; |
|
|
167 | socklen_t sl = sizeof (sa); |
|
|
168 | |
|
|
169 | if (!getsockname (fd, (sockaddr *)&sa, &sl)) |
|
|
170 | is_local = sa.sun_family == AF_LOCAL; |
|
|
171 | #endif |
|
|
172 | |
335 | |
173 | #ifdef POINTER_BLANK |
336 | #ifdef POINTER_BLANK |
174 | XColor blackcolour; |
337 | XColor blackcolour; |
175 | blackcolour.red = 0; |
338 | blackcolour.red = 0; |
176 | blackcolour.green = 0; |
339 | blackcolour.green = 0; |
… | |
… | |
179 | blank_cursor = XCreateGlyphCursor (display, f, f, ' ', ' ', |
342 | blank_cursor = XCreateGlyphCursor (display, f, f, ' ', ' ', |
180 | &blackcolour, &blackcolour); |
343 | &blackcolour, &blackcolour); |
181 | XUnloadFont (display, f); |
344 | XUnloadFont (display, f); |
182 | #endif |
345 | #endif |
183 | |
346 | |
184 | #ifdef PREFER_24BIT |
347 | int fd = XConnectionNumber (display); |
185 | /* |
|
|
186 | * If depth is not 24, look for a 24bit visual. |
|
|
187 | */ |
|
|
188 | if (depth != 24) |
|
|
189 | { |
|
|
190 | XVisualInfo vinfo; |
|
|
191 | |
348 | |
192 | if (XMatchVisualInfo (display, screen, 24, TrueColor, &vinfo)) |
349 | #ifndef NO_SLOW_LINK_SUPPORT |
193 | { |
350 | // try to detect wether we have a local connection. |
194 | depth = 24; |
351 | // assume unix domains socket == local, everything else not |
195 | visual = vinfo.visual; |
352 | // TODO: might want to check for inet/127.0.0.1 |
196 | cmap = XCreateColormap (display, |
353 | is_local = 0; |
197 | RootWindow (display, screen), |
354 | sockaddr_un sa; |
198 | visual, AllocNone); |
355 | socklen_t sl = sizeof (sa); |
199 | } |
356 | |
200 | } |
357 | if (!getsockname (fd, (sockaddr *)&sa, &sl)) |
|
|
358 | is_local = sa.sun_family == AF_LOCAL; |
201 | #endif |
359 | #endif |
202 | |
360 | |
203 | x_ev.start (fd, EVENT_READ); |
361 | x_ev.start (fd, EVENT_READ); |
204 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
362 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
205 | |
363 | |
206 | XSelectInput (display, root, PropertyChangeMask); |
364 | XSelectInput (display, root, PropertyChangeMask); |
207 | #ifdef USE_XIM |
|
|
208 | xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0); |
|
|
209 | #endif |
|
|
210 | |
365 | |
211 | flush (); |
366 | flush (); |
212 | |
367 | |
213 | return true; |
368 | return true; |
214 | } |
369 | } |
215 | |
370 | |
|
|
371 | void |
|
|
372 | rxvt_display::ref_next () |
|
|
373 | { |
|
|
374 | // TODO: somehow check wether the database files/resources changed |
|
|
375 | // before re-loading/parsing |
|
|
376 | XrmDestroyDatabase (XrmGetDatabase (display)); |
|
|
377 | XrmSetDatabase (display, get_resources ()); |
|
|
378 | } |
|
|
379 | |
216 | rxvt_display::~rxvt_display () |
380 | rxvt_display::~rxvt_display () |
217 | { |
381 | { |
|
|
382 | if (!display) |
|
|
383 | return; |
|
|
384 | |
|
|
385 | #ifdef POINTER_BLANK |
|
|
386 | XFreeCursor (display, blank_cursor); |
|
|
387 | #endif |
218 | x_ev.stop (); |
388 | x_ev.stop (); |
219 | #ifdef USE_XIM |
389 | #ifdef USE_XIM |
220 | xims.clear (); |
390 | xims.clear (); |
221 | #endif |
391 | #endif |
222 | |
|
|
223 | if (display) |
|
|
224 | XCloseDisplay (display); |
392 | XCloseDisplay (display); |
225 | } |
393 | } |
226 | |
394 | |
227 | #ifdef USE_XIM |
395 | #ifdef USE_XIM |
228 | void rxvt_display::im_change_cb () |
396 | void rxvt_display::im_change_cb () |
229 | { |
397 | { |
… | |
… | |
237 | // registers, as xlib crashes due to a race otherwise. |
405 | // registers, as xlib crashes due to a race otherwise. |
238 | Atom actual_type, *atoms; |
406 | Atom actual_type, *atoms; |
239 | int actual_format; |
407 | int actual_format; |
240 | unsigned long nitems, bytes_after; |
408 | unsigned long nitems, bytes_after; |
241 | |
409 | |
242 | if (XGetWindowProperty (display, root, xa_xim_servers, 0L, 1000000L, |
410 | if (XGetWindowProperty (display, root, xa[XA_XIM_SERVERS], 0L, 1000000L, |
243 | False, XA_ATOM, &actual_type, &actual_format, |
411 | False, XA_ATOM, &actual_type, &actual_format, |
244 | &nitems, &bytes_after, (unsigned char **)&atoms) |
412 | &nitems, &bytes_after, (unsigned char **)&atoms) |
245 | != Success ) |
413 | != Success ) |
246 | return; |
414 | return; |
247 | |
415 | |
… | |
… | |
265 | XNextEvent (display, &xev); |
433 | XNextEvent (display, &xev); |
266 | |
434 | |
267 | #ifdef USE_XIM |
435 | #ifdef USE_XIM |
268 | if (!XFilterEvent (&xev, None)) |
436 | if (!XFilterEvent (&xev, None)) |
269 | { |
437 | { |
270 | |
|
|
271 | if (xev.type == PropertyNotify |
438 | if (xev.type == PropertyNotify |
272 | && xev.xany.window == root |
439 | && xev.xany.window == root |
273 | && xev.xproperty.atom == xa_xim_servers) |
440 | && xev.xproperty.atom == xa[XA_XIM_SERVERS]) |
274 | im_change_check (); |
441 | im_change_check (); |
275 | #endif |
442 | #endif |
276 | for (int i = xw.size (); i--; ) |
443 | for (int i = xw.size (); i--; ) |
277 | { |
444 | { |
278 | if (!xw[i]) |
445 | if (!xw[i]) |
… | |
… | |
368 | refcache<rxvt_display> displays; |
535 | refcache<rxvt_display> displays; |
369 | |
536 | |
370 | ///////////////////////////////////////////////////////////////////////////// |
537 | ///////////////////////////////////////////////////////////////////////////// |
371 | |
538 | |
372 | bool |
539 | bool |
373 | rxvt_color::set (rxvt_display *display, Pixel p) |
540 | rxvt_color::set (rxvt_screen *screen, Pixel p) |
374 | { |
541 | { |
375 | #if XFT |
542 | #if XFT |
376 | XColor xc; |
543 | XColor xc; |
377 | |
544 | |
378 | xc.pixel = p; |
545 | xc.pixel = p; |
379 | if (!XQueryColor (display->display, display->cmap, &xc)) |
546 | if (!XQueryColor (screen->xdisp, screen->cmap, &xc)) |
380 | return false; |
547 | return false; |
381 | |
548 | |
382 | XRenderColor d; |
549 | XRenderColor d; |
383 | |
550 | |
384 | d.red = xc.red; |
551 | d.red = xc.red; |
385 | d.green = xc.green; |
552 | d.green = xc.green; |
386 | d.blue = xc.blue; |
553 | d.blue = xc.blue; |
387 | d.alpha = 0xffff; |
554 | d.alpha = 0xffff; |
388 | |
555 | |
389 | return |
556 | return |
390 | XftColorAllocValue (display->display, |
557 | XftColorAllocValue (screen->xdisp, |
391 | display->visual, |
558 | screen->visual, |
392 | display->cmap, |
559 | screen->cmap, |
393 | &d, &c); |
560 | &d, &c); |
394 | #else |
561 | #else |
395 | this->p = p; |
562 | this->p = p; |
396 | #endif |
563 | #endif |
397 | |
564 | |
398 | return true; |
565 | return true; |
399 | } |
566 | } |
400 | |
567 | |
401 | bool |
568 | bool |
402 | rxvt_color::set (rxvt_display *display, const char *name) |
569 | rxvt_color::set (rxvt_screen *screen, const char *name) |
403 | { |
570 | { |
404 | #if XFT |
571 | #if XFT |
405 | return XftColorAllocName (display->display, display->visual, display->cmap, |
572 | return XftColorAllocName (screen->xdisp, screen->visual, screen->cmap, name, &c); |
406 | name, &c); |
|
|
407 | #else |
573 | #else |
408 | XColor xc; |
574 | XColor xc; |
409 | |
575 | |
410 | if (XParseColor (display->display, display->cmap, name, &xc)) |
576 | if (XParseColor (screen->xdisp, screen->cmap, name, &xc)) |
411 | return set (display, xc.red, xc.green, xc.blue); |
577 | return set (screen, xc.red, xc.green, xc.blue); |
412 | |
578 | |
413 | return false; |
579 | return false; |
414 | #endif |
580 | #endif |
415 | } |
581 | } |
416 | |
582 | |
417 | bool |
583 | bool |
418 | rxvt_color::set (rxvt_display *display, unsigned short cr, unsigned short cg, unsigned short cb) |
584 | rxvt_color::set (rxvt_screen *screen, unsigned short cr, unsigned short cg, unsigned short cb) |
419 | { |
585 | { |
420 | XColor xc; |
586 | XColor xc; |
421 | |
587 | |
422 | xc.red = cr; |
588 | xc.red = cr; |
423 | xc.green = cg; |
589 | xc.green = cg; |
424 | xc.blue = cb; |
590 | xc.blue = cb; |
425 | xc.flags = DoRed | DoGreen | DoBlue; |
591 | xc.flags = DoRed | DoGreen | DoBlue; |
426 | |
592 | |
427 | if (XAllocColor (display->display, display->cmap, &xc)) |
593 | if (XAllocColor (screen->xdisp, screen->cmap, &xc)) |
428 | return set (display, xc.pixel); |
594 | return set (screen, xc.pixel); |
429 | |
595 | |
430 | return false; |
596 | return false; |
431 | } |
597 | } |
432 | |
598 | |
433 | void |
599 | void |
434 | rxvt_color::get (rxvt_display *display, unsigned short &cr, unsigned short &cg, unsigned short &cb) |
600 | rxvt_color::get (rxvt_screen *screen, unsigned short &cr, unsigned short &cg, unsigned short &cb) |
435 | { |
601 | { |
436 | #if XFT |
602 | #if XFT |
437 | cr = c.color.red; |
603 | cr = c.color.red; |
438 | cg = c.color.green; |
604 | cg = c.color.green; |
439 | cb = c.color.blue; |
605 | cb = c.color.blue; |
440 | #else |
606 | #else |
441 | XColor c; |
607 | XColor c; |
442 | |
608 | |
443 | c.pixel = p; |
609 | c.pixel = p; |
444 | XQueryColor (display->display, display->cmap, &c); |
610 | XQueryColor (screen->xdisp, screen->cmap, &c); |
445 | |
611 | |
446 | cr = c.red; |
612 | cr = c.red; |
447 | cg = c.green; |
613 | cg = c.green; |
448 | cb = c.blue; |
614 | cb = c.blue; |
449 | #endif |
615 | #endif |
450 | } |
616 | } |
451 | |
617 | |
452 | void |
618 | void |
453 | rxvt_color::free (rxvt_display *display) |
619 | rxvt_color::free (rxvt_screen *screen) |
454 | { |
620 | { |
455 | #if XFT |
621 | #if XFT |
456 | XftColorFree (display->display, display->visual, display->cmap, &c); |
622 | XftColorFree (screen->xdisp, screen->visual, screen->cmap, &c); |
457 | #else |
623 | #else |
458 | XFreeColors (display->display, display->cmap, &p, 1, AllPlanes); |
624 | XFreeColors (screen->xdisp, screen->cmap, &p, 1, AllPlanes); |
459 | #endif |
625 | #endif |
460 | } |
626 | } |
461 | |
627 | |
462 | rxvt_color |
628 | rxvt_color |
463 | rxvt_color::fade (rxvt_display *display, int percent) |
629 | rxvt_color::fade (rxvt_screen *screen, int percent) |
464 | { |
630 | { |
|
|
631 | percent = 100 - percent; |
|
|
632 | |
465 | unsigned short cr, cg, cb; |
633 | unsigned short cr, cg, cb; |
466 | rxvt_color faded; |
634 | rxvt_color faded; |
467 | |
635 | |
468 | get (display, cr, cg, cb); |
636 | get (screen, cr, cg, cb); |
|
|
637 | |
469 | faded.set (display, |
638 | faded.set ( |
|
|
639 | screen, |
470 | cr * percent / 100, |
640 | cr * percent / 100, |
471 | cg * percent / 100, |
641 | cg * percent / 100, |
472 | cb * percent / 100); |
642 | cb * percent / 100 |
|
|
643 | ); |
473 | |
644 | |
474 | return faded; |
645 | return faded; |
475 | } |
646 | } |
476 | |
647 | |
|
|
648 | #define LERP(a,b,p) (a * p + b * (100 - p)) / 100 |
|
|
649 | |
|
|
650 | rxvt_color |
|
|
651 | rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &fadeto) |
|
|
652 | { |
|
|
653 | percent = 100 - percent; |
|
|
654 | |
|
|
655 | unsigned short cr, cg, cb; |
|
|
656 | unsigned short fcr, fcg, fcb; |
|
|
657 | rxvt_color faded; |
|
|
658 | |
|
|
659 | get (screen, cr, cg, cb); |
|
|
660 | fadeto.get (screen, fcr, fcg, fcb); |
|
|
661 | |
|
|
662 | faded.set ( |
|
|
663 | screen, |
|
|
664 | LERP (cr, fcr, percent), |
|
|
665 | LERP (cg, fcg, percent), |
|
|
666 | LERP (cb, fcb, percent) |
|
|
667 | ); |
|
|
668 | |
|
|
669 | return faded; |
|
|
670 | } |
|
|
671 | |