428
|
1 /* Device functions for X windows.
|
|
2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
|
|
3 Copyright (C) 1994, 1995 Free Software Foundation, Inc.
|
2367
|
4 Copyright (C) 2001, 2002, 2004 Ben Wing.
|
428
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: Not in FSF. */
|
|
24
|
442
|
25 /* 7-8-00 !!#### This file needs definite Mule review. */
|
|
26
|
428
|
27 /* Original authors: Jamie Zawinski and the FSF */
|
|
28 /* Rewritten by Ben Wing and Chuck Thompson. */
|
|
29
|
|
30 #include <config.h>
|
|
31 #include "lisp.h"
|
|
32
|
|
33 #include "buffer.h"
|
872
|
34 #include "device-impl.h"
|
428
|
35 #include "elhash.h"
|
|
36 #include "events.h"
|
|
37 #include "faces.h"
|
872
|
38 #include "frame-impl.h"
|
2684
|
39 #include "process.h" /* for egetenv */
|
428
|
40 #include "redisplay.h"
|
|
41 #include "sysdep.h"
|
|
42 #include "window.h"
|
|
43
|
872
|
44 #include "console-x-impl.h"
|
800
|
45 #include "glyphs-x.h"
|
|
46 #include "objects-x.h"
|
|
47
|
428
|
48 #include "sysfile.h"
|
|
49 #include "systime.h"
|
|
50
|
800
|
51 #include "xintrinsicp.h" /* CoreP.h needs this */
|
|
52 #include <X11/CoreP.h> /* Numerous places access the fields of
|
|
53 a core widget directly. We could
|
|
54 use XtGetValues(), but ... */
|
|
55 #include "xgccache.h"
|
|
56 #include <X11/Shell.h>
|
|
57 #include "xmu.h"
|
|
58
|
442
|
59 #if defined(HAVE_SHLIB) && defined(LWLIB_USES_ATHENA) && !defined(HAVE_ATHENA_3D)
|
440
|
60 #include "sysdll.h"
|
442
|
61 #endif /* HAVE_SHLIB and LWLIB_USES_ATHENA and not HAVE_ATHENA_3D */
|
440
|
62
|
428
|
63 #ifdef HAVE_OFFIX_DND
|
|
64 #include "offix.h"
|
|
65 #endif
|
|
66
|
771
|
67 #ifdef MULE
|
428
|
68 Lisp_Object Vx_app_defaults_directory;
|
771
|
69 Lisp_Object Qget_coding_system_from_locale;
|
428
|
70 #endif
|
|
71
|
|
72 /* Qdisplay in general.c */
|
|
73 Lisp_Object Qx_error;
|
|
74 Lisp_Object Qinit_pre_x_win, Qinit_post_x_win;
|
|
75
|
|
76 /* The application class of Emacs. */
|
|
77 Lisp_Object Vx_emacs_application_class;
|
|
78
|
|
79 Lisp_Object Vx_initial_argv_list; /* #### ugh! */
|
|
80
|
|
81 static XrmOptionDescRec emacs_options[] =
|
|
82 {
|
|
83 {"-geometry", ".geometry", XrmoptionSepArg, NULL},
|
|
84 {"-iconic", ".iconic", XrmoptionNoArg, "yes"},
|
|
85
|
|
86 {"-internal-border-width", "*EmacsFrame.internalBorderWidth", XrmoptionSepArg, NULL},
|
|
87 {"-ib", "*EmacsFrame.internalBorderWidth", XrmoptionSepArg, NULL},
|
|
88 {"-scrollbar-width", "*EmacsFrame.scrollBarWidth", XrmoptionSepArg, NULL},
|
|
89 {"-scrollbar-height", "*EmacsFrame.scrollBarHeight", XrmoptionSepArg, NULL},
|
|
90
|
|
91 {"-privatecolormap", ".privateColormap", XrmoptionNoArg, "yes"},
|
|
92 {"-visual", ".EmacsVisual", XrmoptionSepArg, NULL},
|
|
93
|
|
94 /* #### Beware! If the type of the shell changes, update this. */
|
|
95 {"-T", "*TopLevelEmacsShell.title", XrmoptionSepArg, NULL},
|
|
96 {"-wn", "*TopLevelEmacsShell.title", XrmoptionSepArg, NULL},
|
|
97 {"-title", "*TopLevelEmacsShell.title", XrmoptionSepArg, NULL},
|
|
98
|
|
99 {"-iconname", "*TopLevelEmacsShell.iconName", XrmoptionSepArg, NULL},
|
|
100 {"-in", "*TopLevelEmacsShell.iconName", XrmoptionSepArg, NULL},
|
|
101 {"-mc", "*pointerColor", XrmoptionSepArg, NULL},
|
|
102 {"-cr", "*cursorColor", XrmoptionSepArg, NULL},
|
|
103 {"-fontset", "*FontSet", XrmoptionSepArg, NULL},
|
|
104 };
|
|
105
|
1204
|
106 static const struct memory_description x_device_data_description_1 [] = {
|
|
107 { XD_LISP_OBJECT, offsetof (struct x_device, x_keysym_map_hash_table) },
|
|
108 { XD_LISP_OBJECT, offsetof (struct x_device, WM_COMMAND_frame) },
|
|
109 { XD_END }
|
|
110 };
|
|
111
|
3092
|
112 #ifdef NEW_GC
|
|
113 DEFINE_LRECORD_IMPLEMENTATION ("x-device", x_device,
|
|
114 1, /*dumpable-flag*/
|
|
115 0, 0, 0, 0, 0,
|
|
116 x_device_data_description_1,
|
|
117 Lisp_X_Device);
|
|
118 #else /* not NEW_GC */
|
1204
|
119 extern const struct sized_memory_description x_device_data_description;
|
|
120
|
|
121 const struct sized_memory_description x_device_data_description = {
|
|
122 sizeof (struct x_device), x_device_data_description_1
|
|
123 };
|
3092
|
124 #endif /* not NEW_GC */
|
1204
|
125
|
428
|
126 /* Functions to synchronize mirroring resources and specifiers */
|
|
127 int in_resource_setting;
|
|
128
|
|
129 /************************************************************************/
|
|
130 /* helper functions */
|
|
131 /************************************************************************/
|
|
132
|
|
133 /* JH 97/11/25 removed the static declaration because I need it during setup in event-Xt... */
|
|
134 struct device * get_device_from_display_1 (Display *dpy);
|
|
135 struct device *
|
|
136 get_device_from_display_1 (Display *dpy)
|
|
137 {
|
|
138 Lisp_Object devcons, concons;
|
|
139
|
|
140 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
141 {
|
|
142 struct device *d = XDEVICE (XCAR (devcons));
|
|
143 if (DEVICE_X_P (d) && DEVICE_X_DISPLAY (d) == dpy)
|
|
144 return d;
|
|
145 }
|
|
146
|
|
147 return 0;
|
|
148 }
|
|
149
|
|
150 struct device *
|
|
151 get_device_from_display (Display *dpy)
|
|
152 {
|
|
153 struct device *d = get_device_from_display_1 (dpy);
|
|
154
|
|
155 #if !defined(INFODOCK)
|
|
156 # define FALLBACK_RESOURCE_NAME "xemacs"
|
|
157 # else
|
|
158 # define FALLBACK_RESOURCE_NAME "infodock"
|
|
159 #endif
|
|
160
|
853
|
161 if (!d)
|
|
162 {
|
|
163 /* This isn't one of our displays. Let's crash? */
|
|
164 stderr_out
|
|
165 ("\n%s: Fatal X Condition. Asked about display we don't own: \"%s\"\n",
|
|
166 (STRINGP (Vinvocation_name) ?
|
|
167 (char *) XSTRING_DATA (Vinvocation_name) : FALLBACK_RESOURCE_NAME),
|
|
168 DisplayString (dpy) ? DisplayString (dpy) : "???");
|
2500
|
169 ABORT();
|
853
|
170 }
|
428
|
171
|
|
172 #undef FALLBACK_RESOURCE_NAME
|
|
173
|
|
174 return d;
|
|
175 }
|
|
176
|
|
177 struct device *
|
|
178 decode_x_device (Lisp_Object device)
|
|
179 {
|
793
|
180 device = wrap_device (decode_device (device));
|
428
|
181 CHECK_X_DEVICE (device);
|
|
182 return XDEVICE (device);
|
|
183 }
|
|
184
|
|
185 static Display *
|
|
186 get_x_display (Lisp_Object device)
|
|
187 {
|
|
188 return DEVICE_X_DISPLAY (decode_x_device (device));
|
|
189 }
|
|
190
|
771
|
191 static Lisp_Object
|
2333
|
192 coding_system_of_xrm_database (XrmDatabase USED_IF_MULE (db))
|
771
|
193 {
|
|
194 #ifdef MULE
|
|
195 const Extbyte *locale = XrmLocaleOfDatabase (db);
|
|
196 Lisp_Object localestr = build_ext_string (locale, Qbinary);
|
|
197 return call1 (Qget_coding_system_from_locale, localestr);
|
|
198 #else
|
|
199 return Qbinary;
|
|
200 #endif
|
|
201 }
|
|
202
|
428
|
203
|
|
204 /************************************************************************/
|
|
205 /* initializing an X connection */
|
|
206 /************************************************************************/
|
|
207
|
756
|
208 static struct device *device_being_initialized = NULL;
|
|
209
|
428
|
210 static void
|
|
211 allocate_x_device_struct (struct device *d)
|
|
212 {
|
3092
|
213 #ifdef NEW_GC
|
|
214 d->device_data = alloc_lrecord_type (struct x_device, &lrecord_x_device);
|
|
215 #else /* not NEW_GC */
|
428
|
216 d->device_data = xnew_and_zero (struct x_device);
|
3092
|
217 #endif /* not NEW_GC */
|
428
|
218 }
|
|
219
|
|
220 static void
|
|
221 Xatoms_of_device_x (struct device *d)
|
|
222 {
|
|
223 Display *D = DEVICE_X_DISPLAY (d);
|
|
224
|
|
225 DEVICE_XATOM_WM_PROTOCOLS (d) = XInternAtom (D, "WM_PROTOCOLS", False);
|
|
226 DEVICE_XATOM_WM_DELETE_WINDOW(d) = XInternAtom (D, "WM_DELETE_WINDOW",False);
|
|
227 DEVICE_XATOM_WM_SAVE_YOURSELF(d) = XInternAtom (D, "WM_SAVE_YOURSELF",False);
|
|
228 DEVICE_XATOM_WM_TAKE_FOCUS (d) = XInternAtom (D, "WM_TAKE_FOCUS", False);
|
|
229 DEVICE_XATOM_WM_STATE (d) = XInternAtom (D, "WM_STATE", False);
|
|
230 }
|
|
231
|
|
232 static void
|
|
233 sanity_check_geometry_resource (Display *dpy)
|
|
234 {
|
771
|
235 Extbyte *app_name, *app_class, *s;
|
|
236 Extbyte buf1 [255], buf2 [255];
|
|
237 Extbyte *type;
|
428
|
238 XrmValue value;
|
|
239 XtGetApplicationNameAndClass (dpy, &app_name, &app_class);
|
|
240 strcpy (buf1, app_name);
|
|
241 strcpy (buf2, app_class);
|
|
242 for (s = buf1; *s; s++) if (*s == '.') *s = '_';
|
|
243 strcat (buf1, "._no_._such_._resource_.geometry");
|
|
244 strcat (buf2, "._no_._such_._resource_.Geometry");
|
|
245 if (XrmGetResource (XtDatabase (dpy), buf1, buf2, &type, &value) == True)
|
|
246 {
|
867
|
247 Ibyte *app_name_int, *app_class_int, *value_addr_int;
|
771
|
248 Lisp_Object codesys = coding_system_of_xrm_database (XtDatabase (dpy));
|
|
249 EXTERNAL_TO_C_STRING (app_name, app_name_int, codesys);
|
|
250 EXTERNAL_TO_C_STRING (app_class, app_class_int, codesys);
|
|
251 EXTERNAL_TO_C_STRING (value.addr, value_addr_int, codesys);
|
|
252
|
428
|
253 warn_when_safe (Qgeometry, Qerror,
|
|
254 "\n"
|
|
255 "Apparently \"%s*geometry: %s\" or \"%s*geometry: %s\" was\n"
|
|
256 "specified in the resource database. Specifying \"*geometry\" will make\n"
|
|
257 "XEmacs (and most other X programs) malfunction in obscure ways. (i.e.\n"
|
|
258 "the Xt or Xm libraries will probably crash, which is a very bad thing.)\n"
|
|
259 "You should always use \".geometry\" or \"*EmacsFrame.geometry\" instead.\n",
|
771
|
260 app_name_int, value_addr_int,
|
|
261 app_class_int, value_addr_int);
|
428
|
262 suppress_early_error_handler_backtrace = 1;
|
563
|
263 syntax_error ("Invalid geometry resource", Qunbound);
|
428
|
264 }
|
|
265 }
|
|
266
|
|
267 static void
|
|
268 x_init_device_class (struct device *d)
|
|
269 {
|
|
270 if (DEVICE_X_DEPTH(d) > 2)
|
|
271 {
|
1204
|
272 switch (DEVICE_X_VISUAL(d)->X_CLASSFIELD)
|
428
|
273 {
|
|
274 case StaticGray:
|
|
275 case GrayScale:
|
|
276 DEVICE_CLASS (d) = Qgrayscale;
|
|
277 break;
|
|
278 default:
|
|
279 DEVICE_CLASS (d) = Qcolor;
|
|
280 }
|
|
281 }
|
|
282 else
|
|
283 DEVICE_CLASS (d) = Qmono;
|
|
284 }
|
|
285
|
|
286 /*
|
|
287 * Figure out what application name to use for xemacs
|
|
288 *
|
|
289 * Since we have decomposed XtOpenDisplay into XOpenDisplay and
|
|
290 * XtDisplayInitialize, we no longer get this for free.
|
|
291 *
|
|
292 * If there is a `-name' argument in argv, use that.
|
|
293 * Otherwise use the last component of argv[0].
|
|
294 *
|
|
295 * I have removed the gratuitous use of getenv("RESOURCE_NAME")
|
|
296 * which was in X11R5, but left the matching of any prefix of `-name'.
|
|
297 * Finally, if all else fails, return `xemacs', as it is more
|
|
298 * appropriate (X11R5 returns `main').
|
|
299 */
|
442
|
300 static Extbyte *
|
|
301 compute_x_app_name (int argc, Extbyte **argv)
|
428
|
302 {
|
|
303 int i;
|
442
|
304 Extbyte *ptr;
|
428
|
305
|
|
306 for (i = 1; i < argc - 1; i++)
|
|
307 if (!strncmp(argv[i], "-name", max (2, strlen (argv[1]))))
|
|
308 return argv[i+1];
|
|
309
|
|
310 if (argc > 0 && argv[0] && *argv[0])
|
|
311 return (ptr = strrchr (argv[0], '/')) ? ++ptr : argv[0];
|
|
312
|
|
313 return "xemacs";
|
|
314 }
|
|
315
|
|
316 /*
|
|
317 * This function figures out whether the user has any resources of the
|
|
318 * form "XEmacs.foo" or "XEmacs*foo".
|
|
319 *
|
|
320 * Currently we only consult the display's global resources; to look
|
|
321 * for screen specific resources, we would need to also consult:
|
|
322 * xdefs = XScreenResourceString(ScreenOfDisplay(dpy, scrno));
|
|
323 */
|
|
324 static int
|
|
325 have_xemacs_resources_in_xrdb (Display *dpy)
|
|
326 {
|
|
327 char *xdefs, *key;
|
|
328 int len;
|
|
329
|
|
330 #ifdef INFODOCK
|
|
331 key = "InfoDock";
|
|
332 #else
|
|
333 key = "XEmacs";
|
|
334 #endif
|
|
335 len = strlen (key);
|
|
336
|
|
337 if (!dpy)
|
|
338 return 0;
|
|
339
|
|
340 xdefs = XResourceManagerString (dpy); /* don't free - owned by X */
|
|
341 while (xdefs && *xdefs)
|
|
342 {
|
|
343 if (strncmp (xdefs, key, len) == 0 &&
|
|
344 (xdefs[len] == '*' || xdefs[len] == '.'))
|
|
345 return 1;
|
|
346
|
|
347 while (*xdefs && *xdefs++ != '\n') /* find start of next entry.. */
|
|
348 ;
|
|
349 }
|
|
350
|
|
351 return 0;
|
|
352 }
|
|
353
|
|
354 /* Only the characters [-_A-Za-z0-9] are allowed in the individual
|
|
355 components of a resource. Convert invalid characters to `-' */
|
|
356
|
|
357 static char valid_resource_char_p[256];
|
|
358
|
|
359 static void
|
771
|
360 validify_resource_component (Extbyte *str, Bytecount len)
|
428
|
361 {
|
|
362 for (; len; len--, str++)
|
|
363 if (!valid_resource_char_p[(unsigned char) (*str)])
|
|
364 *str = '-';
|
|
365 }
|
|
366
|
|
367 static void
|
771
|
368 Dynarr_add_validified_lisp_string (Extbyte_dynarr *cda, Lisp_Object str)
|
428
|
369 {
|
771
|
370 Bytecount len;
|
|
371 Extbyte *data;
|
|
372
|
|
373 TO_EXTERNAL_FORMAT (LISP_STRING, str, ALLOCA, (data, len), Qbinary);
|
|
374 Dynarr_add_many (cda, data, len);
|
|
375 validify_resource_component (Dynarr_atp (cda, Dynarr_length (cda) - len),
|
|
376 len);
|
428
|
377 }
|
|
378
|
|
379 #if 0
|
|
380 /* compare visual info for qsorting */
|
|
381 static int
|
|
382 x_comp_visual_info (const void *elem1, const void *elem2)
|
|
383 {
|
|
384 XVisualInfo *left, *right;
|
|
385
|
|
386 left = (XVisualInfo *)elem1;
|
|
387 right = (XVisualInfo *)elem2;
|
|
388
|
|
389 if ( left == NULL )
|
|
390 return -1;
|
|
391 if ( right == NULL )
|
|
392 return 1;
|
|
393
|
771
|
394 if ( left->depth > right->depth )
|
428
|
395 return 1;
|
771
|
396 else if ( left->depth == right->depth )
|
|
397 {
|
|
398 if ( left->colormap_size > right->colormap_size )
|
|
399 return 1;
|
1204
|
400 if ( left->X_CLASSFIELD > right->X_CLASSFIELD )
|
771
|
401 return 1;
|
1204
|
402 else if ( left->X_CLASSFIELD < right->X_CLASSFIELD )
|
771
|
403 return -1;
|
|
404 else
|
|
405 return 0;
|
|
406 }
|
|
407 else
|
428
|
408 return -1;
|
|
409 }
|
|
410 #endif /* if 0 */
|
|
411
|
|
412 #define XXX_IMAGE_LIBRARY_IS_SOMEWHAT_BROKEN
|
|
413 static Visual *
|
|
414 x_try_best_visual_class (Screen *screen, int scrnum, int visual_class)
|
|
415 {
|
|
416 Display *dpy = DisplayOfScreen (screen);
|
|
417 XVisualInfo vi_in;
|
|
418 XVisualInfo *vi_out = NULL;
|
|
419 int out_count;
|
|
420
|
1204
|
421 vi_in.X_CLASSFIELD = visual_class;
|
428
|
422 vi_in.screen = scrnum;
|
|
423 vi_out = XGetVisualInfo (dpy, (VisualClassMask | VisualScreenMask),
|
|
424 &vi_in, &out_count);
|
|
425 if ( vi_out )
|
|
426 {
|
|
427 int i, best;
|
|
428 Visual *visual;
|
|
429 for (i = 0, best = 0; i < out_count; i++)
|
|
430 /* It's better if it's deeper, or if it's the same depth with
|
|
431 more cells (does that ever happen? Well, it could...)
|
|
432 NOTE: don't allow pseudo color to get larger than 8! */
|
|
433 if (((vi_out [i].depth > vi_out [best].depth) ||
|
|
434 ((vi_out [i].depth == vi_out [best].depth) &&
|
|
435 (vi_out [i].colormap_size > vi_out [best].colormap_size)))
|
|
436 #ifdef XXX_IMAGE_LIBRARY_IS_SOMEWHAT_BROKEN
|
|
437 /* For now, the image library doesn't like PseudoColor visuals
|
|
438 of depths other than 1 or 8. Depths greater than 8 only occur
|
|
439 on machines which have TrueColor anyway, so probably we'll end
|
|
440 up using that (it is the one that `Best' would pick) but if a
|
|
441 PseudoColor visual is explicitly specified, pick the 8 bit one.
|
|
442 */
|
|
443 && (visual_class != PseudoColor ||
|
|
444 vi_out [i].depth == 1 ||
|
|
445 vi_out [i].depth == 8)
|
|
446 #endif
|
|
447
|
|
448 /* SGI has 30-bit deep visuals. Ignore them.
|
|
449 (We only have 24-bit data anyway.)
|
|
450 */
|
|
451 && (vi_out [i].depth <= 24)
|
|
452 )
|
|
453 best = i;
|
|
454 visual = vi_out[best].visual;
|
|
455 XFree ((char *) vi_out);
|
|
456 return visual;
|
|
457 }
|
|
458 else
|
|
459 return 0;
|
|
460 }
|
|
461
|
|
462 static int
|
|
463 x_get_visual_depth (Display *dpy, Visual *visual)
|
|
464 {
|
|
465 XVisualInfo vi_in;
|
|
466 XVisualInfo *vi_out;
|
|
467 int out_count, d;
|
|
468
|
|
469 vi_in.visualid = XVisualIDFromVisual (visual);
|
|
470 vi_out = XGetVisualInfo (dpy, /*VisualScreenMask|*/VisualIDMask,
|
|
471 &vi_in, &out_count);
|
2500
|
472 if (! vi_out) ABORT ();
|
428
|
473 d = vi_out [0].depth;
|
|
474 XFree ((char *) vi_out);
|
|
475 return d;
|
|
476 }
|
|
477
|
|
478 static Visual *
|
|
479 x_try_best_visual (Display *dpy, int scrnum)
|
|
480 {
|
|
481 Visual *visual = NULL;
|
|
482 Screen *screen = ScreenOfDisplay (dpy, scrnum);
|
|
483 if ((visual = x_try_best_visual_class (screen, scrnum, TrueColor))
|
|
484 && x_get_visual_depth (dpy, visual) >= 16 )
|
|
485 return visual;
|
|
486 if ((visual = x_try_best_visual_class (screen, scrnum, PseudoColor)))
|
|
487 return visual;
|
|
488 if ((visual = x_try_best_visual_class (screen, scrnum, TrueColor)))
|
|
489 return visual;
|
|
490 #ifdef DIRECTCOLOR_WORKS
|
|
491 if ((visual = x_try_best_visual_class (screen, scrnum, DirectColor)))
|
|
492 return visual;
|
|
493 #endif
|
|
494
|
|
495 visual = DefaultVisualOfScreen (screen);
|
|
496 if ( x_get_visual_depth (dpy, visual) >= 8 )
|
|
497 return visual;
|
|
498
|
|
499 if ((visual = x_try_best_visual_class (screen, scrnum, StaticGray)))
|
|
500 return visual;
|
|
501 if ((visual = x_try_best_visual_class (screen, scrnum, GrayScale)))
|
|
502 return visual;
|
|
503 return DefaultVisualOfScreen (screen);
|
|
504 }
|
|
505
|
|
506
|
|
507 static void
|
2286
|
508 x_init_device (struct device *d, Lisp_Object UNUSED (props))
|
428
|
509 {
|
2367
|
510 /* !!#### */
|
428
|
511 Lisp_Object display;
|
|
512 Display *dpy;
|
|
513 Widget app_shell;
|
|
514 int argc;
|
442
|
515 Extbyte **argv;
|
|
516 const char *app_class;
|
|
517 const char *app_name;
|
|
518 const char *disp_name;
|
428
|
519 Visual *visual = NULL;
|
|
520 int depth = 8; /* shut up the compiler */
|
|
521 Colormap cmap;
|
|
522 int screen;
|
|
523 /* */
|
|
524 int best_visual_found = 0;
|
|
525
|
442
|
526 #if defined(HAVE_SHLIB) && defined(LWLIB_USES_ATHENA) && !defined(HAVE_ATHENA_3D)
|
440
|
527 /*
|
|
528 * In order to avoid the lossage with flat Athena widgets dynamically
|
|
529 * linking to one of the ThreeD variants, using the dynamic symbol helpers
|
|
530 * to look for symbols that shouldn't be there and refusing to run if they
|
|
531 * are seems a less toxic idea than having XEmacs crash when we try and
|
|
532 * use a subclass of a widget that has changed size.
|
|
533 *
|
|
534 * It's ugly, I know, and not going to work everywhere. It seems better to
|
|
535 * do our damnedest to try and tell the user what to expect rather than
|
|
536 * simply blow up though.
|
|
537 *
|
|
538 * All the ThreeD variants I have access to define the following function
|
|
539 * symbols in the shared library. The flat Xaw library does not define them:
|
|
540 *
|
|
541 * Xaw3dComputeBottomShadowRGB
|
|
542 * Xaw3dComputeTopShadowRGB
|
|
543 *
|
|
544 * So far only Linux has shown this problem. This seems to be portable to
|
|
545 * all the distributions (certainly all the ones I checked - Debian and
|
|
546 * Redhat)
|
|
547 *
|
|
548 * This will only work, sadly, with dlopen() -- the other dynamic linkers
|
|
549 * are simply not capable of doing what is needed. :/
|
|
550 */
|
|
551
|
|
552 {
|
|
553 /* Get a dll handle to the main process. */
|
1706
|
554 dll_handle xaw_dll_handle = dll_open (Qnil);
|
440
|
555
|
|
556 /* Did that fail? If so, continue without error.
|
|
557 * We could die here but, well, that's unfriendly and all -- plus I feel
|
|
558 * better about some crashing somewhere rather than preventing a perfectly
|
|
559 * good configuration working just because dll_open failed.
|
|
560 */
|
|
561 if (xaw_dll_handle != NULL)
|
|
562 {
|
|
563 /* Look for the Xaw3d function */
|
|
564 dll_func xaw_function_handle =
|
|
565 dll_function (xaw_dll_handle, "Xaw3dComputeTopShadowRGB");
|
|
566
|
|
567 /* If we found it, warn the user in big, nasty, unfriendly letters */
|
|
568 if (xaw_function_handle != NULL)
|
|
569 {
|
793
|
570 warn_when_safe (Qdevice, Qcritical, "\n"
|
440
|
571 "It seems that XEmacs is built dynamically linked to the flat Athena widget\n"
|
|
572 "library but it finds a 3D Athena variant with the same name at runtime.\n"
|
|
573 "\n"
|
|
574 "This WILL cause your XEmacs process to dump core at some point.\n"
|
|
575 "You should not continue to use this binary without resolving this issue.\n"
|
|
576 "\n"
|
|
577 "This can be solved with the xaw-wrappers package under Debian\n"
|
|
578 "(register XEmacs as incompatible with all 3d widget sets, see\n"
|
|
579 "update-xaw-wrappers(8) and .../doc/xaw-wrappers/README.packagers). It\n"
|
|
580 "can be verified by checking the runtime path in /etc/ld.so.conf and by\n"
|
|
581 "using `ldd /path/to/xemacs' under other Linux distributions. One\n"
|
|
582 "solution is to use LD_PRELOAD or LD_LIBRARY_PATH to force ld.so to\n"
|
|
583 "load the flat Athena widget library instead of the aliased 3D widget\n"
|
|
584 "library (see ld.so(8) for use of these environment variables).\n\n"
|
|
585 );
|
|
586
|
|
587 }
|
|
588
|
|
589 /* Otherwise release the handle to the library
|
|
590 * No error catch here; I can't think of a way to recover anyhow.
|
|
591 */
|
|
592 dll_close (xaw_dll_handle);
|
|
593 }
|
|
594 }
|
442
|
595 #endif /* HAVE_SHLIB and LWLIB_USES_ATHENA and not HAVE_ATHENA_3D */
|
440
|
596
|
428
|
597 display = DEVICE_CONNECTION (d);
|
|
598
|
|
599 allocate_x_device_struct (d);
|
|
600
|
|
601 make_argc_argv (Vx_initial_argv_list, &argc, &argv);
|
|
602
|
442
|
603 LISP_STRING_TO_EXTERNAL (display, disp_name, Qctext);
|
428
|
604
|
|
605 /*
|
|
606 * Break apart the old XtOpenDisplay call into XOpenDisplay and
|
|
607 * XtDisplayInitialize so we can figure out whether there
|
|
608 * are any XEmacs resources in the resource database before
|
|
609 * we initialize Xt. This is so we can automagically support
|
|
610 * both `Emacs' and `XEmacs' application classes.
|
|
611 */
|
|
612 slow_down_interrupts ();
|
|
613 /* May not be needed but XtOpenDisplay could not deal with signals here. */
|
756
|
614 device_being_initialized = d;
|
428
|
615 dpy = DEVICE_X_DISPLAY (d) = XOpenDisplay (disp_name);
|
756
|
616 device_being_initialized = NULL;
|
428
|
617 speed_up_interrupts ();
|
|
618
|
|
619 if (dpy == 0)
|
|
620 {
|
|
621 suppress_early_error_handler_backtrace = 1;
|
563
|
622 gui_error ("X server not responding\n", display);
|
428
|
623 }
|
|
624
|
|
625 if (STRINGP (Vx_emacs_application_class) &&
|
|
626 XSTRING_LENGTH (Vx_emacs_application_class) > 0)
|
442
|
627 LISP_STRING_TO_EXTERNAL (Vx_emacs_application_class, app_class, Qctext);
|
428
|
628 else
|
|
629 {
|
2681
|
630 if (egetenv ("USE_EMACS_AS_DEFAULT_APPLICATION_CLASS"))
|
|
631 {
|
|
632 app_class = (NILP (Vx_emacs_application_class) &&
|
|
633 have_xemacs_resources_in_xrdb (dpy))
|
428
|
634 #ifdef INFODOCK
|
2681
|
635 ? "InfoDock"
|
428
|
636 #else
|
2681
|
637 ? "XEmacs"
|
428
|
638 #endif
|
2681
|
639 : "Emacs";
|
|
640 }
|
|
641 else
|
|
642 {
|
|
643 app_class = "XEmacs";
|
|
644 }
|
|
645
|
428
|
646 /* need to update Vx_emacs_application_class: */
|
|
647 Vx_emacs_application_class = build_string (app_class);
|
|
648 }
|
|
649
|
|
650 slow_down_interrupts ();
|
|
651 /* May not be needed but XtOpenDisplay could not deal with signals here.
|
|
652 Yuck. */
|
|
653 XtDisplayInitialize (Xt_app_con, dpy, compute_x_app_name (argc, argv),
|
|
654 app_class, emacs_options,
|
442
|
655 XtNumber (emacs_options), &argc, (char **) argv);
|
428
|
656 speed_up_interrupts ();
|
|
657
|
|
658 screen = DefaultScreen (dpy);
|
|
659
|
|
660 #ifdef MULE
|
|
661 {
|
|
662 /* Read in locale-specific resources from
|
|
663 data-directory/app-defaults/$LANG/Emacs.
|
|
664 This is in addition to the standard app-defaults files, and
|
|
665 does not override resources defined elsewhere */
|
771
|
666 const Extbyte *data_dir;
|
|
667 Extbyte *path;
|
3644
|
668 Extbyte *format;
|
428
|
669 XrmDatabase db = XtDatabase (dpy); /* #### XtScreenDatabase(dpy) ? */
|
3644
|
670 Extbyte *locale = xstrdup (XrmLocaleOfDatabase (db));
|
|
671 Extbyte *locale_end;
|
428
|
672
|
|
673 if (STRINGP (Vx_app_defaults_directory) &&
|
|
674 XSTRING_LENGTH (Vx_app_defaults_directory) > 0)
|
|
675 {
|
771
|
676 LISP_STRING_TO_EXTERNAL (Vx_app_defaults_directory, data_dir,
|
|
677 Qfile_name);
|
2367
|
678 path = alloca_extbytes (strlen (data_dir) + strlen (locale) + 7);
|
3644
|
679 format = "%s%s/Emacs";
|
428
|
680 }
|
|
681 else if (STRINGP (Vdata_directory) && XSTRING_LENGTH (Vdata_directory) > 0)
|
|
682 {
|
442
|
683 LISP_STRING_TO_EXTERNAL (Vdata_directory, data_dir, Qfile_name);
|
2367
|
684 path = alloca_extbytes (strlen (data_dir) + 13 + strlen (locale) + 7);
|
3644
|
685 format = "%sapp-defaults/%s/Emacs";
|
428
|
686 }
|
3644
|
687
|
|
688 /*
|
|
689 * The general form for $LANG is <language>_<country>.<encoding>. Try
|
|
690 * that form, <language>_<country> and <language> and load for first
|
|
691 * app-defaults file found.
|
|
692 */
|
|
693
|
|
694 sprintf (path, format, data_dir, locale);
|
|
695 if (!access (path, R_OK))
|
|
696 XrmCombineFileDatabase (path, &db, False);
|
|
697
|
|
698 if ((locale_end = strchr(locale, '.'))) {
|
|
699 *locale_end = '\0';
|
|
700 sprintf (path, format, data_dir, locale);
|
|
701
|
|
702 if (!access (path, R_OK))
|
|
703 XrmCombineFileDatabase (path, &db, False);
|
|
704 }
|
|
705
|
|
706 if ((locale_end = strchr(locale, '_'))) {
|
|
707 *locale_end = '\0';
|
|
708 sprintf (path, format, data_dir, locale);
|
|
709
|
|
710 if (!access (path, R_OK))
|
|
711 XrmCombineFileDatabase (path, &db, False);
|
|
712 }
|
|
713
|
|
714 xfree (locale, Extbyte*);
|
428
|
715 }
|
|
716 #endif /* MULE */
|
|
717
|
|
718 if (NILP (DEVICE_NAME (d)))
|
|
719 DEVICE_NAME (d) = display;
|
|
720
|
|
721 /* We're going to modify the string in-place, so be a nice XEmacs */
|
|
722 DEVICE_NAME (d) = Fcopy_sequence (DEVICE_NAME (d));
|
|
723 /* colons and periods can't appear in individual elements of resource
|
|
724 strings */
|
|
725
|
|
726 XtGetApplicationNameAndClass (dpy, (char **) &app_name, (char **) &app_class);
|
|
727 /* search for a matching visual if requested by the user, or setup the display default */
|
|
728 {
|
|
729 int resource_name_length = max (sizeof (".emacsVisual"),
|
|
730 sizeof (".privateColormap"));
|
|
731 char *buf1 = alloca_array (char, strlen (app_name) + resource_name_length);
|
|
732 char *buf2 = alloca_array (char, strlen (app_class) + resource_name_length);
|
|
733 char *type;
|
|
734 XrmValue value;
|
|
735
|
|
736 sprintf (buf1, "%s.emacsVisual", app_name);
|
|
737 sprintf (buf2, "%s.EmacsVisual", app_class);
|
|
738 if (XrmGetResource (XtDatabase (dpy), buf1, buf2, &type, &value) == True)
|
|
739 {
|
|
740 int cnt = 0;
|
|
741 int vis_class = PseudoColor;
|
|
742 XVisualInfo vinfo;
|
|
743 char *str = (char*) value.addr;
|
|
744
|
|
745 #define CHECK_VIS_CLASS(visual_class) \
|
|
746 else if (memcmp (str, #visual_class, sizeof (#visual_class) - 1) == 0) \
|
|
747 cnt = sizeof (#visual_class) - 1, vis_class = visual_class
|
|
748
|
|
749 if (1)
|
|
750 ;
|
|
751 CHECK_VIS_CLASS (StaticGray);
|
|
752 CHECK_VIS_CLASS (StaticColor);
|
|
753 CHECK_VIS_CLASS (TrueColor);
|
|
754 CHECK_VIS_CLASS (GrayScale);
|
|
755 CHECK_VIS_CLASS (PseudoColor);
|
|
756 CHECK_VIS_CLASS (DirectColor);
|
|
757
|
|
758 if (cnt)
|
|
759 {
|
|
760 depth = atoi (str + cnt);
|
|
761 if (depth == 0)
|
|
762 {
|
771
|
763 stderr_out ("Invalid Depth specification in %s... "
|
|
764 "ignoring...\n", str);
|
428
|
765 }
|
|
766 else
|
|
767 {
|
|
768 if (XMatchVisualInfo (dpy, screen, depth, vis_class, &vinfo))
|
|
769 {
|
|
770 visual = vinfo.visual;
|
|
771 }
|
|
772 else
|
|
773 {
|
771
|
774 stderr_out ("Can't match the requested visual %s... "
|
|
775 "using defaults\n", str);
|
428
|
776 }
|
|
777 }
|
|
778 }
|
|
779 else
|
|
780 {
|
771
|
781 stderr_out ("Invalid Visual specification in %s... "
|
|
782 "ignoring.\n", str);
|
428
|
783 }
|
|
784 }
|
|
785 if (visual == NULL)
|
|
786 {
|
|
787 /*
|
|
788 visual = DefaultVisual(dpy, screen);
|
|
789 depth = DefaultDepth(dpy, screen);
|
|
790 */
|
|
791 visual = x_try_best_visual (dpy, screen);
|
|
792 depth = x_get_visual_depth (dpy, visual);
|
|
793 best_visual_found = (visual != DefaultVisual (dpy, screen));
|
|
794 }
|
|
795
|
|
796 /* If we've got the same visual as the default and it's PseudoColor,
|
|
797 check to see if the user specified that we need a private colormap */
|
|
798 if (visual == DefaultVisual (dpy, screen))
|
|
799 {
|
|
800 sprintf (buf1, "%s.privateColormap", app_name);
|
|
801 sprintf (buf2, "%s.PrivateColormap", app_class);
|
1204
|
802 if ((visual->X_CLASSFIELD == PseudoColor) &&
|
771
|
803 (XrmGetResource (XtDatabase (dpy), buf1, buf2, &type, &value)
|
|
804 == True))
|
|
805 cmap = XCopyColormapAndFree (dpy, DefaultColormap (dpy, screen));
|
428
|
806 else
|
771
|
807 cmap = DefaultColormap (dpy, screen);
|
428
|
808 }
|
|
809 else
|
|
810 {
|
|
811 if ( best_visual_found )
|
771
|
812 cmap = XCreateColormap (dpy, RootWindow (dpy, screen), visual,
|
|
813 AllocNone);
|
428
|
814 else
|
|
815 {
|
771
|
816 /* We have to create a matching colormap anyway... ####
|
|
817 think about using standard colormaps (need the Xmu
|
|
818 libs?) */
|
|
819 cmap = XCreateColormap (dpy, RootWindow (dpy, screen), visual,
|
|
820 AllocNone);
|
|
821 XInstallColormap (dpy, cmap);
|
428
|
822 }
|
|
823 }
|
|
824 }
|
|
825
|
|
826 DEVICE_X_VISUAL (d) = visual;
|
|
827 DEVICE_X_COLORMAP (d) = cmap;
|
|
828 DEVICE_X_DEPTH (d) = depth;
|
|
829 validify_resource_component ((char *) XSTRING_DATA (DEVICE_NAME (d)),
|
|
830 XSTRING_LENGTH (DEVICE_NAME (d)));
|
|
831
|
2007
|
832 /* #### If we're going to implement X session management, this would
|
|
833 be the place. Make sure it doesn't conflict with GNOME. */
|
428
|
834 {
|
|
835 Arg al[3];
|
|
836 XtSetArg (al[0], XtNvisual, visual);
|
|
837 XtSetArg (al[1], XtNdepth, depth);
|
|
838 XtSetArg (al[2], XtNcolormap, cmap);
|
|
839
|
|
840 app_shell = XtAppCreateShell (NULL, app_class,
|
|
841 applicationShellWidgetClass,
|
|
842 dpy, al, countof (al));
|
|
843 }
|
|
844
|
|
845 DEVICE_XT_APP_SHELL (d) = app_shell;
|
|
846
|
|
847 #ifdef HAVE_XIM
|
|
848 XIM_init_device(d);
|
|
849 #endif /* HAVE_XIM */
|
|
850
|
|
851 /* Realize the app_shell so that its window exists for GC creation purposes,
|
|
852 and set it to the size of the root window for child placement purposes */
|
|
853 {
|
|
854 Arg al[5];
|
|
855 XtSetArg (al[0], XtNmappedWhenManaged, False);
|
|
856 XtSetArg (al[1], XtNx, 0);
|
|
857 XtSetArg (al[2], XtNy, 0);
|
|
858 XtSetArg (al[3], XtNwidth, WidthOfScreen (ScreenOfDisplay (dpy, screen)));
|
|
859 XtSetArg (al[4], XtNheight, HeightOfScreen (ScreenOfDisplay (dpy, screen)));
|
|
860 XtSetValues (app_shell, al, countof (al));
|
|
861 XtRealizeWidget (app_shell);
|
|
862 }
|
|
863
|
|
864 #ifdef HAVE_WMCOMMAND
|
|
865 {
|
|
866 int new_argc;
|
442
|
867 Extbyte **new_argv;
|
428
|
868 make_argc_argv (Vcommand_line_args, &new_argc, &new_argv);
|
442
|
869 XSetCommand (XtDisplay (app_shell), XtWindow (app_shell),
|
|
870 (char **) new_argv, new_argc);
|
428
|
871 free_argc_argv (new_argv);
|
|
872 }
|
|
873 #endif /* HAVE_WMCOMMAND */
|
|
874
|
|
875
|
|
876 #ifdef HAVE_OFFIX_DND
|
771
|
877 DndInitialize (app_shell);
|
428
|
878 #endif
|
|
879
|
|
880 Vx_initial_argv_list = make_arg_list (argc, argv);
|
|
881 free_argc_argv (argv);
|
|
882
|
|
883 DEVICE_X_WM_COMMAND_FRAME (d) = Qnil;
|
|
884
|
|
885 sanity_check_geometry_resource (dpy);
|
|
886
|
|
887 /* In event-Xt.c */
|
|
888 x_init_modifier_mapping (d);
|
|
889
|
|
890 DEVICE_INFD (d) = DEVICE_OUTFD (d) = ConnectionNumber (dpy);
|
|
891 init_baud_rate (d);
|
|
892 init_one_device (d);
|
|
893
|
771
|
894 DEVICE_X_GC_CACHE (d) = make_gc_cache (dpy, XtWindow (app_shell));
|
428
|
895 DEVICE_X_GRAY_PIXMAP (d) = None;
|
|
896 Xatoms_of_device_x (d);
|
440
|
897 Xatoms_of_select_x (d);
|
428
|
898 Xatoms_of_objects_x (d);
|
|
899 x_init_device_class (d);
|
|
900
|
|
901 /* Run the elisp side of the X device initialization. */
|
|
902 call0 (Qinit_pre_x_win);
|
|
903 }
|
|
904
|
|
905 static void
|
2286
|
906 x_finish_init_device (struct device *UNUSED (d), Lisp_Object UNUSED (props))
|
428
|
907 {
|
|
908 call0 (Qinit_post_x_win);
|
|
909 }
|
|
910
|
|
911 static void
|
|
912 x_mark_device (struct device *d)
|
|
913 {
|
|
914 mark_object (DEVICE_X_WM_COMMAND_FRAME (d));
|
|
915 mark_object (DEVICE_X_DATA (d)->x_keysym_map_hash_table);
|
|
916 }
|
|
917
|
|
918
|
|
919 /************************************************************************/
|
|
920 /* closing an X connection */
|
|
921 /************************************************************************/
|
|
922
|
|
923 static void
|
|
924 free_x_device_struct (struct device *d)
|
|
925 {
|
3092
|
926 #ifdef NEW_GC
|
|
927 mc_free (d->device_data);
|
|
928 #else /* not NEW_GC */
|
1726
|
929 xfree (d->device_data, void *);
|
3092
|
930 #endif /* not NEW_GC */
|
428
|
931 }
|
|
932
|
|
933 static void
|
|
934 x_delete_device (struct device *d)
|
|
935 {
|
|
936 Display *display;
|
|
937 #ifdef FREE_CHECKING
|
|
938 extern void (*__free_hook) (void *);
|
|
939 int checking_free;
|
|
940 #endif
|
|
941
|
|
942 display = DEVICE_X_DISPLAY (d);
|
|
943
|
|
944 if (display)
|
|
945 {
|
|
946 #ifdef FREE_CHECKING
|
|
947 checking_free = (__free_hook != 0);
|
|
948
|
|
949 /* Disable strict free checking, to avoid bug in X library */
|
|
950 if (checking_free)
|
|
951 disable_strict_free_check ();
|
|
952 #endif
|
|
953
|
|
954 free_gc_cache (DEVICE_X_GC_CACHE (d));
|
|
955 if (DEVICE_X_DATA (d)->x_modifier_keymap)
|
|
956 XFreeModifiermap (DEVICE_X_DATA (d)->x_modifier_keymap);
|
|
957 if (DEVICE_X_DATA (d)->x_keysym_map)
|
|
958 XFree ((char *) DEVICE_X_DATA (d)->x_keysym_map);
|
|
959
|
|
960 if (DEVICE_XT_APP_SHELL (d))
|
|
961 {
|
|
962 XtDestroyWidget (DEVICE_XT_APP_SHELL (d));
|
|
963 DEVICE_XT_APP_SHELL (d) = NULL;
|
|
964 }
|
|
965
|
|
966 XtCloseDisplay (display);
|
|
967 DEVICE_X_DISPLAY (d) = 0;
|
|
968 #ifdef FREE_CHECKING
|
|
969 if (checking_free)
|
|
970 enable_strict_free_check ();
|
|
971 #endif
|
|
972 }
|
|
973
|
|
974 free_x_device_struct (d);
|
|
975 }
|
|
976
|
|
977
|
|
978 /************************************************************************/
|
|
979 /* handle X errors */
|
|
980 /************************************************************************/
|
|
981
|
442
|
982 const char *
|
428
|
983 x_event_name (int event_type)
|
|
984 {
|
442
|
985 static const char *events[] =
|
428
|
986 {
|
|
987 "0: ERROR!",
|
|
988 "1: REPLY",
|
|
989 "KeyPress",
|
|
990 "KeyRelease",
|
|
991 "ButtonPress",
|
|
992 "ButtonRelease",
|
|
993 "MotionNotify",
|
|
994 "EnterNotify",
|
|
995 "LeaveNotify",
|
|
996 "FocusIn",
|
|
997 "FocusOut",
|
|
998 "KeymapNotify",
|
|
999 "Expose",
|
|
1000 "GraphicsExpose",
|
|
1001 "NoExpose",
|
|
1002 "VisibilityNotify",
|
|
1003 "CreateNotify",
|
|
1004 "DestroyNotify",
|
|
1005 "UnmapNotify",
|
|
1006 "MapNotify",
|
|
1007 "MapRequest",
|
|
1008 "ReparentNotify",
|
|
1009 "ConfigureNotify",
|
|
1010 "ConfigureRequest",
|
|
1011 "GravityNotify",
|
|
1012 "ResizeRequest",
|
|
1013 "CirculateNotify",
|
|
1014 "CirculateRequest",
|
|
1015 "PropertyNotify",
|
|
1016 "SelectionClear",
|
|
1017 "SelectionRequest",
|
|
1018 "SelectionNotify",
|
|
1019 "ColormapNotify",
|
|
1020 "ClientMessage",
|
|
1021 "MappingNotify",
|
|
1022 "LASTEvent"
|
|
1023 };
|
|
1024
|
|
1025 if (event_type < 0 || event_type >= countof (events))
|
|
1026 return NULL;
|
|
1027 return events [event_type];
|
|
1028 }
|
|
1029
|
|
1030 /* Handling errors.
|
|
1031
|
|
1032 If an X error occurs which we are not expecting, we have no alternative
|
|
1033 but to print it to stderr. It would be nice to stuff it into a pop-up
|
|
1034 buffer, or to print it in the minibuffer, but that's not possible, because
|
|
1035 one is not allowed to do any I/O on the display connection from an error
|
|
1036 handler. The guts of Xlib expect these functions to either return or exit.
|
|
1037
|
|
1038 However, there are occasions when we might expect an error to reasonably
|
|
1039 occur. The interface to this is as follows:
|
|
1040
|
|
1041 Before calling some X routine which may error, call
|
|
1042 expect_x_error (dpy);
|
|
1043
|
|
1044 Just after calling the X routine, call either:
|
|
1045
|
|
1046 x_error_occurred_p (dpy);
|
|
1047
|
|
1048 to ask whether an error happened (and was ignored), or:
|
|
1049
|
|
1050 signal_if_x_error (dpy, resumable_p);
|
|
1051
|
|
1052 which will call Fsignal() with args appropriate to the X error, if there
|
|
1053 was one. (Resumable_p is whether the debugger should be allowed to
|
|
1054 continue from the call to signal.)
|
|
1055
|
|
1056 You must call one of these two routines immediately after calling the X
|
|
1057 routine; think of them as bookends like BLOCK_INPUT and UNBLOCK_INPUT.
|
|
1058 */
|
|
1059
|
|
1060 static int error_expected;
|
|
1061 static int error_occurred;
|
|
1062 static XErrorEvent last_error;
|
|
1063
|
|
1064 /* OVERKILL! */
|
|
1065
|
|
1066 #ifdef EXTERNAL_WIDGET
|
|
1067 static Lisp_Object
|
|
1068 x_error_handler_do_enqueue (Lisp_Object frame)
|
|
1069 {
|
|
1070 enqueue_magic_eval_event (io_error_delete_frame, frame);
|
|
1071 return Qt;
|
|
1072 }
|
|
1073
|
|
1074 static Lisp_Object
|
2333
|
1075 x_error_handler_error (Lisp_Object UNUSED (data), Lisp_Object UNUSED (dummy))
|
428
|
1076 {
|
|
1077 return Qnil;
|
|
1078 }
|
|
1079 #endif /* EXTERNAL_WIDGET */
|
|
1080
|
|
1081 int
|
|
1082 x_error_handler (Display *disp, XErrorEvent *event)
|
|
1083 {
|
|
1084 if (error_expected)
|
|
1085 {
|
|
1086 error_expected = 0;
|
|
1087 error_occurred = 1;
|
|
1088 last_error = *event;
|
|
1089 }
|
|
1090 else
|
|
1091 {
|
853
|
1092 int depth;
|
|
1093
|
428
|
1094 #ifdef EXTERNAL_WIDGET
|
|
1095 struct frame *f;
|
|
1096 struct device *d = get_device_from_display (disp);
|
|
1097
|
|
1098 if ((event->error_code == BadWindow ||
|
|
1099 event->error_code == BadDrawable)
|
|
1100 && ((f = x_any_window_to_frame (d, event->resourceid)) != 0))
|
|
1101 {
|
|
1102 Lisp_Object frame;
|
|
1103
|
|
1104 /* one of the windows comprising one of our frames has died.
|
|
1105 This occurs particularly with ExternalShell frames when the
|
|
1106 client that owns the ExternalShell's window dies.
|
|
1107
|
|
1108 We cannot do any I/O on the display connection so we need
|
|
1109 to enqueue an eval event so that the deletion happens
|
|
1110 later.
|
|
1111
|
|
1112 Furthermore, we need to trap any errors (out-of-memory) that
|
|
1113 may occur when Fenqueue_eval_event is called.
|
|
1114 */
|
|
1115
|
|
1116 if (f->being_deleted)
|
|
1117 return 0;
|
793
|
1118 frame = wrap_frame (f);
|
428
|
1119 if (!NILP (condition_case_1 (Qerror, x_error_handler_do_enqueue,
|
|
1120 frame, x_error_handler_error, Qnil)))
|
|
1121 {
|
|
1122 f->being_deleted = 1;
|
|
1123 f->visible = 0;
|
|
1124 }
|
|
1125 return 0;
|
|
1126 }
|
|
1127 #endif /* EXTERNAL_WIDGET */
|
|
1128
|
853
|
1129 /* #### this should issue a warning instead of outputting to stderr */
|
|
1130 depth = begin_dont_check_for_quit ();
|
2007
|
1131 #if 0
|
|
1132 /* This ends up calling X, which isn't allowed in an X error handler
|
|
1133 */
|
428
|
1134 stderr_out ("\n%s: ",
|
|
1135 (STRINGP (Vinvocation_name)
|
|
1136 ? (char *) XSTRING_DATA (Vinvocation_name)
|
|
1137 : "xemacs"));
|
2007
|
1138 #endif
|
428
|
1139 XmuPrintDefaultErrorMessage (disp, event, stderr);
|
853
|
1140 unbind_to (depth);
|
428
|
1141 }
|
|
1142 return 0;
|
|
1143 }
|
|
1144
|
|
1145 void
|
|
1146 expect_x_error (Display *dpy)
|
|
1147 {
|
|
1148 assert (!error_expected);
|
|
1149 XSync (dpy, 0); /* handle pending errors before setting flag */
|
|
1150 error_expected = 1;
|
|
1151 error_occurred = 0;
|
|
1152 }
|
|
1153
|
|
1154 int
|
|
1155 x_error_occurred_p (Display *dpy)
|
|
1156 {
|
|
1157 int val;
|
|
1158 XSync (dpy, 0); /* handle pending errors before setting flag */
|
|
1159 val = error_occurred;
|
|
1160 error_expected = 0;
|
|
1161 error_occurred = 0;
|
|
1162 return val;
|
|
1163 }
|
|
1164
|
|
1165 int
|
|
1166 signal_if_x_error (Display *dpy, int resumable_p)
|
|
1167 {
|
771
|
1168 Extbyte buf[1024];
|
867
|
1169 Ibyte num[100];
|
428
|
1170 Lisp_Object data;
|
|
1171 if (! x_error_occurred_p (dpy))
|
|
1172 return 0;
|
|
1173 data = Qnil;
|
771
|
1174 qxesprintf (num, "0x%X", (unsigned int) last_error.resourceid);
|
|
1175 data = Fcons (build_intstring (num), data);
|
|
1176 qxesprintf (num, "%d", last_error.request_code);
|
|
1177 XGetErrorDatabaseText (last_error.display, "XRequest", (char *) num, "",
|
|
1178 buf, sizeof (buf));
|
|
1179 if (*buf)
|
|
1180 data = Fcons (build_ext_string (buf, Qnative), data);
|
|
1181 else
|
|
1182 {
|
|
1183 qxesprintf (num, "Request-%d", last_error.request_code);
|
|
1184 data = Fcons (build_intstring (num), data);
|
|
1185 }
|
428
|
1186 XGetErrorText (last_error.display, last_error.error_code, buf, sizeof (buf));
|
771
|
1187 data = Fcons (build_ext_string (buf, Qnative), data);
|
428
|
1188 again:
|
|
1189 Fsignal (Qx_error, data);
|
|
1190 if (! resumable_p) goto again;
|
|
1191 return 1;
|
|
1192 }
|
|
1193
|
|
1194 int
|
|
1195 x_IO_error_handler (Display *disp)
|
|
1196 {
|
|
1197 /* This function can GC */
|
|
1198 Lisp_Object dev;
|
|
1199 struct device *d = get_device_from_display_1 (disp);
|
|
1200
|
756
|
1201 if (!d)
|
|
1202 d = device_being_initialized;
|
|
1203
|
428
|
1204 assert (d != NULL);
|
793
|
1205 dev = wrap_device (d);
|
428
|
1206
|
|
1207 if (NILP (find_nonminibuffer_frame_not_on_device (dev)))
|
|
1208 {
|
853
|
1209 int depth = begin_dont_check_for_quit ();
|
428
|
1210 /* We're going down. */
|
867
|
1211 Ibyte *errmess;
|
771
|
1212 GET_STRERROR (errmess, errno);
|
|
1213 stderr_out ("\n%s: Fatal I/O Error %d (%s) on display "
|
|
1214 "connection \"%s\"\n",
|
|
1215 (STRINGP (Vinvocation_name) ?
|
|
1216 (char *) XSTRING_DATA (Vinvocation_name) : "xemacs"),
|
|
1217 errno, errmess, DisplayString (disp));
|
|
1218 stderr_out (" after %lu requests (%lu known processed) with %d "
|
|
1219 "events remaining.\n",
|
|
1220 NextRequest (disp) - 1, LastKnownRequestProcessed (disp),
|
|
1221 QLength (disp));
|
428
|
1222 /* assert (!_Xdebug); */
|
853
|
1223 unbind_to (depth);
|
428
|
1224 }
|
|
1225 else
|
|
1226 {
|
867
|
1227 Ibyte *errmess;
|
771
|
1228 GET_STRERROR (errmess, errno);
|
428
|
1229 warn_when_safe
|
|
1230 (Qx, Qcritical,
|
|
1231 "I/O Error %d (%s) on display connection\n"
|
2116
|
1232 " \"%s\" after %lu requests (%lu known processed)\n"
|
428
|
1233 " with %d events remaining.\n"
|
|
1234 " Throwing to top level.\n",
|
771
|
1235 errno, errmess, DisplayString (disp),
|
428
|
1236 NextRequest (disp) - 1, LastKnownRequestProcessed (disp),
|
|
1237 QLength (disp));
|
|
1238 }
|
|
1239
|
|
1240 /* According to X specs, we should not return from this function, or
|
|
1241 Xlib might just decide to exit(). So we mark the offending
|
|
1242 console for deletion and throw to top level. */
|
|
1243 if (d)
|
3466
|
1244 {
|
|
1245 enqueue_magic_eval_event (io_error_delete_device, dev);
|
|
1246 DEVICE_X_BEING_DELETED (d) = 1;
|
|
1247 }
|
428
|
1248 Fthrow (Qtop_level, Qnil);
|
|
1249
|
2268
|
1250 RETURN_NOT_REACHED (0);
|
428
|
1251 }
|
|
1252
|
|
1253 DEFUN ("x-debug-mode", Fx_debug_mode, 1, 2, 0, /*
|
|
1254 With a true arg, make the connection to the X server synchronous.
|
|
1255 With false, make it asynchronous. Synchronous connections are much slower,
|
|
1256 but are useful for debugging. (If you get X errors, make the connection
|
|
1257 synchronous, and use a debugger to set a breakpoint on `x_error_handler'.
|
|
1258 Your backtrace of the C stack will now be useful. In asynchronous mode,
|
|
1259 the stack above `x_error_handler' isn't helpful because of buffering.)
|
|
1260 If DEVICE is not specified, the selected device is assumed.
|
|
1261
|
|
1262 Calling this function is the same as calling the C function `XSynchronize',
|
|
1263 or starting the program with the `-sync' command line argument.
|
|
1264 */
|
|
1265 (arg, device))
|
|
1266 {
|
|
1267 struct device *d = decode_x_device (device);
|
|
1268
|
|
1269 XSynchronize (DEVICE_X_DISPLAY (d), !NILP (arg));
|
|
1270
|
|
1271 if (!NILP (arg))
|
|
1272 message ("X connection is synchronous");
|
|
1273 else
|
|
1274 message ("X connection is asynchronous");
|
|
1275
|
|
1276 return arg;
|
|
1277 }
|
|
1278
|
|
1279
|
|
1280 /************************************************************************/
|
|
1281 /* X resources */
|
|
1282 /************************************************************************/
|
|
1283
|
|
1284 #if 0 /* bah humbug. The whole "widget == resource" stuff is such
|
|
1285 a crock of shit that I'm just going to ignore it all. */
|
|
1286
|
|
1287 /* If widget is NULL, we are retrieving device or global face data. */
|
|
1288
|
|
1289 static void
|
|
1290 construct_name_list (Display *display, Widget widget, char *fake_name,
|
1204
|
1291 char *fake_class, char *name, char *class_)
|
428
|
1292 {
|
|
1293 char *stack [100][2];
|
2552
|
1294 Widget this_widget;
|
428
|
1295 int count = 0;
|
|
1296 char *name_tail, *class_tail;
|
|
1297
|
|
1298 if (widget)
|
|
1299 {
|
2552
|
1300 for (this_widget = widget; this_widget;
|
|
1301 this_widget = XtParent (this_widget))
|
428
|
1302 {
|
2552
|
1303 stack [count][0] = this_widget->core.name;
|
|
1304 stack [count][1] = XtClass (this_widget)->core_class.class_name;
|
428
|
1305 count++;
|
|
1306 }
|
|
1307 count--;
|
|
1308 }
|
|
1309 else if (fake_name && fake_class)
|
|
1310 {
|
|
1311 stack [count][0] = fake_name;
|
|
1312 stack [count][1] = fake_class;
|
|
1313 count++;
|
|
1314 }
|
|
1315
|
|
1316 /* The root widget is an application shell; resource lookups use the
|
|
1317 specified application name and application class in preference to
|
|
1318 the name/class of that widget (which is argv[0] / "ApplicationShell").
|
|
1319 Generally the app name and class will be argv[0] / "Emacs" but
|
|
1320 the former can be set via the -name command-line option, and the
|
|
1321 latter can be set by changing `x-emacs-application-class' in
|
|
1322 lisp/term/x-win.el.
|
|
1323 */
|
|
1324 XtGetApplicationNameAndClass (display,
|
|
1325 &stack [count][0],
|
|
1326 &stack [count][1]);
|
|
1327
|
|
1328 name [0] = 0;
|
1204
|
1329 class_ [0] = 0;
|
428
|
1330
|
|
1331 name_tail = name;
|
1204
|
1332 class_tail = class_;
|
428
|
1333 for (; count >= 0; count--)
|
|
1334 {
|
|
1335 strcat (name_tail, stack [count][0]);
|
|
1336 for (; *name_tail; name_tail++)
|
|
1337 if (*name_tail == '.') *name_tail = '_';
|
|
1338 strcat (name_tail, ".");
|
|
1339 name_tail++;
|
|
1340
|
|
1341 strcat (class_tail, stack [count][1]);
|
|
1342 for (; *class_tail; class_tail++)
|
|
1343 if (*class_tail == '.') *class_tail = '_';
|
|
1344 strcat (class_tail, ".");
|
|
1345 class_tail++;
|
|
1346 }
|
|
1347 }
|
|
1348
|
|
1349 #endif /* 0 */
|
|
1350
|
771
|
1351 static Extbyte_dynarr *name_Extbyte_dynarr;
|
|
1352 static Extbyte_dynarr *class_Extbyte_dynarr;
|
428
|
1353
|
|
1354 /* Given a locale and device specification from x-get-resource or
|
|
1355 x-get-resource-prefix, return the resource prefix and display to
|
|
1356 fetch the resource on. */
|
|
1357
|
|
1358 static void
|
|
1359 x_get_resource_prefix (Lisp_Object locale, Lisp_Object device,
|
771
|
1360 Display **display_out, Extbyte_dynarr *name,
|
1204
|
1361 Extbyte_dynarr *class_)
|
428
|
1362 {
|
|
1363 if (NILP (locale))
|
|
1364 locale = Qglobal;
|
|
1365 if (NILP (Fvalid_specifier_locale_p (locale)))
|
563
|
1366 invalid_argument ("Invalid locale", locale);
|
428
|
1367 if (WINDOWP (locale))
|
|
1368 /* #### I can't come up with any coherent way of naming windows.
|
|
1369 By relative position? That seems tricky because windows
|
|
1370 can change position, be split, etc. By order of creation?
|
|
1371 That seems less than useful. */
|
563
|
1372 signal_error (Qunimplemented,
|
|
1373 "Windows currently can't be resourced", locale);
|
428
|
1374
|
|
1375 if (!NILP (device) && !DEVICEP (device))
|
|
1376 CHECK_DEVICE (device);
|
|
1377 if (DEVICEP (device) && !DEVICE_X_P (XDEVICE (device)))
|
|
1378 device = Qnil;
|
|
1379 if (NILP (device))
|
|
1380 {
|
|
1381 device = DFW_DEVICE (locale);
|
|
1382 if (DEVICEP (device) && !DEVICE_X_P (XDEVICE (device)))
|
|
1383 device = Qnil;
|
|
1384 if (NILP (device))
|
872
|
1385 device = get_default_device (Qx);
|
428
|
1386 if (NILP (device))
|
|
1387 {
|
|
1388 *display_out = 0;
|
|
1389 return;
|
|
1390 }
|
|
1391 }
|
|
1392
|
|
1393 *display_out = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
1394
|
|
1395 {
|
771
|
1396 Extbyte *appname, *appclass;
|
428
|
1397 int name_len, class_len;
|
|
1398 XtGetApplicationNameAndClass (*display_out, &appname, &appclass);
|
|
1399 name_len = strlen (appname);
|
|
1400 class_len = strlen (appclass);
|
771
|
1401 Dynarr_add_many (name, appname, name_len);
|
1204
|
1402 Dynarr_add_many (class_, appclass, class_len);
|
428
|
1403 validify_resource_component (Dynarr_atp (name, 0), name_len);
|
1204
|
1404 validify_resource_component (Dynarr_atp (class_, 0), class_len);
|
428
|
1405 }
|
|
1406
|
|
1407 if (EQ (locale, Qglobal))
|
|
1408 return;
|
|
1409 if (BUFFERP (locale))
|
|
1410 {
|
|
1411 Dynarr_add_literal_string (name, ".buffer.");
|
|
1412 /* we know buffer is live; otherwise we got an error above. */
|
|
1413 Dynarr_add_validified_lisp_string (name, Fbuffer_name (locale));
|
1204
|
1414 Dynarr_add_literal_string (class_, ".EmacsLocaleType.EmacsBuffer");
|
428
|
1415 }
|
|
1416 else if (FRAMEP (locale))
|
|
1417 {
|
|
1418 Dynarr_add_literal_string (name, ".frame.");
|
|
1419 /* we know frame is live; otherwise we got an error above. */
|
|
1420 Dynarr_add_validified_lisp_string (name, Fframe_name (locale));
|
1204
|
1421 Dynarr_add_literal_string (class_, ".EmacsLocaleType.EmacsFrame");
|
428
|
1422 }
|
|
1423 else
|
|
1424 {
|
|
1425 assert (DEVICEP (locale));
|
|
1426 Dynarr_add_literal_string (name, ".device.");
|
|
1427 /* we know device is live; otherwise we got an error above. */
|
|
1428 Dynarr_add_validified_lisp_string (name, Fdevice_name (locale));
|
1204
|
1429 Dynarr_add_literal_string (class_, ".EmacsLocaleType.EmacsDevice");
|
428
|
1430 }
|
|
1431 return;
|
|
1432 }
|
|
1433
|
|
1434 DEFUN ("x-get-resource", Fx_get_resource, 3, 6, 0, /*
|
|
1435 Retrieve an X resource from the resource manager.
|
|
1436
|
|
1437 The first arg is the name of the resource to retrieve, such as "font".
|
|
1438 The second arg is the class of the resource to retrieve, such as "Font".
|
3025
|
1439 The third arg must be one of the symbols `string', `integer', `natnum', or
|
|
1440 `boolean', specifying the type of object that the database is searched for.
|
428
|
1441 The fourth arg is the locale to search for the resources on, and can
|
3025
|
1442 currently be a buffer, a frame, a device, or `global'. If omitted, it
|
|
1443 defaults to `global'.
|
428
|
1444 The fifth arg is the device to search for the resources on. (The resource
|
|
1445 database for a particular device is constructed by combining non-device-
|
|
1446 specific resources such as any command-line resources specified and any
|
|
1447 app-defaults files found [or the fallback resources supplied by XEmacs,
|
|
1448 if no app-defaults file is found] with device-specific resources such as
|
|
1449 those supplied using xrdb.) If omitted, it defaults to the device of
|
|
1450 LOCALE, if a device can be derived (i.e. if LOCALE is a frame or device),
|
|
1451 and otherwise defaults to the value of `default-x-device'.
|
|
1452 The sixth arg NOERROR, if non-nil, means do not signal an error if a
|
|
1453 bogus resource specification was retrieved (e.g. if a non-integer was
|
|
1454 given when an integer was requested). In this case, a warning is issued
|
442
|
1455 instead, unless NOERROR is t, in which case no warning is issued.
|
428
|
1456
|
|
1457 The resource names passed to this function are looked up relative to the
|
|
1458 locale.
|
|
1459
|
|
1460 If you want to search for a subresource, you just need to specify the
|
|
1461 resource levels in NAME and CLASS. For example, NAME could be
|
|
1462 "modeline.attributeFont", and CLASS "Face.AttributeFont".
|
|
1463
|
|
1464 Specifically,
|
|
1465
|
|
1466 1) If LOCALE is a buffer, a call
|
|
1467
|
|
1468 (x-get-resource "foreground" "Foreground" 'string SOME-BUFFER)
|
|
1469
|
|
1470 is an interface to a C call something like
|
|
1471
|
|
1472 XrmGetResource (db, "xemacs.buffer.BUFFER-NAME.foreground",
|
|
1473 "Emacs.EmacsLocaleType.EmacsBuffer.Foreground",
|
|
1474 "String");
|
|
1475
|
|
1476 2) If LOCALE is a frame, a call
|
|
1477
|
|
1478 (x-get-resource "foreground" "Foreground" 'string SOME-FRAME)
|
|
1479
|
|
1480 is an interface to a C call something like
|
|
1481
|
|
1482 XrmGetResource (db, "xemacs.frame.FRAME-NAME.foreground",
|
|
1483 "Emacs.EmacsLocaleType.EmacsFrame.Foreground",
|
|
1484 "String");
|
|
1485
|
|
1486 3) If LOCALE is a device, a call
|
|
1487
|
|
1488 (x-get-resource "foreground" "Foreground" 'string SOME-DEVICE)
|
|
1489
|
|
1490 is an interface to a C call something like
|
|
1491
|
|
1492 XrmGetResource (db, "xemacs.device.DEVICE-NAME.foreground",
|
|
1493 "Emacs.EmacsLocaleType.EmacsDevice.Foreground",
|
|
1494 "String");
|
|
1495
|
3025
|
1496 4) If LOCALE is `global', a call
|
428
|
1497
|
|
1498 (x-get-resource "foreground" "Foreground" 'string 'global)
|
|
1499
|
|
1500 is an interface to a C call something like
|
|
1501
|
|
1502 XrmGetResource (db, "xemacs.foreground",
|
|
1503 "Emacs.Foreground",
|
|
1504 "String");
|
|
1505
|
3025
|
1506 Note that for `global', no prefix is added other than that of the
|
428
|
1507 application itself; thus, you can use this locale to retrieve
|
|
1508 arbitrary application resources, if you really want to.
|
|
1509
|
|
1510 The returned value of this function is nil if the queried resource is not
|
|
1511 found. If the third arg is `string', a string is returned, and if it is
|
|
1512 `integer', an integer is returned. If the third arg is `boolean', then the
|
|
1513 returned value is the list (t) for true, (nil) for false, and is nil to
|
430
|
1514 mean ``unspecified''.
|
428
|
1515 */
|
1204
|
1516 (name, class_, type, locale, device, noerror))
|
428
|
1517 {
|
771
|
1518 Extbyte *name_string, *class_string;
|
|
1519 Extbyte *raw_result;
|
428
|
1520 XrmDatabase db;
|
|
1521 Display *display;
|
578
|
1522 Error_Behavior errb = decode_error_behavior_flag (noerror);
|
771
|
1523 Lisp_Object codesys;
|
428
|
1524
|
|
1525 CHECK_STRING (name);
|
1204
|
1526 CHECK_STRING (class_);
|
428
|
1527 CHECK_SYMBOL (type);
|
|
1528
|
771
|
1529 Dynarr_reset (name_Extbyte_dynarr);
|
|
1530 Dynarr_reset (class_Extbyte_dynarr);
|
428
|
1531
|
|
1532 x_get_resource_prefix (locale, device, &display,
|
771
|
1533 name_Extbyte_dynarr, class_Extbyte_dynarr);
|
428
|
1534 if (!display)
|
|
1535 return Qnil;
|
|
1536
|
|
1537 db = XtDatabase (display);
|
771
|
1538 codesys = coding_system_of_xrm_database (db);
|
|
1539 Dynarr_add (name_Extbyte_dynarr, '.');
|
|
1540 Dynarr_add_lisp_string (name_Extbyte_dynarr, name, Qbinary);
|
|
1541 Dynarr_add (class_Extbyte_dynarr, '.');
|
1204
|
1542 Dynarr_add_lisp_string (class_Extbyte_dynarr, class_, Qbinary);
|
771
|
1543 Dynarr_add (name_Extbyte_dynarr, '\0');
|
|
1544 Dynarr_add (class_Extbyte_dynarr, '\0');
|
428
|
1545
|
771
|
1546 name_string = Dynarr_atp (name_Extbyte_dynarr, 0);
|
|
1547 class_string = Dynarr_atp (class_Extbyte_dynarr, 0);
|
428
|
1548
|
|
1549 {
|
|
1550 XrmValue xrm_value;
|
|
1551 XrmName namelist[100];
|
|
1552 XrmClass classlist[100];
|
|
1553 XrmName *namerest = namelist;
|
|
1554 XrmClass *classrest = classlist;
|
|
1555 XrmRepresentation xrm_type;
|
|
1556 XrmRepresentation string_quark;
|
|
1557 int result;
|
|
1558 XrmStringToNameList (name_string, namelist);
|
|
1559 XrmStringToClassList (class_string, classlist);
|
|
1560 string_quark = XrmStringToQuark ("String");
|
|
1561
|
|
1562 /* ensure that they have the same length */
|
|
1563 while (namerest[0] && classrest[0])
|
|
1564 namerest++, classrest++;
|
|
1565 if (namerest[0] || classrest[0])
|
563
|
1566 {
|
|
1567 maybe_signal_error_2
|
|
1568 (Qstructure_formation_error,
|
1204
|
1569 "class list and name list must be the same length", name, class_,
|
563
|
1570 Qresource, errb);
|
|
1571 return Qnil;
|
|
1572 }
|
428
|
1573 result = XrmQGetResource (db, namelist, classlist, &xrm_type, &xrm_value);
|
|
1574
|
|
1575 if (result != True || xrm_type != string_quark)
|
|
1576 return Qnil;
|
771
|
1577 raw_result = (Extbyte *) xrm_value.addr;
|
428
|
1578 }
|
|
1579
|
|
1580 if (EQ (type, Qstring))
|
771
|
1581 return build_ext_string (raw_result, codesys);
|
428
|
1582 else if (EQ (type, Qboolean))
|
|
1583 {
|
771
|
1584 if (!strcasecmp (raw_result, "off") ||
|
|
1585 !strcasecmp (raw_result, "false") ||
|
|
1586 !strcasecmp (raw_result, "no"))
|
428
|
1587 return Fcons (Qnil, Qnil);
|
771
|
1588 if (!strcasecmp (raw_result, "on") ||
|
|
1589 !strcasecmp (raw_result, "true") ||
|
|
1590 !strcasecmp (raw_result, "yes"))
|
428
|
1591 return Fcons (Qt, Qnil);
|
563
|
1592 return maybe_signal_continuable_error_2
|
|
1593 (Qinvalid_operation, "Can't convert to a Boolean",
|
771
|
1594 build_ext_string (name_string, Qbinary),
|
|
1595 build_ext_string (raw_result, codesys), Qresource,
|
563
|
1596 errb);
|
428
|
1597 }
|
|
1598 else if (EQ (type, Qinteger) || EQ (type, Qnatnum))
|
|
1599 {
|
|
1600 int i;
|
|
1601 char c;
|
|
1602 if (1 != sscanf (raw_result, "%d%c", &i, &c))
|
563
|
1603 return maybe_signal_continuable_error_2
|
|
1604 (Qinvalid_operation, "Can't convert to an integer",
|
771
|
1605 build_ext_string (name_string, Qbinary),
|
|
1606 build_ext_string (raw_result, codesys), Qresource,
|
563
|
1607 errb);
|
428
|
1608 else if (EQ (type, Qnatnum) && i < 0)
|
563
|
1609 return maybe_signal_continuable_error_2
|
|
1610 (Qinvalid_argument, "Invalid numerical value for resource",
|
771
|
1611 make_int (i), build_ext_string (name_string, Qbinary),
|
|
1612 Qresource, errb);
|
428
|
1613 else
|
|
1614 return make_int (i);
|
|
1615 }
|
|
1616 else
|
|
1617 {
|
|
1618 return maybe_signal_continuable_error
|
563
|
1619 (Qwrong_type_argument, "Should be string, integer, natnum or boolean",
|
|
1620 type, Qresource, errb);
|
428
|
1621 }
|
|
1622 }
|
|
1623
|
|
1624 DEFUN ("x-get-resource-prefix", Fx_get_resource_prefix, 1, 2, 0, /*
|
|
1625 Return the resource prefix for LOCALE on DEVICE.
|
|
1626 The resource prefix is the strings used to prefix resources if
|
|
1627 the LOCALE and DEVICE arguments were passed to `x-get-resource'.
|
|
1628 The returned value is a cons of a name prefix and a class prefix.
|
|
1629 For example, if LOCALE is a frame, the returned value might be
|
|
1630 \("xemacs.frame.FRAME-NAME" . "Emacs.EmacsLocaleType.EmacsFrame").
|
|
1631 If no valid X device for resourcing can be obtained, this function
|
|
1632 returns nil. (In such a case, `x-get-resource' would always return nil.)
|
|
1633 */
|
|
1634 (locale, device))
|
|
1635 {
|
|
1636 Display *display;
|
|
1637
|
771
|
1638 Dynarr_reset (name_Extbyte_dynarr );
|
|
1639 Dynarr_reset (class_Extbyte_dynarr);
|
428
|
1640
|
|
1641 x_get_resource_prefix (locale, device, &display,
|
771
|
1642 name_Extbyte_dynarr, class_Extbyte_dynarr);
|
428
|
1643 if (!display)
|
|
1644 return Qnil;
|
|
1645
|
867
|
1646 return Fcons (make_string ((Ibyte *) Dynarr_atp (name_Extbyte_dynarr, 0),
|
771
|
1647 Dynarr_length (name_Extbyte_dynarr)),
|
867
|
1648 make_string ((Ibyte *) Dynarr_atp (class_Extbyte_dynarr, 0),
|
771
|
1649 Dynarr_length (class_Extbyte_dynarr)));
|
428
|
1650 }
|
|
1651
|
|
1652 DEFUN ("x-put-resource", Fx_put_resource, 1, 2, 0, /*
|
|
1653 Add a resource to the resource database for DEVICE.
|
|
1654 RESOURCE-LINE specifies the resource to add and should be a
|
|
1655 standard resource specification.
|
|
1656 */
|
|
1657 (resource_line, device))
|
|
1658 {
|
|
1659 struct device *d = decode_device (device);
|
|
1660
|
|
1661 if (DEVICE_X_P (d))
|
|
1662 {
|
|
1663 XrmDatabase db = XtDatabase (DEVICE_X_DISPLAY (d));
|
771
|
1664 Extbyte *str, *colon_pos;
|
|
1665
|
|
1666 CHECK_STRING (resource_line);
|
|
1667 LISP_STRING_TO_EXTERNAL (resource_line, str,
|
|
1668 coding_system_of_xrm_database (db));
|
|
1669 if (!(colon_pos = strchr (str, ':')) || strchr (str, '\n'))
|
|
1670 invalid:
|
|
1671 syntax_error ("Invalid resource line", resource_line);
|
|
1672 if ((int)
|
|
1673 strspn (str,
|
|
1674 /* Only the following chars are allowed before the colon */
|
|
1675 " \t.*?abcdefghijklmnopqrstuvwxyz"
|
|
1676 "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-")
|
|
1677 != colon_pos - str)
|
|
1678 goto invalid;
|
|
1679
|
428
|
1680 XrmPutLineResource (&db, str);
|
|
1681 }
|
|
1682
|
|
1683 return Qnil;
|
|
1684 }
|
|
1685
|
|
1686
|
|
1687 /************************************************************************/
|
|
1688 /* display information functions */
|
|
1689 /************************************************************************/
|
|
1690
|
|
1691 DEFUN ("default-x-device", Fdefault_x_device, 0, 0, 0, /*
|
|
1692 Return the default X device for resourcing.
|
|
1693 This is the first-created X device that still exists.
|
872
|
1694 See also `default-device'.
|
428
|
1695 */
|
|
1696 ())
|
|
1697 {
|
872
|
1698 return get_default_device (Qx);
|
428
|
1699 }
|
|
1700
|
|
1701 DEFUN ("x-display-visual-class", Fx_display_visual_class, 0, 1, 0, /*
|
|
1702 Return the visual class of the X display DEVICE is using.
|
|
1703 This can be altered from the default at startup using the XResource "EmacsVisual".
|
|
1704 The returned value will be one of the symbols `static-gray', `gray-scale',
|
|
1705 `static-color', `pseudo-color', `true-color', or `direct-color'.
|
|
1706 */
|
|
1707 (device))
|
|
1708 {
|
|
1709 Visual *vis = DEVICE_X_VISUAL (decode_x_device (device));
|
1204
|
1710 switch (vis->X_CLASSFIELD)
|
428
|
1711 {
|
|
1712 case StaticGray: return intern ("static-gray");
|
|
1713 case GrayScale: return intern ("gray-scale");
|
|
1714 case StaticColor: return intern ("static-color");
|
|
1715 case PseudoColor: return intern ("pseudo-color");
|
|
1716 case TrueColor: return intern ("true-color");
|
|
1717 case DirectColor: return intern ("direct-color");
|
|
1718 default:
|
563
|
1719 invalid_state ("display has an unknown visual class", Qunbound);
|
428
|
1720 return Qnil; /* suppress compiler warning */
|
|
1721 }
|
|
1722 }
|
|
1723
|
|
1724 DEFUN ("x-display-visual-depth", Fx_display_visual_depth, 0, 1, 0, /*
|
|
1725 Return the bitplane depth of the visual the X display DEVICE is using.
|
|
1726 */
|
|
1727 (device))
|
|
1728 {
|
|
1729 return make_int (DEVICE_X_DEPTH (decode_x_device (device)));
|
|
1730 }
|
|
1731
|
|
1732 static Lisp_Object
|
|
1733 x_device_system_metrics (struct device *d,
|
|
1734 enum device_metrics m)
|
|
1735 {
|
|
1736 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1737
|
|
1738 switch (m)
|
|
1739 {
|
|
1740 case DM_size_device:
|
|
1741 return Fcons (make_int (DisplayWidth (dpy, DefaultScreen (dpy))),
|
|
1742 make_int (DisplayHeight (dpy, DefaultScreen (dpy))));
|
|
1743 case DM_size_device_mm:
|
|
1744 return Fcons (make_int (DisplayWidthMM (dpy, DefaultScreen (dpy))),
|
|
1745 make_int (DisplayHeightMM (dpy, DefaultScreen (dpy))));
|
|
1746 case DM_num_bit_planes:
|
|
1747 return make_int (DisplayPlanes (dpy, DefaultScreen (dpy)));
|
|
1748 case DM_num_color_cells:
|
|
1749 return make_int (DisplayCells (dpy, DefaultScreen (dpy)));
|
1942
|
1750 case DM_num_screens:
|
|
1751 return make_int (ScreenCount (dpy));
|
|
1752 case DM_backing_store:
|
|
1753 switch (DoesBackingStore (DefaultScreenOfDisplay (dpy)))
|
|
1754 {
|
|
1755 case Always:
|
|
1756 return intern ("always");
|
|
1757 case WhenMapped:
|
|
1758 return intern ("when-mapped");
|
|
1759 default:
|
|
1760 return intern ("not-useful");
|
|
1761 }
|
|
1762 case DM_save_under:
|
|
1763 return (DoesSaveUnders (DefaultScreenOfDisplay (dpy)) == True)
|
|
1764 ? Qt : Qnil;
|
428
|
1765 default: /* No such device metric property for X devices */
|
|
1766 return Qunbound;
|
|
1767 }
|
|
1768 }
|
|
1769
|
|
1770 DEFUN ("x-server-vendor", Fx_server_vendor, 0, 1, 0, /*
|
|
1771 Return the vendor ID string of the X server DEVICE is on.
|
|
1772 Return the empty string if the vendor ID string cannot be determined.
|
|
1773 */
|
|
1774 (device))
|
|
1775 {
|
|
1776 Display *dpy = get_x_display (device);
|
2367
|
1777 Extbyte *vendor = ServerVendor (dpy);
|
428
|
1778
|
2367
|
1779 return build_ext_string (vendor ? vendor : "", Qx_hpc_encoding);
|
428
|
1780 }
|
|
1781
|
|
1782 DEFUN ("x-server-version", Fx_server_version, 0, 1, 0, /*
|
|
1783 Return the version numbers of the X server DEVICE is on.
|
|
1784 The returned value is a list of three integers: the major and minor
|
|
1785 version numbers of the X Protocol in use, and the vendor-specific release
|
|
1786 number. See also `x-server-vendor'.
|
|
1787 */
|
|
1788 (device))
|
|
1789 {
|
|
1790 Display *dpy = get_x_display (device);
|
|
1791
|
|
1792 return list3 (make_int (ProtocolVersion (dpy)),
|
|
1793 make_int (ProtocolRevision (dpy)),
|
|
1794 make_int (VendorRelease (dpy)));
|
|
1795 }
|
|
1796
|
|
1797 DEFUN ("x-valid-keysym-name-p", Fx_valid_keysym_name_p, 1, 1, 0, /*
|
|
1798 Return true if KEYSYM names a keysym that the X library knows about.
|
|
1799 Valid keysyms are listed in the files /usr/include/X11/keysymdef.h and in
|
|
1800 /usr/lib/X11/XKeysymDB, or whatever the equivalents are on your system.
|
|
1801 */
|
|
1802 (keysym))
|
|
1803 {
|
2367
|
1804 const Extbyte *keysym_ext;
|
428
|
1805
|
|
1806 CHECK_STRING (keysym);
|
442
|
1807 LISP_STRING_TO_EXTERNAL (keysym, keysym_ext, Qctext);
|
428
|
1808
|
|
1809 return XStringToKeysym (keysym_ext) ? Qt : Qnil;
|
|
1810 }
|
|
1811
|
|
1812 DEFUN ("x-keysym-hash-table", Fx_keysym_hash_table, 0, 1, 0, /*
|
440
|
1813 Return a hash table containing a key for all keysyms on DEVICE.
|
|
1814 DEVICE must be an X11 display device. See `x-keysym-on-keyboard-p'.
|
428
|
1815 */
|
|
1816 (device))
|
|
1817 {
|
|
1818 struct device *d = decode_device (device);
|
|
1819 if (!DEVICE_X_P (d))
|
563
|
1820 gui_error ("Not an X device", device);
|
428
|
1821
|
|
1822 return DEVICE_X_DATA (d)->x_keysym_map_hash_table;
|
|
1823 }
|
|
1824
|
|
1825 DEFUN ("x-keysym-on-keyboard-sans-modifiers-p", Fx_keysym_on_keyboard_sans_modifiers_p,
|
|
1826 1, 2, 0, /*
|
|
1827 Return true if KEYSYM names a key on the keyboard of DEVICE.
|
|
1828 More precisely, return true if pressing a physical key
|
|
1829 on the keyboard of DEVICE without any modifier keys generates KEYSYM.
|
|
1830 Valid keysyms are listed in the files /usr/include/X11/keysymdef.h and in
|
|
1831 /usr/lib/X11/XKeysymDB, or whatever the equivalents are on your system.
|
|
1832 The keysym name can be provided in two forms:
|
|
1833 - if keysym is a string, it must be the name as known to X windows.
|
|
1834 - if keysym is a symbol, it must be the name as known to XEmacs.
|
|
1835 The two names differ in capitalization and underscoring.
|
|
1836 */
|
|
1837 (keysym, device))
|
|
1838 {
|
|
1839 struct device *d = decode_device (device);
|
|
1840 if (!DEVICE_X_P (d))
|
563
|
1841 gui_error ("Not an X device", device);
|
428
|
1842
|
|
1843 return (EQ (Qsans_modifiers,
|
|
1844 Fgethash (keysym, DEVICE_X_KEYSYM_MAP_HASH_TABLE (d), Qnil)) ?
|
|
1845 Qt : Qnil);
|
|
1846 }
|
|
1847
|
|
1848
|
|
1849 DEFUN ("x-keysym-on-keyboard-p", Fx_keysym_on_keyboard_p, 1, 2, 0, /*
|
|
1850 Return true if KEYSYM names a key on the keyboard of DEVICE.
|
|
1851 More precisely, return true if some keystroke (possibly including modifiers)
|
|
1852 on the keyboard of DEVICE keys generates KEYSYM.
|
|
1853 Valid keysyms are listed in the files /usr/include/X11/keysymdef.h and in
|
|
1854 /usr/lib/X11/XKeysymDB, or whatever the equivalents are on your system.
|
|
1855 The keysym name can be provided in two forms:
|
|
1856 - if keysym is a string, it must be the name as known to X windows.
|
|
1857 - if keysym is a symbol, it must be the name as known to XEmacs.
|
|
1858 The two names differ in capitalization and underscoring.
|
2828
|
1859
|
|
1860 This function is not entirely trustworthy, in that Xlib compose processing
|
|
1861 can produce keysyms that XEmacs will not have seen when it examined the
|
|
1862 keysyms available on startup. So pressing `dead-diaeresis' and then 'a' may
|
|
1863 pass `adiaeresis' to XEmacs, or (in some implementations) even `U00E4',
|
|
1864 where `(x-keysym-on-keyboard-p 'adiaeresis)' and `(x-keysym-on-keyboard-p
|
|
1865 'U00E4)' would both have returned nil. Subsequent to XEmacs seeing a keysym
|
|
1866 it was previously unaware of, the predicate will take note of it, though.
|
428
|
1867 */
|
|
1868 (keysym, device))
|
|
1869 {
|
|
1870 struct device *d = decode_device (device);
|
|
1871 if (!DEVICE_X_P (d))
|
563
|
1872 gui_error ("Not an X device", device);
|
428
|
1873
|
|
1874 return (NILP (Fgethash (keysym, DEVICE_X_KEYSYM_MAP_HASH_TABLE (d), Qnil)) ?
|
|
1875 Qnil : Qt);
|
|
1876 }
|
|
1877
|
|
1878
|
|
1879 /************************************************************************/
|
|
1880 /* grabs and ungrabs */
|
|
1881 /************************************************************************/
|
|
1882
|
|
1883 DEFUN ("x-grab-pointer", Fx_grab_pointer, 0, 3, 0, /*
|
|
1884 Grab the pointer and restrict it to its current window.
|
|
1885 If optional DEVICE argument is nil, the default device will be used.
|
|
1886 If optional CURSOR argument is non-nil, change the pointer shape to that
|
|
1887 until `x-ungrab-pointer' is called (it should be an object returned by the
|
|
1888 `make-cursor-glyph' function).
|
|
1889 If the second optional argument IGNORE-KEYBOARD is non-nil, ignore all
|
|
1890 keyboard events during the grab.
|
|
1891 Returns t if the grab is successful, nil otherwise.
|
|
1892 */
|
|
1893 (device, cursor, ignore_keyboard))
|
|
1894 {
|
|
1895 Window w;
|
|
1896 int pointer_mode, result;
|
|
1897 struct device *d = decode_x_device (device);
|
|
1898
|
|
1899 if (!NILP (cursor))
|
|
1900 {
|
|
1901 CHECK_POINTER_GLYPH (cursor);
|
|
1902 cursor = glyph_image_instance (cursor, device, ERROR_ME, 0);
|
|
1903 }
|
|
1904
|
|
1905 if (!NILP (ignore_keyboard))
|
|
1906 pointer_mode = GrabModeSync;
|
|
1907 else
|
|
1908 pointer_mode = GrabModeAsync;
|
|
1909
|
|
1910 w = XtWindow (FRAME_X_TEXT_WIDGET (device_selected_frame (d)));
|
|
1911
|
|
1912 /* #### Possibly this needs to gcpro the cursor somehow, but it doesn't
|
|
1913 seem to cause a problem if XFreeCursor is called on a cursor in use
|
|
1914 in a grab; I suppose the X server counts the grab as a reference
|
|
1915 and doesn't free it until it exits? */
|
|
1916 result = XGrabPointer (DEVICE_X_DISPLAY (d), w,
|
|
1917 False,
|
|
1918 ButtonMotionMask |
|
|
1919 ButtonPressMask |
|
|
1920 ButtonReleaseMask |
|
|
1921 PointerMotionHintMask,
|
|
1922 GrabModeAsync, /* Keep pointer events flowing */
|
|
1923 pointer_mode, /* Stall keyboard events */
|
|
1924 w, /* Stay in this window */
|
|
1925 (NILP (cursor) ? 0
|
|
1926 : XIMAGE_INSTANCE_X_CURSOR (cursor)),
|
|
1927 CurrentTime);
|
|
1928 return (result == GrabSuccess) ? Qt : Qnil;
|
|
1929 }
|
|
1930
|
|
1931 DEFUN ("x-ungrab-pointer", Fx_ungrab_pointer, 0, 1, 0, /*
|
|
1932 Release a pointer grab made with `x-grab-pointer'.
|
|
1933 If optional first arg DEVICE is nil the default device is used.
|
|
1934 If it is t the pointer will be released on all X devices.
|
|
1935 */
|
|
1936 (device))
|
|
1937 {
|
|
1938 if (!EQ (device, Qt))
|
|
1939 {
|
|
1940 Display *dpy = get_x_display (device);
|
|
1941 XUngrabPointer (dpy, CurrentTime);
|
|
1942 }
|
|
1943 else
|
|
1944 {
|
|
1945 Lisp_Object devcons, concons;
|
|
1946
|
|
1947 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
1948 {
|
|
1949 struct device *d = XDEVICE (XCAR (devcons));
|
|
1950
|
|
1951 if (DEVICE_X_P (d))
|
|
1952 XUngrabPointer (DEVICE_X_DISPLAY (d), CurrentTime);
|
|
1953 }
|
|
1954 }
|
|
1955
|
|
1956 return Qnil;
|
|
1957 }
|
|
1958
|
|
1959 DEFUN ("x-grab-keyboard", Fx_grab_keyboard, 0, 1, 0, /*
|
|
1960 Grab the keyboard on the given device (defaulting to the selected one).
|
|
1961 So long as the keyboard is grabbed, all keyboard events will be delivered
|
|
1962 to emacs -- it is not possible for other X clients to eavesdrop on them.
|
|
1963 Ungrab the keyboard with `x-ungrab-keyboard' (use an unwind-protect).
|
|
1964 Returns t if the grab is successful, nil otherwise.
|
|
1965 */
|
|
1966 (device))
|
|
1967 {
|
|
1968 struct device *d = decode_x_device (device);
|
|
1969 Window w = XtWindow (FRAME_X_TEXT_WIDGET (device_selected_frame (d)));
|
|
1970 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1971 Status status;
|
|
1972 XSync (dpy, False);
|
|
1973 status = XGrabKeyboard (dpy, w, True,
|
|
1974 /* I don't really understand sync-vs-async
|
|
1975 grabs, but this is what xterm does. */
|
|
1976 GrabModeAsync, GrabModeAsync,
|
|
1977 /* Use the timestamp of the last user action
|
|
1978 read by emacs proper; xterm uses CurrentTime
|
|
1979 but there's a comment that says "wrong"...
|
|
1980 (Despite the name this is the time of the
|
|
1981 last key or mouse event.) */
|
|
1982 DEVICE_X_MOUSE_TIMESTAMP (d));
|
|
1983 if (status == GrabSuccess)
|
|
1984 {
|
|
1985 /* The XUngrabKeyboard should generate a FocusIn back to this
|
|
1986 window but it doesn't unless we explicitly set focus to the
|
|
1987 window first (which should already have it. The net result
|
|
1988 is that without this call when x-ungrab-keyboard is called
|
|
1989 the selected frame ends up not having focus. */
|
|
1990 XSetInputFocus (dpy, w, RevertToParent, DEVICE_X_MOUSE_TIMESTAMP (d));
|
|
1991 return Qt;
|
|
1992 }
|
|
1993 else
|
|
1994 return Qnil;
|
|
1995 }
|
|
1996
|
|
1997 DEFUN ("x-ungrab-keyboard", Fx_ungrab_keyboard, 0, 1, 0, /*
|
|
1998 Release a keyboard grab made with `x-grab-keyboard'.
|
|
1999 */
|
|
2000 (device))
|
|
2001 {
|
|
2002 Display *dpy = get_x_display (device);
|
|
2003 XUngrabKeyboard (dpy, CurrentTime);
|
|
2004 return Qnil;
|
|
2005 }
|
|
2006
|
|
2007 DEFUN ("x-get-font-path", Fx_get_font_path, 0, 1, 0, /*
|
|
2008 Get the X Server's font path.
|
|
2009
|
|
2010 See also `x-set-font-path'.
|
|
2011 */
|
|
2012 (device))
|
|
2013 {
|
|
2014 Display *dpy = get_x_display (device);
|
|
2015 int ndirs_return;
|
2367
|
2016 const Extbyte **directories =
|
|
2017 (const Extbyte **) XGetFontPath (dpy, &ndirs_return);
|
428
|
2018 Lisp_Object font_path = Qnil;
|
|
2019
|
|
2020 if (!directories)
|
563
|
2021 gui_error ("Can't get X font path", device);
|
428
|
2022
|
|
2023 while (ndirs_return--)
|
|
2024 font_path = Fcons (build_ext_string (directories[ndirs_return],
|
440
|
2025 Qfile_name),
|
|
2026 font_path);
|
428
|
2027
|
|
2028 return font_path;
|
|
2029 }
|
|
2030
|
|
2031 DEFUN ("x-set-font-path", Fx_set_font_path, 1, 2, 0, /*
|
|
2032 Set the X Server's font path to FONT-PATH.
|
|
2033
|
|
2034 There is only one font path per server, not one per client. Use this
|
|
2035 sparingly. It uncaches all of the X server's font information.
|
|
2036
|
|
2037 Font directories should end in the path separator and should contain
|
|
2038 a file called fonts.dir usually created with the program mkfontdir.
|
|
2039
|
|
2040 Setting the FONT-PATH to nil tells the X server to use the default
|
|
2041 font path.
|
|
2042
|
|
2043 See also `x-get-font-path'.
|
|
2044 */
|
|
2045 (font_path, device))
|
|
2046 {
|
|
2047 Display *dpy = get_x_display (device);
|
2367
|
2048 Extbyte **directories;
|
428
|
2049 int i=0,ndirs=0;
|
|
2050
|
2367
|
2051 {
|
|
2052 EXTERNAL_LIST_LOOP_2 (path_entry, font_path)
|
|
2053 {
|
|
2054 CHECK_STRING (path_entry);
|
|
2055 ndirs++;
|
|
2056 }
|
|
2057 }
|
428
|
2058
|
2367
|
2059 directories = alloca_array (Extbyte *, ndirs);
|
428
|
2060
|
2367
|
2061 {
|
|
2062 EXTERNAL_LIST_LOOP_2 (path_entry, font_path)
|
|
2063 {
|
|
2064 LISP_STRING_TO_EXTERNAL (path_entry, directories[i++],
|
|
2065 Qfile_name);
|
|
2066 }
|
|
2067 }
|
428
|
2068
|
|
2069 expect_x_error (dpy);
|
2367
|
2070 XSetFontPath (dpy, directories, ndirs);
|
428
|
2071 signal_if_x_error (dpy, 1/*resumable_p*/);
|
|
2072
|
|
2073 return Qnil;
|
|
2074 }
|
|
2075
|
|
2076
|
|
2077 /************************************************************************/
|
|
2078 /* initialization */
|
|
2079 /************************************************************************/
|
|
2080
|
|
2081 void
|
|
2082 syms_of_device_x (void)
|
|
2083 {
|
3092
|
2084 #ifdef NEW_GC
|
|
2085 INIT_LRECORD_IMPLEMENTATION (x_device);
|
|
2086 #endif /* NEW_GC */
|
|
2087
|
428
|
2088 DEFSUBR (Fx_debug_mode);
|
|
2089 DEFSUBR (Fx_get_resource);
|
|
2090 DEFSUBR (Fx_get_resource_prefix);
|
|
2091 DEFSUBR (Fx_put_resource);
|
|
2092
|
|
2093 DEFSUBR (Fdefault_x_device);
|
|
2094 DEFSUBR (Fx_display_visual_class);
|
|
2095 DEFSUBR (Fx_display_visual_depth);
|
|
2096 DEFSUBR (Fx_server_vendor);
|
|
2097 DEFSUBR (Fx_server_version);
|
|
2098 DEFSUBR (Fx_valid_keysym_name_p);
|
|
2099 DEFSUBR (Fx_keysym_hash_table);
|
|
2100 DEFSUBR (Fx_keysym_on_keyboard_p);
|
|
2101 DEFSUBR (Fx_keysym_on_keyboard_sans_modifiers_p);
|
|
2102
|
|
2103 DEFSUBR (Fx_grab_pointer);
|
|
2104 DEFSUBR (Fx_ungrab_pointer);
|
|
2105 DEFSUBR (Fx_grab_keyboard);
|
|
2106 DEFSUBR (Fx_ungrab_keyboard);
|
|
2107
|
|
2108 DEFSUBR (Fx_get_font_path);
|
|
2109 DEFSUBR (Fx_set_font_path);
|
|
2110
|
563
|
2111 DEFSYMBOL (Qx_error);
|
|
2112 DEFSYMBOL (Qinit_pre_x_win);
|
|
2113 DEFSYMBOL (Qinit_post_x_win);
|
771
|
2114
|
|
2115 #ifdef MULE
|
|
2116 DEFSYMBOL (Qget_coding_system_from_locale);
|
|
2117 #endif
|
428
|
2118 }
|
|
2119
|
|
2120 void
|
|
2121 reinit_console_type_create_device_x (void)
|
|
2122 {
|
|
2123 /* Initialize variables to speed up X resource interactions */
|
2367
|
2124 const Ascbyte *valid_resource_chars =
|
428
|
2125 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
2126 while (*valid_resource_chars)
|
|
2127 valid_resource_char_p[(unsigned int) (*valid_resource_chars++)] = 1;
|
|
2128
|
771
|
2129 name_Extbyte_dynarr = Dynarr_new (Extbyte);
|
|
2130 class_Extbyte_dynarr = Dynarr_new (Extbyte);
|
428
|
2131 }
|
|
2132
|
|
2133 void
|
|
2134 console_type_create_device_x (void)
|
|
2135 {
|
|
2136 reinit_console_type_create_device_x ();
|
|
2137 CONSOLE_HAS_METHOD (x, init_device);
|
|
2138 CONSOLE_HAS_METHOD (x, finish_init_device);
|
|
2139 CONSOLE_HAS_METHOD (x, mark_device);
|
|
2140 CONSOLE_HAS_METHOD (x, delete_device);
|
|
2141 CONSOLE_HAS_METHOD (x, device_system_metrics);
|
|
2142 }
|
|
2143
|
|
2144 void
|
|
2145 reinit_vars_of_device_x (void)
|
|
2146 {
|
|
2147 error_expected = 0;
|
|
2148 error_occurred = 0;
|
|
2149
|
|
2150 in_resource_setting = 0;
|
|
2151 }
|
|
2152
|
|
2153 void
|
|
2154 vars_of_device_x (void)
|
|
2155 {
|
|
2156 DEFVAR_LISP ("x-emacs-application-class", &Vx_emacs_application_class /*
|
|
2157 The X application class of the XEmacs process.
|
|
2158 This controls, among other things, the name of the `app-defaults' file
|
|
2159 that XEmacs will use. For changes to this variable to take effect, they
|
|
2160 must be made before the connection to the X server is initialized, that is,
|
|
2161 this variable may only be changed before emacs is dumped, or by setting it
|
|
2162 in the file lisp/term/x-win.el.
|
|
2163
|
2681
|
2164 If this variable is nil on startup, the application uses `XEmacs'. Versions
|
|
2165 previous to 21.5.21 examined the resource database and used `XEmacs' if any
|
|
2166 resources beginning with that string existed, and `Emacs' otherwise, for
|
2828
|
2167 greater backward compatibility. However, this has always tended to conflict
|
2681
|
2168 with GNU Emacs, so this behavior is deprecated--in the short term, you can
|
|
2169 restore it in a post-21.5.21 XEmacs by setting the
|
|
2170 USE_EMACS_AS_DEFAULT_APPLICATION_CLASS environment variable to some value,
|
|
2171 but in the medium and long term, you should migrate your X resources.
|
428
|
2172 */ );
|
|
2173 Vx_emacs_application_class = Qnil;
|
|
2174
|
|
2175 DEFVAR_LISP ("x-initial-argv-list", &Vx_initial_argv_list /*
|
|
2176 You don't want to know.
|
|
2177 This is used during startup to communicate the remaining arguments in
|
|
2178 `command-line-args-left' to the C code, which passes the args to
|
|
2179 the X initialization code, which removes some args, and then the
|
|
2180 args are placed back into `x-initial-arg-list' and thence into
|
|
2181 `command-line-args-left'. Perhaps `command-line-args-left' should
|
|
2182 just reside in C.
|
|
2183 */ );
|
|
2184 Vx_initial_argv_list = Qnil;
|
|
2185
|
771
|
2186 #ifdef MULE
|
428
|
2187 DEFVAR_LISP ("x-app-defaults-directory", &Vx_app_defaults_directory /*
|
|
2188 Used by the Lisp code to communicate to the low level X initialization
|
|
2189 where the localized init files are.
|
|
2190 */ );
|
|
2191 Vx_app_defaults_directory = Qnil;
|
|
2192 #endif
|
|
2193
|
|
2194 Fprovide (Qx);
|
|
2195 }
|