1 | /*----------------------------------------------------------------------* |
1 | /*----------------------------------------------------------------------* |
2 | * File: rxvttoolkit.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-2006 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2003-2007 Marc Lehmann <pcg@goof.com> |
7 | * |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
… | |
… | |
64 | #endif |
64 | #endif |
65 | #if USE_XIM |
65 | #if USE_XIM |
66 | "WM_LOCALE_NAME", |
66 | "WM_LOCALE_NAME", |
67 | "XIM_SERVERS", |
67 | "XIM_SERVERS", |
68 | #endif |
68 | #endif |
69 | #ifdef TRANSPARENT |
69 | #ifdef ENABLE_TRANSPARENCY |
70 | "_XROOTPMAP_ID", |
70 | "_XROOTPMAP_ID", |
71 | "ESETROOT_PMAP_ID", |
71 | "ESETROOT_PMAP_ID", |
72 | #endif |
72 | #endif |
73 | #if ENABLE_XEMBED |
73 | #if ENABLE_XEMBED |
74 | "_XEMBED", |
74 | "_XEMBED", |
… | |
… | |
183 | |
183 | |
184 | XIMCallback ximcallback; |
184 | XIMCallback ximcallback; |
185 | ximcallback.client_data = (XPointer)this; |
185 | ximcallback.client_data = (XPointer)this; |
186 | ximcallback.callback = im_destroy_cb; |
186 | ximcallback.callback = im_destroy_cb; |
187 | |
187 | |
188 | XSetIMValues (xim, XNDestroyCallback, &ximcallback, 0); |
188 | XSetIMValues (xim, XNDestroyCallback, &ximcallback, (char *)0); |
189 | |
189 | |
190 | return true; |
190 | return true; |
191 | } |
191 | } |
192 | |
192 | |
193 | rxvt_xim::~rxvt_xim () |
193 | rxvt_xim::~rxvt_xim () |
… | |
… | |
262 | visual = DefaultVisualOfScreen (screen); |
262 | visual = DefaultVisualOfScreen (screen); |
263 | cmap = DefaultColormapOfScreen (screen); |
263 | cmap = DefaultColormapOfScreen (screen); |
264 | } |
264 | } |
265 | |
265 | |
266 | void |
266 | void |
267 | rxvt_screen::set (rxvt_display *disp, int bitdepth) |
267 | rxvt_screen::select_visual (int bitdepth) |
268 | { |
268 | { |
269 | set (disp); |
|
|
270 | |
|
|
271 | #if XFT |
269 | #if XFT |
272 | XVisualInfo vinfo; |
270 | XVisualInfo vinfo; |
273 | |
271 | |
274 | if (XMatchVisualInfo (dpy, display->screen, bitdepth, TrueColor, &vinfo)) |
272 | if (XMatchVisualInfo (dpy, display->screen, bitdepth, TrueColor, &vinfo)) |
275 | { |
273 | { |
276 | depth = bitdepth; |
274 | depth = bitdepth; |
277 | visual = vinfo.visual; |
275 | visual = vinfo.visual; |
278 | cmap = XCreateColormap (dpy, disp->root, visual, AllocNone); |
276 | cmap = XCreateColormap (dpy, display->root, visual, AllocNone); |
279 | } |
277 | } |
280 | #endif |
278 | #endif |
281 | } |
279 | } |
282 | |
280 | |
283 | void |
281 | void |
… | |
… | |
297 | |
295 | |
298 | ///////////////////////////////////////////////////////////////////////////// |
296 | ///////////////////////////////////////////////////////////////////////////// |
299 | |
297 | |
300 | rxvt_display::rxvt_display (const char *id) |
298 | rxvt_display::rxvt_display (const char *id) |
301 | : refcounted (id) |
299 | : refcounted (id) |
302 | , x_ev (this, &rxvt_display::x_cb) |
|
|
303 | , selection_owner (0) |
300 | , selection_owner (0) |
304 | { |
301 | { |
|
|
302 | x_ev .set<rxvt_display, &rxvt_display::x_cb > (this); |
|
|
303 | flush_ev.set<rxvt_display, &rxvt_display::flush_cb> (this); |
305 | } |
304 | } |
306 | |
305 | |
307 | XrmDatabase |
306 | XrmDatabase |
308 | rxvt_display::get_resources (bool refresh) |
307 | rxvt_display::get_resources (bool refresh) |
309 | { |
308 | { |
310 | char *homedir = (char *)getenv ("HOME"); |
309 | char *homedir = getenv ("HOME"); |
311 | char fname[1024]; |
310 | char fname[1024]; |
312 | |
311 | |
313 | /* |
312 | /* |
314 | * get resources using the X library function |
313 | * get resources using the X library function |
315 | */ |
314 | */ |
316 | char *displayResource, *xe; |
315 | char *displayResource, *xe; |
317 | XrmDatabase rdb1, database = 0; |
316 | XrmDatabase rdb1, database = 0; |
318 | |
317 | |
319 | // for ordering, see for example http://www.faqs.org/faqs/Xt-FAQ/ Subject: 20 |
318 | // for ordering, see for example http://www.faqs.org/faqs/Xt-FAQ/ Subject: 20 |
|
|
319 | // as opposed to "standard practise", we always read in ~/.Xdefaults |
320 | |
320 | |
321 | // 6. System wide per application default file. |
321 | // 6. System wide per application default file. |
322 | |
322 | |
323 | /* Add in $XAPPLRESDIR/Rxvt only; not bothering with XUSERFILESEARCHPATH */ |
323 | /* Add in $XAPPLRESDIR/Rxvt only; not bothering with XUSERFILESEARCHPATH */ |
324 | if ((xe = (char *)getenv ("XAPPLRESDIR"))) |
324 | if ((xe = getenv ("XAPPLRESDIR"))) |
325 | { |
325 | { |
326 | snprintf (fname, sizeof (fname), "%s/%s", xe, RESCLASS); |
326 | snprintf (fname, sizeof (fname), "%s/%s", xe, RESCLASS); |
327 | |
327 | |
328 | if ((rdb1 = XrmGetFileDatabase (fname))) |
328 | if ((rdb1 = XrmGetFileDatabase (fname))) |
329 | XrmMergeDatabases (rdb1, &database); |
329 | XrmMergeDatabases (rdb1, &database); |
… | |
… | |
331 | |
331 | |
332 | // 5. User's per application default file. |
332 | // 5. User's per application default file. |
333 | // none |
333 | // none |
334 | |
334 | |
335 | // 4. User's defaults file. |
335 | // 4. User's defaults file. |
|
|
336 | if (homedir) |
|
|
337 | { |
|
|
338 | snprintf (fname, sizeof (fname), "%s/.Xdefaults", homedir); |
|
|
339 | |
|
|
340 | if ((rdb1 = XrmGetFileDatabase (fname))) |
|
|
341 | XrmMergeDatabases (rdb1, &database); |
|
|
342 | } |
|
|
343 | |
336 | /* Get any Xserver defaults */ |
344 | /* Get any Xserver defaults */ |
337 | if (refresh) |
345 | if (refresh) |
338 | { |
346 | { |
339 | // fucking xlib keeps a copy of the rm string |
347 | // fucking xlib keeps a copy of the rm string |
340 | Atom actual_type; |
348 | Atom actual_type; |
… | |
… | |
356 | && actual_format == 8) |
364 | && actual_format == 8) |
357 | displayResource = val; |
365 | displayResource = val; |
358 | else |
366 | else |
359 | { |
367 | { |
360 | displayResource = 0; |
368 | displayResource = 0; |
|
|
369 | |
361 | if (val) |
370 | if (val) |
362 | XFree(val); |
371 | XFree(val); |
363 | } |
372 | } |
364 | |
373 | |
365 | #if XLIB_ILLEGAL_ACCESS |
374 | #if XLIB_ILLEGAL_ACCESS |
… | |
… | |
372 | if (displayResource) |
381 | if (displayResource) |
373 | { |
382 | { |
374 | if ((rdb1 = XrmGetStringDatabase (displayResource))) |
383 | if ((rdb1 = XrmGetStringDatabase (displayResource))) |
375 | XrmMergeDatabases (rdb1, &database); |
384 | XrmMergeDatabases (rdb1, &database); |
376 | } |
385 | } |
377 | else if (homedir) |
|
|
378 | { |
|
|
379 | snprintf (fname, sizeof (fname), "%s/.Xdefaults", homedir); |
|
|
380 | |
|
|
381 | if ((rdb1 = XrmGetFileDatabase (fname))) |
|
|
382 | XrmMergeDatabases (rdb1, &database); |
|
|
383 | } |
|
|
384 | |
386 | |
385 | #if !XLIB_ILLEGAL_ACCESS |
387 | #if !XLIB_ILLEGAL_ACCESS |
386 | if (refresh && displayResource) |
388 | if (refresh && displayResource) |
387 | XFree (displayResource); |
389 | XFree (displayResource); |
388 | #endif |
390 | #endif |
… | |
… | |
399 | XFree (displayResource); |
401 | XFree (displayResource); |
400 | } |
402 | } |
401 | |
403 | |
402 | // 3. User's per host defaults file |
404 | // 3. User's per host defaults file |
403 | /* Add in XENVIRONMENT file */ |
405 | /* Add in XENVIRONMENT file */ |
404 | if ((xe = (char *)getenv ("XENVIRONMENT")) |
406 | if ((xe = getenv ("XENVIRONMENT")) |
405 | && (rdb1 = XrmGetFileDatabase (xe))) |
407 | && (rdb1 = XrmGetFileDatabase (xe))) |
406 | XrmMergeDatabases (rdb1, &database); |
408 | XrmMergeDatabases (rdb1, &database); |
407 | else if (homedir) |
409 | else if (homedir) |
408 | { |
410 | { |
409 | struct utsname un; |
411 | struct utsname un; |
… | |
… | |
461 | #endif |
463 | #endif |
462 | |
464 | |
463 | int fd = XConnectionNumber (dpy); |
465 | int fd = XConnectionNumber (dpy); |
464 | |
466 | |
465 | // try to detect wether we have a local connection. |
467 | // try to detect wether we have a local connection. |
466 | // assume unix domains socket == local, everything else not |
468 | // assume unix domain socket == local, everything else not |
467 | // TODO: might want to check for inet/127.0.0.1 |
469 | // TODO: might want to check for inet/127.0.0.1 |
468 | is_local = 0; |
470 | is_local = 0; |
469 | sockaddr_un sa; |
471 | sockaddr_un sa; |
470 | socklen_t sl = sizeof (sa); |
472 | socklen_t sl = sizeof (sa); |
471 | |
473 | |
472 | if (!getsockname (fd, (sockaddr *)&sa, &sl)) |
474 | if (!getsockname (fd, (sockaddr *)&sa, &sl)) |
473 | is_local = sa.sun_family == AF_LOCAL; |
475 | is_local = sa.sun_family == AF_UNIX; |
474 | |
476 | |
|
|
477 | flush_ev.start (); |
475 | x_ev.start (fd, EVENT_READ); |
478 | x_ev.start (fd, ev::READ); |
476 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
479 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
477 | |
480 | |
478 | XSelectInput (dpy, root, PropertyChangeMask); |
481 | XSelectInput (dpy, root, PropertyChangeMask); |
479 | |
482 | |
480 | flush (); |
483 | flush (); |
… | |
… | |
498 | |
501 | |
499 | #ifdef POINTER_BLANK |
502 | #ifdef POINTER_BLANK |
500 | XFreeCursor (dpy, blank_cursor); |
503 | XFreeCursor (dpy, blank_cursor); |
501 | #endif |
504 | #endif |
502 | x_ev.stop (); |
505 | x_ev.stop (); |
|
|
506 | flush_ev.stop (); |
503 | #ifdef USE_XIM |
507 | #ifdef USE_XIM |
504 | xims.clear (); |
508 | xims.clear (); |
505 | #endif |
509 | #endif |
506 | XCloseDisplay (dpy); |
510 | XCloseDisplay (dpy); |
507 | } |
511 | } |
… | |
… | |
537 | |
541 | |
538 | XFree (atoms); |
542 | XFree (atoms); |
539 | } |
543 | } |
540 | #endif |
544 | #endif |
541 | |
545 | |
542 | void rxvt_display::x_cb (io_watcher &w, short revents) |
546 | void rxvt_display::x_cb (ev::io &w, int revents) |
543 | { |
547 | { |
544 | do |
548 | while (XEventsQueued (dpy, QueuedAfterReading)) |
545 | { |
549 | { |
546 | XEvent xev; |
550 | XEvent xev; |
547 | XNextEvent (dpy, &xev); |
551 | XNextEvent (dpy, &xev); |
548 | |
552 | |
|
|
553 | flush_ev.start (); |
|
|
554 | |
549 | #ifdef USE_XIM |
555 | #ifdef USE_XIM |
550 | if (!XFilterEvent (&xev, None)) |
556 | if (!XFilterEvent (&xev, None)) |
|
|
557 | #endif |
551 | { |
558 | { |
552 | if (xev.type == PropertyNotify |
559 | if (xev.type == PropertyNotify |
553 | && xev.xany.window == root |
560 | && xev.xany.window == root |
554 | && xev.xproperty.atom == xa[XA_XIM_SERVERS]) |
561 | && xev.xproperty.atom == xa[XA_XIM_SERVERS]) |
555 | im_change_check (); |
562 | im_change_check (); |
556 | #endif |
563 | if (xev.type == MappingNotify) |
|
|
564 | XRefreshKeyboardMapping (&xev.xmapping); |
|
|
565 | |
557 | for (int i = xw.size (); i--; ) |
566 | for (int i = xw.size (); i--; ) |
558 | { |
567 | { |
559 | if (!xw[i]) |
568 | if (!xw[i]) |
560 | xw.erase_unordered (i); |
569 | xw.erase_unordered (i); |
561 | else if (xw[i]->window == xev.xany.window) |
570 | else if (xw[i]->window == xev.xany.window) |
562 | xw[i]->call (xev); |
571 | xw[i]->call (xev); |
563 | } |
572 | } |
564 | #ifdef USE_XIM |
|
|
565 | } |
573 | } |
566 | #endif |
|
|
567 | } |
574 | } |
568 | while (XEventsQueued (dpy, QueuedAlready)); |
|
|
569 | |
575 | |
570 | XFlush (dpy); |
576 | XFlush (dpy); |
571 | } |
577 | } |
572 | |
578 | |
573 | void rxvt_display::flush () |
579 | void rxvt_display::flush_cb (ev::idle &w, int revents) |
574 | { |
580 | { |
575 | if (XEventsQueued (dpy, QueuedAlready)) |
|
|
576 | x_cb (x_ev, EVENT_READ); |
|
|
577 | |
|
|
578 | XFlush (dpy); |
581 | XFlush (dpy); |
579 | } |
582 | } |
580 | |
583 | |
581 | void rxvt_display::reg (xevent_watcher *w) |
584 | void rxvt_display::reg (xevent_watcher *w) |
582 | { |
585 | { |
|
|
586 | if (!w->active) |
|
|
587 | { |
583 | xw.push_back (w); |
588 | xw.push_back (w); |
584 | w->active = xw.size (); |
589 | w->active = xw.size (); |
|
|
590 | } |
585 | } |
591 | } |
586 | |
592 | |
587 | void rxvt_display::unreg (xevent_watcher *w) |
593 | void rxvt_display::unreg (xevent_watcher *w) |
588 | { |
594 | { |
589 | if (w->active) |
595 | if (w->active) |
|
|
596 | { |
590 | xw[w->active - 1] = 0; |
597 | xw[w->active - 1] = 0; |
|
|
598 | w->active = 0; |
|
|
599 | } |
591 | } |
600 | } |
592 | |
601 | |
593 | void rxvt_display::set_selection_owner (rxvt_term *owner) |
602 | void rxvt_display::set_selection_owner (rxvt_term *owner) |
594 | { |
603 | { |
595 | if (selection_owner && selection_owner != owner) |
604 | if (selection_owner && selection_owner != owner) |
|
|
605 | { |
|
|
606 | rxvt_term *owner = selection_owner; |
|
|
607 | |
596 | selection_owner->selection_clear (); |
608 | owner->selection_clear (); |
|
|
609 | owner->flush (); |
|
|
610 | } |
597 | |
611 | |
598 | selection_owner = owner; |
612 | selection_owner = owner; |
599 | } |
613 | } |
600 | |
614 | |
601 | #ifdef USE_XIM |
615 | #ifdef USE_XIM |
… | |
… | |
656 | static unsigned int |
670 | static unsigned int |
657 | insert_component (unsigned int value, unsigned int mask, unsigned int shift) |
671 | insert_component (unsigned int value, unsigned int mask, unsigned int shift) |
658 | { |
672 | { |
659 | return (value * (mask + 1) >> 16) << shift; |
673 | return (value * (mask + 1) >> 16) << shift; |
660 | } |
674 | } |
661 | |
675 | |
662 | bool |
676 | bool |
663 | rxvt_color::alloc (rxvt_screen *screen, const rgba &color) |
677 | rxvt_color::alloc (rxvt_screen *screen, const rgba &color) |
664 | { |
678 | { |
|
|
679 | //TODO: only supports 24 bit |
|
|
680 | int alpha = color.a >= 0xff00 ? 0xffff : color.a; |
|
|
681 | |
665 | #if XFT |
682 | #if XFT |
666 | XRenderPictFormat *format; |
683 | XRenderPictFormat *format; |
667 | |
684 | |
668 | // FUCKING Xft gets it wrong, of course, so work around it. |
685 | // FUCKING Xft gets it wrong, of course, so work around it. |
669 | // Transparency users should eat shit and die, and then |
686 | // Transparency users should eat shit and die, and then |
… | |
… | |
673 | { |
690 | { |
674 | // the fun lies in doing everything manually... |
691 | // the fun lies in doing everything manually... |
675 | c.color.red = color.r; |
692 | c.color.red = color.r; |
676 | c.color.green = color.g; |
693 | c.color.green = color.g; |
677 | c.color.blue = color.b; |
694 | c.color.blue = color.b; |
678 | c.color.alpha = color.a; |
695 | c.color.alpha = alpha; |
679 | |
696 | |
680 | c.pixel = insert_component (color.r, format->direct.redMask , format->direct.red ) |
697 | c.pixel = insert_component (color.r, format->direct.redMask , format->direct.red ) |
681 | | insert_component (color.g, format->direct.greenMask, format->direct.green) |
698 | | insert_component (color.g, format->direct.greenMask, format->direct.green) |
682 | | insert_component (color.b, format->direct.blueMask , format->direct.blue ) |
699 | | insert_component (color.b, format->direct.blueMask , format->direct.blue ) |
683 | | insert_component (color.a, format->direct.alphaMask, format->direct.alpha); |
700 | | insert_component (alpha , format->direct.alphaMask, format->direct.alpha); |
684 | |
701 | |
685 | return true; |
702 | return true; |
686 | } |
703 | } |
687 | else |
704 | else |
688 | { |
705 | { |
689 | XRenderColor d; |
706 | XRenderColor d; |
690 | |
707 | |
691 | d.red = color.r; |
708 | d.red = color.r; |
692 | d.green = color.g; |
709 | d.green = color.g; |
693 | d.blue = color.b; |
710 | d.blue = color.b; |
694 | d.alpha = color.a; |
711 | d.alpha = alpha; |
695 | |
712 | |
696 | return XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c); |
713 | return XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c); |
697 | } |
714 | } |
698 | #else |
715 | #else |
699 | c.red = color.r; |
716 | c.red = color.r; |
700 | c.green = color.g; |
717 | c.green = color.g; |
701 | c.blue = color.b; |
718 | c.blue = color.b; |
702 | |
719 | |
703 | if (screen->visual->c_class == TrueColor) |
720 | if (screen->visual->c_class == TrueColor) |
704 | { |
721 | { |
705 | c.pixel = (color.r * (screen->visual->red_mask >> ctz (screen->visual->red_mask )) |
722 | c.pixel = (color.r >> (16 - popcount (screen->visual->red_mask )) << ctz (screen->visual->red_mask )) |
706 | / rgba::MAX_CC) << ctz (screen->visual->red_mask ) |
723 | | (color.g >> (16 - popcount (screen->visual->green_mask)) << ctz (screen->visual->green_mask)) |
707 | | (color.g * (screen->visual->green_mask >> ctz (screen->visual->green_mask)) |
|
|
708 | / rgba::MAX_CC) << ctz (screen->visual->green_mask) |
|
|
709 | | (color.b * (screen->visual->blue_mask >> ctz (screen->visual->blue_mask )) |
724 | | (color.b >> (16 - popcount (screen->visual->blue_mask )) << ctz (screen->visual->blue_mask )); |
710 | / rgba::MAX_CC) << ctz (screen->visual->blue_mask ); |
|
|
711 | |
725 | |
712 | return true; |
726 | return true; |
713 | } |
727 | } |
714 | else if (XAllocColor (screen->dpy, screen->cmap, &c)) |
728 | else if (XAllocColor (screen->dpy, screen->cmap, &c)) |
715 | return true; |
729 | return true; |
… | |
… | |
727 | { |
741 | { |
728 | rgba c; |
742 | rgba c; |
729 | char eos; |
743 | char eos; |
730 | int skip; |
744 | int skip; |
731 | |
745 | |
|
|
746 | c.a = rgba::MAX_CC; |
|
|
747 | |
732 | // parse the nonstandard "[alphapercent]" prefix |
748 | // parse the nonstandard "[alphapercent]" prefix |
733 | if (1 <= sscanf (name, "[%hd]%n", &c.a, &skip)) |
749 | if (1 <= sscanf (name, "[%hd]%n", &c.a, &skip)) |
734 | { |
750 | { |
735 | c.a = lerp<int, int, int> (0, rgba::MAX_CC, c.a); |
751 | c.a = lerp<int, int, int> (0, rgba::MAX_CC, c.a); |
736 | name += skip; |
752 | name += skip; |
737 | } |
753 | } |
738 | else |
|
|
739 | c.a = rgba::MAX_CC; |
|
|
740 | |
754 | |
741 | // parse the non-standard "rgba:rrrr/gggg/bbbb/aaaa" format |
755 | // parse the non-standard "rgba:rrrr/gggg/bbbb/aaaa" format |
742 | if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%4hx/%4hx/%4hx/%4hx%c", &c.r, &c.g, &c.b, &c.a, &eos)) |
756 | if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%4hx/%4hx/%4hx/%4hx%c", &c.r, &c.g, &c.b, &c.a, &eos)) |
743 | { |
757 | { |
744 | XColor xc, xc_exact; |
758 | XColor xc; |
745 | |
759 | |
746 | if (XParseColor (screen->dpy, screen->cmap, name, &xc)) |
760 | if (XParseColor (screen->dpy, screen->cmap, name, &xc)) |
747 | { |
761 | { |
748 | c.r = xc.red; |
762 | c.r = xc.red; |
749 | c.g = xc.green; |
763 | c.g = xc.green; |
… | |
… | |
776 | { |
790 | { |
777 | XColor *colors = new XColor [screen->visual->map_entries]; |
791 | XColor *colors = new XColor [screen->visual->map_entries]; |
778 | |
792 | |
779 | for (int i = 0; i < cmap_size; i++) |
793 | for (int i = 0; i < cmap_size; i++) |
780 | colors [i].pixel = i; |
794 | colors [i].pixel = i; |
781 | |
795 | |
782 | // many kilobytes transfer per colour, but pseudocolor isn't worth |
796 | // many kilobytes transfer per colour, but pseudocolor isn't worth |
783 | // many extra optimisations. |
797 | // many extra optimisations. |
784 | XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); |
798 | XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); |
785 | |
799 | |
786 | int diff = 0x7fffffffUL; |
800 | int diff = 0x7fffffffUL; |
… | |
… | |
799 | } |
813 | } |
800 | } |
814 | } |
801 | |
815 | |
802 | //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d)\n", |
816 | //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d)\n", |
803 | // color.r, color.g, color.b, best->red, best->green, best->blue, diff); |
817 | // color.r, color.g, color.b, best->red, best->green, best->blue, diff); |
804 | |
818 | |
805 | got = alloc (screen, rgba (best->red, best->green, best->blue)); |
819 | got = alloc (screen, rgba (best->red, best->green, best->blue)); |
806 | |
820 | |
807 | delete colors; |
821 | delete [] colors; |
808 | } |
822 | } |
809 | #endif |
823 | #endif |
810 | |
824 | |
811 | return got; |
825 | return got; |
812 | } |
826 | } |
… | |
… | |
837 | color.green = c.g; |
851 | color.green = c.g; |
838 | color.blue = c.b; |
852 | color.blue = c.b; |
839 | color.pixel = (Pixel)*this; |
853 | color.pixel = (Pixel)*this; |
840 | } |
854 | } |
841 | |
855 | |
842 | void |
856 | void |
843 | rxvt_color::free (rxvt_screen *screen) |
857 | rxvt_color::free (rxvt_screen *screen) |
844 | { |
858 | { |
845 | if (screen->visual->c_class == TrueColor) |
859 | if (screen->visual->c_class == TrueColor) |
846 | return; // nothing to do |
860 | return; // nothing to do |
847 | |
861 | |
… | |
… | |
867 | lerp (c.a, to.a, percent) |
881 | lerp (c.a, to.a, percent) |
868 | ) |
882 | ) |
869 | ); |
883 | ); |
870 | } |
884 | } |
871 | |
885 | |
|
|
886 | #if TRACE_PIXMAPS |
|
|
887 | # undef XCreatePixmap |
|
|
888 | # undef XFreePixmap |
|
|
889 | Pixmap trace_XCreatePixmap (const char *file, int line, Display *dpy, Window r, unsigned int w, unsigned int h, unsigned int d) |
|
|
890 | { |
|
|
891 | Pixmap res = XCreatePixmap (dpy, r, w, h, d); |
|
|
892 | fprintf (stderr, "%s:%d: XCreatePixmap (%p,%lX,%u,%u,%u) returned %lX\n", file, line, dpy, r, w, h, d, res); |
|
|
893 | return res; |
|
|
894 | } |
|
|
895 | |
|
|
896 | void trace_XFreePixmap (const char *file, int line, Display *dpy, Pixmap p) |
|
|
897 | { |
|
|
898 | fprintf (stderr, "%s:%d: XFreePixmap (%p,%lX)\n", file, line, dpy, p); |
|
|
899 | XFreePixmap (dpy,p); |
|
|
900 | } |
|
|
901 | #endif |