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 make_argc_argv (Vx_initial_argv_list, &argc, &argv);
|
|
228
|
|
229 if (STRINGP (Vx_emacs_application_class) &&
|
14
|
230 XSTRING_LENGTH (Vx_emacs_application_class) > 0)
|
0
|
231 GET_C_STRING_CTEXT_DATA_ALLOCA (Vx_emacs_application_class, app_class);
|
|
232 else
|
|
233 app_class = "Emacs";
|
|
234
|
|
235 GET_C_STRING_CTEXT_DATA_ALLOCA (display, disp_name);
|
|
236
|
|
237 slow_down_interrupts ();
|
|
238 /* The Xt code can't deal with signals here. Yuck. */
|
|
239 dpy = DEVICE_X_DISPLAY (d) =
|
|
240 XtOpenDisplay (Xt_app_con, disp_name, NULL, app_class, emacs_options,
|
|
241 XtNumber (emacs_options), &argc, argv);
|
|
242 speed_up_interrupts ();
|
|
243
|
|
244 if (dpy == 0)
|
|
245 {
|
|
246 suppress_early_backtrace = 1;
|
|
247 signal_simple_error ("X server not responding\n", display);
|
|
248 }
|
|
249
|
6
|
250 if (NILP (Vdefault_x_device))
|
|
251 Vdefault_x_device = device;
|
|
252
|
0
|
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 */
|
14
|
260 validify_resource_string ((char *) XSTRING_DATA (DEVICE_NAME (d)));
|
0
|
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)
|
14
|
522 ? (char *) XSTRING_DATA (Vinvocation_name)
|
0
|
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) ?
|
14
|
590 (char *) XSTRING_DATA (Vinvocation_name) : "xemacs"),
|
0
|
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
|
20
|
615 DEFUN ("x-debug-mode", Fx_debug_mode, 1, 2, 0, /*
|
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.
|
20
|
626 */
|
|
627 (arg, device))
|
0
|
628 {
|
|
629 struct device *d = decode_x_device (device);
|
|
630
|
|
631 XSynchronize (DEVICE_X_DISPLAY (d), !NILP (arg));
|
|
632
|
|
633 if (!NILP (arg))
|
|
634 message ("X connection is synchronous");
|
|
635 else
|
|
636 message ("X connection is asynchronous");
|
|
637
|
|
638 return arg;
|
|
639 }
|
|
640
|
|
641
|
|
642 /************************************************************************/
|
|
643 /* X resources */
|
|
644 /************************************************************************/
|
|
645
|
|
646 #if 0 /* bah humbug. The whole "widget == resource" stuff is such
|
|
647 a crock of shit that I'm just going to ignore it all. */
|
|
648
|
|
649 /* If widget is NULL, we are retrieving device or global face data. */
|
|
650
|
|
651 static void
|
|
652 construct_name_list (Display *display, Widget widget, char *fake_name,
|
|
653 char *fake_class, char *name, char *class)
|
|
654 {
|
|
655 char *stack [100][2];
|
|
656 Widget this;
|
|
657 int count = 0;
|
|
658 char *name_tail, *class_tail;
|
|
659
|
|
660 if (widget)
|
|
661 {
|
|
662 for (this = widget; this; this = XtParent (this))
|
|
663 {
|
|
664 stack [count][0] = this->core.name;
|
|
665 stack [count][1] = XtClass (this)->core_class.class_name;
|
|
666 count++;
|
|
667 }
|
|
668 count--;
|
|
669 }
|
|
670 else if (fake_name && fake_class)
|
|
671 {
|
|
672 stack [count][0] = fake_name;
|
|
673 stack [count][1] = fake_class;
|
|
674 count++;
|
|
675 }
|
|
676
|
|
677 /* The root widget is an application shell; resource lookups use the
|
|
678 specified application name and application class in preference to
|
|
679 the name/class of that widget (which is argv[0] / "ApplicationShell").
|
|
680 Generally the app name and class will be argv[0] / "Emacs" but
|
|
681 the former can be set via the -name command-line option, and the
|
|
682 latter can be set by changing `x-emacs-application-class' in
|
|
683 lisp/term/x-win.el.
|
|
684 */
|
|
685 XtGetApplicationNameAndClass (display,
|
|
686 &stack [count][0],
|
|
687 &stack [count][1]);
|
|
688
|
|
689 name [0] = 0;
|
|
690 class [0] = 0;
|
|
691
|
|
692 name_tail = name;
|
|
693 class_tail = class;
|
|
694 for (; count >= 0; count--)
|
|
695 {
|
|
696 strcat (name_tail, stack [count][0]);
|
|
697 for (; *name_tail; name_tail++)
|
|
698 if (*name_tail == '.') *name_tail = '_';
|
|
699 strcat (name_tail, ".");
|
|
700 name_tail++;
|
|
701
|
|
702 strcat (class_tail, stack [count][1]);
|
|
703 for (; *class_tail; class_tail++)
|
|
704 if (*class_tail == '.') *class_tail = '_';
|
|
705 strcat (class_tail, ".");
|
|
706 class_tail++;
|
|
707 }
|
|
708 }
|
|
709
|
|
710 #endif
|
|
711
|
|
712 /* Only the characters [-_A-Za-z0-9] are allowed in the individual
|
|
713 sections of a resource. Convert invalid characters to -. */
|
|
714
|
|
715 static void
|
|
716 validify_resource_string (char *str)
|
|
717 {
|
|
718 while (*str)
|
|
719 {
|
|
720 if (!strchr ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
721 "abcdefghijklmnopqrstuvwxyz"
|
|
722 "0123456789-_", *str))
|
|
723 *str = '-';
|
|
724 str++;
|
|
725 }
|
|
726 }
|
|
727
|
|
728 /* Given a locale and device specification from x-get-resource or
|
|
729 x-get-resource-prefix, return the resource prefix and display to
|
|
730 fetch the resource on. */
|
|
731
|
|
732 static void
|
|
733 x_get_resource_prefix (Lisp_Object locale, Lisp_Object device,
|
|
734 Display **display_out, char *name_out,
|
|
735 char *class_out)
|
|
736 {
|
|
737 char *appname, *appclass;
|
|
738
|
|
739 if (NILP (locale))
|
|
740 locale = Qglobal;
|
|
741 if (NILP (Fvalid_specifier_locale_p (locale)))
|
|
742 signal_simple_error ("Invalid locale", locale);
|
|
743 if (WINDOWP (locale))
|
|
744 /* #### I can't come up with any coherent way of naming windows.
|
|
745 By relative position? That seems tricky because windows
|
|
746 can change position, be split, etc. By order of creation?
|
|
747 That seems less than useful. */
|
|
748 signal_simple_error ("Windows currently can't be resourced", locale);
|
|
749
|
|
750 if (!NILP (device) && !DEVICEP (device))
|
|
751 CHECK_DEVICE (device);
|
|
752 if (DEVICEP (device) && !DEVICE_X_P (XDEVICE (device)))
|
|
753 device = Qnil;
|
|
754 if (NILP (device))
|
|
755 {
|
|
756 device = DFW_DEVICE (locale);
|
|
757 if (DEVICEP (device) && !DEVICE_X_P (XDEVICE (device)))
|
|
758 device = Qnil;
|
|
759 if (NILP (device))
|
|
760 device = Vdefault_x_device;
|
|
761 if (NILP (device))
|
|
762 {
|
|
763 *display_out = 0;
|
|
764 return;
|
|
765 }
|
|
766 }
|
|
767
|
|
768 *display_out = DEVICE_X_DISPLAY (XDEVICE (device));
|
|
769
|
|
770 XtGetApplicationNameAndClass (*display_out, &appname, &appclass);
|
|
771 strcpy (name_out, appname);
|
|
772 strcpy (class_out, appclass);
|
|
773 validify_resource_string (name_out);
|
|
774 validify_resource_string (class_out);
|
|
775
|
|
776 if (EQ (locale, Qglobal))
|
|
777 return;
|
|
778 if (BUFFERP (locale))
|
|
779 {
|
|
780 strcat (name_out, ".buffer.");
|
|
781 /* we know buffer is live; otherwise we got an error above. */
|
14
|
782 strcat (name_out, (CONST char *) XSTRING_DATA (Fbuffer_name (locale)));
|
0
|
783 strcat (class_out, ".EmacsLocaleType.EmacsBuffer");
|
|
784 }
|
|
785 else if (FRAMEP (locale))
|
|
786 {
|
|
787 strcat (name_out, ".frame.");
|
|
788 /* we know frame is live; otherwise we got an error above. */
|
14
|
789 strcat (name_out, (CONST char *) XSTRING_DATA (Fframe_name (locale)));
|
0
|
790 strcat (class_out, ".EmacsLocaleType.EmacsFrame");
|
|
791 }
|
|
792 else
|
|
793 {
|
|
794 assert (DEVICEP (locale));
|
|
795 strcat (name_out, ".device.");
|
|
796 /* we know device is live; otherwise we got an error above. */
|
14
|
797 strcat (name_out, (CONST char *) XSTRING_DATA (Fdevice_name (locale)));
|
0
|
798 strcat (class_out, ".EmacsLocaleType.EmacsDevice");
|
|
799 }
|
|
800 return;
|
|
801 }
|
|
802
|
20
|
803 DEFUN ("x-get-resource", Fx_get_resource, 3, 6, 0, /*
|
0
|
804 Retrieve an X resource from the resource manager.
|
|
805
|
|
806 The first arg is the name of the resource to retrieve, such as \"font\".
|
|
807 The second arg is the class of the resource to retrieve, like \"Font\".
|
|
808 The third arg should be one of the symbols 'string, 'integer, 'natnum, or
|
|
809 'boolean, specifying the type of object that the database is searched for.
|
|
810 The fourth arg is the locale to search for the resources on, and can
|
|
811 currently be a a buffer, a frame, a device, or 'global. If omitted, it
|
|
812 defaults to 'global.
|
|
813 The fifth arg is the device to search for the resources on. (The resource
|
|
814 database for a particular device is constructed by combining non-device-
|
|
815 specific resources such any command-line resources specified and any
|
|
816 app-defaults files found [or the fallback resources supplied by XEmacs,
|
|
817 if no app-defaults file is found] with device-specific resources such as
|
|
818 those supplied using xrdb.) If omitted, it defaults to the device of
|
|
819 LOCALE, if a device can be derived (i.e. if LOCALE is a frame or device),
|
|
820 and otherwise defaults to the value of `default-x-device'.
|
|
821 The sixth arg NOERROR, if non-nil, means do not signal an error if a
|
|
822 bogus resource specification was retrieved (e.g. if a non-integer was
|
|
823 given when an integer was requested). In this case, a warning is issued
|
|
824 instead.
|
|
825
|
|
826 The resource names passed to this function are looked up relative to the
|
|
827 locale.
|
|
828
|
|
829 If you want to search for a subresource, you just need to specify the
|
|
830 resource levels in NAME and CLASS. For example, NAME could be
|
|
831 \"modeline.attributeFont\", and CLASS \"Face.AttributeFont\".
|
|
832
|
|
833 Specifically,
|
|
834
|
|
835 1) If LOCALE is a buffer, a call
|
|
836
|
|
837 (x-get-resource \"foreground\" \"Foreground\" 'string SOME-BUFFER)
|
|
838
|
|
839 is an interface to a C call something like
|
|
840
|
|
841 XrmGetResource (db, \"xemacs.buffer.BUFFER-NAME.foreground\",
|
|
842 \"Emacs.EmacsLocaleType.EmacsBuffer.Foreground\",
|
|
843 \"String\");
|
|
844
|
|
845 2) If LOCALE is a frame, a call
|
|
846
|
|
847 (x-get-resource \"foreground\" \"Foreground\" 'string SOME-FRAME)
|
|
848
|
|
849 is an interface to a C call something like
|
|
850
|
|
851 XrmGetResource (db, \"xemacs.frame.FRAME-NAME.foreground\",
|
|
852 \"Emacs.EmacsLocaleType.EmacsFrame.Foreground\",
|
|
853 \"String\");
|
|
854
|
|
855 3) If LOCALE is a device, a call
|
|
856
|
|
857 (x-get-resource \"foreground\" \"Foreground\" 'string SOME-DEVICE)
|
|
858
|
|
859 is an interface to a C call something like
|
|
860
|
|
861 XrmGetResource (db, \"xemacs.device.DEVICE-NAME.foreground\",
|
|
862 \"Emacs.EmacsLocaleType.EmacsDevice.Foreground\",
|
|
863 \"String\");
|
|
864
|
|
865 4) If LOCALE is 'global, a call
|
|
866
|
|
867 (x-get-resource \"foreground\" \"Foreground\" 'string 'global)
|
|
868
|
|
869 is an interface to a C call something like
|
|
870
|
|
871 XrmGetResource (db, \"xemacs.foreground\",
|
|
872 \"Emacs.Foreground\",
|
|
873 \"String\");
|
|
874
|
|
875 Note that for 'global, no prefix is added other than that of the
|
|
876 application itself; thus, you can use this locale to retrieve
|
|
877 arbitrary application resources, if you really want to.
|
|
878
|
|
879 The returned value of this function is nil if the queried resource is not
|
|
880 found. If the third arg is `string', a string is returned, and if it is
|
|
881 `integer', an integer is returned. If the third arg is `boolean', then the
|
|
882 returned value is the list (t) for true, (nil) for false, and is nil to
|
|
883 mean ``unspecified.''
|
20
|
884 */
|
|
885 (name, class, type, locale, device, no_error))
|
0
|
886 {
|
|
887 /* #### fixed limit, could be overflowed */
|
|
888 char name_string[2048], class_string[2048];
|
|
889 char *raw_result;
|
|
890 XrmDatabase db;
|
|
891 Display *display;
|
|
892 Error_behavior errb = decode_error_behavior_flag (no_error);
|
|
893
|
|
894 CHECK_STRING (name);
|
|
895 CHECK_STRING (class);
|
|
896 CHECK_SYMBOL (type);
|
|
897
|
|
898 if (!EQ (type, Qstring) && !EQ (type, Qboolean) &&
|
|
899 !EQ (type, Qinteger) && !EQ (type, Qnatnum))
|
|
900 return maybe_signal_continuable_error
|
|
901 (Qwrong_type_argument,
|
|
902 list2 (build_translated_string
|
|
903 ("should be string, integer, natnum or boolean"),
|
|
904 type),
|
|
905 Qresource, errb);
|
|
906
|
|
907 x_get_resource_prefix (locale, device, &display, name_string,
|
|
908 class_string);
|
|
909 if (!display)
|
|
910 return Qnil;
|
|
911
|
|
912 db = XtDatabase (display);
|
|
913
|
|
914 strcat (name_string, ".");
|
14
|
915 strcat (name_string, (CONST char *) XSTRING_DATA (name));
|
0
|
916 strcat (class_string, ".");
|
14
|
917 strcat (class_string, (CONST char *) XSTRING_DATA (class));
|
0
|
918
|
|
919 {
|
|
920 XrmValue xrm_value;
|
|
921 XrmName namelist[100];
|
|
922 XrmClass classlist[100];
|
|
923 XrmName *namerest = namelist;
|
|
924 XrmClass *classrest = classlist;
|
|
925 XrmRepresentation xrm_type;
|
|
926 XrmRepresentation string_quark;
|
|
927 int result;
|
|
928 XrmStringToNameList (name_string, namelist);
|
|
929 XrmStringToClassList (class_string, classlist);
|
|
930 string_quark = XrmStringToQuark ("String");
|
|
931
|
|
932 /* ensure that they have the same length */
|
|
933 while (namerest[0] && classrest[0])
|
|
934 namerest++, classrest++;
|
|
935 if (namerest[0] || classrest[0])
|
|
936 signal_simple_error_2
|
|
937 ("class list and name list must be the same length", name, class);
|
|
938 result = XrmQGetResource (db, namelist, classlist, &xrm_type, &xrm_value);
|
|
939
|
|
940 if (result != True || xrm_type != string_quark)
|
|
941 return Qnil;
|
|
942 raw_result = (char *) xrm_value.addr;
|
|
943 }
|
|
944
|
|
945 if (EQ (type, Qstring))
|
|
946 return build_string (raw_result);
|
|
947 else if (EQ (type, Qboolean))
|
|
948 {
|
|
949 if (!strcasecmp (raw_result, "off") ||
|
|
950 !strcasecmp (raw_result, "false") ||
|
|
951 !strcasecmp (raw_result,"no"))
|
|
952 return Fcons (Qnil, Qnil);
|
|
953 else if (!strcasecmp (raw_result, "on") ||
|
|
954 !strcasecmp (raw_result, "true") ||
|
|
955 !strcasecmp (raw_result, "yes"))
|
|
956 return Fcons (Qt, Qnil);
|
|
957 else
|
|
958 return maybe_continuable_error (Qresource, errb,
|
|
959 "can't convert %s: %s to a Boolean",
|
|
960 name_string, raw_result);
|
|
961 }
|
|
962 else if (EQ (type, Qinteger) || EQ (type, Qnatnum))
|
|
963 {
|
|
964 int i;
|
|
965 char c;
|
|
966 if (1 != sscanf (raw_result, "%d%c", &i, &c))
|
|
967 return maybe_continuable_error
|
|
968 (Qresource, errb,
|
|
969 "can't convert %s: %s to an integer",
|
|
970 name_string, raw_result);
|
|
971 else if (EQ (type, Qnatnum) && i < 0)
|
|
972 return maybe_continuable_error
|
|
973 (Qresource, errb,
|
|
974 "invalid numerical value %d for resource %s",
|
|
975 i, name_string);
|
|
976 else
|
|
977 return make_int (i);
|
|
978 }
|
|
979 else
|
|
980 abort ();
|
|
981
|
|
982 /* Can't get here. */
|
|
983 return Qnil; /* shut up compiler */
|
|
984 }
|
|
985
|
20
|
986 DEFUN ("x-get-resource-prefix", Fx_get_resource_prefix, 1, 2, 0, /*
|
0
|
987 Return the resource prefix for LOCALE on DEVICE.
|
|
988 The resource prefix is the strings used to prefix resources if
|
|
989 the LOCALE and DEVICE arguments were passed to `x-get-resource'.
|
|
990 The returned value is a cons of a name prefix and a class prefix.
|
|
991 For example, if LOCALE is a frame, the returned value might be
|
|
992 \(\"xemacs.frame.FRAME-NAME\" . \"Emacs.EmacsLocaleType.EmacsFrame\").
|
|
993 If no valid X device for resourcing can be obtained, this function
|
|
994 returns nil. (In such a case, `x-get-resource' would always return nil.)
|
20
|
995 */
|
|
996 (locale, device))
|
0
|
997 {
|
|
998 /* #### fixed limit, could be overflowed */
|
|
999 char name[1024], class[1024];
|
|
1000 Display *display;
|
|
1001
|
|
1002 x_get_resource_prefix (locale, device, &display, name, class);
|
|
1003 if (!display)
|
|
1004 return Qnil;
|
|
1005 return Fcons (build_string (name), build_string (class));
|
|
1006 }
|
|
1007
|
20
|
1008 DEFUN ("x-put-resource", Fx_put_resource, 1, 2, 0, /*
|
0
|
1009 Add a resource to the resource database for DEVICE.
|
|
1010 RESOURCE-LINE specifies the resource to add and should be a
|
|
1011 standard resource specification.
|
20
|
1012 */
|
|
1013 (resource_line, device))
|
0
|
1014 {
|
|
1015 struct device *d = decode_device (device);
|
|
1016 char *str, *colon_pos;
|
|
1017
|
|
1018 CHECK_STRING (resource_line);
|
14
|
1019 str = (char *) XSTRING_DATA (resource_line);
|
0
|
1020 if (!(colon_pos = strchr (str, ':')) || strchr (str, '\n'))
|
|
1021 invalid:
|
|
1022 signal_simple_error ("Invalid resource line", resource_line);
|
|
1023 if (strspn (str,
|
|
1024 /* Only the following chars are allowed before the colon */
|
|
1025 " \t.*?abcdefghijklmnopqrstuvwxyz"
|
|
1026 "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-") != colon_pos - str)
|
|
1027 goto invalid;
|
|
1028
|
|
1029 if (DEVICE_X_P (d))
|
|
1030 {
|
|
1031 XrmDatabase db = XtDatabase (DEVICE_X_DISPLAY (d));
|
|
1032 XrmPutLineResource (&db, str);
|
|
1033 }
|
|
1034
|
|
1035 return Qnil;
|
|
1036 }
|
|
1037
|
|
1038
|
|
1039 /************************************************************************/
|
|
1040 /* display information functions */
|
|
1041 /************************************************************************/
|
|
1042
|
20
|
1043 DEFUN ("default-x-device", Fdefault_x_device, 0, 0, 0, /*
|
0
|
1044 Return the default X device for resourcing.
|
|
1045 This is the first-created X device that still exists.
|
20
|
1046 */
|
|
1047 ())
|
0
|
1048 {
|
|
1049 return Vdefault_x_device;
|
|
1050 }
|
|
1051
|
20
|
1052 DEFUN ("x-display-visual-class", Fx_display_visual_class, 0, 1, 0, /*
|
0
|
1053 Return the visual class of the X display `device' is on.
|
|
1054 The returned value will be one of the symbols `static-gray', `gray-scale',
|
|
1055 `static-color', `pseudo-color', `true-color', or `direct-color'.
|
20
|
1056 */
|
|
1057 (device))
|
0
|
1058 {
|
|
1059 switch (DefaultVisualOfScreen
|
|
1060 (DefaultScreenOfDisplay (get_x_display (device)))->class)
|
|
1061 {
|
|
1062 case StaticGray: return (intern ("static-gray"));
|
|
1063 case GrayScale: return (intern ("gray-scale"));
|
|
1064 case StaticColor: return (intern ("static-color"));
|
|
1065 case PseudoColor: return (intern ("pseudo-color"));
|
|
1066 case TrueColor: return (intern ("true-color"));
|
|
1067 case DirectColor: return (intern ("direct-color"));
|
|
1068 default:
|
|
1069 error ("display has an unknown visual class");
|
|
1070 }
|
|
1071
|
|
1072 return Qnil; /* suppress compiler warning */
|
|
1073 }
|
|
1074
|
|
1075 static int
|
|
1076 x_device_pixel_width (struct device *d)
|
|
1077 {
|
|
1078 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1079
|
|
1080 return DisplayWidth (dpy, DefaultScreen (dpy));
|
|
1081 }
|
|
1082
|
|
1083 static int
|
|
1084 x_device_pixel_height (struct device *d)
|
|
1085 {
|
|
1086 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1087
|
|
1088 return DisplayHeight (dpy, DefaultScreen (dpy));
|
|
1089 }
|
|
1090
|
|
1091 static int
|
|
1092 x_device_mm_width (struct device *d)
|
|
1093 {
|
|
1094 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1095
|
|
1096 return DisplayWidthMM (dpy, DefaultScreen (dpy));
|
|
1097 }
|
|
1098
|
|
1099 static int
|
|
1100 x_device_mm_height (struct device *d)
|
|
1101 {
|
|
1102 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1103
|
|
1104 return DisplayHeightMM (dpy, DefaultScreen (dpy));
|
|
1105 }
|
|
1106
|
|
1107 static int
|
|
1108 x_device_bitplanes (struct device *d)
|
|
1109 {
|
|
1110 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1111
|
|
1112 return DisplayPlanes (dpy, DefaultScreen (dpy));
|
|
1113 }
|
|
1114
|
|
1115 static int
|
|
1116 x_device_color_cells (struct device *d)
|
|
1117 {
|
|
1118 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1119
|
|
1120 return DisplayCells (dpy, DefaultScreen (dpy));
|
|
1121 }
|
|
1122
|
20
|
1123 DEFUN ("x-server-vendor", Fx_server_vendor, 0, 1, 0, /*
|
0
|
1124 Return the vendor ID string of the X server `device' on.
|
20
|
1125 */
|
|
1126 (device))
|
0
|
1127 {
|
|
1128 Display *dpy = get_x_display (device);
|
|
1129 char *vendor = ServerVendor (dpy);
|
|
1130
|
|
1131 if (vendor)
|
|
1132 return (build_string (vendor));
|
|
1133 else
|
|
1134 return (build_string (""));
|
|
1135 }
|
|
1136
|
20
|
1137 DEFUN ("x-server-version", Fx_server_version, 0, 1, 0, /*
|
0
|
1138 Return the version numbers of the X server `device' is on.
|
|
1139 The returned value is a list of three integers: the major and minor
|
|
1140 version numbers of the X Protocol in use, and the vendor-specific release
|
|
1141 number. See also `x-server-vendor'.
|
20
|
1142 */
|
|
1143 (device))
|
0
|
1144 {
|
|
1145 Display *dpy = get_x_display (device);
|
|
1146
|
|
1147 return list3 (make_int (ProtocolVersion (dpy)),
|
|
1148 make_int (ProtocolRevision (dpy)),
|
|
1149 make_int (VendorRelease (dpy)));
|
|
1150 }
|
|
1151
|
20
|
1152 DEFUN ("x-valid-keysym-name-p", Fx_valid_keysym_name_p, 1, 1, 0, /*
|
0
|
1153 Return true if KEYSYM names a keysym that the X library knows about.
|
|
1154 Valid keysyms are listed in the files /usr/include/X11/keysymdef.h and in
|
|
1155 /usr/lib/X11/XKeysymDB, or whatever the equivalents are on your system.
|
20
|
1156 */
|
|
1157 (keysym))
|
0
|
1158 {
|
|
1159 CONST char *keysym_ext;
|
|
1160
|
|
1161 CHECK_STRING (keysym);
|
|
1162 GET_C_STRING_CTEXT_DATA_ALLOCA (keysym, keysym_ext);
|
|
1163 if (XStringToKeysym (keysym_ext))
|
|
1164 return Qt;
|
|
1165 return Qnil;
|
|
1166 }
|
|
1167
|
20
|
1168 DEFUN ("x-keysym-on-keyboard-p", Fx_keysym_on_keyboard_p, 1, 2, 0, /*
|
0
|
1169 Return true if KEYSYM names a key on the keyboard of DEVICE.
|
|
1170 More precisely, return true if pressing a physical key
|
|
1171 on the keyboard of DEVICE without any modifier keys generates KEYSYM.
|
|
1172 Valid keysyms are listed in the files /usr/include/X11/keysymdef.h and in
|
|
1173 /usr/lib/X11/XKeysymDB, or whatever the equivalents are on your system.
|
20
|
1174 */
|
|
1175 (keysym, device))
|
0
|
1176 {
|
|
1177 struct device *d = decode_device(device);
|
|
1178 CONST char *keysym_string;
|
|
1179 KeySym keysym_KeySym;
|
|
1180 KeySym *keysym_ptr, *keysym_last;
|
2
|
1181 int min_code, max_code, keysyms_per_code;
|
0
|
1182
|
|
1183 if (!DEVICE_X_P (d))
|
|
1184 signal_simple_error ("Not an X device", device);
|
|
1185 CHECK_STRING (keysym);
|
|
1186 GET_C_STRING_CTEXT_DATA_ALLOCA (keysym, keysym_string);
|
|
1187 keysym_KeySym = XStringToKeysym (keysym_string);
|
|
1188 if (!keysym_KeySym) /* Invalid keysym */
|
|
1189 return Qnil;
|
|
1190
|
|
1191 XDisplayKeycodes (DEVICE_X_DISPLAY (d), &min_code, &max_code);
|
|
1192 keysyms_per_code = DEVICE_X_DATA (d)->x_keysym_map_keysyms_per_code;
|
|
1193 keysym_ptr = DEVICE_X_DATA (d)->x_keysym_map;
|
|
1194 keysym_last = keysym_ptr + (max_code - min_code) * keysyms_per_code;
|
|
1195 for ( ; keysym_ptr <= keysym_last; keysym_ptr += keysyms_per_code)
|
|
1196 {
|
|
1197 if (keysym_KeySym == *keysym_ptr)
|
|
1198 return Qt;
|
|
1199 }
|
|
1200
|
|
1201 return Qnil;
|
|
1202 }
|
|
1203
|
|
1204
|
|
1205 /************************************************************************/
|
|
1206 /* grabs and ungrabs */
|
|
1207 /************************************************************************/
|
|
1208
|
20
|
1209 DEFUN ("x-grab-pointer", Fx_grab_pointer, 0, 3, 0, /*
|
0
|
1210 Grab the pointer and restrict it to its current window.
|
|
1211 If optional DEVICE argument is nil, the default device will be used.
|
|
1212 If optional CURSOR argument is non-nil, change the pointer shape to that
|
|
1213 until `x-ungrab-pointer' is called (it should be an object returned by the
|
|
1214 `make-cursor-glyph' function).
|
|
1215 If the second optional argument IGNORE-KEYBOARD is non-nil, ignore all
|
|
1216 keyboard events during the grab.
|
|
1217 Returns t if the grab is successful, nil otherwise.
|
20
|
1218 */
|
|
1219 (device, cursor, ignore_keyboard))
|
0
|
1220 {
|
|
1221 Window w;
|
|
1222 int pointer_mode, result;
|
|
1223 struct device *d = decode_x_device (device);
|
|
1224
|
|
1225 if (!NILP (cursor))
|
|
1226 {
|
|
1227 CHECK_POINTER_GLYPH (cursor);
|
|
1228 cursor = glyph_image_instance (cursor, device, ERROR_ME, 0);
|
|
1229 }
|
|
1230
|
|
1231 if (!NILP (ignore_keyboard))
|
|
1232 pointer_mode = GrabModeSync;
|
|
1233 else
|
|
1234 pointer_mode = GrabModeAsync;
|
|
1235
|
|
1236 w = XtWindow (FRAME_X_TEXT_WIDGET (device_selected_frame (d)));
|
|
1237
|
|
1238 /* #### Possibly this needs to gcpro the cursor somehow, but it doesn't
|
|
1239 seem to cause a problem if XFreeCursor is called on a cursor in use
|
|
1240 in a grab; I suppose the X server counts the grab as a reference
|
|
1241 and doesn't free it until it exits? */
|
|
1242 result = XGrabPointer (DEVICE_X_DISPLAY (d), w,
|
|
1243 False,
|
|
1244 ButtonMotionMask | ButtonPressMask
|
|
1245 | ButtonReleaseMask | PointerMotionHintMask,
|
|
1246 GrabModeAsync, /* Keep pointer events flowing */
|
|
1247 pointer_mode, /* Stall keyboard events */
|
|
1248 w, /* Stay in this window */
|
|
1249 (NILP (cursor) ? 0
|
|
1250 : XIMAGE_INSTANCE_X_CURSOR (cursor)),
|
|
1251 CurrentTime);
|
|
1252 return ((result == GrabSuccess) ? Qt : Qnil);
|
|
1253 }
|
|
1254
|
20
|
1255 DEFUN ("x-ungrab-pointer", Fx_ungrab_pointer, 0, 1, 0, /*
|
0
|
1256 Release a pointer grab made with `x-grab-pointer'.
|
|
1257 If optional first arg DEVICE is nil the default device is used.
|
|
1258 If it is t the pointer will be released on all X devices.
|
20
|
1259 */
|
|
1260 (device))
|
0
|
1261 {
|
|
1262 if (!EQ (device, Qt))
|
|
1263 {
|
|
1264 Display *dpy = get_x_display (device);
|
|
1265 XUngrabPointer (dpy, CurrentTime);
|
|
1266 }
|
|
1267 else
|
|
1268 {
|
|
1269 Lisp_Object devcons, concons;
|
|
1270
|
|
1271 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
1272 {
|
|
1273 struct device *d = XDEVICE (XCAR (devcons));
|
|
1274
|
|
1275 if (DEVICE_X_P (d))
|
|
1276 XUngrabPointer (DEVICE_X_DISPLAY (d), CurrentTime);
|
|
1277 }
|
|
1278 }
|
|
1279
|
|
1280 return Qnil;
|
|
1281 }
|
|
1282
|
20
|
1283 DEFUN ("x-grab-keyboard", Fx_grab_keyboard, 0, 1, 0, /*
|
0
|
1284 Grab the keyboard on the given device (defaulting to the selected one).
|
|
1285 So long as the keyboard is grabbed, all keyboard events will be delivered
|
|
1286 to emacs -- it is not possible for other X clients to eavesdrop on them.
|
|
1287 Ungrab the keyboard with `x-ungrab-keyboard' (use an unwind-protect).
|
|
1288 Returns t if the grab was successful; nil otherwise.
|
20
|
1289 */
|
|
1290 (device))
|
0
|
1291 {
|
|
1292 struct device *d = decode_x_device (device);
|
|
1293 Window w = XtWindow (FRAME_X_TEXT_WIDGET (device_selected_frame (d)));
|
|
1294 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
1295 Status status;
|
|
1296 XSync (dpy, False);
|
|
1297 status = XGrabKeyboard (dpy, w, True,
|
|
1298 /* I don't really understand sync-vs-async
|
|
1299 grabs, but this is what xterm does. */
|
|
1300 GrabModeAsync, GrabModeAsync,
|
|
1301 /* Use the timestamp of the last user action
|
|
1302 read by emacs proper; xterm uses CurrentTime
|
|
1303 but there's a comment that says "wrong"...
|
|
1304 (Despite the name this is the time of the
|
|
1305 last key or mouse event.) */
|
|
1306 DEVICE_X_MOUSE_TIMESTAMP (d));
|
|
1307 if (status == GrabSuccess)
|
|
1308 {
|
|
1309 /* The XUngrabKeyboard should generate a FocusIn back to this
|
|
1310 window but it doesn't unless we explicitly set focus to the
|
|
1311 window first (which should already have it. The net result
|
|
1312 is that without this call when x-ungrab-keyboard is called
|
|
1313 the selected frame ends up not having focus. */
|
|
1314 XSetInputFocus (dpy, w, RevertToParent, DEVICE_X_MOUSE_TIMESTAMP (d));
|
|
1315 return Qt;
|
|
1316 }
|
|
1317 else
|
|
1318 return Qnil;
|
|
1319 }
|
|
1320
|
20
|
1321 DEFUN ("x-ungrab-keyboard", Fx_ungrab_keyboard, 0, 1, 0, /*
|
0
|
1322 Release a keyboard grab made with `x-grab-keyboard'.
|
20
|
1323 */
|
|
1324 (device))
|
0
|
1325 {
|
|
1326 Display *dpy = get_x_display (device);
|
|
1327 XUngrabKeyboard (dpy, CurrentTime);
|
|
1328 return Qnil;
|
|
1329 }
|
|
1330
|
|
1331
|
|
1332 /************************************************************************/
|
|
1333 /* initialization */
|
|
1334 /************************************************************************/
|
|
1335
|
|
1336 void
|
|
1337 syms_of_device_x (void)
|
|
1338 {
|
20
|
1339 DEFSUBR (Fx_debug_mode);
|
|
1340 DEFSUBR (Fx_get_resource);
|
|
1341 DEFSUBR (Fx_get_resource_prefix);
|
|
1342 DEFSUBR (Fx_put_resource);
|
0
|
1343
|
20
|
1344 DEFSUBR (Fdefault_x_device);
|
|
1345 DEFSUBR (Fx_display_visual_class);
|
|
1346 DEFSUBR (Fx_server_vendor);
|
|
1347 DEFSUBR (Fx_server_version);
|
|
1348 DEFSUBR (Fx_valid_keysym_name_p);
|
|
1349 DEFSUBR (Fx_keysym_on_keyboard_p);
|
0
|
1350
|
20
|
1351 DEFSUBR (Fx_grab_pointer);
|
|
1352 DEFSUBR (Fx_ungrab_pointer);
|
|
1353 DEFSUBR (Fx_grab_keyboard);
|
|
1354 DEFSUBR (Fx_ungrab_keyboard);
|
0
|
1355
|
|
1356 defsymbol (&Qx_error, "x-error");
|
|
1357 defsymbol (&Qinit_pre_x_win, "init-pre-x-win");
|
|
1358 defsymbol (&Qinit_post_x_win, "init-post-x-win");
|
|
1359 }
|
|
1360
|
|
1361 void
|
|
1362 console_type_create_device_x (void)
|
|
1363 {
|
|
1364 CONSOLE_HAS_METHOD (x, init_device);
|
|
1365 CONSOLE_HAS_METHOD (x, finish_init_device);
|
|
1366 CONSOLE_HAS_METHOD (x, mark_device);
|
|
1367 CONSOLE_HAS_METHOD (x, delete_device);
|
|
1368 CONSOLE_HAS_METHOD (x, device_pixel_width);
|
|
1369 CONSOLE_HAS_METHOD (x, device_pixel_height);
|
|
1370 CONSOLE_HAS_METHOD (x, device_mm_width);
|
|
1371 CONSOLE_HAS_METHOD (x, device_mm_height);
|
|
1372 CONSOLE_HAS_METHOD (x, device_bitplanes);
|
|
1373 CONSOLE_HAS_METHOD (x, device_color_cells);
|
|
1374 }
|
|
1375
|
|
1376 void
|
|
1377 vars_of_device_x (void)
|
|
1378 {
|
|
1379 DEFVAR_LISP ("x-emacs-application-class", &Vx_emacs_application_class /*
|
|
1380 The X application class of the XEmacs process.
|
|
1381 This controls, among other things, the name of the `app-defaults' file
|
|
1382 that XEmacs will use. For changes to this variable to take effect, they
|
|
1383 must be made before the connection to the X server is initialized, that is,
|
|
1384 this variable may only be changed before emacs is dumped, or by setting it
|
|
1385 in the file lisp/term/x-win.el.
|
|
1386 */ );
|
|
1387 Vx_emacs_application_class = Fpurecopy (build_string ("Emacs"));
|
|
1388
|
|
1389 DEFVAR_LISP ("x-initial-argv-list", &Vx_initial_argv_list /*
|
|
1390 You don't want to know.
|
|
1391 This is used during startup to communicate the remaining arguments in
|
|
1392 `command-line-args-left' to the C code, which passes the args to
|
|
1393 the X initialization code, which removes some args, and then the
|
|
1394 args are placed back into `x-initial-arg-list' and thence into
|
|
1395 `command-line-args-left'. Perhaps `command-line-args-left' should
|
|
1396 just reside in C.
|
|
1397 */ );
|
|
1398 Vx_initial_argv_list = Qnil;
|
|
1399
|
|
1400 Fprovide (Qx);
|
|
1401
|
|
1402 staticpro (&Vdefault_x_device);
|
|
1403 Vdefault_x_device = Qnil;
|
|
1404
|
|
1405 error_expected = 0;
|
|
1406 error_occurred = 0;
|
|
1407
|
|
1408 in_resource_setting = 0;
|
|
1409 in_specifier_change_function = 0;
|
|
1410 }
|