ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvttoolkit.C
(Generate patch)

Comparing rxvt-unicode/src/rxvttoolkit.C (file contents):
Revision 1.19 by root, Mon Nov 28 19:04:39 2005 UTC vs.
Revision 1.25 by root, Wed Jan 25 02:42:06 2006 UTC

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
37const char *const xa_names[] =
38 {
39 "TEXT",
40 "COMPOUND_TEXT",
41 "UTF8_STRING",
42 "MULTIPLE",
43 "TARGETS",
44 "TIMESTAMP",
45 "VT_SELECTION",
46 "INCR",
47 "WM_PROTOCOLS",
48 "WM_DELETE_WINDOW",
49 "CLIPBOARD",
50#if ENABLE_FRILLS
51 "_MOTIF_WM_HINTS",
52#endif
53#if ENABLE_EWMH
54 "_NET_WM_PID",
55 "_NET_WM_NAME",
56 "_NET_WM_ICON_NAME",
57 "_NET_WM_PING",
58#endif
59#if USE_XIM
60 "WM_LOCALE_NAME",
61 "XIM_SERVERS",
62#endif
63#ifdef TRANSPARENT
64 "_XROOTPMAP_ID",
65 "ESETROOT_PMAP_ID",
66#endif
67#if ENABLE_XEMBED
68 "_XEMBED",
69 "_XEMBED_INFO",
70#endif
71 };
72
73/////////////////////////////////////////////////////////////////////////////
74
35refcounted::refcounted (const char *id) 75refcounted::refcounted (const char *id)
36{ 76{
37 this->id = strdup (id); 77 this->id = strdup (id);
38} 78}
39 79
47{ 87{
48 for (T **i = this->begin (); i < this->end (); ++i) 88 for (T **i = this->begin (); i < this->end (); ++i)
49 { 89 {
50 if (!strcmp (id, (*i)->id)) 90 if (!strcmp (id, (*i)->id))
51 { 91 {
52 (*i)->referenced++; 92 ++(*i)->referenced;
93 (*i)->ref_next ();
53 return *i; 94 return *i;
54 } 95 }
55 } 96 }
56 97
57 T *obj = new T (id); 98 T *obj = new T (id);
58 99
59 obj->referenced = 1;
60
61 if (obj && obj->init ()) 100 if (obj && obj->ref_init ())
62 { 101 {
102 obj->referenced = 1;
63 this->push_back (obj); 103 this->push_back (obj);
64 return obj; 104 return obj;
65 } 105 }
66 else 106 else
67 { 107 {
91} 131}
92 132
93///////////////////////////////////////////////////////////////////////////// 133/////////////////////////////////////////////////////////////////////////////
94 134
95#ifdef USE_XIM 135#ifdef USE_XIM
136
96static void 137static void
97#if XIMCB_PROTO_BROKEN 138#if XIMCB_PROTO_BROKEN
98im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3) 139im_destroy_cb (XIC unused1, XPointer client_data, XPointer unused3)
99#else 140#else
100im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3) 141im_destroy_cb (XIM unused1, XPointer client_data, XPointer unused3)
107 148
108 display->xims.erase (find (display->xims.begin (), display->xims.end (), xim)); 149 display->xims.erase (find (display->xims.begin (), display->xims.end (), xim));
109 display->im_change_cb (); 150 display->im_change_cb ();
110} 151}
111 152
153bool
112bool rxvt_xim::init () 154rxvt_xim::ref_init ()
113{ 155{
114 display = GET_R->display; //HACK: TODO 156 display = GET_R->display; //HACK: TODO
115 157
116 xim = XOpenIM (display->display, NULL, NULL, NULL); 158 xim = XOpenIM (display->display, NULL, NULL, NULL);
117 159
130rxvt_xim::~rxvt_xim () 172rxvt_xim::~rxvt_xim ()
131{ 173{
132 if (xim) 174 if (xim)
133 XCloseIM (xim); 175 XCloseIM (xim);
134} 176}
177
135#endif 178#endif
136 179
137///////////////////////////////////////////////////////////////////////////// 180/////////////////////////////////////////////////////////////////////////////
138 181
139rxvt_display::rxvt_display (const char *id) 182rxvt_display::rxvt_display (const char *id)
141, x_ev (this, &rxvt_display::x_cb) 184, x_ev (this, &rxvt_display::x_cb)
142, selection_owner (0) 185, selection_owner (0)
143{ 186{
144} 187}
145 188
189XrmDatabase
190rxvt_display::get_resources ()
191{
192 char *homedir = (char *)getenv ("HOME");
193 char fname[1024];
194
195 /*
196 * get resources using the X library function
197 */
198 char *displayResource, *xe;
199 XrmDatabase database, rdb1;
200
201 database = NULL;
202
203 // for ordering, see for example http://www.faqs.org/faqs/Xt-FAQ/ Subject: 20
204
205 // 6. System wide per application default file.
206
207 /* Add in $XAPPLRESDIR/Rxvt only; not bothering with XUSERFILESEARCHPATH */
208 if ((xe = (char *)getenv ("XAPPLRESDIR")))
209 {
210 snprintf (fname, sizeof (fname), "%s/%s", xe, RESCLASS);
211
212 if ((rdb1 = XrmGetFileDatabase (fname)))
213 XrmMergeDatabases (rdb1, &database);
214 }
215
216 // 5. User's per application default file.
217 // none
218
219 // 4. User's defaults file.
220 /* Get any Xserver defaults */
221 displayResource = XResourceManagerString (display);
222
223 if (displayResource != NULL)
224 {
225 if ((rdb1 = XrmGetStringDatabase (displayResource)))
226 XrmMergeDatabases (rdb1, &database);
227 }
228 else if (homedir)
229 {
230 snprintf (fname, sizeof (fname), "%s/.Xdefaults", homedir);
231
232 if ((rdb1 = XrmGetFileDatabase (fname)))
233 XrmMergeDatabases (rdb1, &database);
234 }
235
236 /* Get screen specific resources */
237 displayResource = XScreenResourceString (ScreenOfDisplay (display, screen));
238
239 if (displayResource != NULL)
240 {
241 if ((rdb1 = XrmGetStringDatabase (displayResource)))
242 /* Merge with screen-independent resources */
243 XrmMergeDatabases (rdb1, &database);
244
245 XFree (displayResource);
246 }
247
248 // 3. User's per host defaults file
249 /* Add in XENVIRONMENT file */
250 if ((xe = (char *)getenv ("XENVIRONMENT"))
251 && (rdb1 = XrmGetFileDatabase (xe)))
252 XrmMergeDatabases (rdb1, &database);
253 else if (homedir)
254 {
255 struct utsname un;
256
257 if (!uname (&un))
258 {
259 snprintf (fname, sizeof (fname), "%s/.Xdefaults-%s", homedir, un.nodename);
260
261 if ((rdb1 = XrmGetFileDatabase (fname)))
262 XrmMergeDatabases (rdb1, &database);
263 }
264 }
265
266 return database;
267}
268
146bool rxvt_display::init () 269bool rxvt_display::ref_init ()
147{ 270{
148#ifdef LOCAL_X_IS_UNIX 271#ifdef LOCAL_X_IS_UNIX
149 if (id[0] == ':') 272 if (id[0] == ':')
150 { 273 {
151 val = rxvt_malloc (5 + strlen (id) + 1); 274 val = rxvt_malloc (5 + strlen (id) + 1);
168 root = DefaultRootWindow (display); 291 root = DefaultRootWindow (display);
169 visual = DefaultVisual (display, screen); 292 visual = DefaultVisual (display, screen);
170 cmap = DefaultColormap (display, screen); 293 cmap = DefaultColormap (display, screen);
171 depth = DefaultDepth (display, screen); 294 depth = DefaultDepth (display, screen);
172 295
173 int fd = XConnectionNumber (display); 296 assert (sizeof (xa_names) / sizeof (char *) == NUM_XA);
297 XInternAtoms (display, (char **)xa_names, NUM_XA, False, xa);
174 298
175#ifndef NO_SLOW_LINK_SUPPORT 299 XrmSetDatabase (display, get_resources ());
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 300
187#ifdef POINTER_BLANK 301#ifdef POINTER_BLANK
188 XColor blackcolour; 302 XColor blackcolour;
189 blackcolour.red = 0; 303 blackcolour.red = 0;
190 blackcolour.green = 0; 304 blackcolour.green = 0;
212 visual, AllocNone); 326 visual, AllocNone);
213 } 327 }
214 } 328 }
215#endif 329#endif
216 330
331 int fd = XConnectionNumber (display);
332
333#ifndef NO_SLOW_LINK_SUPPORT
334 // try to detect wether we have a local connection.
335 // assume unix domains socket == local, everything else not
336 // TODO: might want to check for inet/127.0.0.1
337 is_local = 0;
338 sockaddr_un sa;
339 socklen_t sl = sizeof (sa);
340
341 if (!getsockname (fd, (sockaddr *)&sa, &sl))
342 is_local = sa.sun_family == AF_LOCAL;
343#endif
344
217 x_ev.start (fd, EVENT_READ); 345 x_ev.start (fd, EVENT_READ);
218 fcntl (fd, F_SETFD, FD_CLOEXEC); 346 fcntl (fd, F_SETFD, FD_CLOEXEC);
219 347
220 XSelectInput (display, root, PropertyChangeMask); 348 XSelectInput (display, root, PropertyChangeMask);
221#ifdef USE_XIM
222 xa_xim_servers = XInternAtom (display, "XIM_SERVERS", 0);
223#endif
224 349
225 flush (); 350 flush ();
226 351
227 return true; 352 return true;
228} 353}
229 354
355void
356rxvt_display::ref_next ()
357{
358 // TODO: somehow check wether the database files/resources changed
359 // before re-loading/parsing
360 XrmDestroyDatabase (XrmGetDatabase (display));
361 XrmSetDatabase (display, get_resources ());
362}
363
230rxvt_display::~rxvt_display () 364rxvt_display::~rxvt_display ()
231{ 365{
366 if (!display)
367 return;
368
369#ifdef POINTER_BLANK
370 XFreeCursor (display, blank_cursor);
371#endif
232 x_ev.stop (); 372 x_ev.stop ();
233#ifdef USE_XIM 373#ifdef USE_XIM
234 xims.clear (); 374 xims.clear ();
235#endif 375#endif
236
237 if (display)
238 XCloseDisplay (display); 376 XCloseDisplay (display);
239} 377}
240 378
241#ifdef USE_XIM 379#ifdef USE_XIM
242void rxvt_display::im_change_cb () 380void rxvt_display::im_change_cb ()
243{ 381{
251 // registers, as xlib crashes due to a race otherwise. 389 // registers, as xlib crashes due to a race otherwise.
252 Atom actual_type, *atoms; 390 Atom actual_type, *atoms;
253 int actual_format; 391 int actual_format;
254 unsigned long nitems, bytes_after; 392 unsigned long nitems, bytes_after;
255 393
256 if (XGetWindowProperty (display, root, xa_xim_servers, 0L, 1000000L, 394 if (XGetWindowProperty (display, root, xa[XA_XIM_SERVERS], 0L, 1000000L,
257 False, XA_ATOM, &actual_type, &actual_format, 395 False, XA_ATOM, &actual_type, &actual_format,
258 &nitems, &bytes_after, (unsigned char **)&atoms) 396 &nitems, &bytes_after, (unsigned char **)&atoms)
259 != Success ) 397 != Success )
260 return; 398 return;
261 399
279 XNextEvent (display, &xev); 417 XNextEvent (display, &xev);
280 418
281#ifdef USE_XIM 419#ifdef USE_XIM
282 if (!XFilterEvent (&xev, None)) 420 if (!XFilterEvent (&xev, None))
283 { 421 {
284
285 if (xev.type == PropertyNotify 422 if (xev.type == PropertyNotify
286 && xev.xany.window == root 423 && xev.xany.window == root
287 && xev.xproperty.atom == xa_xim_servers) 424 && xev.xproperty.atom == xa[XA_XIM_SERVERS])
288 im_change_check (); 425 im_change_check ();
289#endif 426#endif
290 for (int i = xw.size (); i--; ) 427 for (int i = xw.size (); i--; )
291 { 428 {
292 if (!xw[i]) 429 if (!xw[i])

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines