… | |
… | |
32 | #ifndef NO_SLOW_LINK_SUPPORT |
32 | #ifndef NO_SLOW_LINK_SUPPORT |
33 | # include <sys/socket.h> |
33 | # include <sys/socket.h> |
34 | # include <sys/un.h> |
34 | # include <sys/un.h> |
35 | #endif |
35 | #endif |
36 | |
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 | |
37 | refcounted::refcounted (const char *id) |
75 | refcounted::refcounted (const char *id) |
38 | { |
76 | { |
39 | this->id = strdup (id); |
77 | this->id = strdup (id); |
40 | } |
78 | } |
41 | |
79 | |
… | |
… | |
139 | |
177 | |
140 | #endif |
178 | #endif |
141 | |
179 | |
142 | ///////////////////////////////////////////////////////////////////////////// |
180 | ///////////////////////////////////////////////////////////////////////////// |
143 | |
181 | |
|
|
182 | void |
|
|
183 | rxvt_screen::set (rxvt_display *disp) |
|
|
184 | { |
|
|
185 | display = disp; |
|
|
186 | xdisp = disp->display; |
|
|
187 | |
|
|
188 | Screen *screen = ScreenOfDisplay (xdisp, disp->screen); |
|
|
189 | |
|
|
190 | depth = DefaultDepthOfScreen (screen); |
|
|
191 | visual = DefaultVisualOfScreen (screen); |
|
|
192 | cmap = DefaultColormapOfScreen (screen); |
|
|
193 | } |
|
|
194 | |
|
|
195 | void |
|
|
196 | rxvt_screen::set (rxvt_display *disp, int bitdepth) |
|
|
197 | { |
|
|
198 | set (disp); |
|
|
199 | |
|
|
200 | XVisualInfo vinfo; |
|
|
201 | |
|
|
202 | if (XMatchVisualInfo (xdisp, display->screen, bitdepth, TrueColor, &vinfo)) |
|
|
203 | { |
|
|
204 | depth = bitdepth; |
|
|
205 | visual = vinfo.visual; |
|
|
206 | cmap = XCreateColormap (xdisp, disp->root, visual, AllocNone); |
|
|
207 | } |
|
|
208 | } |
|
|
209 | |
|
|
210 | void |
|
|
211 | rxvt_screen::clear () |
|
|
212 | { |
|
|
213 | if (cmap != DefaultColormapOfScreen (ScreenOfDisplay (xdisp, display->screen))) |
|
|
214 | XFreeColormap (xdisp, cmap); |
|
|
215 | } |
|
|
216 | |
|
|
217 | ///////////////////////////////////////////////////////////////////////////// |
|
|
218 | |
144 | rxvt_display::rxvt_display (const char *id) |
219 | rxvt_display::rxvt_display (const char *id) |
145 | : refcounted (id) |
220 | : refcounted (id) |
146 | , x_ev (this, &rxvt_display::x_cb) |
221 | , x_ev (this, &rxvt_display::x_cb) |
147 | , selection_owner (0) |
222 | , selection_owner (0) |
148 | { |
223 | { |
… | |
… | |
249 | if (!display) |
324 | if (!display) |
250 | return false; |
325 | return false; |
251 | |
326 | |
252 | screen = DefaultScreen (display); |
327 | screen = DefaultScreen (display); |
253 | root = DefaultRootWindow (display); |
328 | root = DefaultRootWindow (display); |
254 | visual = DefaultVisual (display, screen); |
329 | |
255 | cmap = DefaultColormap (display, screen); |
330 | assert (sizeof (xa_names) / sizeof (char *) == NUM_XA); |
256 | depth = DefaultDepth (display, screen); |
331 | XInternAtoms (display, (char **)xa_names, NUM_XA, False, xa); |
257 | |
332 | |
258 | XrmSetDatabase (display, get_resources ()); |
333 | XrmSetDatabase (display, get_resources ()); |
259 | |
334 | |
260 | #ifdef POINTER_BLANK |
335 | #ifdef POINTER_BLANK |
261 | XColor blackcolour; |
336 | XColor blackcolour; |
… | |
… | |
266 | blank_cursor = XCreateGlyphCursor (display, f, f, ' ', ' ', |
341 | blank_cursor = XCreateGlyphCursor (display, f, f, ' ', ' ', |
267 | &blackcolour, &blackcolour); |
342 | &blackcolour, &blackcolour); |
268 | XUnloadFont (display, f); |
343 | XUnloadFont (display, f); |
269 | #endif |
344 | #endif |
270 | |
345 | |
271 | #ifdef PREFER_24BIT |
|
|
272 | /* |
|
|
273 | * If depth is not 24, look for a 24bit visual. |
|
|
274 | */ |
|
|
275 | if (depth != 24) |
|
|
276 | { |
|
|
277 | XVisualInfo vinfo; |
|
|
278 | |
|
|
279 | if (XMatchVisualInfo (display, screen, 24, TrueColor, &vinfo)) |
|
|
280 | { |
|
|
281 | depth = 24; |
|
|
282 | visual = vinfo.visual; |
|
|
283 | cmap = XCreateColormap (display, |
|
|
284 | RootWindow (display, screen), |
|
|
285 | visual, AllocNone); |
|
|
286 | } |
|
|
287 | } |
|
|
288 | #endif |
|
|
289 | |
|
|
290 | int fd = XConnectionNumber (display); |
346 | int fd = XConnectionNumber (display); |
291 | |
347 | |
292 | #ifndef NO_SLOW_LINK_SUPPORT |
348 | #ifndef NO_SLOW_LINK_SUPPORT |
293 | // try to detect wether we have a local connection. |
349 | // try to detect wether we have a local connection. |
294 | // assume unix domains socket == local, everything else not |
350 | // assume unix domains socket == local, everything else not |
… | |
… | |
303 | |
359 | |
304 | x_ev.start (fd, EVENT_READ); |
360 | x_ev.start (fd, EVENT_READ); |
305 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
361 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
306 | |
362 | |
307 | XSelectInput (display, root, PropertyChangeMask); |
363 | XSelectInput (display, root, PropertyChangeMask); |
308 | #ifdef USE_XIM |
|
|
309 | xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0); |
|
|
310 | #endif |
|
|
311 | |
364 | |
312 | flush (); |
365 | flush (); |
313 | |
366 | |
314 | return true; |
367 | return true; |
315 | } |
368 | } |
… | |
… | |
351 | // registers, as xlib crashes due to a race otherwise. |
404 | // registers, as xlib crashes due to a race otherwise. |
352 | Atom actual_type, *atoms; |
405 | Atom actual_type, *atoms; |
353 | int actual_format; |
406 | int actual_format; |
354 | unsigned long nitems, bytes_after; |
407 | unsigned long nitems, bytes_after; |
355 | |
408 | |
356 | if (XGetWindowProperty (display, root, xa_xim_servers, 0L, 1000000L, |
409 | if (XGetWindowProperty (display, root, xa[XA_XIM_SERVERS], 0L, 1000000L, |
357 | False, XA_ATOM, &actual_type, &actual_format, |
410 | False, XA_ATOM, &actual_type, &actual_format, |
358 | &nitems, &bytes_after, (unsigned char **)&atoms) |
411 | &nitems, &bytes_after, (unsigned char **)&atoms) |
359 | != Success ) |
412 | != Success ) |
360 | return; |
413 | return; |
361 | |
414 | |
… | |
… | |
381 | #ifdef USE_XIM |
434 | #ifdef USE_XIM |
382 | if (!XFilterEvent (&xev, None)) |
435 | if (!XFilterEvent (&xev, None)) |
383 | { |
436 | { |
384 | if (xev.type == PropertyNotify |
437 | if (xev.type == PropertyNotify |
385 | && xev.xany.window == root |
438 | && xev.xany.window == root |
386 | && xev.xproperty.atom == xa_xim_servers) |
439 | && xev.xproperty.atom == xa[XA_XIM_SERVERS]) |
387 | im_change_check (); |
440 | im_change_check (); |
388 | #endif |
441 | #endif |
389 | for (int i = xw.size (); i--; ) |
442 | for (int i = xw.size (); i--; ) |
390 | { |
443 | { |
391 | if (!xw[i]) |
444 | if (!xw[i]) |
… | |
… | |
481 | refcache<rxvt_display> displays; |
534 | refcache<rxvt_display> displays; |
482 | |
535 | |
483 | ///////////////////////////////////////////////////////////////////////////// |
536 | ///////////////////////////////////////////////////////////////////////////// |
484 | |
537 | |
485 | bool |
538 | bool |
486 | rxvt_color::set (rxvt_display *display, Pixel p) |
539 | rxvt_color::set (rxvt_screen *screen, const char *name) |
487 | { |
540 | { |
488 | #if XFT |
541 | #if XFT |
489 | XColor xc; |
542 | int l = strlen (name); |
|
|
543 | rxvt_rgba r; |
|
|
544 | char eos; |
|
|
545 | int mult; |
490 | |
546 | |
491 | xc.pixel = p; |
547 | if ( l == 1+4*1 && 4 == sscanf (name, "#%1hx%1hx%1hx%1hx%c", &r.a, &r.r, &r.g, &r.b, &eos)) |
492 | if (!XQueryColor (display->display, display->cmap, &xc)) |
548 | mult = 0x1111; |
493 | return false; |
549 | else if (l == 1+4*2 && 4 == sscanf (name, "#%2hx%2hx%2hx%2hx%c", &r.a, &r.r, &r.g, &r.b, &eos)) |
|
|
550 | mult = 0x0101; |
|
|
551 | else if (l == 1+4*4 && 4 == sscanf (name, "#%4hx%4hx%4hx%4hx%c", &r.a, &r.r, &r.g, &r.b, &eos)) |
|
|
552 | mult = 0x0001; |
|
|
553 | else |
|
|
554 | return XftColorAllocName (screen->xdisp, screen->visual, screen->cmap, name, &c); |
494 | |
555 | |
495 | XRenderColor d; |
556 | r.r *= mult; r.g *= mult; r.b *= mult; r.a *= mult; |
496 | |
557 | return set (screen, r); |
497 | d.red = xc.red; |
|
|
498 | d.green = xc.green; |
|
|
499 | d.blue = xc.blue; |
|
|
500 | d.alpha = 0xffff; |
|
|
501 | |
|
|
502 | return |
|
|
503 | XftColorAllocValue (display->display, |
|
|
504 | display->visual, |
|
|
505 | display->cmap, |
|
|
506 | &d, &c); |
|
|
507 | #else |
|
|
508 | this->p = p; |
|
|
509 | #endif |
|
|
510 | |
|
|
511 | return true; |
|
|
512 | } |
|
|
513 | |
|
|
514 | bool |
|
|
515 | rxvt_color::set (rxvt_display *display, const char *name) |
|
|
516 | { |
|
|
517 | #if XFT |
|
|
518 | return XftColorAllocName (display->display, display->visual, display->cmap, |
|
|
519 | name, &c); |
|
|
520 | #else |
558 | #else |
521 | XColor xc; |
559 | XColor xc; |
522 | |
560 | |
523 | if (XParseColor (display->display, display->cmap, name, &xc)) |
561 | if (XParseColor (screen->xdisp, screen->cmap, name, &xc)) |
524 | return set (display, xc.red, xc.green, xc.blue); |
562 | return set (screen, rxvt_rgba (xc.red, xc.green, xc.blue)); |
525 | |
563 | |
526 | return false; |
564 | return false; |
527 | #endif |
565 | #endif |
528 | } |
566 | } |
529 | |
567 | |
530 | bool |
568 | bool |
531 | rxvt_color::set (rxvt_display *display, unsigned short cr, unsigned short cg, unsigned short cb) |
569 | rxvt_color::set (rxvt_screen *screen, rxvt_rgba rgba) |
532 | { |
570 | { |
|
|
571 | #if XFT |
|
|
572 | XRenderColor d; |
|
|
573 | |
|
|
574 | d.red = rgba.r; |
|
|
575 | d.green = rgba.g; |
|
|
576 | d.blue = rgba.b; |
|
|
577 | d.alpha = rgba.a; |
|
|
578 | |
|
|
579 | return XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c); |
|
|
580 | #else |
533 | XColor xc; |
581 | XColor xc; |
534 | |
582 | |
535 | xc.red = cr; |
583 | xc.red = rgba.r; |
536 | xc.green = cg; |
584 | xc.green = rgba.g; |
537 | xc.blue = cb; |
585 | xc.blue = rgba.b; |
538 | xc.flags = DoRed | DoGreen | DoBlue; |
586 | xc.flags = DoRed | DoGreen | DoBlue; |
539 | |
587 | |
540 | if (XAllocColor (display->display, display->cmap, &xc)) |
588 | if (XAllocColor (screen->xdisp, screen->cmap, &xc)) |
541 | return set (display, xc.pixel); |
589 | { |
|
|
590 | p = xc.pixel; |
|
|
591 | return true; |
|
|
592 | } |
542 | |
593 | |
543 | return false; |
594 | return false; |
|
|
595 | #endif |
544 | } |
596 | } |
545 | |
597 | |
546 | void |
598 | void |
547 | rxvt_color::get (rxvt_display *display, unsigned short &cr, unsigned short &cg, unsigned short &cb) |
599 | rxvt_color::get (rxvt_screen *screen, rxvt_rgba &rgba) |
548 | { |
600 | { |
549 | #if XFT |
601 | #if XFT |
550 | cr = c.color.red; |
602 | rgba.r = c.color.red; |
551 | cg = c.color.green; |
603 | rgba.g = c.color.green; |
552 | cb = c.color.blue; |
604 | rgba.b = c.color.blue; |
|
|
605 | rgba.a = c.color.alpha; |
553 | #else |
606 | #else |
554 | XColor c; |
607 | XColor c; |
555 | |
608 | |
556 | c.pixel = p; |
609 | c.pixel = p; |
557 | XQueryColor (display->display, display->cmap, &c); |
610 | XQueryColor (screen->xdisp, screen->cmap, &c); |
558 | |
611 | |
559 | cr = c.red; |
612 | rgba.r = c.red; |
560 | cg = c.green; |
613 | rgba.g = c.green; |
561 | cb = c.blue; |
614 | rgba.b = c.blue; |
|
|
615 | rgba.a = rxvt_rgba::MAX_CC; |
562 | #endif |
616 | #endif |
563 | } |
617 | } |
564 | |
618 | |
565 | void |
619 | void |
566 | rxvt_color::free (rxvt_display *display) |
620 | rxvt_color::free (rxvt_screen *screen) |
567 | { |
621 | { |
568 | #if XFT |
622 | #if XFT |
569 | XftColorFree (display->display, display->visual, display->cmap, &c); |
623 | XftColorFree (screen->xdisp, screen->visual, screen->cmap, &c); |
570 | #else |
624 | #else |
571 | XFreeColors (display->display, display->cmap, &p, 1, AllPlanes); |
625 | XFreeColors (screen->xdisp, screen->cmap, &p, 1, AllPlanes); |
572 | #endif |
626 | #endif |
573 | } |
627 | } |
574 | |
628 | |
575 | rxvt_color |
629 | rxvt_color |
576 | rxvt_color::fade (rxvt_display *display, int percent) |
630 | rxvt_color::fade (rxvt_screen *screen, int percent) |
577 | { |
631 | { |
578 | percent = 100 - percent; |
|
|
579 | |
|
|
580 | unsigned short cr, cg, cb; |
|
|
581 | rxvt_color faded; |
632 | rxvt_color faded; |
582 | |
633 | |
583 | get (display, cr, cg, cb); |
634 | rxvt_rgba c; |
|
|
635 | get (screen, c); |
584 | |
636 | |
585 | faded.set ( |
637 | c.r = lerp (0, c.r, percent); |
586 | display, |
638 | c.g = lerp (0, c.g, percent); |
587 | cr * percent / 100, |
639 | c.b = lerp (0, c.b, percent); |
588 | cg * percent / 100, |
640 | |
589 | cb * percent / 100 |
641 | faded.set (screen, c); |
590 | ); |
|
|
591 | |
642 | |
592 | return faded; |
643 | return faded; |
593 | } |
644 | } |
594 | |
645 | |
595 | #define LERP(a,b,p) (a * p + b * (100 - p)) / 100 |
|
|
596 | |
|
|
597 | rxvt_color |
646 | rxvt_color |
598 | rxvt_color::fade (rxvt_display *display, int percent, rxvt_color &fadeto) |
647 | rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &fadeto) |
599 | { |
648 | { |
600 | percent = 100 - percent; |
649 | rxvt_rgba c, fc; |
601 | |
|
|
602 | unsigned short cr, cg, cb; |
|
|
603 | unsigned short fcr, fcg, fcb; |
|
|
604 | rxvt_color faded; |
650 | rxvt_color faded; |
605 | |
651 | |
606 | get (display, cr, cg, cb); |
652 | get (screen, c); |
607 | fadeto.get(display, fcr, fcg, fcb); |
653 | fadeto.get (screen, fc); |
608 | |
654 | |
609 | faded.set ( |
655 | faded.set ( |
610 | display, |
656 | screen, |
|
|
657 | rxvt_rgba ( |
611 | LERP (cr, fcr, percent), |
658 | lerp (fc.r, c.r, percent), |
612 | LERP (cg, fcg, percent), |
659 | lerp (fc.g, c.g, percent), |
613 | LERP (cb, fcb, percent) |
660 | lerp (fc.b, c.b, percent), |
|
|
661 | lerp (fc.a, c.a, percent) |
|
|
662 | ) |
614 | ); |
663 | ); |
615 | |
664 | |
616 | return faded; |
665 | return faded; |
617 | } |
666 | } |
618 | |
667 | |