ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvttoolkit.C
(Generate patch)

Comparing rxvt-unicode/src/rxvttoolkit.C (file contents):
Revision 1.80 by ayin, Fri Dec 7 01:29:00 2007 UTC vs.
Revision 1.91 by root, Sat Jan 26 10:03:35 2008 UTC

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.
297 297
298rxvt_display::rxvt_display (const char *id) 298rxvt_display::rxvt_display (const char *id)
299: refcounted (id) 299: refcounted (id)
300, selection_owner (0) 300, selection_owner (0)
301{ 301{
302 x_ev.set<rxvt_display, &rxvt_display::x_cb> (this); 302 x_ev .set<rxvt_display, &rxvt_display::x_cb > (this);
303 flush_ev.set<rxvt_display, &rxvt_display::flush_cb> (this);
303} 304}
304 305
305XrmDatabase 306XrmDatabase
306rxvt_display::get_resources (bool refresh) 307rxvt_display::get_resources (bool refresh)
307{ 308{
471 socklen_t sl = sizeof (sa); 472 socklen_t sl = sizeof (sa);
472 473
473 if (!getsockname (fd, (sockaddr *)&sa, &sl)) 474 if (!getsockname (fd, (sockaddr *)&sa, &sl))
474 is_local = sa.sun_family == AF_UNIX; 475 is_local = sa.sun_family == AF_UNIX;
475 476
477 flush_ev.start ();
476 x_ev.start (fd, ev::READ); 478 x_ev.start (fd, ev::READ);
477 fcntl (fd, F_SETFD, FD_CLOEXEC); 479 fcntl (fd, F_SETFD, FD_CLOEXEC);
478 480
479 XSelectInput (dpy, root, PropertyChangeMask); 481 XSelectInput (dpy, root, PropertyChangeMask);
480 482
499 501
500#ifdef POINTER_BLANK 502#ifdef POINTER_BLANK
501 XFreeCursor (dpy, blank_cursor); 503 XFreeCursor (dpy, blank_cursor);
502#endif 504#endif
503 x_ev.stop (); 505 x_ev.stop ();
506 flush_ev.stop ();
504#ifdef USE_XIM 507#ifdef USE_XIM
505 xims.clear (); 508 xims.clear ();
506#endif 509#endif
507 XCloseDisplay (dpy); 510 XCloseDisplay (dpy);
508} 511}
545 while (XEventsQueued (dpy, QueuedAfterReading)) 548 while (XEventsQueued (dpy, QueuedAfterReading))
546 { 549 {
547 XEvent xev; 550 XEvent xev;
548 XNextEvent (dpy, &xev); 551 XNextEvent (dpy, &xev);
549 552
553 flush_ev.start ();
554
550#ifdef USE_XIM 555#ifdef USE_XIM
551 if (!XFilterEvent (&xev, None)) 556 if (!XFilterEvent (&xev, None))
557#endif
552 { 558 {
553 if (xev.type == PropertyNotify 559 if (xev.type == PropertyNotify
554 && xev.xany.window == root 560 && xev.xany.window == root
555 && xev.xproperty.atom == xa[XA_XIM_SERVERS]) 561 && xev.xproperty.atom == xa[XA_XIM_SERVERS])
556 im_change_check (); 562 im_change_check ();
557#endif
558 if (xev.type == MappingNotify) 563 if (xev.type == MappingNotify)
559 XRefreshKeyboardMapping (&xev.xmapping); 564 XRefreshKeyboardMapping (&xev.xmapping);
560 565
561 for (int i = xw.size (); i--; ) 566 for (int i = xw.size (); i--; )
562 { 567 {
563 if (!xw[i]) 568 if (!xw[i])
564 xw.erase_unordered (i); 569 xw.erase_unordered (i);
565 else if (xw[i]->window == xev.xany.window) 570 else if (xw[i]->window == xev.xany.window)
566 xw[i]->call (xev); 571 xw[i]->call (xev);
567 } 572 }
568#ifdef USE_XIM
569 } 573 }
570#endif
571 } 574 }
575}
572 576
577void rxvt_display::flush_cb (ev::prepare &w, int revents)
578{
579 w.stop ();
573 XFlush (dpy); 580 XFlush (dpy);
574}
575
576void rxvt_display::flush ()
577{
578 x_cb (x_ev, ev::READ);
579} 581}
580 582
581void rxvt_display::reg (xevent_watcher *w) 583void rxvt_display::reg (xevent_watcher *w)
582{ 584{
583 if (!w->active) 585 if (!w->active)
597} 599}
598 600
599void rxvt_display::set_selection_owner (rxvt_term *owner) 601void rxvt_display::set_selection_owner (rxvt_term *owner)
600{ 602{
601 if (selection_owner && selection_owner != owner) 603 if (selection_owner && selection_owner != owner)
604 {
605 rxvt_term *owner = selection_owner;
606
602 selection_owner->selection_clear (); 607 owner->selection_clear ();
608 owner->flush ();
609 }
603 610
604 selection_owner = owner; 611 selection_owner = owner;
605} 612}
606 613
607#ifdef USE_XIM 614#ifdef USE_XIM
666} 673}
667 674
668bool 675bool
669rxvt_color::alloc (rxvt_screen *screen, const rgba &color) 676rxvt_color::alloc (rxvt_screen *screen, const rgba &color)
670{ 677{
678 //TODO: only supports 24 bit
679 int alpha = color.a >= 0xff00 ? 0xffff : color.a;
680
671#if XFT 681#if XFT
672 XRenderPictFormat *format; 682 XRenderPictFormat *format;
673 683
674 // FUCKING Xft gets it wrong, of course, so work around it. 684 // FUCKING Xft gets it wrong, of course, so work around it.
675 // Transparency users should eat shit and die, and then 685 // Transparency users should eat shit and die, and then
679 { 689 {
680 // the fun lies in doing everything manually... 690 // the fun lies in doing everything manually...
681 c.color.red = color.r; 691 c.color.red = color.r;
682 c.color.green = color.g; 692 c.color.green = color.g;
683 c.color.blue = color.b; 693 c.color.blue = color.b;
684 c.color.alpha = color.a; 694 c.color.alpha = alpha;
685 695
686 c.pixel = insert_component (color.r, format->direct.redMask , format->direct.red ) 696 c.pixel = insert_component (color.r, format->direct.redMask , format->direct.red )
687 | insert_component (color.g, format->direct.greenMask, format->direct.green) 697 | insert_component (color.g, format->direct.greenMask, format->direct.green)
688 | insert_component (color.b, format->direct.blueMask , format->direct.blue ) 698 | insert_component (color.b, format->direct.blueMask , format->direct.blue )
689 | insert_component (color.a, format->direct.alphaMask, format->direct.alpha); 699 | insert_component (alpha , format->direct.alphaMask, format->direct.alpha);
690 700
691 return true; 701 return true;
692 } 702 }
693 else 703 else
694 { 704 {
695 XRenderColor d; 705 XRenderColor d;
696 706
697 d.red = color.r; 707 d.red = color.r;
698 d.green = color.g; 708 d.green = color.g;
699 d.blue = color.b; 709 d.blue = color.b;
700 d.alpha = color.a; 710 d.alpha = alpha;
701 711
702 return XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c); 712 return XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c);
703 } 713 }
704#else 714#else
705 c.red = color.r; 715 c.red = color.r;
730{ 740{
731 rgba c; 741 rgba c;
732 char eos; 742 char eos;
733 int skip; 743 int skip;
734 744
745 c.a = rgba::MAX_CC;
746
735 // parse the nonstandard "[alphapercent]" prefix 747 // parse the nonstandard "[alphapercent]" prefix
736 if (1 <= sscanf (name, "[%hd]%n", &c.a, &skip)) 748 if (1 <= sscanf (name, "[%hd]%n", &c.a, &skip))
737 { 749 {
738 c.a = lerp<int, int, int> (0, rgba::MAX_CC, c.a); 750 c.a = lerp<int, int, int> (0, rgba::MAX_CC, c.a);
739 name += skip; 751 name += skip;
740 } 752 }
741 else
742 c.a = rgba::MAX_CC;
743 753
744 // parse the non-standard "#aarrggbb" format
745 if (name[0] == '#' && strlen (name) == 1+2+2+2+2 && 4 == sscanf (name+1, "%2hx%2hx%2hx%2hx%c", &c.a, &c.r, &c.g, &c.b, &eos))
746 {
747 if (c.r)
748 c.r = (c.r << 8) | 0x0ff;
749 if (c.g)
750 c.g = (c.g << 8) | 0x0ff;
751 if (c.b)
752 c.b = (c.b << 8) | 0x0ff;
753 if (c.a)
754 c.a = (c.a << 8) | 0x0ff;
755 }
756 // parse the non-standard "rgba:rrrr/gggg/bbbb/aaaa" format 754 // parse the non-standard "rgba:rrrr/gggg/bbbb/aaaa" format
757 else if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%4hx/%4hx/%4hx/%4hx%c", &c.r, &c.g, &c.b, &c.a, &eos)) 755 if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%4hx/%4hx/%4hx/%4hx%c", &c.r, &c.g, &c.b, &c.a, &eos))
758 { 756 {
759 XColor xc; 757 XColor xc;
760 758
761 if (XParseColor (screen->dpy, screen->cmap, name, &xc)) 759 if (XParseColor (screen->dpy, screen->cmap, name, &xc))
762 { 760 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines