… | |
… | |
25 | #include <rxvttoolkit.h> |
25 | #include <rxvttoolkit.h> |
26 | |
26 | |
27 | #include <unistd.h> |
27 | #include <unistd.h> |
28 | #include <fcntl.h> |
28 | #include <fcntl.h> |
29 | |
29 | |
|
|
30 | #include <sys/utsname.h> |
|
|
31 | |
30 | #ifndef NO_SLOW_LINK_SUPPORT |
32 | #ifndef NO_SLOW_LINK_SUPPORT |
31 | # include <sys/socket.h> |
33 | # include <sys/socket.h> |
32 | # include <sys/un.h> |
34 | # include <sys/un.h> |
33 | #endif |
35 | #endif |
34 | |
36 | |
… | |
… | |
47 | { |
49 | { |
48 | for (T **i = this->begin (); i < this->end (); ++i) |
50 | for (T **i = this->begin (); i < this->end (); ++i) |
49 | { |
51 | { |
50 | if (!strcmp (id, (*i)->id)) |
52 | if (!strcmp (id, (*i)->id)) |
51 | { |
53 | { |
52 | (*i)->referenced++; |
54 | ++(*i)->referenced; |
|
|
55 | (*i)->ref_next (); |
53 | return *i; |
56 | return *i; |
54 | } |
57 | } |
55 | } |
58 | } |
56 | |
59 | |
57 | T *obj = new T (id); |
60 | T *obj = new T (id); |
58 | |
61 | |
59 | obj->referenced = 1; |
|
|
60 | |
|
|
61 | if (obj && obj->init ()) |
62 | if (obj && obj->ref_init ()) |
62 | { |
63 | { |
|
|
64 | obj->referenced = 1; |
63 | this->push_back (obj); |
65 | this->push_back (obj); |
64 | return obj; |
66 | return obj; |
65 | } |
67 | } |
66 | else |
68 | else |
67 | { |
69 | { |
… | |
… | |
107 | |
109 | |
108 | display->xims.erase (find (display->xims.begin (), display->xims.end (), xim)); |
110 | display->xims.erase (find (display->xims.begin (), display->xims.end (), xim)); |
109 | display->im_change_cb (); |
111 | display->im_change_cb (); |
110 | } |
112 | } |
111 | |
113 | |
|
|
114 | bool |
112 | bool rxvt_xim::init () |
115 | rxvt_xim::ref_init () |
113 | { |
116 | { |
114 | display = GET_R->display; //HACK: TODO |
117 | display = GET_R->display; //HACK: TODO |
115 | |
118 | |
116 | xim = XOpenIM (display->display, NULL, NULL, NULL); |
119 | xim = XOpenIM (display->display, NULL, NULL, NULL); |
117 | |
120 | |
… | |
… | |
141 | , x_ev (this, &rxvt_display::x_cb) |
144 | , x_ev (this, &rxvt_display::x_cb) |
142 | , selection_owner (0) |
145 | , selection_owner (0) |
143 | { |
146 | { |
144 | } |
147 | } |
145 | |
148 | |
|
|
149 | XrmDatabase |
|
|
150 | rxvt_display::get_resources () |
|
|
151 | { |
|
|
152 | char *homedir = (char *)getenv ("HOME"); |
|
|
153 | char fname[1024]; |
|
|
154 | |
|
|
155 | /* |
|
|
156 | * get resources using the X library function |
|
|
157 | */ |
|
|
158 | char *displayResource, *xe; |
|
|
159 | XrmDatabase database, rdb1; |
|
|
160 | |
|
|
161 | database = NULL; |
|
|
162 | |
|
|
163 | // for ordering, see for example http://www.faqs.org/faqs/Xt-FAQ/ Subject: 20 |
|
|
164 | |
|
|
165 | // 6. System wide per application default file. |
|
|
166 | |
|
|
167 | /* Add in $XAPPLRESDIR/Rxvt only; not bothering with XUSERFILESEARCHPATH */ |
|
|
168 | if ((xe = (char *)getenv ("XAPPLRESDIR"))) |
|
|
169 | { |
|
|
170 | snprintf (fname, sizeof (fname), "%s/%s", xe, RESCLASS); |
|
|
171 | |
|
|
172 | if ((rdb1 = XrmGetFileDatabase (fname))) |
|
|
173 | XrmMergeDatabases (rdb1, &database); |
|
|
174 | } |
|
|
175 | |
|
|
176 | // 5. User's per application default file. |
|
|
177 | // none |
|
|
178 | |
|
|
179 | // 4. User's defaults file. |
|
|
180 | /* Get any Xserver defaults */ |
|
|
181 | displayResource = XResourceManagerString (display); |
|
|
182 | |
|
|
183 | if (displayResource != NULL) |
|
|
184 | { |
|
|
185 | if ((rdb1 = XrmGetStringDatabase (displayResource))) |
|
|
186 | XrmMergeDatabases (rdb1, &database); |
|
|
187 | } |
|
|
188 | else if (homedir) |
|
|
189 | { |
|
|
190 | snprintf (fname, sizeof (fname), "%s/.Xdefaults", homedir); |
|
|
191 | |
|
|
192 | if ((rdb1 = XrmGetFileDatabase (fname))) |
|
|
193 | XrmMergeDatabases (rdb1, &database); |
|
|
194 | } |
|
|
195 | |
|
|
196 | /* Get screen specific resources */ |
|
|
197 | displayResource = XScreenResourceString (ScreenOfDisplay (display, screen)); |
|
|
198 | |
|
|
199 | if (displayResource != NULL) |
|
|
200 | { |
|
|
201 | if ((rdb1 = XrmGetStringDatabase (displayResource))) |
|
|
202 | /* Merge with screen-independent resources */ |
|
|
203 | XrmMergeDatabases (rdb1, &database); |
|
|
204 | |
|
|
205 | XFree (displayResource); |
|
|
206 | } |
|
|
207 | |
|
|
208 | // 3. User's per host defaults file |
|
|
209 | /* Add in XENVIRONMENT file */ |
|
|
210 | if ((xe = (char *)getenv ("XENVIRONMENT")) |
|
|
211 | && (rdb1 = XrmGetFileDatabase (xe))) |
|
|
212 | XrmMergeDatabases (rdb1, &database); |
|
|
213 | else if (homedir) |
|
|
214 | { |
|
|
215 | struct utsname un; |
|
|
216 | |
|
|
217 | if (!uname (&un)) |
|
|
218 | { |
|
|
219 | snprintf (fname, sizeof (fname), "%s/.Xdefaults-%s", homedir, un.nodename); |
|
|
220 | |
|
|
221 | if ((rdb1 = XrmGetFileDatabase (fname))) |
|
|
222 | XrmMergeDatabases (rdb1, &database); |
|
|
223 | } |
|
|
224 | } |
|
|
225 | |
|
|
226 | return database; |
|
|
227 | } |
|
|
228 | |
146 | bool rxvt_display::init () |
229 | bool rxvt_display::ref_init () |
147 | { |
230 | { |
148 | #ifdef LOCAL_X_IS_UNIX |
231 | #ifdef LOCAL_X_IS_UNIX |
149 | if (id[0] == ':') |
232 | if (id[0] == ':') |
150 | { |
233 | { |
151 | val = rxvt_malloc (5 + strlen (id) + 1); |
234 | val = rxvt_malloc (5 + strlen (id) + 1); |
… | |
… | |
168 | root = DefaultRootWindow (display); |
251 | root = DefaultRootWindow (display); |
169 | visual = DefaultVisual (display, screen); |
252 | visual = DefaultVisual (display, screen); |
170 | cmap = DefaultColormap (display, screen); |
253 | cmap = DefaultColormap (display, screen); |
171 | depth = DefaultDepth (display, screen); |
254 | depth = DefaultDepth (display, screen); |
172 | |
255 | |
173 | int fd = XConnectionNumber (display); |
256 | XrmSetDatabase (display, get_resources ()); |
174 | |
|
|
175 | #ifndef NO_SLOW_LINK_SUPPORT |
|
|
176 | // try to detetc wether we have a local connection. |
|
|
177 | // assume unix domains socket == local, everything else not |
|
|
178 | // TODO: might want to check for inet/127.0.0.1 |
|
|
179 | is_local = 0; |
|
|
180 | sockaddr_un sa; |
|
|
181 | socklen_t sl = sizeof (sa); |
|
|
182 | |
|
|
183 | if (!getsockname (fd, (sockaddr *)&sa, &sl)) |
|
|
184 | is_local = sa.sun_family == AF_LOCAL; |
|
|
185 | #endif |
|
|
186 | |
257 | |
187 | #ifdef POINTER_BLANK |
258 | #ifdef POINTER_BLANK |
188 | XColor blackcolour; |
259 | XColor blackcolour; |
189 | blackcolour.red = 0; |
260 | blackcolour.red = 0; |
190 | blackcolour.green = 0; |
261 | blackcolour.green = 0; |
… | |
… | |
212 | visual, AllocNone); |
283 | visual, AllocNone); |
213 | } |
284 | } |
214 | } |
285 | } |
215 | #endif |
286 | #endif |
216 | |
287 | |
|
|
288 | int fd = XConnectionNumber (display); |
|
|
289 | |
|
|
290 | #ifndef NO_SLOW_LINK_SUPPORT |
|
|
291 | // try to detect wether we have a local connection. |
|
|
292 | // assume unix domains socket == local, everything else not |
|
|
293 | // TODO: might want to check for inet/127.0.0.1 |
|
|
294 | is_local = 0; |
|
|
295 | sockaddr_un sa; |
|
|
296 | socklen_t sl = sizeof (sa); |
|
|
297 | |
|
|
298 | if (!getsockname (fd, (sockaddr *)&sa, &sl)) |
|
|
299 | is_local = sa.sun_family == AF_LOCAL; |
|
|
300 | #endif |
|
|
301 | |
217 | x_ev.start (fd, EVENT_READ); |
302 | x_ev.start (fd, EVENT_READ); |
218 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
303 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
219 | |
304 | |
220 | XSelectInput (display, root, PropertyChangeMask); |
305 | XSelectInput (display, root, PropertyChangeMask); |
221 | #ifdef USE_XIM |
306 | #ifdef USE_XIM |
… | |
… | |
225 | flush (); |
310 | flush (); |
226 | |
311 | |
227 | return true; |
312 | return true; |
228 | } |
313 | } |
229 | |
314 | |
|
|
315 | void |
|
|
316 | rxvt_display::ref_next () |
|
|
317 | { |
|
|
318 | // TODO: somehow check wether the database files/resources changed |
|
|
319 | // before re-loading/parsing |
|
|
320 | XrmDestroyDatabase (XrmGetDatabase (display)); |
|
|
321 | XrmSetDatabase (display, get_resources ()); |
|
|
322 | } |
|
|
323 | |
230 | rxvt_display::~rxvt_display () |
324 | rxvt_display::~rxvt_display () |
231 | { |
325 | { |
|
|
326 | if (!display) |
|
|
327 | return; |
|
|
328 | |
|
|
329 | #ifdef POINTER_BLANK |
|
|
330 | XFreeCursor (display, blank_cursor); |
|
|
331 | #endif |
232 | x_ev.stop (); |
332 | x_ev.stop (); |
233 | #ifdef USE_XIM |
333 | #ifdef USE_XIM |
234 | xims.clear (); |
334 | xims.clear (); |
235 | #endif |
335 | #endif |
236 | |
|
|
237 | if (display) |
|
|
238 | XCloseDisplay (display); |
336 | XCloseDisplay (display); |
239 | } |
337 | } |
240 | |
338 | |
241 | #ifdef USE_XIM |
339 | #ifdef USE_XIM |
242 | void rxvt_display::im_change_cb () |
340 | void rxvt_display::im_change_cb () |
243 | { |
341 | { |
… | |
… | |
279 | XNextEvent (display, &xev); |
377 | XNextEvent (display, &xev); |
280 | |
378 | |
281 | #ifdef USE_XIM |
379 | #ifdef USE_XIM |
282 | if (!XFilterEvent (&xev, None)) |
380 | if (!XFilterEvent (&xev, None)) |
283 | { |
381 | { |
284 | |
|
|
285 | if (xev.type == PropertyNotify |
382 | if (xev.type == PropertyNotify |
286 | && xev.xany.window == root |
383 | && xev.xany.window == root |
287 | && xev.xproperty.atom == xa_xim_servers) |
384 | && xev.xproperty.atom == xa_xim_servers) |
288 | im_change_check (); |
385 | im_change_check (); |
289 | #endif |
386 | #endif |
… | |
… | |
474 | } |
571 | } |
475 | |
572 | |
476 | rxvt_color |
573 | rxvt_color |
477 | rxvt_color::fade (rxvt_display *display, int percent) |
574 | rxvt_color::fade (rxvt_display *display, int percent) |
478 | { |
575 | { |
|
|
576 | percent = 100 - percent; |
|
|
577 | |
479 | unsigned short cr, cg, cb; |
578 | unsigned short cr, cg, cb; |
480 | rxvt_color faded; |
579 | rxvt_color faded; |
481 | |
580 | |
482 | get (display, cr, cg, cb); |
581 | get (display, cr, cg, cb); |
|
|
582 | |
483 | faded.set (display, |
583 | faded.set ( |
|
|
584 | display, |
484 | cr * percent / 100, |
585 | cr * percent / 100, |
485 | cg * percent / 100, |
586 | cg * percent / 100, |
486 | cb * percent / 100); |
587 | cb * percent / 100 |
|
|
588 | ); |
487 | |
589 | |
488 | return faded; |
590 | return faded; |
489 | } |
591 | } |
490 | |
592 | |
|
|
593 | #define LERP(a,b,p) (a * p + b * (100 - p)) / 100 |
|
|
594 | |
|
|
595 | rxvt_color |
|
|
596 | rxvt_color::fade (rxvt_display *display, int percent, rxvt_color &fadeto) |
|
|
597 | { |
|
|
598 | percent = 100 - percent; |
|
|
599 | |
|
|
600 | unsigned short cr, cg, cb; |
|
|
601 | unsigned short fcr, fcg, fcb; |
|
|
602 | rxvt_color faded; |
|
|
603 | |
|
|
604 | get (display, cr, cg, cb); |
|
|
605 | fadeto.get(display, fcr, fcg, fcb); |
|
|
606 | |
|
|
607 | faded.set ( |
|
|
608 | display, |
|
|
609 | LERP (cr, fcr, percent), |
|
|
610 | LERP (cg, fcg, percent), |
|
|
611 | LERP (cb, fcb, percent) |
|
|
612 | ); |
|
|
613 | |
|
|
614 | return faded; |
|
|
615 | } |
|
|
616 | |