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