0
|
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.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Not in FSF. */
|
|
23
|
|
24 /* Original authors: Jamie Zawinski and the FSF */
|
|
25 /* Rewritten by Ben Wing and Chuck Thompson. */
|
|
26
|
|
27 #include <config.h>
|
|
28 #include "lisp.h"
|
|
29
|
|
30 #include "console-x.h"
|
|
31 #include "xintrinsicp.h" /* CoreP.h needs this */
|
|
32 #include <X11/CoreP.h> /* Numerous places access the fields of
|
|
33 a core widget directly. We could
|
165
|
34 use XtGetValues(), but ... */
|
0
|
35 #include "xgccache.h"
|
|
36 #include <X11/Shell.h>
|
|
37 #include "xmu.h"
|
|
38 #include "glyphs-x.h"
|
|
39 #include "objects-x.h"
|
|
40
|
|
41 #include "buffer.h"
|
|
42 #include "events.h"
|
|
43 #include "faces.h"
|
|
44 #include "frame.h"
|
|
45 #include "redisplay.h"
|
|
46 #include "sysdep.h"
|
|
47 #include "window.h"
|
|
48
|
|
49 #include "sysfile.h"
|
|
50 #include "systime.h"
|
|
51
|
|
52 Lisp_Object Vdefault_x_device;
|
|
53
|
|
54 /* Qdisplay in general.c */
|
|
55 Lisp_Object Qx_error;
|
|
56 Lisp_Object Qinit_pre_x_win, Qinit_post_x_win;
|
|
57
|
167
|
58 /* $B@ZJ"(B, n. Japanese ritual suicide. */
|
|
59 int x_seppuku_on_epipe;
|
|
60
|
0
|
61 /* The application class of Emacs. */
|
|
62 Lisp_Object Vx_emacs_application_class;
|
|
63
|
|
64 Lisp_Object Vx_initial_argv_list; /* #### ugh! */
|
|
65
|
|
66 static XrmOptionDescRec emacs_options[] =
|
|
67 {
|
2
|
68 {(String)"-geometry", (String)".geometry", XrmoptionSepArg, NULL},
|
|
69 {(String)"-iconic", (String)".iconic", XrmoptionNoArg, (XtPointer) "yes"},
|
|
70
|
|
71 {(String)"-internal-border-width", (String)"*EmacsFrame.internalBorderWidth",
|
|
72 XrmoptionSepArg, NULL},
|
|
73 {(String)"-ib", (String)"*EmacsFrame.internalBorderWidth", XrmoptionSepArg,
|
|
74 NULL},
|
|
75 {(String)"-scrollbar-width", (String)"*EmacsFrame.scrollBarWidth",
|
|
76 XrmoptionSepArg, NULL},
|
|
77 {(String)"-scrollbar-height", (String)"*EmacsFrame.scrollBarHeight",
|
|
78 XrmoptionSepArg, NULL},
|
0
|
79
|
|
80 /* #### Beware! If the type of the shell changes, update this. */
|
2
|
81 {(String)"-T", (String)"*TopLevelEmacsShell.title", XrmoptionSepArg, NULL},
|
|
82 {(String)"-wn", (String)"*TopLevelEmacsShell.title", XrmoptionSepArg, NULL},
|
|
83 {(String)"-title", (String)"*TopLevelEmacsShell.title", XrmoptionSepArg,
|
|
84 NULL},
|
|
85 {(String)"-iconname", (String)"*TopLevelEmacsShell.iconName",
|
|
86 XrmoptionSepArg, NULL},
|
|
87 {(String)"-in", (String)"*TopLevelEmacsShell.iconName", XrmoptionSepArg,
|
|
88 NULL},
|
|
89 {(String)"-mc", (String)"*pointerColor", XrmoptionSepArg, NULL},
|
|
90 {(String)"-cr", (String)"*cursorColor", XrmoptionSepArg, NULL},
|
|
91 {(String)"-fontset", (String)"*FontSet", XrmoptionSepArg, NULL},
|
0
|
92 };
|
|
93
|
|
94 static void validify_resource_string (char *str);
|
|
95
|
|
96 /* Functions to synchronize mirroring resources and specifiers */
|
|
97 int in_resource_setting;
|
|
98 int in_specifier_change_function;
|
|
99
|
|
100
|
|
101 /************************************************************************/
|
|
102 /* helper functions */
|
|
103 /************************************************************************/
|
|
104
|
114
|
105 static struct device *
|
|
106 get_device_from_display_1 (Display *dpy)
|
0
|
107 {
|
|
108 Lisp_Object devcons, concons;
|
|
109
|
|
110 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
111 {
|
|
112 struct device *d = XDEVICE (XCAR (devcons));
|
|
113 if (DEVICE_X_P (d) && DEVICE_X_DISPLAY (d) == dpy)
|
|
114 return d;
|
|
115 }
|
|
116
|
114
|
117 return 0;
|
|
118 }
|
|
119
|
|
120 struct device *
|
|
121 get_device_from_display (Display *dpy)
|
|
122 {
|
|
123 struct device *d = get_device_from_display_1 (dpy);
|
0
|
124
|
114
|
125 if (!d) {
|
|
126 /* This isn't one of our displays. Let's crash? */
|
|
127 stderr_out
|
|
128 ("\n%s: Fatal X Condition. Asked about display we don't own: \"%s\"\n",
|
|
129 (STRINGP (Vinvocation_name) ?
|
|
130 (char *) XSTRING_DATA (Vinvocation_name) : "xemacs"),
|
|
131 DisplayString (dpy) ? DisplayString (dpy) : "???");
|
|
132 abort();
|
|
133 }
|
|
134
|
|
135 return d;
|
0
|
136 }
|
|
137
|
|
138 struct device *
|
|
139 decode_x_device (Lisp_Object device)
|
|
140 {
|
|
141 XSETDEVICE (device, decode_device (device));
|
|
142 CHECK_X_DEVICE (device);
|
|
143 return XDEVICE (device);
|
|
144 }
|
|
145
|
|
146 Display *
|
|
147 get_x_display (Lisp_Object device)
|
|
148 {
|
|
149 return DEVICE_X_DISPLAY (decode_x_device (device));
|
|
150 }
|
|
151
|
|
152
|
|
153 /************************************************************************/
|
|
154 /* initializing an X connection */
|
|
155 /************************************************************************/
|
|
156
|
|
157 static void
|
|
158 allocate_x_device_struct (struct device *d)
|
|
159 {
|
|
160 d->device_data = (struct x_device *) xmalloc (sizeof (struct x_device));
|
|
161
|
|
162 /* zero out all slots. */
|
|
163 memset (d->device_data, 0, sizeof (struct x_device));
|
|
164 }
|
|
165
|
|
166 static void
|
|
167 Xatoms_of_device_x (struct device *d)
|
|
168 {
|
149
|
169 Display *D = DEVICE_X_DISPLAY (d);
|
0
|
170
|
149
|
171 DEVICE_XATOM_WM_PROTOCOLS (d) = XInternAtom (D, "WM_PROTOCOLS", False);
|
|
172 DEVICE_XATOM_WM_DELETE_WINDOW(d) = XInternAtom (D, "WM_DELETE_WINDOW",False);
|
|
173 DEVICE_XATOM_WM_SAVE_YOURSELF(d) = XInternAtom (D, "WM_SAVE_YOURSELF",False);
|
|
174 DEVICE_XATOM_WM_TAKE_FOCUS (d) = XInternAtom (D, "WM_TAKE_FOCUS", False);
|
|
175 DEVICE_XATOM_WM_STATE (d) = XInternAtom (D, "WM_STATE", False);
|
0
|
176 }
|
|
177
|
|
178 static void
|
|
179 sanity_check_geometry_resource (Display *dpy)
|
|
180 {
|
|
181 char *app_name, *app_class, *s;
|
|
182 char buf1 [255], buf2 [255];
|
|
183 char *type;
|
|
184 XrmValue value;
|
|
185 XtGetApplicationNameAndClass (dpy, &app_name, &app_class);
|
|
186 strcpy (buf1, app_name);
|
|
187 strcpy (buf2, app_class);
|
|
188 for (s = buf1; *s; s++) if (*s == '.') *s = '_';
|
|
189 strcat (buf1, "._no_._such_._resource_.geometry");
|
|
190 strcat (buf2, "._no_._such_._resource_.Geometry");
|
|
191 if (XrmGetResource (XtDatabase (dpy), buf1, buf2, &type, &value) == True)
|
|
192 {
|
|
193 warn_when_safe (Qgeometry, Qerror,
|
|
194 "\n"
|
|
195 "Apparently \"%s*geometry: %s\" or \"%s*geometry: %s\" was\n"
|
|
196 "specified in the resource database. Specifying \"*geometry\" will make\n"
|
|
197 "XEmacs (and most other X programs) malfunction in obscure ways. (i.e.\n"
|
|
198 "the Xt or Xm libraries will probably crash, which is a very bad thing.)\n"
|
|
199 "You should always use \".geometry\" or \"*EmacsFrame.geometry\" instead.\n",
|
|
200 app_name, (char *) value.addr,
|
|
201 app_class, (char *) value.addr);
|
|
202 suppress_early_backtrace = 1;
|
|
203 error ("Invalid geometry resource");
|
|
204 }
|
|
205 }
|
|
206
|
|
207 static void
|
|
208 x_init_device_class (struct device *d)
|
|
209 {
|
|
210 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
211 if (DisplayCells (dpy, DefaultScreen (dpy)) > 2)
|
|
212 {
|
|
213 switch (DefaultVisualOfScreen (DefaultScreenOfDisplay (dpy))->class)
|
|
214 {
|
|
215 case StaticGray:
|
|
216 case GrayScale:
|
|
217 DEVICE_CLASS (d) = Qgrayscale;
|
|
218 break;
|
|
219 default:
|
|
220 DEVICE_CLASS (d) = Qcolor;
|
|
221 }
|
|
222 }
|
|
223 else
|
|
224 DEVICE_CLASS (d) = Qmono;
|
|
225 }
|
|
226
|
|
227 static void
|
|
228 x_init_device (struct device *d, Lisp_Object props)
|
|
229 {
|
|
230 Lisp_Object display;
|
|
231 Lisp_Object device;
|
|
232 Display *dpy;
|
|
233 int argc;
|
|
234 char **argv;
|
|
235 CONST char *app_class;
|
|
236 CONST char *disp_name;
|
|
237
|
|
238 XSETDEVICE (device, d);
|
|
239 display = DEVICE_CONNECTION (d);
|
|
240
|
|
241 allocate_x_device_struct (d);
|
|
242
|
|
243 make_argc_argv (Vx_initial_argv_list, &argc, &argv);
|
|
244
|
|
245 if (STRINGP (Vx_emacs_application_class) &&
|
14
|
246 XSTRING_LENGTH (Vx_emacs_application_class) > 0)
|
0
|
247 GET_C_STRING_CTEXT_DATA_ALLOCA (Vx_emacs_application_class, app_class);
|
|
248 else
|
|
249 app_class = "Emacs";
|
|
250
|
|
251 GET_C_STRING_CTEXT_DATA_ALLOCA (display, disp_name);
|
|
252
|
|
253 slow_down_interrupts ();
|
|
254 /* The Xt code can't deal with signals here. Yuck. */
|
|
255 dpy = DEVICE_X_DISPLAY (d) =
|
|
256 XtOpenDisplay (Xt_app_con, disp_name, NULL, app_class, emacs_options,
|
|
257 XtNumber (emacs_options), &argc, argv);
|
|
258 speed_up_interrupts ();
|
|
259
|
|
260 if (dpy == 0)
|
|
261 {
|
|
262 suppress_early_backtrace = 1;
|
|
263 signal_simple_error ("X server not responding\n", display);
|
|
264 }
|
|
265
|
74
|
266 if (NILP (Vdefault_x_device))
|
|
267 Vdefault_x_device = device;
|
|
268
|
70
|
269 #ifdef MULE
|
|
270 {
|
|
271 /* Read in locale-specific resources from
|
|
272 data-directory/app-defaults/$LANG/emacs-application-class.
|
|
273 This is in addition to the standard app-defaults files, and
|
|
274 does not override resources defined elsewhere */
|
|
275 CONST char *data_dir;
|
|
276 char path[MAXPATHLEN];
|
|
277 XrmDatabase db = XtDatabase (dpy); /* ### XtScreenDatabase(dpy) ? */
|
|
278 CONST char *locale = XrmLocaleOfDatabase (db);
|
|
279
|
|
280 if (STRINGP (Vdata_directory) && XSTRING_LENGTH (Vdata_directory) > 0)
|
|
281 GET_C_STRING_FILENAME_DATA_ALLOCA (Vdata_directory, data_dir);
|
|
282 sprintf (path, "%sapp-defaults/%s/%s", data_dir, locale, app_class);
|
|
283 if (!access (path, R_OK))
|
|
284 XrmCombineFileDatabase (path, &db, False);
|
|
285 }
|
149
|
286 #endif /* MULE */
|
6
|
287
|
0
|
288 if (NILP (DEVICE_NAME (d)))
|
|
289 DEVICE_NAME (d) = display;
|
|
290
|
|
291 /* We're going to modify the string in-place, so be a nice XEmacs */
|
|
292 DEVICE_NAME (d) = Fcopy_sequence (DEVICE_NAME (d));
|
|
293 /* colons and periods can't appear in individual elements of resource
|
|
294 strings */
|
14
|
295 validify_resource_string ((char *) XSTRING_DATA (DEVICE_NAME (d)));
|
0
|
296 DEVICE_XT_APP_SHELL (d) = XtAppCreateShell (NULL, app_class,
|
|
297 applicationShellWidgetClass,
|
|
298 dpy, NULL, 0);
|
|
299
|
70
|
300 #ifdef HAVE_XIM
|
|
301 XIM_init_device(d);
|
|
302 #endif /* HAVE_XIM */
|
0
|
303
|
|
304 Vx_initial_argv_list = make_arg_list (argc, argv);
|
|
305 free_argc_argv (argv);
|
|
306
|
|
307 DEVICE_X_WM_COMMAND_FRAME (d) = Qnil;
|
|
308
|
|
309 sanity_check_geometry_resource (dpy);
|
|
310
|
|
311 /* In event-Xt.c */
|
|
312 x_init_modifier_mapping (d);
|
|
313
|
|
314 DEVICE_INFD (d) = DEVICE_OUTFD (d) = ConnectionNumber (dpy);
|
|
315 init_baud_rate (d);
|
|
316 init_one_device (d);
|
|
317
|
|
318 DEVICE_X_GC_CACHE (d) =
|
|
319 make_gc_cache (dpy, RootWindow (dpy, DefaultScreen (dpy)));
|
|
320 DEVICE_X_GRAY_PIXMAP (d) = None;
|
|
321 Xatoms_of_device_x (d);
|
|
322 Xatoms_of_xselect (d);
|
|
323 Xatoms_of_objects_x (d);
|
|
324 x_init_device_class (d);
|
|
325
|
2
|
326 /* Run the elisp side of the X device initialization. */
|
0
|
327 call0 (Qinit_pre_x_win);
|
|
328 }
|
|
329
|
|
330 static void
|
|
331 x_finish_init_device (struct device *d, Lisp_Object props)
|
|
332 {
|
|
333 call0 (Qinit_post_x_win);
|
|
334 }
|
|
335
|
|
336 static void
|
|
337 x_mark_device (struct device *d, void (*markobj) (Lisp_Object))
|
|
338 {
|
|
339 ((markobj) (DEVICE_X_DATA (d)->WM_COMMAND_frame));
|
|
340 }
|
|
341
|
|
342
|
|
343 /************************************************************************/
|
|
344 /* closing an X connection */
|
|
345 /************************************************************************/
|
|
346
|
|
347 static void
|
|
348 free_x_device_struct (struct device *d)
|
|
349 {
|
|
350 xfree (d->device_data);
|
|
351 }
|
|
352
|
|
353 static void
|
|
354 x_delete_device (struct device *d)
|
|
355 {
|
|
356 Lisp_Object device;
|
|
357 Display *display;
|
|
358 #ifdef FREE_CHECKING
|
|
359 extern void (*__free_hook)();
|
|
360 int checking_free;
|
|
361 #endif
|
|
362
|
|
363 XSETDEVICE (device, d);
|
|
364 display = DEVICE_X_DISPLAY (d);
|
|
365
|
|
366 if (display)
|
|
367 {
|
|
368 #ifdef FREE_CHECKING
|
|
369 checking_free = (__free_hook != 0);
|
|
370
|
|
371 /* Disable strict free checking, to avoid bug in X library */
|
|
372 if (checking_free)
|
|
373 disable_strict_free_check ();
|
|
374 #endif
|
|
375
|
|
376 free_gc_cache (DEVICE_X_GC_CACHE (d));
|
|
377 if (DEVICE_X_DATA (d)->x_modifier_keymap)
|
|
378 XFreeModifiermap (DEVICE_X_DATA (d)->x_modifier_keymap);
|
|
379 if (DEVICE_X_DATA (d)->x_keysym_map)
|
|
380 XFree ((char *) DEVICE_X_DATA (d)->x_keysym_map);
|
|
381
|
|
382 XtCloseDisplay (display);
|
|
383 DEVICE_X_DISPLAY (d) = 0;
|
|
384 #ifdef FREE_CHECKING
|
|
385 if (checking_free)
|
|
386 enable_strict_free_check ();
|
|
387 #endif
|
|
388 }
|
|
389
|
|
390 if (EQ (device, Vdefault_x_device))
|
|
391 {
|
|
392 Lisp_Object devcons, concons;
|
|
393 /* #### handle deleting last X device */
|
|
394 Vdefault_x_device = Qnil;
|
|
395 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
396 {
|
157
|
397 if (DEVICE_X_P (XDEVICE (XCAR (devcons))) &&
|
|
398 !EQ (device, XCAR (devcons)))
|
0
|
399 {
|
|
400 Vdefault_x_device = XCAR (devcons);
|
|
401 goto double_break;
|
|
402 }
|
|
403 }
|
|
404 }
|
|
405 double_break:
|
|
406 free_x_device_struct (d);
|
|
407 }
|
|
408
|
|
409
|
|
410 /************************************************************************/
|
|
411 /* handle X errors */
|
|
412 /************************************************************************/
|
|
413
|
|
414 static CONST char *events[] =
|
|
415 {
|
|
416 "0: ERROR!",
|
|
417 "1: REPLY",
|
|
418 "KeyPress",
|
|
419 "KeyRelease",
|
|
420 "ButtonPress",
|
|
421 "ButtonRelease",
|
|
422 "MotionNotify",
|
|
423 "EnterNotify",
|
|
424 "LeaveNotify",
|
|
425 "FocusIn",
|
|
426 "FocusOut",
|
|
427 "KeymapNotify",
|
|
428 "Expose",
|
|
429 "GraphicsExpose",
|
|
430 "NoExpose",
|
|
431 "VisibilityNotify",
|
|
432 "CreateNotify",
|
|
433 "DestroyNotify",
|
|
434 "UnmapNotify",
|
|
435 "MapNotify",
|
|
436 "MapRequest",
|
|
437 "ReparentNotify",
|
|
438 "ConfigureNotify",
|
|
439 "ConfigureRequest",
|
|
440 "GravityNotify",
|
|
441 "ResizeRequest",
|
|
442 "CirculateNotify",
|
|
443 "CirculateRequest",
|
|
444 "PropertyNotify",
|
|
445 "SelectionClear",
|
|
446 "SelectionRequest",
|
|
447 "SelectionNotify",
|
|
448 "ColormapNotify",
|
|
449 "ClientMessage",
|
|
450 "MappingNotify",
|
|
451 "LASTEvent"
|
|
452 };
|
|
453
|
|
454 CONST char *
|
|
455 x_event_name (int event_type)
|
|
456 {
|
|
457 if (event_type < 0) return 0;
|
|
458 if (event_type >= (sizeof (events) / sizeof (char *))) return 0;
|
|
459 return events [event_type];
|
|
460 }
|
|
461
|
|
462 /* Handling errors.
|
|
463
|
|
464 If an X error occurs which we are not expecting, we have no alternative
|
|
465 but to print it to stderr. It would be nice to stuff it into a pop-up
|
|
466 buffer, or to print it in the minibuffer, but that's not possible, because
|
|
467 one is not allowed to do any I/O on the display connection from an error
|
|
468 handler. The guts of Xlib expect these functions to either return or exit.
|
|
469
|
|
470 However, there are occasions when we might expect an error to reasonably
|
|
471 occur. The interface to this is as follows:
|
|
472
|
|
473 Before calling some X routine which may error, call
|
|
474 expect_x_error (dpy);
|
|
475
|
|
476 Just after calling the X routine, call either:
|
|
477
|
|
478 x_error_occurred_p (dpy);
|
|
479
|
|
480 to ask whether an error happened (and was ignored), or:
|
|
481
|
|
482 signal_if_x_error (dpy, resumable_p);
|
|
483
|
|
484 which will call Fsignal() with args appropriate to the X error, if there
|
|
485 was one. (Resumable_p is whether the debugger should be allowed to
|
|
486 continue from the call to signal.)
|
|
487
|
|
488 You must call one of these two routines immediately after calling the X
|
|
489 routine; think of them as bookends like BLOCK_INPUT and UNBLOCK_INPUT.
|
|
490 */
|
|
491
|
|
492 static int error_expected;
|
|
493 static int error_occurred;
|
|
494 static XErrorEvent last_error;
|
|
495
|
|
496 /* OVERKILL! */
|
|
497
|
|
498 #ifdef EXTERNAL_WIDGET
|
|
499 static Lisp_Object
|
|
500 x_error_handler_do_enqueue (Lisp_Object frame)
|
|
501 {
|
|
502 enqueue_magic_eval_event (io_error_delete_frame, frame);
|
|
503 return Qt;
|
|
504 }
|
|
505
|
|
506 static Lisp_Object
|
|
507 x_error_handler_error (Lisp_Object data, Lisp_Object dummy)
|
|
508 {
|
|
509 return Qnil;
|
|
510 }
|
|
511 #endif /* EXTERNAL_WIDGET */
|
|
512
|
|
513 int
|
|
514 x_error_handler (Display *disp, XErrorEvent *event)
|
|
515 {
|
|
516 if (error_expected)
|
|
517 {
|
|
518 error_expected = 0;
|
|
519 error_occurred = 1;
|
|
520 last_error = *event;
|
|
521 }
|
|
522 else
|
|
523 {
|
|
524 #ifdef EXTERNAL_WIDGET
|
|
525 struct frame *f;
|
|
526 struct device *d = get_device_from_display (disp);
|
|
527
|
|
528 if ((event->error_code == BadWindow ||
|
|
529 event->error_code == BadDrawable)
|
|
530 && ((f = x_any_window_to_frame (d, event->resourceid)) != 0))
|
|
531 {
|
|
532 Lisp_Object frame;
|
|
533
|
|
534 /* one of the windows comprising one of our frames has died.
|
|
535 This occurs particularly with ExternalShell frames when the
|
|
536 client that owns the ExternalShell's window dies.
|
|
537
|
|
538 We cannot do any I/O on the display connection so we need
|
|
539 to enqueue an eval event so that the deletion happens
|
|
540 later.
|
|
541
|
|
542 Furthermore, we need to trap any errors (out-of-memory) that
|
|
543 may occur when Fenqueue_eval_event is called.
|
|
544 */
|
|
545
|
|
546 if (f->being_deleted)
|
|
547 return 0;
|
|
548 XSETFRAME (frame, f);
|
|
549 if (!NILP (condition_case_1 (Qerror, x_error_handler_do_enqueue,
|
|
550 frame, x_error_handler_error, Qnil)))
|
|
551 {
|
|
552 f->being_deleted = 1;
|
|
553 f->visible = 0;
|
|
554 }
|
|
555 return 0;
|
|
556 }
|
|
557 #endif /* EXTERNAL_WIDGET */
|
|
558
|
|
559 stderr_out ("\n%s: ",
|
|
560 (STRINGP (Vinvocation_name)
|
14
|
561 ? (char *) XSTRING_DATA (Vinvocation_name)
|
0
|
562 : "xemacs"));
|
|
563 XmuPrintDefaultErrorMessage (disp, event, stderr);
|
|
564 }
|
|
565 return 0;
|
|
566 }
|
|
567
|
|
568 void
|
|
569 expect_x_error (Display *dpy)
|
|
570 {
|
|
571 assert (!error_expected);
|
|
572 XSync (dpy, 0); /* handle pending errors before setting flag */
|
|
573 error_expected = 1;
|
|
574 error_occurred = 0;
|
|
575 }
|
|
576
|
|
577 int
|
|
578 x_error_occurred_p (Display *dpy)
|
|
579 {
|
|
580 int val;
|
|
581 XSync (dpy, 0); /* handle pending errors before setting flag */
|
|
582 val = error_occurred;
|
|
583 error_expected = 0;
|
|
584 error_occurred = 0;
|
|
585 return val;
|
|
586 }
|
|
587
|
|
588 int
|
|
589 signal_if_x_error (Display *dpy, int resumable_p)
|
|
590 {
|
|
591 char buf[1024];
|
|
592 Lisp_Object data;
|
|
593 if (! x_error_occurred_p (dpy))
|
|
594 return 0;
|
|
595 data = Qnil;
|
|
596 sprintf (buf, "0x%X", (unsigned int) last_error.resourceid);
|
|
597 data = Fcons (build_string (buf), data);
|
|
598 {
|
|
599 char num [32];
|
|
600 sprintf (num, "%d", last_error.request_code);
|
|
601 XGetErrorDatabaseText (last_error.display, "XRequest", num, "",
|
|
602 buf, sizeof (buf));
|
|
603 if (! *buf)
|
|
604 sprintf (buf, "Request-%d", last_error.request_code);
|
|
605 data = Fcons (build_string (buf), data);
|
|
606 }
|
|
607 XGetErrorText (last_error.display, last_error.error_code, buf, sizeof (buf));
|
|
608 data = Fcons (build_string (buf), data);
|
|
609 again:
|
|
610 Fsignal (Qx_error, data);
|
|
611 if (! resumable_p) goto again;
|
|
612 return 1;
|
|
613 }
|
|
614
|
|
615 int
|
|
616 x_IO_error_handler (Display *disp)
|
|
617 {
|
|
618 /* This function can GC */
|
|
619 Lisp_Object dev;
|
114
|
620 struct device *d = get_device_from_display_1 (disp);
|
|
621
|
|
622 if (d)
|
|
623 XSETDEVICE (dev, d);
|
|
624 else
|
|
625 dev = Qnil;
|
0
|
626
|
|
627 if (NILP (find_nonminibuffer_frame_not_on_device (dev)))
|
|
628 {
|
|
629 /* We're going down. */
|
|
630 stderr_out
|
|
631 ("\n%s: Fatal I/O Error %d (%s) on display connection \"%s\"\n",
|
|
632 (STRINGP (Vinvocation_name) ?
|
14
|
633 (char *) XSTRING_DATA (Vinvocation_name) : "xemacs"),
|
0
|
634 errno, strerror (errno), DisplayString (disp));
|
|
635 stderr_out
|
|
636 (" after %lu requests (%lu known processed) with %d events remaining.\n",
|
|
637 NextRequest (disp) - 1, LastKnownRequestProcessed (disp),
|
|
638 QLength (disp));
|
|
639 /* assert (!_Xdebug); */
|
|
640 }
|
|
641 else
|
|
642 {
|
|
643 warn_when_safe
|
|
644 (Qx, Qcritical,
|
|
645 "I/O Error %d (%s) on display connection \"%s\"\n"
|
|
646 " after %lu requests (%lu known processed) with "
|
|
647 "%d events remaining.\n",
|
|
648 errno, strerror (errno), DisplayString (disp),
|
|
649 NextRequest (disp) - 1, LastKnownRequestProcessed (disp),
|
|
650 QLength (disp));
|
|
651 }
|
|
652
|
114
|
653 if (d)
|
|
654 enqueue_magic_eval_event (io_error_delete_device, dev);
|
0
|
655
|
167
|
656 /* CvE, July 16, 1996, XEmacs 19.14 */
|
|
657 /* Test for broken pipe error, which indicates X-server has gone down */
|
|
658 if (errno == EPIPE && x_seppuku_on_epipe)
|
|
659 {
|
|
660 /* Most probably X-server has gone down: Avoid infinite loop by just */
|
|
661 /* exiting */
|
|
662 /* slb: This sounds really, really dangerous to do by default, so */
|
|
663 /* I'm adding a guard to avoid doing this as default behavior */
|
|
664 stderr_out( "\n\nXEmacs exiting on broken pipe (errno %d, %s)\n",
|
|
665 errno, strerror(errno));
|
|
666 exit(errno);
|
|
667 }
|
|
668
|
0
|
669 return 0;
|
|
670 }
|
|
671
|
20
|
672 DEFUN ("x-debug-mode", Fx_debug_mode, 1, 2, 0, /*
|
0
|
673 With a true arg, make the connection to the X server synchronous.
|
|
674 With false, make it asynchronous. Synchronous connections are much slower,
|
|
675 but are useful for debugging. (If you get X errors, make the connection
|
|
676 synchronous, and use a debugger to set a breakpoint on `x_error_handler'.
|
|
677 Your backtrace of the C stack will now be useful. In asynchronous mode,
|
|
678 the stack above `x_error_handler' isn't helpful because of buffering.)
|
|
679 If DEVICE is not specified, the selected device is assumed.
|
|
680
|
|
681 Calling this function is the same as calling the C function `XSynchronize',
|
|
682 or starting the program with the `-sync' command line argument.
|
20
|
683 */
|
|
684 (arg, device))
|
0
|
685 {
|
|
686 struct device *d = decode_x_device (device);
|
|
687
|
|
688 XSynchronize (DEVICE_X_DISPLAY (d), !NILP (arg));
|
|
689
|
|
690 if (!NILP (arg))
|
|
691 message ("X connection is synchronous");
|
|
692 else
|
|
693 message ("X connection is asynchronous");
|
|
694
|
|
695 return arg;
|
|
696 }
|
|
697
|
|
698
|
|
699 /************************************************************************/
|
|
700 /* X resources */
|
|
701 /************************************************************************/
|
|
702
|
|
703 #if 0 /* bah humbug. The whole "widget == resource" stuff is such
|
|
704 a crock of shit that I'm just going to ignore it all. */
|
|
705
|
|
706 /* If widget is NULL, we are retrieving device or global face data. */
|
|
707
|
|
708 static void
|
|
709 construct_name_list (Display *display, Widget widget, char *fake_name,
|
|
710 char *fake_class, char *name, char *class)
|
|
711 {
|
|
712 char *stack [100][2];
|
|
713 Widget this;
|
|
714 int count = 0;
|
|
715 char *name_tail, *class_tail;
|
|
716
|
|
717 if (widget)
|
|
718 {
|
|
719 for (this = widget; this; this = XtParent (this))
|
|
720 {
|
|
721 stack [count][0] = this->core.name;
|
|
722 stack [count][1] = XtClass (this)->core_class.class_name;
|
|
723 count++;
|
|
724 }
|
|
725 count--;
|
|
726 }
|
|
727 else if (fake_name && fake_class)
|
|
728 {
|
|
729 stack [count][0] = fake_name;
|
|
730 stack [count][1] = fake_class;
|
|
731 count++;
|
|
732 }
|
|
733
|
|
734 /* The root widget is an application shell; resource lookups use the
|
|
735 specified application name and application class in preference to
|
|
736 the name/class of that widget (which is argv[0] / "ApplicationShell").
|
|
737 Generally the app name and class will be argv[0] / "Emacs" but
|
|
738 the former can be set via the -name command-line option, and the
|
|
739 latter can be set by changing `x-emacs-application-class' in
|
|
740 lisp/term/x-win.el.
|
|
741 */
|
|
742 XtGetApplicationNameAndClass (display,
|
|
743 &stack [count][0],
|
|
744 &stack [count][1]);
|
|
745
|
|
746 name [0] = 0;
|
|
747 class [0] = 0;
|
|
748
|
|
749 name_tail = name;
|
|
750 class_tail = class;
|
|
751 for (; count >= 0; count--)
|
|
752 {
|
|
753 strcat (name_tail, stack [count][0]);
|
|
754 for (; *name_tail; name_tail++)
|
|
755 if (*name_tail == '.') *name_tail = '_';
|
|
756 strcat (name_tail, ".");
|
|
757 name_tail++;
|
|
758
|
|
759 strcat (class_tail, stack [count][1]);
|
|
760 for (; *class_tail; class_tail++)
|
|
761 if (*class_tail == '.') *class_tail = '_';
|
|
762 strcat (class_tail, ".");
|
|
763 class_tail++;
|
|
764 }
|
|
765 }
|
|
766
|
|
767 #endif
|
|
768
|
|
769 /* Only the characters [-_A-Za-z0-9] are allowed in the individual
|
|
770 sections of a resource. Convert invalid characters to -. */
|
|
771
|
|
772 static void
|
|
773 validify_resource_string (char *str)
|
|
774 {
|
|
775 while (*str)
|
|
776 {
|
|
777 if (!strchr ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
778 "abcdefghijklmnopqrstuvwxyz"
|
|
779 "0123456789-_", *str))
|
|
780 *str = '-';
|
|
781 str++;
|
|
782 }
|
|
783 }
|
|
784
|
|
785 /* Given a locale and device specification from x-get-resource or
|
|
786 x-get-resource-prefix, return the resource prefix and display to
|
|
787 fetch the resource on. */
|
|
788
|
|
789 static void
|
|
790 x_get_resource_prefix (Lisp_Object locale, Lisp_Object device,
|
|
791 Display **display_out, char *name_out,
|
|
792 char *class_out)
|
|
793 {
|
|
794 char *appname, *appclass;
|
|
795
|
|
796 if (NILP (locale))
|
|
797 locale = Qglobal;
|
|
798 if (NILP (Fvalid_specifier_locale_p (locale)))
|
|
799 signal_simple_error ("Invalid locale", locale);
|
|
800 if (WINDOWP (locale))
|
|
801 /* #### I can't come up with any coherent way of naming windows.
|
|
802 By relative position? That seems tricky because windows
|
|
803 can change position, be split, etc. By order of creation?
|
|
804 That seems less than useful. */
|
|
805 signal_simple_error ("Windows currently can't be resourced", locale);
|
|
806
|
|
807 if (!NILP (device) && !DEVICEP (device))
|
|
808 CHECK_DEVICE (device);
|
|
809 if (DEVICEP (device) && !DEVICE_X_P (XDEVICE (device)))
|
|
810 device = Qnil;
|
|
811 if (NILP (device))
|
|
812 {
|
|
813 device = DFW_DEVICE (locale);
|
|
814 if (DEVICEP (device) && !DEVICE_X_P (XDEVICE (device)))
|
|
815 device = Qnil;
|
|
816 if (NILP (device))
|
|
817 device = Vdefault_x_device;
|
|
818 if (NILP (device))
|
|
819 {
|
|
820 *display_out = 0;
|
|
821 return;
|
|
822 }
|
|
823 }
|
|
824
|
|
825 *display_out = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
826
|
|
827 XtGetApplicationNameAndClass (*display_out, &appname, &appclass);
|
|
828 strcpy (name_out, appname);
|
|
829 strcpy (class_out, appclass);
|
|
830 validify_resource_string (name_out);
|
|
831 validify_resource_string (class_out);
|
|
832
|
|
833 if (EQ (locale, Qglobal))
|
|
834 return;
|
|
835 if (BUFFERP (locale))
|
|
836 {
|
|
837 strcat (name_out, ".buffer.");
|
|
838 /* we know buffer is live; otherwise we got an error above. */
|
14
|
839 strcat (name_out, (CONST char *) XSTRING_DATA (Fbuffer_name (locale)));
|
0
|
840 strcat (class_out, ".EmacsLocaleType.EmacsBuffer");
|
|
841 }
|
|
842 else if (FRAMEP (locale))
|
|
843 {
|
|
844 strcat (name_out, ".frame.");
|
|
845 /* we know frame is live; otherwise we got an error above. */
|
14
|
846 strcat (name_out, (CONST char *) XSTRING_DATA (Fframe_name (locale)));
|
0
|
847 strcat (class_out, ".EmacsLocaleType.EmacsFrame");
|
|
848 }
|
|
849 else
|
|
850 {
|
|
851 assert (DEVICEP (locale));
|
|
852 strcat (name_out, ".device.");
|
|
853 /* we know device is live; otherwise we got an error above. */
|
14
|
854 strcat (name_out, (CONST char *) XSTRING_DATA (Fdevice_name (locale)));
|
0
|
855 strcat (class_out, ".EmacsLocaleType.EmacsDevice");
|
|
856 }
|
|
857 return;
|
|
858 }
|
|
859
|
20
|
860 DEFUN ("x-get-resource", Fx_get_resource, 3, 6, 0, /*
|
0
|
861 Retrieve an X resource from the resource manager.
|
|
862
|
|
863 The first arg is the name of the resource to retrieve, such as \"font\".
|
|
864 The second arg is the class of the resource to retrieve, like \"Font\".
|
|
865 The third arg should be one of the symbols 'string, 'integer, 'natnum, or
|
|
866 'boolean, specifying the type of object that the database is searched for.
|
|
867 The fourth arg is the locale to search for the resources on, and can
|
|
868 currently be a a buffer, a frame, a device, or 'global. If omitted, it
|
|
869 defaults to 'global.
|
|
870 The fifth arg is the device to search for the resources on. (The resource
|
|
871 database for a particular device is constructed by combining non-device-
|
|
872 specific resources such any command-line resources specified and any
|
|
873 app-defaults files found [or the fallback resources supplied by XEmacs,
|
|
874 if no app-defaults file is found] with device-specific resources such as
|
|
875 those supplied using xrdb.) If omitted, it defaults to the device of
|
|
876 LOCALE, if a device can be derived (i.e. if LOCALE is a frame or device),
|
|
877 and otherwise defaults to the value of `default-x-device'.
|
|
878 The sixth arg NOERROR, if non-nil, means do not signal an error if a
|
|
879 bogus resource specification was retrieved (e.g. if a non-integer was
|
|
880 given when an integer was requested). In this case, a warning is issued
|
|
881 instead.
|
|
882
|
|
883 The resource names passed to this function are looked up relative to the
|
|
884 locale.
|
|
885
|
|
886 If you want to search for a subresource, you just need to specify the
|
|
887 resource levels in NAME and CLASS. For example, NAME could be
|
|
888 \"modeline.attributeFont\", and CLASS \"Face.AttributeFont\".
|
|
889
|
|
890 Specifically,
|
|
891
|
|
892 1) If LOCALE is a buffer, a call
|
|
893
|
|
894 (x-get-resource \"foreground\" \"Foreground\" 'string SOME-BUFFER)
|
|
895
|
|
896 is an interface to a C call something like
|
|
897
|
|
898 XrmGetResource (db, \"xemacs.buffer.BUFFER-NAME.foreground\",
|
|
899 \"Emacs.EmacsLocaleType.EmacsBuffer.Foreground\",
|
|
900 \"String\");
|
|
901
|
|
902 2) If LOCALE is a frame, a call
|
|
903
|
|
904 (x-get-resource \"foreground\" \"Foreground\" 'string SOME-FRAME)
|
|
905
|
|
906 is an interface to a C call something like
|
|
907
|
|
908 XrmGetResource (db, \"xemacs.frame.FRAME-NAME.foreground\",
|
|
909 \"Emacs.EmacsLocaleType.EmacsFrame.Foreground\",
|
|
910 \"String\");
|
|
911
|
|
912 3) If LOCALE is a device, a call
|
|
913
|
|
914 (x-get-resource \"foreground\" \"Foreground\" 'string SOME-DEVICE)
|
|
915
|
|
916 is an interface to a C call something like
|
|
917
|
|
918 XrmGetResource (db, \"xemacs.device.DEVICE-NAME.foreground\",
|
|
919 \"Emacs.EmacsLocaleType.EmacsDevice.Foreground\",
|
|
920 \"String\");
|
|
921
|
|
922 4) If LOCALE is 'global, a call
|
|
923
|
|
924 (x-get-resource \"foreground\" \"Foreground\" 'string 'global)
|
|
925
|
|
926 is an interface to a C call something like
|
|
927
|
|
928 XrmGetResource (db, \"xemacs.foreground\",
|
|
929 \"Emacs.Foreground\",
|
|
930 \"String\");
|
|
931
|
|
932 Note that for 'global, no prefix is added other than that of the
|
|
933 application itself; thus, you can use this locale to retrieve
|
|
934 arbitrary application resources, if you really want to.
|
|
935
|
|
936 The returned value of this function is nil if the queried resource is not
|
|
937 found. If the third arg is `string', a string is returned, and if it is
|
|
938 `integer', an integer is returned. If the third arg is `boolean', then the
|
|
939 returned value is the list (t) for true, (nil) for false, and is nil to
|
|
940 mean ``unspecified.''
|
20
|
941 */
|
|
942 (name, class, type, locale, device, no_error))
|
0
|
943 {
|
|
944 /* #### fixed limit, could be overflowed */
|
|
945 char name_string[2048], class_string[2048];
|
|
946 char *raw_result;
|
|
947 XrmDatabase db;
|
|
948 Display *display;
|
|
949 Error_behavior errb = decode_error_behavior_flag (no_error);
|
|
950
|
|
951 CHECK_STRING (name);
|
|
952 CHECK_STRING (class);
|
|
953 CHECK_SYMBOL (type);
|
|
954
|
|
955 if (!EQ (type, Qstring) && !EQ (type, Qboolean) &&
|
|
956 !EQ (type, Qinteger) && !EQ (type, Qnatnum))
|
|
957 return maybe_signal_continuable_error
|
|
958 (Qwrong_type_argument,
|
|
959 list2 (build_translated_string
|
|
960 ("should be string, integer, natnum or boolean"),
|
|
961 type),
|
|
962 Qresource, errb);
|
|
963
|
|
964 x_get_resource_prefix (locale, device, &display, name_string,
|
|
965 class_string);
|
|
966 if (!display)
|
|
967 return Qnil;
|
|
968
|
|
969 db = XtDatabase (display);
|
|
970
|
|
971 strcat (name_string, ".");
|
14
|
972 strcat (name_string, (CONST char *) XSTRING_DATA (name));
|
0
|
973 strcat (class_string, ".");
|
14
|
974 strcat (class_string, (CONST char *) XSTRING_DATA (class));
|
0
|
975
|
|
976 {
|
|
977 XrmValue xrm_value;
|
|
978 XrmName namelist[100];
|
|
979 XrmClass classlist[100];
|
|
980 XrmName *namerest = namelist;
|
|
981 XrmClass *classrest = classlist;
|
|
982 XrmRepresentation xrm_type;
|
|
983 XrmRepresentation string_quark;
|
|
984 int result;
|
|
985 XrmStringToNameList (name_string, namelist);
|
|
986 XrmStringToClassList (class_string, classlist);
|
|
987 string_quark = XrmStringToQuark ("String");
|
|
988
|
|
989 /* ensure that they have the same length */
|
|
990 while (namerest[0] && classrest[0])
|
|
991 namerest++, classrest++;
|
|
992 if (namerest[0] || classrest[0])
|
|
993 signal_simple_error_2
|
|
994 ("class list and name list must be the same length", name, class);
|
|
995 result = XrmQGetResource (db, namelist, classlist, &xrm_type, &xrm_value);
|
|
996
|
|
997 if (result != True || xrm_type != string_quark)
|
|
998 return Qnil;
|
|
999 raw_result = (char *) xrm_value.addr;
|
|
1000 }
|
|
1001
|
|
1002 if (EQ (type, Qstring))
|
|
1003 return build_string (raw_result);
|
|
1004 else if (EQ (type, Qboolean))
|
|
1005 {
|
|
1006 if (!strcasecmp (raw_result, "off") ||
|
|
1007 !strcasecmp (raw_result, "false") ||
|
|
1008 !strcasecmp (raw_result,"no"))
|
|
1009 return Fcons (Qnil, Qnil);
|
|
1010 else if (!strcasecmp (raw_result, "on") ||
|
|
1011 !strcasecmp (raw_result, "true") ||
|
|
1012 !strcasecmp (raw_result, "yes"))
|
|
1013 return Fcons (Qt, Qnil);
|
|
1014 else
|
|
1015 return maybe_continuable_error (Qresource, errb,
|
|
1016 "can't convert %s: %s to a Boolean",
|
|
1017 name_string, raw_result);
|
|
1018 }
|
|
1019 else if (EQ (type, Qinteger) || EQ (type, Qnatnum))
|
|
1020 {
|
|
1021 int i;
|
|
1022 char c;
|
|
1023 if (1 != sscanf (raw_result, "%d%c", &i, &c))
|
|
1024 return maybe_continuable_error
|
|
1025 (Qresource, errb,
|
|
1026 "can't convert %s: %s to an integer",
|
|
1027 name_string, raw_result);
|
|
1028 else if (EQ (type, Qnatnum) && i < 0)
|
|
1029 return maybe_continuable_error
|
|
1030 (Qresource, errb,
|
|
1031 "invalid numerical value %d for resource %s",
|
|
1032 i, name_string);
|
|
1033 else
|
|
1034 return make_int (i);
|
|
1035 }
|
|
1036 else
|
|
1037 abort ();
|
|
1038
|
|
1039 /* Can't get here. */
|
|
1040 return Qnil; /* shut up compiler */
|
|
1041 }
|
|
1042
|
20
|
1043 DEFUN ("x-get-resource-prefix", Fx_get_resource_prefix, 1, 2, 0, /*
|
0
|
1044 Return the resource prefix for LOCALE on DEVICE.
|
|
1045 The resource prefix is the strings used to prefix resources if
|
|
1046 the LOCALE and DEVICE arguments were passed to `x-get-resource'.
|
|
1047 The returned value is a cons of a name prefix and a class prefix.
|
|
1048 For example, if LOCALE is a frame, the returned value might be
|
|
1049 \(\"xemacs.frame.FRAME-NAME\" . \"Emacs.EmacsLocaleType.EmacsFrame\").
|
|
1050 If no valid X device for resourcing can be obtained, this function
|
|
1051 returns nil. (In such a case, `x-get-resource' would always return nil.)
|
20
|
1052 */
|
|
1053 (locale, device))
|
0
|
1054 {
|
|
1055 /* #### fixed limit, could be overflowed */
|
|
1056 char name[1024], class[1024];
|
|
1057 Display *display;
|
|
1058
|
|
1059 x_get_resource_prefix (locale, device, &display, name, class);
|
|
1060 if (!display)
|
|
1061 return Qnil;
|
|
1062 return Fcons (build_string (name), build_string (class));
|
|
1063 }
|
|
1064
|
20
|
1065 DEFUN ("x-put-resource", Fx_put_resource, 1, 2, 0, /*
|
0
|
1066 Add a resource to the resource database for DEVICE.
|
|
1067 RESOURCE-LINE specifies the resource to add and should be a
|
|
1068 standard resource specification.
|
20
|
1069 */
|
|
1070 (resource_line, device))
|
0
|
1071 {
|
|
1072 struct device *d = decode_device (device);
|
|
1073 char *str, *colon_pos;
|
|
1074
|
|
1075 CHECK_STRING (resource_line);
|
14
|
1076 str = (char *) XSTRING_DATA (resource_line);
|
0
|
1077 if (!(colon_pos = strchr (str, ':')) || strchr (str, '\n'))
|
|
1078 invalid:
|
|
1079 signal_simple_error ("Invalid resource line", resource_line);
|
|
1080 if (strspn (str,
|
|
1081 /* Only the following chars are allowed before the colon */
|
|
1082 " \t.*?abcdefghijklmnopqrstuvwxyz"
|
|
1083 "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-") != colon_pos - str)
|
|
1084 goto invalid;
|
|
1085
|
|
1086 if (DEVICE_X_P (d))
|
|
1087 {
|
|
1088 XrmDatabase db = XtDatabase (DEVICE_X_DISPLAY (d));
|
|
1089 XrmPutLineResource (&db, str);
|
|
1090 }
|
|
1091
|
|
1092 return Qnil;
|
|
1093 }
|
|
1094
|
|
1095
|
|
1096 /************************************************************************/
|
|
1097 /* display information functions */
|
|
1098 /************************************************************************/
|
|
1099
|
20
|
1100 DEFUN ("default-x-device", Fdefault_x_device, 0, 0, 0, /*
|
0
|
1101 Return the default X device for resourcing.
|
|
1102 This is the first-created X device that still exists.
|
20
|
1103 */
|
|
1104 ())
|
0
|
1105 {
|
|
1106 return Vdefault_x_device;
|
|
1107 }
|
|
1108
|
20
|
1109 DEFUN ("x-display-visual-class", Fx_display_visual_class, 0, 1, 0, /*
|
0
|
1110 Return the visual class of the X display `device' is on.
|
|
1111 The returned value will be one of the symbols `static-gray', `gray-scale',
|
|
1112 `static-color', `pseudo-color', `true-color', or `direct-color'.
|
20
|
1113 */
|
|
1114 (device))
|
0
|
1115 {
|
|
1116 switch (DefaultVisualOfScreen
|
|
1117 (DefaultScreenOfDisplay (get_x_display (device)))->class)
|
|
1118 {
|
|
1119 case StaticGray: return (intern ("static-gray"));
|
|
1120 case GrayScale: return (intern ("gray-scale"));
|
|
1121 case StaticColor: return (intern ("static-color"));
|
|
1122 case PseudoColor: return (intern ("pseudo-color"));
|
|
1123 case TrueColor: return (intern ("true-color"));
|
|
1124 case DirectColor: return (intern ("direct-color"));
|
|
1125 default:
|
|
1126 error ("display has an unknown visual class");
|
|
1127 }
|
|
1128
|
|
1129 return Qnil; /* suppress compiler warning */
|
|
1130 }
|
|
1131
|
|
1132 static int
|
|
1133 x_device_pixel_width (struct device *d)
|
|
1134 {
|
|
1135 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1136
|
|
1137 return DisplayWidth (dpy, DefaultScreen (dpy));
|
|
1138 }
|
|
1139
|
|
1140 static int
|
|
1141 x_device_pixel_height (struct device *d)
|
|
1142 {
|
|
1143 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1144
|
|
1145 return DisplayHeight (dpy, DefaultScreen (dpy));
|
|
1146 }
|
|
1147
|
|
1148 static int
|
|
1149 x_device_mm_width (struct device *d)
|
|
1150 {
|
|
1151 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1152
|
|
1153 return DisplayWidthMM (dpy, DefaultScreen (dpy));
|
|
1154 }
|
|
1155
|
|
1156 static int
|
|
1157 x_device_mm_height (struct device *d)
|
|
1158 {
|
|
1159 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1160
|
|
1161 return DisplayHeightMM (dpy, DefaultScreen (dpy));
|
|
1162 }
|
|
1163
|
|
1164 static int
|
|
1165 x_device_bitplanes (struct device *d)
|
|
1166 {
|
|
1167 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1168
|
|
1169 return DisplayPlanes (dpy, DefaultScreen (dpy));
|
|
1170 }
|
|
1171
|
|
1172 static int
|
|
1173 x_device_color_cells (struct device *d)
|
|
1174 {
|
|
1175 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1176
|
|
1177 return DisplayCells (dpy, DefaultScreen (dpy));
|
|
1178 }
|
|
1179
|
20
|
1180 DEFUN ("x-server-vendor", Fx_server_vendor, 0, 1, 0, /*
|
0
|
1181 Return the vendor ID string of the X server `device' on.
|
20
|
1182 */
|
|
1183 (device))
|
0
|
1184 {
|
|
1185 Display *dpy = get_x_display (device);
|
|
1186 char *vendor = ServerVendor (dpy);
|
|
1187
|
|
1188 if (vendor)
|
|
1189 return (build_string (vendor));
|
|
1190 else
|
|
1191 return (build_string (""));
|
|
1192 }
|
|
1193
|
20
|
1194 DEFUN ("x-server-version", Fx_server_version, 0, 1, 0, /*
|
0
|
1195 Return the version numbers of the X server `device' is on.
|
|
1196 The returned value is a list of three integers: the major and minor
|
|
1197 version numbers of the X Protocol in use, and the vendor-specific release
|
|
1198 number. See also `x-server-vendor'.
|
20
|
1199 */
|
|
1200 (device))
|
0
|
1201 {
|
|
1202 Display *dpy = get_x_display (device);
|
|
1203
|
|
1204 return list3 (make_int (ProtocolVersion (dpy)),
|
|
1205 make_int (ProtocolRevision (dpy)),
|
|
1206 make_int (VendorRelease (dpy)));
|
|
1207 }
|
|
1208
|
20
|
1209 DEFUN ("x-valid-keysym-name-p", Fx_valid_keysym_name_p, 1, 1, 0, /*
|
0
|
1210 Return true if KEYSYM names a keysym that the X library knows about.
|
|
1211 Valid keysyms are listed in the files /usr/include/X11/keysymdef.h and in
|
|
1212 /usr/lib/X11/XKeysymDB, or whatever the equivalents are on your system.
|
20
|
1213 */
|
|
1214 (keysym))
|
0
|
1215 {
|
|
1216 CONST char *keysym_ext;
|
|
1217
|
|
1218 CHECK_STRING (keysym);
|
|
1219 GET_C_STRING_CTEXT_DATA_ALLOCA (keysym, keysym_ext);
|
|
1220 if (XStringToKeysym (keysym_ext))
|
|
1221 return Qt;
|
|
1222 return Qnil;
|
|
1223 }
|
|
1224
|
20
|
1225 DEFUN ("x-keysym-on-keyboard-p", Fx_keysym_on_keyboard_p, 1, 2, 0, /*
|
0
|
1226 Return true if KEYSYM names a key on the keyboard of DEVICE.
|
|
1227 More precisely, return true if pressing a physical key
|
|
1228 on the keyboard of DEVICE without any modifier keys generates KEYSYM.
|
|
1229 Valid keysyms are listed in the files /usr/include/X11/keysymdef.h and in
|
|
1230 /usr/lib/X11/XKeysymDB, or whatever the equivalents are on your system.
|
20
|
1231 */
|
|
1232 (keysym, device))
|
0
|
1233 {
|
|
1234 struct device *d = decode_device(device);
|
|
1235 CONST char *keysym_string;
|
|
1236 KeySym keysym_KeySym;
|
|
1237 KeySym *keysym_ptr, *keysym_last;
|
2
|
1238 int min_code, max_code, keysyms_per_code;
|
0
|
1239
|
|
1240 if (!DEVICE_X_P (d))
|
|
1241 signal_simple_error ("Not an X device", device);
|
|
1242 CHECK_STRING (keysym);
|
|
1243 GET_C_STRING_CTEXT_DATA_ALLOCA (keysym, keysym_string);
|
|
1244 keysym_KeySym = XStringToKeysym (keysym_string);
|
|
1245 if (!keysym_KeySym) /* Invalid keysym */
|
|
1246 return Qnil;
|
|
1247
|
|
1248 XDisplayKeycodes (DEVICE_X_DISPLAY (d), &min_code, &max_code);
|
|
1249 keysyms_per_code = DEVICE_X_DATA (d)->x_keysym_map_keysyms_per_code;
|
|
1250 keysym_ptr = DEVICE_X_DATA (d)->x_keysym_map;
|
|
1251 keysym_last = keysym_ptr + (max_code - min_code) * keysyms_per_code;
|
|
1252 for ( ; keysym_ptr <= keysym_last; keysym_ptr += keysyms_per_code)
|
|
1253 {
|
|
1254 if (keysym_KeySym == *keysym_ptr)
|
|
1255 return Qt;
|
|
1256 }
|
|
1257
|
|
1258 return Qnil;
|
|
1259 }
|
|
1260
|
|
1261
|
|
1262 /************************************************************************/
|
|
1263 /* grabs and ungrabs */
|
|
1264 /************************************************************************/
|
|
1265
|
20
|
1266 DEFUN ("x-grab-pointer", Fx_grab_pointer, 0, 3, 0, /*
|
0
|
1267 Grab the pointer and restrict it to its current window.
|
|
1268 If optional DEVICE argument is nil, the default device will be used.
|
|
1269 If optional CURSOR argument is non-nil, change the pointer shape to that
|
|
1270 until `x-ungrab-pointer' is called (it should be an object returned by the
|
|
1271 `make-cursor-glyph' function).
|
|
1272 If the second optional argument IGNORE-KEYBOARD is non-nil, ignore all
|
|
1273 keyboard events during the grab.
|
|
1274 Returns t if the grab is successful, nil otherwise.
|
20
|
1275 */
|
|
1276 (device, cursor, ignore_keyboard))
|
0
|
1277 {
|
|
1278 Window w;
|
|
1279 int pointer_mode, result;
|
|
1280 struct device *d = decode_x_device (device);
|
|
1281
|
|
1282 if (!NILP (cursor))
|
|
1283 {
|
|
1284 CHECK_POINTER_GLYPH (cursor);
|
|
1285 cursor = glyph_image_instance (cursor, device, ERROR_ME, 0);
|
|
1286 }
|
|
1287
|
|
1288 if (!NILP (ignore_keyboard))
|
|
1289 pointer_mode = GrabModeSync;
|
|
1290 else
|
|
1291 pointer_mode = GrabModeAsync;
|
|
1292
|
|
1293 w = XtWindow (FRAME_X_TEXT_WIDGET (device_selected_frame (d)));
|
|
1294
|
|
1295 /* #### Possibly this needs to gcpro the cursor somehow, but it doesn't
|
|
1296 seem to cause a problem if XFreeCursor is called on a cursor in use
|
|
1297 in a grab; I suppose the X server counts the grab as a reference
|
|
1298 and doesn't free it until it exits? */
|
|
1299 result = XGrabPointer (DEVICE_X_DISPLAY (d), w,
|
|
1300 False,
|
|
1301 ButtonMotionMask | ButtonPressMask
|
|
1302 | ButtonReleaseMask | PointerMotionHintMask,
|
|
1303 GrabModeAsync, /* Keep pointer events flowing */
|
|
1304 pointer_mode, /* Stall keyboard events */
|
|
1305 w, /* Stay in this window */
|
|
1306 (NILP (cursor) ? 0
|
|
1307 : XIMAGE_INSTANCE_X_CURSOR (cursor)),
|
|
1308 CurrentTime);
|
|
1309 return ((result == GrabSuccess) ? Qt : Qnil);
|
|
1310 }
|
|
1311
|
20
|
1312 DEFUN ("x-ungrab-pointer", Fx_ungrab_pointer, 0, 1, 0, /*
|
0
|
1313 Release a pointer grab made with `x-grab-pointer'.
|
|
1314 If optional first arg DEVICE is nil the default device is used.
|
|
1315 If it is t the pointer will be released on all X devices.
|
20
|
1316 */
|
|
1317 (device))
|
0
|
1318 {
|
|
1319 if (!EQ (device, Qt))
|
|
1320 {
|
|
1321 Display *dpy = get_x_display (device);
|
|
1322 XUngrabPointer (dpy, CurrentTime);
|
|
1323 }
|
|
1324 else
|
|
1325 {
|
|
1326 Lisp_Object devcons, concons;
|
|
1327
|
|
1328 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
1329 {
|
|
1330 struct device *d = XDEVICE (XCAR (devcons));
|
|
1331
|
|
1332 if (DEVICE_X_P (d))
|
|
1333 XUngrabPointer (DEVICE_X_DISPLAY (d), CurrentTime);
|
|
1334 }
|
|
1335 }
|
|
1336
|
|
1337 return Qnil;
|
|
1338 }
|
|
1339
|
20
|
1340 DEFUN ("x-grab-keyboard", Fx_grab_keyboard, 0, 1, 0, /*
|
0
|
1341 Grab the keyboard on the given device (defaulting to the selected one).
|
|
1342 So long as the keyboard is grabbed, all keyboard events will be delivered
|
|
1343 to emacs -- it is not possible for other X clients to eavesdrop on them.
|
|
1344 Ungrab the keyboard with `x-ungrab-keyboard' (use an unwind-protect).
|
|
1345 Returns t if the grab was successful; nil otherwise.
|
20
|
1346 */
|
|
1347 (device))
|
0
|
1348 {
|
|
1349 struct device *d = decode_x_device (device);
|
|
1350 Window w = XtWindow (FRAME_X_TEXT_WIDGET (device_selected_frame (d)));
|
|
1351 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1352 Status status;
|
|
1353 XSync (dpy, False);
|
|
1354 status = XGrabKeyboard (dpy, w, True,
|
|
1355 /* I don't really understand sync-vs-async
|
|
1356 grabs, but this is what xterm does. */
|
|
1357 GrabModeAsync, GrabModeAsync,
|
|
1358 /* Use the timestamp of the last user action
|
|
1359 read by emacs proper; xterm uses CurrentTime
|
|
1360 but there's a comment that says "wrong"...
|
|
1361 (Despite the name this is the time of the
|
|
1362 last key or mouse event.) */
|
|
1363 DEVICE_X_MOUSE_TIMESTAMP (d));
|
|
1364 if (status == GrabSuccess)
|
|
1365 {
|
|
1366 /* The XUngrabKeyboard should generate a FocusIn back to this
|
|
1367 window but it doesn't unless we explicitly set focus to the
|
|
1368 window first (which should already have it. The net result
|
|
1369 is that without this call when x-ungrab-keyboard is called
|
|
1370 the selected frame ends up not having focus. */
|
|
1371 XSetInputFocus (dpy, w, RevertToParent, DEVICE_X_MOUSE_TIMESTAMP (d));
|
|
1372 return Qt;
|
|
1373 }
|
|
1374 else
|
|
1375 return Qnil;
|
|
1376 }
|
|
1377
|
20
|
1378 DEFUN ("x-ungrab-keyboard", Fx_ungrab_keyboard, 0, 1, 0, /*
|
0
|
1379 Release a keyboard grab made with `x-grab-keyboard'.
|
20
|
1380 */
|
|
1381 (device))
|
0
|
1382 {
|
|
1383 Display *dpy = get_x_display (device);
|
|
1384 XUngrabKeyboard (dpy, CurrentTime);
|
|
1385 return Qnil;
|
|
1386 }
|
|
1387
|
|
1388
|
|
1389 /************************************************************************/
|
|
1390 /* initialization */
|
|
1391 /************************************************************************/
|
|
1392
|
|
1393 void
|
|
1394 syms_of_device_x (void)
|
|
1395 {
|
20
|
1396 DEFSUBR (Fx_debug_mode);
|
|
1397 DEFSUBR (Fx_get_resource);
|
|
1398 DEFSUBR (Fx_get_resource_prefix);
|
|
1399 DEFSUBR (Fx_put_resource);
|
0
|
1400
|
20
|
1401 DEFSUBR (Fdefault_x_device);
|
|
1402 DEFSUBR (Fx_display_visual_class);
|
|
1403 DEFSUBR (Fx_server_vendor);
|
|
1404 DEFSUBR (Fx_server_version);
|
|
1405 DEFSUBR (Fx_valid_keysym_name_p);
|
|
1406 DEFSUBR (Fx_keysym_on_keyboard_p);
|
0
|
1407
|
20
|
1408 DEFSUBR (Fx_grab_pointer);
|
|
1409 DEFSUBR (Fx_ungrab_pointer);
|
|
1410 DEFSUBR (Fx_grab_keyboard);
|
|
1411 DEFSUBR (Fx_ungrab_keyboard);
|
0
|
1412
|
|
1413 defsymbol (&Qx_error, "x-error");
|
|
1414 defsymbol (&Qinit_pre_x_win, "init-pre-x-win");
|
|
1415 defsymbol (&Qinit_post_x_win, "init-post-x-win");
|
|
1416 }
|
|
1417
|
|
1418 void
|
|
1419 console_type_create_device_x (void)
|
|
1420 {
|
|
1421 CONSOLE_HAS_METHOD (x, init_device);
|
|
1422 CONSOLE_HAS_METHOD (x, finish_init_device);
|
|
1423 CONSOLE_HAS_METHOD (x, mark_device);
|
|
1424 CONSOLE_HAS_METHOD (x, delete_device);
|
|
1425 CONSOLE_HAS_METHOD (x, device_pixel_width);
|
|
1426 CONSOLE_HAS_METHOD (x, device_pixel_height);
|
|
1427 CONSOLE_HAS_METHOD (x, device_mm_width);
|
|
1428 CONSOLE_HAS_METHOD (x, device_mm_height);
|
|
1429 CONSOLE_HAS_METHOD (x, device_bitplanes);
|
|
1430 CONSOLE_HAS_METHOD (x, device_color_cells);
|
|
1431 }
|
|
1432
|
|
1433 void
|
|
1434 vars_of_device_x (void)
|
|
1435 {
|
|
1436 DEFVAR_LISP ("x-emacs-application-class", &Vx_emacs_application_class /*
|
|
1437 The X application class of the XEmacs process.
|
|
1438 This controls, among other things, the name of the `app-defaults' file
|
|
1439 that XEmacs will use. For changes to this variable to take effect, they
|
|
1440 must be made before the connection to the X server is initialized, that is,
|
|
1441 this variable may only be changed before emacs is dumped, or by setting it
|
|
1442 in the file lisp/term/x-win.el.
|
|
1443 */ );
|
|
1444 Vx_emacs_application_class = Fpurecopy (build_string ("Emacs"));
|
|
1445
|
|
1446 DEFVAR_LISP ("x-initial-argv-list", &Vx_initial_argv_list /*
|
|
1447 You don't want to know.
|
|
1448 This is used during startup to communicate the remaining arguments in
|
|
1449 `command-line-args-left' to the C code, which passes the args to
|
|
1450 the X initialization code, which removes some args, and then the
|
|
1451 args are placed back into `x-initial-arg-list' and thence into
|
|
1452 `command-line-args-left'. Perhaps `command-line-args-left' should
|
|
1453 just reside in C.
|
|
1454 */ );
|
|
1455 Vx_initial_argv_list = Qnil;
|
|
1456
|
167
|
1457 DEFVAR_BOOL ("x-seppuku-on-epipe", &x_seppuku_on_epipe /*
|
|
1458 When non-nil terminate XEmacs immediately on SIGPIPE from the X server.
|
|
1459 XEmacs doesn't terminate properly on some systems.
|
|
1460 When this variable is non-nil, XEmacs will commit immediate suicide
|
|
1461 when it gets a sigpipe from the X Server.
|
|
1462 */ );
|
|
1463 x_seppuku_on_epipe = 0;
|
|
1464
|
0
|
1465 Fprovide (Qx);
|
|
1466
|
|
1467 staticpro (&Vdefault_x_device);
|
|
1468 Vdefault_x_device = Qnil;
|
|
1469
|
|
1470 error_expected = 0;
|
|
1471 error_occurred = 0;
|
|
1472
|
|
1473 in_resource_setting = 0;
|
|
1474 in_specifier_change_function = 0;
|
|
1475 }
|