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