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