*** empty log message ***
[dana/urxvt.git] / src / rxvttoolkit.h
1 /*
2  * rxvttoolkit.h - provide toolkit-functionality for rxvt.
3  */
4 #ifndef RXVT_TOOLKIT_H
5 #define RXVT_TOOLKIT_H
6
7 #include <X11/Xlib.h>
8
9 #if XFT
10 # include <X11/Xft/Xft.h>
11 #endif
12
13 #include "iom.h"
14
15 #include "rxvtlib.h"
16 #include "rxvtutil.h"
17
18 #include "callback.h"
19
20 struct rxvt_term;
21 struct rxvt_display;
22
23 struct im_watcher;
24 struct xevent_watcher;
25
26 struct refcounted {
27   int referenced;
28   char *id;
29
30   refcounted (const char *id);
31   bool ref_init () { return false; }
32   void ref_next () { }
33   ~refcounted ();
34 };
35
36 template<class T>
37 struct refcache : vector<T *> {
38   T *get (const char *id);
39   void put (T *obj);
40   void clear ();
41
42   ~refcache ()
43   {
44     clear ();
45   }
46 };
47
48 /////////////////////////////////////////////////////////////////////////////
49
50 #ifdef USE_XIM
51 struct rxvt_xim : refcounted {
52   void destroy ();
53   rxvt_display *display;
54
55 //public
56   XIM xim;
57
58   rxvt_xim (const char *id) : refcounted (id) { }
59   bool ref_init ();
60   ~rxvt_xim ();
61 };
62 #endif
63
64 struct rxvt_display : refcounted {
65   Atom xa_xim_servers;
66
67   io_manager_vec<xevent_watcher> xw;
68
69   io_watcher x_ev; void x_cb (io_watcher &w, short revents);
70
71 #ifdef USE_XIM
72   refcache<rxvt_xim> xims;
73   vector<im_watcher *> imw;
74
75   void im_change_cb ();
76   void im_change_check ();
77 #endif
78
79 //public
80   Display   *display;
81   int       depth;
82   int       screen;
83   Visual    *visual;
84   Colormap  cmap;
85   Window    root;
86   rxvt_term *selection_owner;
87 #ifndef NO_SLOW_LINK_SUPPORT
88   bool      is_local;
89 #endif
90 #ifdef POINTER_BLANK
91   Cursor    blank_cursor;
92 #endif
93
94   rxvt_display (const char *id);
95   XrmDatabase get_resources ();
96   bool ref_init ();
97   void ref_next ();
98   ~rxvt_display ();
99
100   operator Display *() const { return display; }
101
102   void flush ();
103   Atom atom (const char *name);
104   void set_selection_owner (rxvt_term *owner);
105
106   void reg (xevent_watcher *w);
107   void unreg (xevent_watcher *w);
108
109 #ifdef USE_XIM
110   void reg (im_watcher *w);
111   void unreg (im_watcher *w);
112
113   rxvt_xim *get_xim (const char *locale, const char *modifiers);
114   void put_xim (rxvt_xim *xim);
115 #endif
116 };
117
118 #ifdef USE_XIM
119 struct im_watcher : watcher, callback0<void> {
120   template<class O1, class O2>
121   im_watcher (O1 *object, void (O2::*method) ())
122   : callback0<void> (object,method)
123   { }
124
125   void start (rxvt_display *display)
126   {
127     display->reg (this);
128   }
129   void stop (rxvt_display *display)
130   {
131     display->unreg (this);
132   }
133 };
134 #endif
135
136 struct xevent_watcher : watcher, callback1<void, XEvent &> {
137   Window window;
138
139   template<class O1, class O2>
140   xevent_watcher (O1 *object, void (O2::*method) (XEvent &))
141   : callback1<void, XEvent &> (object,method)
142   { }
143
144   void start (rxvt_display *display, Window window)
145   {
146     this->window = window;
147     display->reg (this);
148   }
149   void stop (rxvt_display *display)
150   {
151     display->unreg (this);
152   }
153 };
154
155 extern refcache<rxvt_display> displays;
156
157 /////////////////////////////////////////////////////////////////////////////
158
159 typedef unsigned long Pixel;
160
161 struct rxvt_color {
162 #if XFT
163   XftColor c;
164   operator Pixel () const { return c.pixel; }
165 #else
166   Pixel p;
167   operator Pixel () const { return p; }
168 #endif
169
170   bool operator == (const rxvt_color &b) const { return Pixel (*this) == Pixel (b); }
171   bool operator != (const rxvt_color &b) const { return Pixel (*this) != Pixel (b); }
172
173   void get (rxvt_display *display, unsigned short &cr, unsigned short &cg, unsigned short &cb);
174  
175   bool set (rxvt_display *display, Pixel p);
176   bool set (rxvt_display *display, const char *name);
177   bool set (rxvt_display *display, unsigned short cr, unsigned short cg, unsigned short cb);
178
179   rxvt_color fade (rxvt_display *, int percent); // fades to black
180   rxvt_color fade (rxvt_display *, int percent, rxvt_color &fadeto);
181
182   void free (rxvt_display *display);
183 };
184
185 #endif
186