1 |
root |
1.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 |
|
|
|
22 |
|
|
struct im_watcher; |
23 |
|
|
struct xevent_watcher; |
24 |
|
|
|
25 |
|
|
struct refcounted { |
26 |
|
|
int referenced; |
27 |
|
|
char *id; |
28 |
|
|
|
29 |
|
|
refcounted (const char *id); |
30 |
|
|
bool init () { return false; } |
31 |
|
|
~refcounted (); |
32 |
|
|
}; |
33 |
|
|
|
34 |
|
|
template<class T> |
35 |
|
|
struct refcache : vector<T *> { |
36 |
|
|
T *get (const char *id); |
37 |
|
|
void put (T *obj); |
38 |
|
|
~refcache (); |
39 |
|
|
}; |
40 |
|
|
|
41 |
|
|
///////////////////////////////////////////////////////////////////////////// |
42 |
|
|
|
43 |
|
|
#ifdef USE_XIM |
44 |
|
|
struct rxvt_xim : refcounted { |
45 |
|
|
void destroy (); |
46 |
|
|
rxvt_display *display; |
47 |
|
|
|
48 |
|
|
//public |
49 |
|
|
XIM xim; |
50 |
|
|
|
51 |
|
|
rxvt_xim (const char *id) : refcounted (id) { } |
52 |
|
|
bool init (); |
53 |
|
|
~rxvt_xim (); |
54 |
|
|
}; |
55 |
|
|
#endif |
56 |
|
|
|
57 |
|
|
struct rxvt_display : refcounted { |
58 |
|
|
Atom xa_xim_servers; |
59 |
|
|
|
60 |
|
|
io_manager_vec<xevent_watcher> xw; |
61 |
|
|
|
62 |
|
|
io_watcher x_ev; void x_cb (io_watcher &w, short revents); |
63 |
|
|
|
64 |
|
|
#ifdef USE_XIM |
65 |
|
|
refcache<rxvt_xim> xims; |
66 |
|
|
vector<im_watcher *> imw; |
67 |
|
|
|
68 |
|
|
void im_change_cb (); |
69 |
|
|
#endif |
70 |
|
|
|
71 |
|
|
//public |
72 |
|
|
Display *display; |
73 |
|
|
int depth; |
74 |
|
|
int screen; |
75 |
|
|
Visual *visual; |
76 |
|
|
Colormap cmap; |
77 |
|
|
Window root; |
78 |
|
|
rxvt_term *selection_owner; |
79 |
|
|
#ifndef NO_SLOW_LINK_SUPPORT |
80 |
|
|
bool is_local; |
81 |
|
|
#endif |
82 |
|
|
|
83 |
|
|
rxvt_display (const char *id); |
84 |
|
|
bool init (); |
85 |
|
|
~rxvt_display (); |
86 |
|
|
|
87 |
|
|
void flush (); |
88 |
|
|
|
89 |
|
|
void set_selection_owner (rxvt_term *owner); |
90 |
|
|
|
91 |
|
|
void reg (xevent_watcher *w); |
92 |
|
|
void unreg (xevent_watcher *w); |
93 |
|
|
|
94 |
|
|
#ifdef USE_XIM |
95 |
|
|
void reg (im_watcher *w); |
96 |
|
|
void unreg (im_watcher *w); |
97 |
|
|
|
98 |
|
|
rxvt_xim *get_xim (const char *locale, const char *modifiers); |
99 |
|
|
void put_xim (rxvt_xim *xim); |
100 |
|
|
#endif |
101 |
|
|
|
102 |
|
|
Atom atom (const char *name); |
103 |
|
|
}; |
104 |
|
|
|
105 |
|
|
#ifdef USE_XIM |
106 |
|
|
struct im_watcher : watcher, callback0<void> { |
107 |
|
|
template<class O1, class O2> |
108 |
|
|
im_watcher (O1 *object, void (O2::*method) ()) |
109 |
|
|
: callback0<void> (object,method) |
110 |
|
|
{ } |
111 |
|
|
|
112 |
|
|
void start (rxvt_display *display) |
113 |
|
|
{ |
114 |
|
|
display->reg (this); |
115 |
|
|
} |
116 |
|
|
void stop (rxvt_display *display) |
117 |
|
|
{ |
118 |
|
|
display->unreg (this); |
119 |
|
|
} |
120 |
|
|
}; |
121 |
|
|
#endif |
122 |
|
|
|
123 |
|
|
struct xevent_watcher : watcher, callback1<void, XEvent &> { |
124 |
|
|
Window window; |
125 |
|
|
|
126 |
|
|
template<class O1, class O2> |
127 |
|
|
xevent_watcher (O1 *object, void (O2::*method) (XEvent &)) |
128 |
|
|
: callback1<void, XEvent &> (object,method) |
129 |
|
|
{ } |
130 |
|
|
|
131 |
|
|
void start (rxvt_display *display, Window window) |
132 |
|
|
{ |
133 |
|
|
this->window = window; |
134 |
|
|
display->reg (this); |
135 |
|
|
} |
136 |
|
|
void stop (rxvt_display *display) |
137 |
|
|
{ |
138 |
|
|
display->unreg (this); |
139 |
|
|
} |
140 |
|
|
}; |
141 |
|
|
|
142 |
|
|
extern refcache<rxvt_display> displays; |
143 |
|
|
|
144 |
|
|
///////////////////////////////////////////////////////////////////////////// |
145 |
|
|
|
146 |
|
|
typedef unsigned long Pixel; |
147 |
|
|
|
148 |
|
|
struct rxvt_color { |
149 |
|
|
#if XFT |
150 |
|
|
XftColor c; |
151 |
|
|
operator Pixel () const { return c.pixel; } |
152 |
|
|
#else |
153 |
|
|
Pixel p; |
154 |
|
|
operator Pixel () const { return p; } |
155 |
|
|
#endif |
156 |
|
|
|
157 |
|
|
bool operator == (const rxvt_color &b) const { return Pixel (*this) == Pixel (b); } |
158 |
|
|
bool operator != (const rxvt_color &b) const { return Pixel (*this) != Pixel (b); } |
159 |
|
|
|
160 |
|
|
void get (rxvt_display *display, unsigned short &cr, unsigned short &cg, unsigned short &cb); |
161 |
|
|
|
162 |
|
|
bool set (rxvt_display *display, Pixel p); |
163 |
|
|
bool set (rxvt_display *display, const char *name); |
164 |
|
|
bool set (rxvt_display *display, unsigned short cr, unsigned short cg, unsigned short cb); |
165 |
|
|
|
166 |
|
|
rxvt_color fade (rxvt_display *, int percent); |
167 |
|
|
|
168 |
|
|
void free (rxvt_display *display); |
169 |
|
|
}; |
170 |
|
|
|
171 |
|
|
#endif |
172 |
|
|
|