… | |
… | |
2 | #include <rxvt.h> |
2 | #include <rxvt.h> |
3 | #include <rxvtcolor.h> |
3 | #include <rxvtcolor.h> |
4 | |
4 | |
5 | #include <unistd.h> |
5 | #include <unistd.h> |
6 | #include <fcntl.h> |
6 | #include <fcntl.h> |
|
|
7 | |
|
|
8 | class byteorder byteorder; |
|
|
9 | |
|
|
10 | byteorder::byteorder () |
|
|
11 | { |
|
|
12 | union { |
|
|
13 | uint32_t u; |
|
|
14 | uint8_t b[4]; |
|
|
15 | } w; |
|
|
16 | |
|
|
17 | w.b[0] = 0x11; |
|
|
18 | w.b[1] = 0x22; |
|
|
19 | w.b[2] = 0x33; |
|
|
20 | w.b[3] = 0x44; |
|
|
21 | |
|
|
22 | e = w.u; |
|
|
23 | } |
7 | |
24 | |
8 | refcounted::refcounted (const char *id) |
25 | refcounted::refcounted (const char *id) |
9 | { |
26 | { |
10 | this->id = STRDUP (id); |
27 | this->id = STRDUP (id); |
11 | } |
28 | } |
… | |
… | |
102 | |
119 | |
103 | ///////////////////////////////////////////////////////////////////////////// |
120 | ///////////////////////////////////////////////////////////////////////////// |
104 | |
121 | |
105 | rxvt_display::rxvt_display (const char *id) |
122 | rxvt_display::rxvt_display (const char *id) |
106 | : refcounted (id) |
123 | : refcounted (id) |
107 | , x_watcher (this, &rxvt_display::x_event) |
124 | , x_ev (this, &rxvt_display::x_cb) |
108 | , selection_owner (0) |
125 | , selection_owner (0) |
109 | { |
126 | { |
110 | } |
127 | } |
111 | |
128 | |
112 | bool rxvt_display::init () |
129 | bool rxvt_display::init () |
113 | { |
130 | { |
114 | display = XOpenDisplay (id); |
131 | display = XOpenDisplay (id); |
|
|
132 | |
|
|
133 | if (!display) |
|
|
134 | return false; |
115 | |
135 | |
116 | screen = DefaultScreen (display); |
136 | screen = DefaultScreen (display); |
117 | root = DefaultRootWindow (display); |
137 | root = DefaultRootWindow (display); |
118 | visual = DefaultVisual (display, screen); |
138 | visual = DefaultVisual (display, screen); |
119 | cmap = DefaultColormap (display, screen); |
139 | cmap = DefaultColormap (display, screen); |
… | |
… | |
137 | } |
157 | } |
138 | } |
158 | } |
139 | #endif |
159 | #endif |
140 | |
160 | |
141 | int fd = XConnectionNumber (display); |
161 | int fd = XConnectionNumber (display); |
142 | x_watcher.start (fd, EVENT_READ); |
162 | x_ev.start (fd, EVENT_READ); |
143 | fcntl (fd, F_SETFL, FD_CLOEXEC); |
163 | fcntl (fd, F_SETFL, FD_CLOEXEC); |
144 | |
164 | |
145 | XSelectInput (display, root, PropertyChangeMask); |
165 | XSelectInput (display, root, PropertyChangeMask); |
146 | xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0); |
166 | xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0); |
147 | |
167 | |
|
|
168 | flush (); |
|
|
169 | |
148 | return true; |
170 | return true; |
149 | } |
171 | } |
150 | |
172 | |
151 | rxvt_display::~rxvt_display () |
173 | rxvt_display::~rxvt_display () |
152 | { |
174 | { |
153 | x_watcher.stop (); |
175 | x_ev.stop (); |
154 | |
176 | |
|
|
177 | if (display) |
155 | XCloseDisplay (display); |
178 | XCloseDisplay (display); |
156 | } |
179 | } |
157 | |
180 | |
158 | void rxvt_display::im_change_cb () |
181 | void rxvt_display::im_change_cb () |
159 | { |
182 | { |
160 | for (im_watcher **i = imw.begin (); i != imw.end (); ++i) |
183 | for (im_watcher **i = imw.begin (); i != imw.end (); ++i) |
161 | (*i)->call (); |
184 | (*i)->call (); |
162 | } |
185 | } |
163 | |
186 | |
164 | void rxvt_display::x_event (io_watcher &w, short revents) |
187 | void rxvt_display::x_cb (io_watcher &w, short revents) |
165 | { |
188 | { |
166 | do |
189 | do |
167 | { |
190 | { |
168 | XEvent xev; |
191 | XEvent xev; |
169 | XNextEvent (display, &xev); |
192 | XNextEvent (display, &xev); |
… | |
… | |
182 | else if (xw[i]->window == xev.xany.window) |
205 | else if (xw[i]->window == xev.xany.window) |
183 | xw[i]->call (xev); |
206 | xw[i]->call (xev); |
184 | } |
207 | } |
185 | } |
208 | } |
186 | while (XPending (display)); |
209 | while (XPending (display)); |
|
|
210 | |
|
|
211 | flush (); |
|
|
212 | } |
|
|
213 | |
|
|
214 | void rxvt_display::flush () |
|
|
215 | { |
|
|
216 | for (;;) |
|
|
217 | { |
|
|
218 | XFlush (display); |
|
|
219 | |
|
|
220 | if (!XPending (display)) |
|
|
221 | break; |
|
|
222 | |
|
|
223 | x_cb (x_ev, 0); |
|
|
224 | } |
187 | } |
225 | } |
188 | |
226 | |
189 | void rxvt_display::reg (xevent_watcher *w) |
227 | void rxvt_display::reg (xevent_watcher *w) |
190 | { |
228 | { |
191 | xw.push_back (w); |
229 | xw.push_back (w); |
… | |
… | |
322 | rxvt_color::free (rxvt_display *display) |
360 | rxvt_color::free (rxvt_display *display) |
323 | { |
361 | { |
324 | #if XFT |
362 | #if XFT |
325 | XftColorFree (display->display, display->visual, display->cmap, &c); |
363 | XftColorFree (display->display, display->visual, display->cmap, &c); |
326 | #else |
364 | #else |
327 | XFreeColors (display->display, display->cmap, &c, 1, AllPlanes); |
365 | XFreeColors (display->display, display->cmap, &p, 1, AllPlanes); |
328 | #endif |
366 | #endif |
329 | } |
367 | } |
330 | |
368 | |