… | |
… | |
395 | |
395 | |
396 | void |
396 | void |
397 | rxvt_display::ref_next () |
397 | rxvt_display::ref_next () |
398 | { |
398 | { |
399 | // TODO: somehow check wether the database files/resources changed |
399 | // TODO: somehow check wether the database files/resources changed |
400 | // before re-loading/parsing |
400 | // before affording re-loading/parsing |
401 | XrmDestroyDatabase (XrmGetDatabase (display)); |
401 | XrmDestroyDatabase (XrmGetDatabase (display)); |
402 | XrmSetDatabase (display, get_resources ()); |
402 | XrmSetDatabase (display, get_resources ()); |
403 | } |
403 | } |
404 | |
404 | |
405 | rxvt_display::~rxvt_display () |
405 | rxvt_display::~rxvt_display () |
… | |
… | |
508 | |
508 | |
509 | selection_owner = owner; |
509 | selection_owner = owner; |
510 | } |
510 | } |
511 | |
511 | |
512 | #ifdef USE_XIM |
512 | #ifdef USE_XIM |
|
|
513 | |
513 | void rxvt_display::reg (im_watcher *w) |
514 | void rxvt_display::reg (im_watcher *w) |
514 | { |
515 | { |
515 | imw.push_back (w); |
516 | imw.push_back (w); |
516 | } |
517 | } |
517 | |
518 | |
… | |
… | |
541 | return xim; |
542 | return xim; |
542 | } |
543 | } |
543 | |
544 | |
544 | void rxvt_display::put_xim (rxvt_xim *xim) |
545 | void rxvt_display::put_xim (rxvt_xim *xim) |
545 | { |
546 | { |
546 | #if XLIB_IS_RACEFREE |
547 | # if XLIB_IS_RACEFREE |
547 | xims.put (xim); |
548 | xims.put (xim); |
548 | #endif |
549 | # endif |
549 | } |
550 | } |
|
|
551 | |
550 | #endif |
552 | #endif |
551 | |
553 | |
552 | Atom rxvt_display::atom (const char *name) |
554 | Atom rxvt_display::atom (const char *name) |
553 | { |
555 | { |
554 | return XInternAtom (display, name, False); |
556 | return XInternAtom (display, name, False); |
… | |
… | |
565 | rxvt_color::alloc (rxvt_screen *screen, const rgba &color) |
567 | rxvt_color::alloc (rxvt_screen *screen, const rgba &color) |
566 | { |
568 | { |
567 | #if XFT |
569 | #if XFT |
568 | XRenderPictFormat *format; |
570 | XRenderPictFormat *format; |
569 | |
571 | |
570 | // FUCKING Xft gets it wrong, of course, so work around it |
572 | // FUCKING Xft gets it wrong, of course, so work around it. |
571 | // transparency users should eat shit and die, and then |
573 | // Transparency users should eat shit and die, and then |
572 | // XRenderQueryPictIndexValues themselves plenty. |
574 | // XRenderQueryPictIndexValues themselves plenty. |
573 | if ((screen->visual->c_class == TrueColor || screen->visual->c_class == DirectColor) |
575 | if ((screen->visual->c_class == TrueColor) |
574 | && (format = XRenderFindVisualFormat (screen->xdisp, screen->visual))) |
576 | && (format = XRenderFindVisualFormat (screen->xdisp, screen->visual))) |
575 | { |
577 | { |
576 | // the fun lies in doing everything manually... |
578 | // the fun lies in doing everything manually... |
577 | c.color.red = color.r; |
579 | c.color.red = color.r; |
578 | c.color.green = color.g; |
580 | c.color.green = color.g; |
… | |
… | |
596 | d.alpha = color.a; |
598 | d.alpha = color.a; |
597 | |
599 | |
598 | return XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c); |
600 | return XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c); |
599 | } |
601 | } |
600 | #else |
602 | #else |
601 | if (screen->visual->c_class == TrueColor || screen->visual->c_class == DirectColor) |
|
|
602 | { |
|
|
603 | c.red = color.g; |
603 | c.red = color.r; |
604 | c.green = color.g; |
604 | c.green = color.g; |
605 | c.blue = color.g; |
605 | c.blue = color.b; |
|
|
606 | |
|
|
607 | if (screen->visual->c_class == TrueColor) |
|
|
608 | { |
606 | c.pixel = (color.r * (screen->visual->red_mask >> ctz (screen->visual->red_mask )) |
609 | c.pixel = (color.r * (screen->visual->red_mask >> ctz (screen->visual->red_mask )) |
607 | / rgba::MAX_CC) << ctz (screen->visual->red_mask ) |
610 | / rgba::MAX_CC) << ctz (screen->visual->red_mask ) |
608 | | (color.g * (screen->visual->green_mask >> ctz (screen->visual->green_mask)) |
611 | | (color.g * (screen->visual->green_mask >> ctz (screen->visual->green_mask)) |
609 | / rgba::MAX_CC) << ctz (screen->visual->green_mask) |
612 | / rgba::MAX_CC) << ctz (screen->visual->green_mask) |
610 | | (color.b * (screen->visual->blue_mask >> ctz (screen->visual->blue_mask )) |
613 | | (color.b * (screen->visual->blue_mask >> ctz (screen->visual->blue_mask )) |
611 | / rgba::MAX_CC) << ctz (screen->visual->blue_mask ); |
614 | / rgba::MAX_CC) << ctz (screen->visual->blue_mask ); |
612 | |
615 | |
613 | return true; |
616 | return true; |
614 | } |
617 | } |
|
|
618 | else if (XAllocColor (screen->xdisp, screen->cmap, &c)) |
|
|
619 | return true; |
615 | else |
620 | else |
616 | { |
|
|
617 | c.red = color.r; |
|
|
618 | c.green = color.g; |
|
|
619 | c.blue = color.b; |
|
|
620 | |
|
|
621 | if (XAllocColor (screen->xdisp, screen->cmap, &c)) |
|
|
622 | return true; |
|
|
623 | else |
|
|
624 | c.pixel = (color.r + color.g + color.b) > 128*3 |
621 | c.pixel = (color.r + color.g + color.b) > 128*3 |
625 | ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->xdisp)) |
622 | ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->xdisp)) |
626 | : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->xdisp)); |
623 | : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->xdisp)); |
627 | } |
|
|
628 | #endif |
624 | #endif |
629 | |
625 | |
630 | return false; |
626 | return false; |
631 | } |
627 | } |
632 | |
628 | |
… | |
… | |
635 | { |
631 | { |
636 | rgba c; |
632 | rgba c; |
637 | char eos; |
633 | char eos; |
638 | int skip; |
634 | int skip; |
639 | |
635 | |
|
|
636 | // parse the nonstandard "[alphapercent]" prefix |
640 | if (1 <= sscanf (name, "[%hd]%n", &c.a, &skip)) |
637 | if (1 <= sscanf (name, "[%hd]%n", &c.a, &skip)) |
641 | { |
638 | { |
642 | printf ("X %d\n", c.a); |
|
|
643 | c.a = lerp<int, int, int> (0, rgba::MAX_CC, c.a); |
639 | c.a = lerp<int, int, int> (0, rgba::MAX_CC, c.a); |
644 | name += skip; |
640 | name += skip; |
645 | printf ("y %04x\n", c.a); |
|
|
646 | } |
641 | } |
647 | else |
642 | else |
648 | c.a = rgba::MAX_CC; |
643 | c.a = rgba::MAX_CC; |
649 | |
644 | |
650 | // parse the non-standard rgba format |
645 | // parse the non-standard "rgba:rrrr/gggg/bbbb/aaaa" format |
651 | if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%hx/%hx/%hx/%hx%c", &c.r, &c.g, &c.b, &c.a, &eos)) |
646 | if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%4hx/%4hx/%4hx/%4hx%c", &c.r, &c.g, &c.b, &c.a, &eos)) |
652 | { |
647 | { |
653 | XColor xc, xc_exact; |
648 | XColor xc, xc_exact; |
654 | |
649 | |
655 | if (XParseColor (screen->xdisp, screen->cmap, name, &xc)) |
650 | if (XParseColor (screen->xdisp, screen->cmap, name, &xc)) |
656 | { |
651 | { |
… | |
… | |
734 | color.b = c.blue; |
729 | color.b = c.blue; |
735 | color.a = rgba::MAX_CC; |
730 | color.a = rgba::MAX_CC; |
736 | #endif |
731 | #endif |
737 | } |
732 | } |
738 | |
733 | |
|
|
734 | void |
|
|
735 | rxvt_color::get (XColor &color) |
|
|
736 | { |
|
|
737 | rgba c; |
|
|
738 | get (c); |
|
|
739 | |
|
|
740 | color.red = c.r; |
|
|
741 | color.green = c.g; |
|
|
742 | color.blue = c.b; |
|
|
743 | color.pixel = (Pixel)*this; |
|
|
744 | } |
|
|
745 | |
739 | void |
746 | void |
740 | rxvt_color::free (rxvt_screen *screen) |
747 | rxvt_color::free (rxvt_screen *screen) |
741 | { |
748 | { |
742 | #if XFT |
749 | #if XFT |
743 | XftColorFree (screen->xdisp, screen->visual, screen->cmap, &c); |
750 | XftColorFree (screen->xdisp, screen->visual, screen->cmap, &c); |