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