… | |
… | |
55 | } |
55 | } |
56 | |
56 | |
57 | template<class T> |
57 | template<class T> |
58 | T *refcache<T>::get (const char *id) |
58 | T *refcache<T>::get (const char *id) |
59 | { |
59 | { |
60 | for (T **i = begin (); i < end (); ++i) |
60 | for (T **i = this->begin (); i < this->end (); ++i) |
61 | { |
61 | { |
62 | if (!strcmp (id, (*i)->id)) |
62 | if (!strcmp (id, (*i)->id)) |
63 | { |
63 | { |
64 | (*i)->referenced++; |
64 | (*i)->referenced++; |
65 | return *i; |
65 | return *i; |
… | |
… | |
70 | |
70 | |
71 | obj->referenced = 1; |
71 | obj->referenced = 1; |
72 | |
72 | |
73 | if (obj && obj->init ()) |
73 | if (obj && obj->init ()) |
74 | { |
74 | { |
75 | push_back (obj); |
75 | this->push_back (obj); |
76 | return obj; |
76 | return obj; |
77 | } |
77 | } |
78 | else |
78 | else |
79 | { |
79 | { |
80 | delete obj; |
80 | delete obj; |
… | |
… | |
88 | if (!obj) |
88 | if (!obj) |
89 | return; |
89 | return; |
90 | |
90 | |
91 | if (!--obj->referenced) |
91 | if (!--obj->referenced) |
92 | { |
92 | { |
93 | erase (find (begin (), end (), obj)); |
93 | this->erase (find (this->begin (), this->end (), obj)); |
94 | delete obj; |
94 | delete obj; |
95 | } |
95 | } |
96 | } |
96 | } |
97 | |
97 | |
98 | template<class T> |
98 | template<class T> |
99 | refcache<T>::~refcache () |
99 | refcache<T>::~refcache () |
100 | { |
100 | { |
101 | while (size ()) |
101 | while (this->size ()) |
102 | put (*begin ()); |
102 | put (*this->begin ()); |
103 | } |
103 | } |
104 | |
104 | |
105 | ///////////////////////////////////////////////////////////////////////////// |
105 | ///////////////////////////////////////////////////////////////////////////// |
106 | |
106 | |
|
|
107 | #ifdef USE_XIM |
107 | static void |
108 | static void |
108 | im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3) |
109 | im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3) |
109 | { |
110 | { |
110 | rxvt_xim *xim = (rxvt_xim *)client_data; |
111 | rxvt_xim *xim = (rxvt_xim *)client_data; |
111 | rxvt_display *display = xim->display; |
112 | rxvt_display *display = xim->display; |
… | |
… | |
136 | rxvt_xim::~rxvt_xim () |
137 | rxvt_xim::~rxvt_xim () |
137 | { |
138 | { |
138 | if (xim) |
139 | if (xim) |
139 | XCloseIM (xim); |
140 | XCloseIM (xim); |
140 | } |
141 | } |
|
|
142 | #endif |
141 | |
143 | |
142 | ///////////////////////////////////////////////////////////////////////////// |
144 | ///////////////////////////////////////////////////////////////////////////// |
143 | |
145 | |
144 | rxvt_display::rxvt_display (const char *id) |
146 | rxvt_display::rxvt_display (const char *id) |
145 | : refcounted (id) |
147 | : refcounted (id) |
… | |
… | |
183 | int fd = XConnectionNumber (display); |
185 | int fd = XConnectionNumber (display); |
184 | x_ev.start (fd, EVENT_READ); |
186 | x_ev.start (fd, EVENT_READ); |
185 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
187 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
186 | |
188 | |
187 | XSelectInput (display, root, PropertyChangeMask); |
189 | XSelectInput (display, root, PropertyChangeMask); |
|
|
190 | #ifdef USE_XIM |
188 | xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0); |
191 | xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0); |
|
|
192 | #endif |
189 | |
193 | |
190 | flush (); |
194 | flush (); |
191 | |
195 | |
192 | return true; |
196 | return true; |
193 | } |
197 | } |
… | |
… | |
198 | |
202 | |
199 | if (display) |
203 | if (display) |
200 | XCloseDisplay (display); |
204 | XCloseDisplay (display); |
201 | } |
205 | } |
202 | |
206 | |
|
|
207 | #ifdef USE_XIM |
203 | void rxvt_display::im_change_cb () |
208 | void rxvt_display::im_change_cb () |
204 | { |
209 | { |
205 | for (im_watcher **i = imw.begin (); i != imw.end (); ++i) |
210 | for (im_watcher **i = imw.begin (); i != imw.end (); ++i) |
206 | (*i)->call (); |
211 | (*i)->call (); |
207 | } |
212 | } |
|
|
213 | #endif |
208 | |
214 | |
209 | void rxvt_display::x_cb (io_watcher &w, short revents) |
215 | void rxvt_display::x_cb (io_watcher &w, short revents) |
210 | { |
216 | { |
211 | do |
217 | do |
212 | { |
218 | { |
213 | XEvent xev; |
219 | XEvent xev; |
214 | XNextEvent (display, &xev); |
220 | XNextEvent (display, &xev); |
215 | |
221 | |
216 | //printf ("T %d w %lx\n", xev.type, xev.xany.window);//D |
222 | //printf ("T %d w %lx\n", xev.type, xev.xany.window);//D |
217 | |
223 | |
|
|
224 | #ifdef USE_XIM |
218 | if (xev.type == PropertyNotify |
225 | if (xev.type == PropertyNotify |
219 | && xev.xany.window == root |
226 | && xev.xany.window == root |
220 | && xev.xproperty.atom == xa_xim_servers) |
227 | && xev.xproperty.atom == xa_xim_servers) |
221 | im_change_cb (); |
228 | im_change_cb (); |
|
|
229 | #endif |
222 | |
230 | |
223 | for (int i = xw.size (); i--; ) |
231 | for (int i = xw.size (); i--; ) |
224 | { |
232 | { |
225 | if (!xw[i]) |
233 | if (!xw[i]) |
226 | xw.erase_unordered (i); |
234 | xw.erase_unordered (i); |
… | |
… | |
256 | { |
264 | { |
257 | if (w->active) |
265 | if (w->active) |
258 | xw[w->active - 1] = 0; |
266 | xw[w->active - 1] = 0; |
259 | } |
267 | } |
260 | |
268 | |
261 | void rxvt_display::reg (im_watcher *w) |
|
|
262 | { |
|
|
263 | imw.push_back (w); |
|
|
264 | } |
|
|
265 | |
|
|
266 | void rxvt_display::unreg (im_watcher *w) |
|
|
267 | { |
|
|
268 | imw.erase (find (imw.begin (), imw.end (), w)); |
|
|
269 | } |
|
|
270 | |
|
|
271 | void rxvt_display::set_selection_owner (rxvt_term *owner) |
269 | void rxvt_display::set_selection_owner (rxvt_term *owner) |
272 | { |
270 | { |
273 | if (selection_owner && selection_owner != owner) |
271 | if (selection_owner && selection_owner != owner) |
274 | selection_owner->selection_clear (); |
272 | selection_owner->selection_clear (); |
275 | |
273 | |
276 | selection_owner = owner; |
274 | selection_owner = owner; |
277 | } |
275 | } |
278 | |
276 | |
|
|
277 | #ifdef USE_XIM |
|
|
278 | void rxvt_display::reg (im_watcher *w) |
|
|
279 | { |
|
|
280 | imw.push_back (w); |
|
|
281 | } |
|
|
282 | |
|
|
283 | void rxvt_display::unreg (im_watcher *w) |
|
|
284 | { |
|
|
285 | imw.erase (find (imw.begin (), imw.end (), w)); |
|
|
286 | } |
|
|
287 | |
279 | rxvt_xim *rxvt_display::get_xim (const char *locale, const char *modifiers) |
288 | rxvt_xim *rxvt_display::get_xim (const char *locale, const char *modifiers) |
280 | { |
289 | { |
281 | char *id; |
290 | char *id; |
282 | int l, m; |
291 | int l, m; |
283 | |
292 | |
… | |
… | |
299 | |
308 | |
300 | void rxvt_display::put_xim (rxvt_xim *xim) |
309 | void rxvt_display::put_xim (rxvt_xim *xim) |
301 | { |
310 | { |
302 | xims.put (xim); |
311 | xims.put (xim); |
303 | } |
312 | } |
|
|
313 | #endif |
304 | |
314 | |
305 | Atom rxvt_display::atom (const char *name) |
315 | Atom rxvt_display::atom (const char *name) |
306 | { |
316 | { |
307 | return XInternAtom (display, name, False); |
317 | return XInternAtom (display, name, False); |
308 | } |
318 | } |
309 | |
319 | |
310 | ///////////////////////////////////////////////////////////////////////////// |
320 | ///////////////////////////////////////////////////////////////////////////// |
311 | |
321 | |
312 | template refcache<rxvt_display>; |
322 | template class refcache<rxvt_display>; |
313 | refcache<rxvt_display> displays; |
323 | refcache<rxvt_display> displays; |
314 | |
324 | |
315 | ///////////////////////////////////////////////////////////////////////////// |
325 | ///////////////////////////////////////////////////////////////////////////// |
316 | |
326 | |
317 | bool |
327 | bool |