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.97 by root, Sat Jan 26 12:15:11 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}
547 XEvent xev; 550 XEvent xev;
548 XNextEvent (dpy, &xev); 551 XNextEvent (dpy, &xev);
549 552
550#ifdef USE_XIM 553#ifdef USE_XIM
551 if (!XFilterEvent (&xev, None)) 554 if (!XFilterEvent (&xev, None))
555#endif
552 { 556 {
553 if (xev.type == PropertyNotify 557 if (xev.type == PropertyNotify
554 && xev.xany.window == root 558 && xev.xany.window == root
555 && xev.xproperty.atom == xa[XA_XIM_SERVERS]) 559 && xev.xproperty.atom == xa[XA_XIM_SERVERS])
556 im_change_check (); 560 im_change_check ();
557#endif 561
558 if (xev.type == MappingNotify) 562 if (xev.type == MappingNotify)
559 XRefreshKeyboardMapping (&xev.xmapping); 563 XRefreshKeyboardMapping (&xev.xmapping);
560 564
561 for (int i = xw.size (); i--; ) 565 for (int i = xw.size (); i--; )
562 { 566 {
563 if (!xw[i]) 567 if (!xw[i])
564 xw.erase_unordered (i); 568 xw.erase_unordered (i);
565 else if (xw[i]->window == xev.xany.window) 569 else if (xw[i]->window == xev.xany.window)
566 xw[i]->call (xev); 570 xw[i]->call (xev);
567 } 571 }
568#ifdef USE_XIM
569 } 572 }
570#endif 573 }
574}
575
576void rxvt_display::flush_cb (ev::prepare &w, int revents)
577{
578 while (XEventsQueued (dpy, QueuedAfterFlush))
571 } 579 {
580 x_cb(x_ev,0);//D
581 }
572 582
573 XFlush (dpy); 583 w.stop ();
574}
575
576void rxvt_display::flush ()
577{
578 x_cb (x_ev, ev::READ);
579} 584}
580 585
581void rxvt_display::reg (xevent_watcher *w) 586void rxvt_display::reg (xevent_watcher *w)
582{ 587{
583 if (!w->active) 588 if (!w->active)
597} 602}
598 603
599void rxvt_display::set_selection_owner (rxvt_term *owner) 604void rxvt_display::set_selection_owner (rxvt_term *owner)
600{ 605{
601 if (selection_owner && selection_owner != owner) 606 if (selection_owner && selection_owner != owner)
607 {
608 rxvt_term *owner = selection_owner;
609
602 selection_owner->selection_clear (); 610 owner->selection_clear ();
611 owner->flush ();
612 }
603 613
604 selection_owner = owner; 614 selection_owner = owner;
605} 615}
606 616
607#ifdef USE_XIM 617#ifdef USE_XIM
666} 676}
667 677
668bool 678bool
669rxvt_color::alloc (rxvt_screen *screen, const rgba &color) 679rxvt_color::alloc (rxvt_screen *screen, const rgba &color)
670{ 680{
681 //TODO: only supports 24 bit
682 int alpha = color.a >= 0xff00 ? 0xffff : color.a;
683
671#if XFT 684#if XFT
672 XRenderPictFormat *format; 685 XRenderPictFormat *format;
673 686
674 // FUCKING Xft gets it wrong, of course, so work around it. 687 // FUCKING Xft gets it wrong, of course, so work around it.
675 // Transparency users should eat shit and die, and then 688 // Transparency users should eat shit and die, and then
679 { 692 {
680 // the fun lies in doing everything manually... 693 // the fun lies in doing everything manually...
681 c.color.red = color.r; 694 c.color.red = color.r;
682 c.color.green = color.g; 695 c.color.green = color.g;
683 c.color.blue = color.b; 696 c.color.blue = color.b;
684 c.color.alpha = color.a; 697 c.color.alpha = alpha;
685 698
686 c.pixel = insert_component (color.r, format->direct.redMask , format->direct.red ) 699 c.pixel = insert_component (color.r, format->direct.redMask , format->direct.red )
687 | insert_component (color.g, format->direct.greenMask, format->direct.green) 700 | insert_component (color.g, format->direct.greenMask, format->direct.green)
688 | insert_component (color.b, format->direct.blueMask , format->direct.blue ) 701 | insert_component (color.b, format->direct.blueMask , format->direct.blue )
689 | insert_component (color.a, format->direct.alphaMask, format->direct.alpha); 702 | insert_component (alpha , format->direct.alphaMask, format->direct.alpha);
690 703
691 return true; 704 return true;
692 } 705 }
693 else 706 else
694 { 707 {
695 XRenderColor d; 708 XRenderColor d;
696 709
697 d.red = color.r; 710 d.red = color.r;
698 d.green = color.g; 711 d.green = color.g;
699 d.blue = color.b; 712 d.blue = color.b;
700 d.alpha = color.a; 713 d.alpha = alpha;
701 714
702 return XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c); 715 return XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c);
703 } 716 }
704#else 717#else
705 c.red = color.r; 718 c.red = color.r;
730{ 743{
731 rgba c; 744 rgba c;
732 char eos; 745 char eos;
733 int skip; 746 int skip;
734 747
748 c.a = rgba::MAX_CC;
749
735 // parse the nonstandard "[alphapercent]" prefix 750 // parse the nonstandard "[alphapercent]" prefix
736 if (1 <= sscanf (name, "[%hd]%n", &c.a, &skip)) 751 if (1 <= sscanf (name, "[%hd]%n", &c.a, &skip))
737 { 752 {
738 c.a = lerp<int, int, int> (0, rgba::MAX_CC, c.a); 753 c.a = lerp<int, int, int> (0, rgba::MAX_CC, c.a);
739 name += skip; 754 name += skip;
740 } 755 }
741 else
742 c.a = rgba::MAX_CC;
743 756
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 757 // 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)) 758 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 { 759 {
759 XColor xc; 760 XColor xc;
760 761
761 if (XParseColor (screen->dpy, screen->cmap, name, &xc)) 762 if (XParseColor (screen->dpy, screen->cmap, name, &xc))
762 { 763 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines