Mercurial > hg > xemacs-beta
comparison src/device-x.c @ 276:6330739388db r21-0b36
Import from CVS: tag r21-0b36
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:30:37 +0200 |
parents | c5d627a313b1 |
children | 90d73dddcdc4 |
comparison
equal
deleted
inserted
replaced
275:a68ae4439f57 | 276:6330739388db |
---|---|
124 struct device * | 124 struct device * |
125 get_device_from_display (Display *dpy) | 125 get_device_from_display (Display *dpy) |
126 { | 126 { |
127 struct device *d = get_device_from_display_1 (dpy); | 127 struct device *d = get_device_from_display_1 (dpy); |
128 | 128 |
129 #if !defined(INFODOCK) | |
130 # define FALLBACK_RESOURCE_NAME "xemacs" | |
131 # else | |
132 # define FALLBACK_RESOURCE_NAME "infodock" | |
133 #endif | |
134 | |
129 if (!d) { | 135 if (!d) { |
130 /* This isn't one of our displays. Let's crash? */ | 136 /* This isn't one of our displays. Let's crash? */ |
131 stderr_out | 137 stderr_out |
132 ("\n%s: Fatal X Condition. Asked about display we don't own: \"%s\"\n", | 138 ("\n%s: Fatal X Condition. Asked about display we don't own: \"%s\"\n", |
133 (STRINGP (Vinvocation_name) ? | 139 (STRINGP (Vinvocation_name) ? |
134 (char *) XSTRING_DATA (Vinvocation_name) : "xemacs"), | 140 (char *) XSTRING_DATA (Vinvocation_name) : FALLBACK_RESOURCE_NAME), |
135 DisplayString (dpy) ? DisplayString (dpy) : "???"); | 141 DisplayString (dpy) ? DisplayString (dpy) : "???"); |
136 abort(); | 142 abort(); |
137 } | 143 } |
144 | |
145 #undef FALLBACK_RESOURCE_NAME | |
138 | 146 |
139 return d; | 147 return d; |
140 } | 148 } |
141 | 149 |
142 struct device * | 150 struct device * |
222 } | 230 } |
223 else | 231 else |
224 DEVICE_CLASS (d) = Qmono; | 232 DEVICE_CLASS (d) = Qmono; |
225 } | 233 } |
226 | 234 |
235 /* | |
236 * Figure out what application name to use for xemacs | |
237 * | |
238 * Since we have decomposed XtOpenDisplay into XOpenDisplay and | |
239 * XtDisplayInitialize, we no longer get this for free. | |
240 * | |
241 * If there is a `-name' argument in argv, use that. | |
242 * Otherwise use the last component of argv[0]. | |
243 * | |
244 * I have removed the gratuitous use of getenv("RESOURCE_NAME") | |
245 * which was in X11R5, but left the matching of any prefix of `-name'. | |
246 * Finally, if all else fails, return `xemacs', as it is more | |
247 * appropriate (X11R5 returns `main'). | |
248 */ | |
249 static char * | |
250 compute_x_app_name (int argc, char **argv) | |
251 { | |
252 int i; | |
253 char *ptr; | |
254 | |
255 for (i = 1; i < argc - 1; i++) | |
256 if (!strncmp(argv[i], "-name", max (2, strlen (argv[1])))) | |
257 return argv[i+1]; | |
258 | |
259 if (argc > 0 && argv[0] && *argv[0]) | |
260 return (ptr = strrchr (argv[0], '/')) ? ++ptr : argv[0]; | |
261 | |
262 return "xemacs"; | |
263 } | |
264 | |
265 /* | |
266 * This function figures out whether the user has any resources of the | |
267 * form "XEmacs.foo" or "XEmacs*foo". | |
268 * | |
269 * Currently we only consult the display's global resources; to look | |
270 * for screen specific resources, we would need to also consult: | |
271 * xdefs = XScreenResourceString(ScreenOfDisplay(dpy, scrno)); | |
272 */ | |
227 static int | 273 static int |
228 have_xemacs_resources_in_xrdb (CONST char *disp_name) | 274 have_xemacs_resources_in_xrdb (Display *dpy) |
229 { | 275 { |
230 Display *dpy; | |
231 char *xdefs, *key; | 276 char *xdefs, *key; |
232 int len, found; | 277 int len; |
233 | |
234 /* | |
235 ** This function figures out whether the user has any resources of the | |
236 ** form "XEmacs.foo" or "XEmacs*foo". | |
237 ** | |
238 ** Currently we only consult the display's global resources; to look | |
239 ** for screen specific resources, we would need to also consult: | |
240 ** xdefs = XScreenResourceString(ScreenOfDisplay(dpy, scrno)); | |
241 */ | |
242 | 278 |
243 key = "XEmacs"; | 279 key = "XEmacs"; |
244 len = strlen(key); | 280 len = strlen (key); |
245 | 281 |
246 dpy = XOpenDisplay(disp_name); | 282 if (!dpy) |
247 | 283 return 0; |
248 if (!dpy) return 0; | 284 |
249 | 285 xdefs = XResourceManagerString (dpy); /* don't free - owned by X */ |
250 xdefs = XResourceManagerString(dpy); /* don't free - owned by X */ | 286 while (xdefs && *xdefs) |
251 for (found = 0; xdefs && *xdefs; ) { | 287 { |
252 if (strncmp(xdefs, key, len) == 0 && | 288 if (strncmp (xdefs, key, len) == 0 && |
253 (xdefs[len] == '*' || xdefs[len] == '.')) { | 289 (xdefs[len] == '*' || xdefs[len] == '.')) |
254 found = 1; | 290 return 1; |
255 break; | 291 |
256 } | 292 while (*xdefs && *xdefs++ != '\n') /* find start of next entry.. */ |
257 | 293 ; |
258 while (*xdefs && *xdefs++ != '\n') /* find start of next entry.. */ | 294 } |
259 ; | 295 |
260 } | 296 return 0; |
261 | |
262 XCloseDisplay(dpy); | |
263 return found; | |
264 } | 297 } |
265 | 298 |
266 /* Only the characters [-_A-Za-z0-9] are allowed in the individual | 299 /* Only the characters [-_A-Za-z0-9] are allowed in the individual |
267 components of a resource. Convert invalid characters to `-' */ | 300 components of a resource. Convert invalid characters to `-' */ |
268 | 301 |
310 | 343 |
311 make_argc_argv (Vx_initial_argv_list, &argc, &argv); | 344 make_argc_argv (Vx_initial_argv_list, &argc, &argv); |
312 | 345 |
313 GET_C_STRING_CTEXT_DATA_ALLOCA (display, disp_name); | 346 GET_C_STRING_CTEXT_DATA_ALLOCA (display, disp_name); |
314 | 347 |
348 /* | |
349 * Break apart the old XtOpenDisplay call into XOpenDisplay and | |
350 * XtDisplayInitialize so we can figure out whether there | |
351 * are any XEmacs resources in the resource database before | |
352 * we intitialize Xt. This is so we can automagically support | |
353 * both `Emacs' and `XEmacs' application classes. | |
354 */ | |
355 slow_down_interrupts (); | |
356 /* May not be needed but XtOpenDisplay could not deal with signals here. */ | |
357 dpy = DEVICE_X_DISPLAY (d) = XOpenDisplay (disp_name); | |
358 speed_up_interrupts (); | |
359 | |
360 if (dpy == 0) | |
361 { | |
362 suppress_early_error_handler_backtrace = 1; | |
363 signal_simple_error ("X server not responding\n", display); | |
364 } | |
365 | |
315 if (STRINGP (Vx_emacs_application_class) && | 366 if (STRINGP (Vx_emacs_application_class) && |
316 XSTRING_LENGTH (Vx_emacs_application_class) > 0) | 367 XSTRING_LENGTH (Vx_emacs_application_class) > 0) |
317 GET_C_STRING_CTEXT_DATA_ALLOCA (Vx_emacs_application_class, app_class); | 368 GET_C_STRING_CTEXT_DATA_ALLOCA (Vx_emacs_application_class, app_class); |
318 else { | 369 else |
319 app_class = (NILP (Vx_emacs_application_class) && | 370 { |
320 have_xemacs_resources_in_xrdb (disp_name)) | 371 app_class = (NILP (Vx_emacs_application_class) && |
321 ? "XEmacs" | 372 have_xemacs_resources_in_xrdb (dpy)) |
322 : "Emacs"; | 373 ? "XEmacs" |
323 /* need to update Vx_emacs_application_class: */ | 374 : "Emacs"; |
324 Vx_emacs_application_class = build_string (app_class); | 375 /* need to update Vx_emacs_application_class: */ |
325 } | 376 Vx_emacs_application_class = build_string (app_class); |
377 } | |
326 | 378 |
327 slow_down_interrupts (); | 379 slow_down_interrupts (); |
328 /* The Xt code can't deal with signals here. Yuck. */ | 380 /* May not be needed but XtOpenDisplay could not deal with signals here. |
329 dpy = DEVICE_X_DISPLAY (d) = | 381 Yuck. */ |
330 XtOpenDisplay (Xt_app_con, disp_name, NULL, app_class, emacs_options, | 382 XtDisplayInitialize (Xt_app_con, dpy, compute_x_app_name (argc, argv), |
331 XtNumber (emacs_options), &argc, argv); | 383 app_class, emacs_options, |
384 XtNumber (emacs_options), &argc, argv); | |
332 speed_up_interrupts (); | 385 speed_up_interrupts (); |
333 | |
334 if (dpy == 0) | |
335 { | |
336 suppress_early_error_handler_backtrace = 1; | |
337 signal_simple_error ("X server not responding\n", display); | |
338 } | |
339 | 386 |
340 screen = DefaultScreen(dpy); | 387 screen = DefaultScreen(dpy); |
341 if (NILP (Vdefault_x_device)) | 388 if (NILP (Vdefault_x_device)) |
342 Vdefault_x_device = device; | 389 Vdefault_x_device = device; |
343 | 390 |