… | |
… | |
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 | { |
… | |
… | |
91 | } |
93 | } |
92 | |
94 | |
93 | ///////////////////////////////////////////////////////////////////////////// |
95 | ///////////////////////////////////////////////////////////////////////////// |
94 | |
96 | |
95 | #ifdef USE_XIM |
97 | #ifdef USE_XIM |
|
|
98 | |
96 | static void |
99 | static void |
97 | #if XIMCB_PROTO_BROKEN |
100 | #if XIMCB_PROTO_BROKEN |
98 | im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3) |
101 | im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3) |
99 | #else |
102 | #else |
100 | im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3) |
103 | im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3) |
… | |
… | |
107 | |
110 | |
108 | display->xims.erase (find (display->xims.begin (), display->xims.end (), xim)); |
111 | display->xims.erase (find (display->xims.begin (), display->xims.end (), xim)); |
109 | display->im_change_cb (); |
112 | display->im_change_cb (); |
110 | } |
113 | } |
111 | |
114 | |
|
|
115 | bool |
112 | bool rxvt_xim::init () |
116 | rxvt_xim::ref_init () |
113 | { |
117 | { |
114 | display = GET_R->display; //HACK: TODO |
118 | display = GET_R->display; //HACK: TODO |
115 | |
119 | |
116 | xim = XOpenIM (display->display, NULL, NULL, NULL); |
120 | xim = XOpenIM (display->display, NULL, NULL, NULL); |
117 | |
121 | |
… | |
… | |
130 | rxvt_xim::~rxvt_xim () |
134 | rxvt_xim::~rxvt_xim () |
131 | { |
135 | { |
132 | if (xim) |
136 | if (xim) |
133 | XCloseIM (xim); |
137 | XCloseIM (xim); |
134 | } |
138 | } |
|
|
139 | |
135 | #endif |
140 | #endif |
136 | |
141 | |
137 | ///////////////////////////////////////////////////////////////////////////// |
142 | ///////////////////////////////////////////////////////////////////////////// |
138 | |
143 | |
139 | rxvt_display::rxvt_display (const char *id) |
144 | rxvt_display::rxvt_display (const char *id) |
… | |
… | |
141 | , x_ev (this, &rxvt_display::x_cb) |
146 | , x_ev (this, &rxvt_display::x_cb) |
142 | , selection_owner (0) |
147 | , selection_owner (0) |
143 | { |
148 | { |
144 | } |
149 | } |
145 | |
150 | |
|
|
151 | XrmDatabase |
|
|
152 | rxvt_display::get_resources () |
|
|
153 | { |
|
|
154 | char *homedir = (char *)getenv ("HOME"); |
|
|
155 | char fname[1024]; |
|
|
156 | |
|
|
157 | /* |
|
|
158 | * get resources using the X library function |
|
|
159 | */ |
|
|
160 | char *displayResource, *xe; |
|
|
161 | XrmDatabase database, rdb1; |
|
|
162 | |
|
|
163 | database = NULL; |
|
|
164 | |
|
|
165 | // for ordering, see for example http://www.faqs.org/faqs/Xt-FAQ/ Subject: 20 |
|
|
166 | |
|
|
167 | // 6. System wide per application default file. |
|
|
168 | |
|
|
169 | /* Add in $XAPPLRESDIR/Rxvt only; not bothering with XUSERFILESEARCHPATH */ |
|
|
170 | if ((xe = (char *)getenv ("XAPPLRESDIR"))) |
|
|
171 | { |
|
|
172 | snprintf (fname, sizeof (fname), "%s/%s", xe, RESCLASS); |
|
|
173 | |
|
|
174 | if ((rdb1 = XrmGetFileDatabase (fname))) |
|
|
175 | XrmMergeDatabases (rdb1, &database); |
|
|
176 | } |
|
|
177 | |
|
|
178 | // 5. User's per application default file. |
|
|
179 | // none |
|
|
180 | |
|
|
181 | // 4. User's defaults file. |
|
|
182 | /* Get any Xserver defaults */ |
|
|
183 | displayResource = XResourceManagerString (display); |
|
|
184 | |
|
|
185 | if (displayResource != NULL) |
|
|
186 | { |
|
|
187 | if ((rdb1 = XrmGetStringDatabase (displayResource))) |
|
|
188 | XrmMergeDatabases (rdb1, &database); |
|
|
189 | } |
|
|
190 | else if (homedir) |
|
|
191 | { |
|
|
192 | snprintf (fname, sizeof (fname), "%s/.Xdefaults", homedir); |
|
|
193 | |
|
|
194 | if ((rdb1 = XrmGetFileDatabase (fname))) |
|
|
195 | XrmMergeDatabases (rdb1, &database); |
|
|
196 | } |
|
|
197 | |
|
|
198 | /* Get screen specific resources */ |
|
|
199 | displayResource = XScreenResourceString (ScreenOfDisplay (display, screen)); |
|
|
200 | |
|
|
201 | if (displayResource != NULL) |
|
|
202 | { |
|
|
203 | if ((rdb1 = XrmGetStringDatabase (displayResource))) |
|
|
204 | /* Merge with screen-independent resources */ |
|
|
205 | XrmMergeDatabases (rdb1, &database); |
|
|
206 | |
|
|
207 | XFree (displayResource); |
|
|
208 | } |
|
|
209 | |
|
|
210 | // 3. User's per host defaults file |
|
|
211 | /* Add in XENVIRONMENT file */ |
|
|
212 | if ((xe = (char *)getenv ("XENVIRONMENT")) |
|
|
213 | && (rdb1 = XrmGetFileDatabase (xe))) |
|
|
214 | XrmMergeDatabases (rdb1, &database); |
|
|
215 | else if (homedir) |
|
|
216 | { |
|
|
217 | struct utsname un; |
|
|
218 | |
|
|
219 | if (!uname (&un)) |
|
|
220 | { |
|
|
221 | snprintf (fname, sizeof (fname), "%s/.Xdefaults-%s", homedir, un.nodename); |
|
|
222 | |
|
|
223 | if ((rdb1 = XrmGetFileDatabase (fname))) |
|
|
224 | XrmMergeDatabases (rdb1, &database); |
|
|
225 | } |
|
|
226 | } |
|
|
227 | |
|
|
228 | return database; |
|
|
229 | } |
|
|
230 | |
146 | bool rxvt_display::init () |
231 | bool rxvt_display::ref_init () |
147 | { |
232 | { |
148 | #ifdef LOCAL_X_IS_UNIX |
233 | #ifdef LOCAL_X_IS_UNIX |
149 | if (id[0] == ':') |
234 | if (id[0] == ':') |
150 | { |
235 | { |
151 | val = rxvt_malloc (5 + strlen (id) + 1); |
236 | val = rxvt_malloc (5 + strlen (id) + 1); |
… | |
… | |
168 | root = DefaultRootWindow (display); |
253 | root = DefaultRootWindow (display); |
169 | visual = DefaultVisual (display, screen); |
254 | visual = DefaultVisual (display, screen); |
170 | cmap = DefaultColormap (display, screen); |
255 | cmap = DefaultColormap (display, screen); |
171 | depth = DefaultDepth (display, screen); |
256 | depth = DefaultDepth (display, screen); |
172 | |
257 | |
173 | int fd = XConnectionNumber (display); |
258 | XrmSetDatabase (display, get_resources ()); |
174 | |
|
|
175 | #ifndef NO_SLOW_LINK_SUPPORT |
|
|
176 | // try to detect 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 | |
259 | |
187 | #ifdef POINTER_BLANK |
260 | #ifdef POINTER_BLANK |
188 | XColor blackcolour; |
261 | XColor blackcolour; |
189 | blackcolour.red = 0; |
262 | blackcolour.red = 0; |
190 | blackcolour.green = 0; |
263 | blackcolour.green = 0; |
… | |
… | |
212 | visual, AllocNone); |
285 | visual, AllocNone); |
213 | } |
286 | } |
214 | } |
287 | } |
215 | #endif |
288 | #endif |
216 | |
289 | |
|
|
290 | int fd = XConnectionNumber (display); |
|
|
291 | |
|
|
292 | #ifndef NO_SLOW_LINK_SUPPORT |
|
|
293 | // try to detect wether we have a local connection. |
|
|
294 | // assume unix domains socket == local, everything else not |
|
|
295 | // TODO: might want to check for inet/127.0.0.1 |
|
|
296 | is_local = 0; |
|
|
297 | sockaddr_un sa; |
|
|
298 | socklen_t sl = sizeof (sa); |
|
|
299 | |
|
|
300 | if (!getsockname (fd, (sockaddr *)&sa, &sl)) |
|
|
301 | is_local = sa.sun_family == AF_LOCAL; |
|
|
302 | #endif |
|
|
303 | |
217 | x_ev.start (fd, EVENT_READ); |
304 | x_ev.start (fd, EVENT_READ); |
218 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
305 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
219 | |
306 | |
220 | XSelectInput (display, root, PropertyChangeMask); |
307 | XSelectInput (display, root, PropertyChangeMask); |
221 | #ifdef USE_XIM |
308 | #ifdef USE_XIM |
… | |
… | |
225 | flush (); |
312 | flush (); |
226 | |
313 | |
227 | return true; |
314 | return true; |
228 | } |
315 | } |
229 | |
316 | |
|
|
317 | void |
|
|
318 | rxvt_display::ref_next () |
|
|
319 | { |
|
|
320 | // TODO: somehow check wether the database files/resources changed |
|
|
321 | // before re-loading/parsing |
|
|
322 | XrmDestroyDatabase (XrmGetDatabase (display)); |
|
|
323 | XrmSetDatabase (display, get_resources ()); |
|
|
324 | } |
|
|
325 | |
230 | rxvt_display::~rxvt_display () |
326 | rxvt_display::~rxvt_display () |
231 | { |
327 | { |
|
|
328 | if (!display) |
|
|
329 | return; |
|
|
330 | |
|
|
331 | #ifdef POINTER_BLANK |
|
|
332 | XFreeCursor (display, blank_cursor); |
|
|
333 | #endif |
232 | x_ev.stop (); |
334 | x_ev.stop (); |
233 | #ifdef USE_XIM |
335 | #ifdef USE_XIM |
234 | xims.clear (); |
336 | xims.clear (); |
235 | #endif |
337 | #endif |
236 | |
|
|
237 | if (display) |
|
|
238 | XCloseDisplay (display); |
338 | XCloseDisplay (display); |
239 | } |
339 | } |
240 | |
340 | |
241 | #ifdef USE_XIM |
341 | #ifdef USE_XIM |
242 | void rxvt_display::im_change_cb () |
342 | void rxvt_display::im_change_cb () |
243 | { |
343 | { |
… | |
… | |
279 | XNextEvent (display, &xev); |
379 | XNextEvent (display, &xev); |
280 | |
380 | |
281 | #ifdef USE_XIM |
381 | #ifdef USE_XIM |
282 | if (!XFilterEvent (&xev, None)) |
382 | if (!XFilterEvent (&xev, None)) |
283 | { |
383 | { |
284 | |
|
|
285 | if (xev.type == PropertyNotify |
384 | if (xev.type == PropertyNotify |
286 | && xev.xany.window == root |
385 | && xev.xany.window == root |
287 | && xev.xproperty.atom == xa_xim_servers) |
386 | && xev.xproperty.atom == xa_xim_servers) |
288 | im_change_check (); |
387 | im_change_check (); |
289 | #endif |
388 | #endif |
… | |
… | |
491 | ); |
590 | ); |
492 | |
591 | |
493 | return faded; |
592 | return faded; |
494 | } |
593 | } |
495 | |
594 | |
496 | #define LERP(a,b,p) (a * p / 100 + b * (100 - p) / 100) |
595 | #define LERP(a,b,p) (a * p + b * (100 - p)) / 100 |
497 | |
596 | |
498 | rxvt_color |
597 | rxvt_color |
499 | rxvt_color::fade (rxvt_display *display, int percent, rxvt_color &fadeto) |
598 | rxvt_color::fade (rxvt_display *display, int percent, rxvt_color &fadeto) |
500 | { |
599 | { |
501 | percent = 100 - percent; |
600 | percent = 100 - percent; |