… | |
… | |
5 | |
5 | |
6 | #if XFT |
6 | #if XFT |
7 | # include <X11/Xft/Xft.h> |
7 | # include <X11/Xft/Xft.h> |
8 | #endif |
8 | #endif |
9 | |
9 | |
|
|
10 | #include "iom.h" |
|
|
11 | |
10 | #include "rxvtlib.h" |
12 | #include "rxvtlib.h" |
|
|
13 | #include "rxvtstl.h" |
11 | |
14 | |
|
|
15 | #include "callback.h" |
|
|
16 | |
|
|
17 | extern class byteorder { |
|
|
18 | uint32_t e; |
|
|
19 | public: |
|
|
20 | byteorder (); |
|
|
21 | |
|
|
22 | bool big_endian () { return e == 0x11223344; }; |
|
|
23 | bool network () { return e == 0x11223344; }; |
|
|
24 | bool little_endian () { return e == 0x44332211; }; |
|
|
25 | bool vax () { return e == 0x44332211; }; |
|
|
26 | } byteorder; |
|
|
27 | |
12 | struct rxvt_vars; |
28 | struct rxvt_term; |
|
|
29 | |
|
|
30 | struct im_watcher; |
|
|
31 | struct xevent_watcher; |
|
|
32 | |
|
|
33 | struct refcounted { |
|
|
34 | int referenced; |
|
|
35 | char *id; |
|
|
36 | |
|
|
37 | refcounted (const char *id); |
|
|
38 | bool init () { return false; } |
|
|
39 | ~refcounted (); |
|
|
40 | }; |
|
|
41 | |
|
|
42 | template<class T> |
|
|
43 | struct refcache : vector<T *> { |
|
|
44 | T *get (const char *id); |
|
|
45 | void put (T *obj); |
|
|
46 | ~refcache (); |
|
|
47 | }; |
|
|
48 | |
|
|
49 | ///////////////////////////////////////////////////////////////////////////// |
|
|
50 | |
|
|
51 | #ifdef USE_XIM |
|
|
52 | struct rxvt_xim : refcounted { |
|
|
53 | void destroy (); |
|
|
54 | rxvt_display *display; |
|
|
55 | |
|
|
56 | //public |
|
|
57 | XIM xim; |
|
|
58 | |
|
|
59 | rxvt_xim (const char *id) : refcounted (id) { } |
|
|
60 | bool init (); |
|
|
61 | ~rxvt_xim (); |
|
|
62 | }; |
|
|
63 | #endif |
|
|
64 | |
|
|
65 | struct rxvt_display : refcounted { |
|
|
66 | Atom xa_xim_servers; |
|
|
67 | |
|
|
68 | io_manager_vec<xevent_watcher> xw; |
|
|
69 | |
|
|
70 | io_watcher x_ev; void x_cb (io_watcher &w, short revents); |
|
|
71 | |
|
|
72 | #ifdef USE_XIM |
|
|
73 | refcache<rxvt_xim> xims; |
|
|
74 | vector<im_watcher *> imw; |
|
|
75 | |
|
|
76 | void im_change_cb (); |
|
|
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 | |
|
|
88 | rxvt_display (const char *id); |
|
|
89 | bool init (); |
|
|
90 | ~rxvt_display (); |
|
|
91 | |
|
|
92 | void flush (); |
|
|
93 | |
|
|
94 | void set_selection_owner (rxvt_term *owner); |
|
|
95 | |
|
|
96 | void reg (xevent_watcher *w); |
|
|
97 | void unreg (xevent_watcher *w); |
|
|
98 | |
|
|
99 | #ifdef USE_XIM |
|
|
100 | void reg (im_watcher *w); |
|
|
101 | void unreg (im_watcher *w); |
|
|
102 | |
|
|
103 | rxvt_xim *get_xim (const char *locale, const char *modifiers); |
|
|
104 | void put_xim (rxvt_xim *xim); |
|
|
105 | #endif |
|
|
106 | |
|
|
107 | Atom atom (const char *name); |
|
|
108 | }; |
|
|
109 | |
|
|
110 | #ifdef USE_XIM |
|
|
111 | struct im_watcher : watcher, callback0<void> { |
|
|
112 | template<class O1, class O2> |
|
|
113 | im_watcher (O1 *object, void (O2::*method) ()) |
|
|
114 | : callback0<void> (object,method) |
|
|
115 | { } |
|
|
116 | |
|
|
117 | void start (rxvt_display *display) |
|
|
118 | { |
|
|
119 | display->reg (this); |
|
|
120 | } |
|
|
121 | void stop (rxvt_display *display) |
|
|
122 | { |
|
|
123 | display->unreg (this); |
|
|
124 | } |
|
|
125 | }; |
|
|
126 | #endif |
|
|
127 | |
|
|
128 | struct xevent_watcher : watcher, callback1<void, XEvent &> { |
|
|
129 | Window window; |
|
|
130 | |
|
|
131 | template<class O1, class O2> |
|
|
132 | xevent_watcher (O1 *object, void (O2::*method) (XEvent &)) |
|
|
133 | : callback1<void, XEvent &> (object,method) |
|
|
134 | { } |
|
|
135 | |
|
|
136 | void start (rxvt_display *display, Window window) |
|
|
137 | { |
|
|
138 | this->window = window; |
|
|
139 | display->reg (this); |
|
|
140 | } |
|
|
141 | void stop (rxvt_display *display) |
|
|
142 | { |
|
|
143 | display->unreg (this); |
|
|
144 | } |
|
|
145 | }; |
|
|
146 | |
|
|
147 | extern refcache<rxvt_display> displays; |
|
|
148 | |
|
|
149 | ///////////////////////////////////////////////////////////////////////////// |
13 | |
150 | |
14 | typedef unsigned long Pixel; |
151 | typedef unsigned long Pixel; |
15 | |
152 | |
16 | struct rxvt_color { |
153 | struct rxvt_color { |
17 | #if XFT |
154 | #if XFT |
18 | XftColor c; |
155 | XftColor c; |
19 | operator Pixel() const { return c.pixel; } |
156 | operator Pixel () const { return c.pixel; } |
20 | #else |
157 | #else |
21 | Pixel p; |
158 | Pixel p; |
22 | operator Pixel() const { return p; } |
159 | operator Pixel () const { return p; } |
23 | #endif |
160 | #endif |
24 | |
161 | |
25 | bool operator == (const rxvt_color &b) const { return Pixel(*this) == Pixel(b); } |
162 | bool operator == (const rxvt_color &b) const { return Pixel (*this) == Pixel (b); } |
26 | bool operator != (const rxvt_color &b) const { return Pixel(*this) != Pixel(b); } |
163 | bool operator != (const rxvt_color &b) const { return Pixel (*this) != Pixel (b); } |
27 | |
164 | |
28 | void get (pR_ unsigned short &cr, unsigned short &cg, unsigned short &cb); |
165 | void get (rxvt_display *display, unsigned short &cr, unsigned short &cg, unsigned short &cb); |
29 | |
166 | |
30 | bool set (pR_ Pixel p); |
167 | bool set (rxvt_display *display, Pixel p); |
31 | bool set (pR_ const char *name); |
168 | bool set (rxvt_display *display, const char *name); |
32 | bool set (pR_ unsigned short cr, unsigned short cg, unsigned short cb); |
169 | bool set (rxvt_display *display, unsigned short cr, unsigned short cg, unsigned short cb); |
|
|
170 | |
|
|
171 | rxvt_color fade (rxvt_display *, int percent); |
|
|
172 | |
|
|
173 | void free (rxvt_display *display); |
33 | }; |
174 | }; |
34 | |
175 | |
35 | #endif |
176 | #endif |
36 | |
177 | |