70
|
1 /* Generic device functions.
|
0
|
2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
|
|
3 Copyright (C) 1994, 1995 Free Software Foundation, Inc.
|
|
4 Copyright (C) 1995, 1996 Ben Wing
|
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: Not in FSF. */
|
|
24
|
|
25 /* Original version by Chuck Thompson;
|
|
26 rewritten and expanded by Ben Wing. */
|
|
27
|
|
28 #include <config.h>
|
|
29 #include "lisp.h"
|
|
30
|
|
31 #include "buffer.h"
|
|
32 #include "console.h"
|
|
33 #include "device.h"
|
|
34 #include "elhash.h"
|
|
35 #include "events.h"
|
|
36 #include "faces.h"
|
|
37 #include "frame.h"
|
|
38 #include "keymap.h"
|
|
39 #include "redisplay.h"
|
|
40 #include "scrollbar.h"
|
|
41 #include "specifier.h"
|
|
42 #include "sysdep.h"
|
|
43 #include "window.h"
|
|
44
|
|
45 #include "syssignal.h"
|
|
46
|
|
47 /* Vdefault_device is the firstly-created non-stream device that's still
|
|
48 around. We don't really use it anywhere currently, but it might
|
|
49 be used for resourcing at some point. (Currently we use
|
|
50 Vdefault_x_device.) */
|
|
51 Lisp_Object Vdefault_device;
|
|
52
|
|
53 Lisp_Object Vcreate_device_hook, Vdelete_device_hook;
|
|
54
|
|
55 /* Device classes */
|
|
56 /* Qcolor defined in general.c */
|
|
57 Lisp_Object Qgrayscale, Qmono;
|
|
58
|
282
|
59 /* Device metrics symbols */
|
|
60 Lisp_Object Qcolor_default, Qcolor_select, Qcolor_balloon, Qcolor_3d_face;
|
|
61 Lisp_Object Qcolor_3d_light, Qcolor_3d_dark, Qcolor_menu, Qcolor_menu_high;
|
|
62 Lisp_Object Qcolor_menu_button, Qcolor_menu_unsel, Qcolor_toolbar;
|
|
63 Lisp_Object Qcolor_scrollbar, Qcolor_desktop, Qcolor_workspace, Qfont_default;
|
|
64 Lisp_Object Qfont_menubar, Qfont_dialog, Qsize_cursor, Qsize_scrollbar;
|
|
65 Lisp_Object Qsize_menu, Qsize_toolbar, Qsize_tbbutton, Qsize_tbborder, Qsize_icon;
|
|
66 Lisp_Object Qsize_icon_small, Qsize_device, Qsize_workspace, Qsize_device_mm;
|
|
67 Lisp_Object Qdevice_dpi, Qmouse_buttons, Qswap_buttons;
|
|
68 Lisp_Object Qshow_sounds, Qslow_device, Qsecurity, Qdbcs, Qime, Qmid_east;
|
|
69 Lisp_Object Qnum_bit_planes, Qnum_color_cells;
|
|
70
|
0
|
71 Lisp_Object Qdevicep, Qdevice_live_p;
|
|
72 Lisp_Object Qdelete_device;
|
|
73 Lisp_Object Qcreate_device_hook;
|
|
74 Lisp_Object Qdelete_device_hook;
|
|
75
|
|
76 Lisp_Object Vdevice_class_list;
|
|
77
|
|
78
|
|
79 static Lisp_Object
|
|
80 mark_device (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
81 {
|
|
82 struct device *d = XDEVICE (obj);
|
|
83
|
|
84 ((markobj) (d->name));
|
|
85 ((markobj) (d->connection));
|
|
86 ((markobj) (d->canon_connection));
|
|
87 ((markobj) (d->console));
|
|
88 ((markobj) (d->_selected_frame));
|
|
89 ((markobj) (d->frame_with_focus_real));
|
|
90 ((markobj) (d->frame_with_focus_for_hooks));
|
|
91 ((markobj) (d->frame_that_ought_to_have_focus));
|
|
92 ((markobj) (d->device_class));
|
|
93 ((markobj) (d->user_defined_tags));
|
|
94 ((markobj) (d->pixel_to_glyph_cache.obj1));
|
|
95 ((markobj) (d->pixel_to_glyph_cache.obj2));
|
|
96
|
|
97 ((markobj) (d->color_instance_cache));
|
|
98 ((markobj) (d->font_instance_cache));
|
70
|
99 #ifdef MULE
|
|
100 ((markobj) (d->charset_font_cache));
|
|
101 #endif
|
0
|
102 ((markobj) (d->image_instance_cache));
|
|
103
|
|
104 if (d->devmeths)
|
|
105 {
|
|
106 ((markobj) (d->devmeths->symbol));
|
|
107 MAYBE_DEVMETH (d, mark_device, (d, markobj));
|
|
108 }
|
|
109
|
|
110 return (d->frame_list);
|
|
111 }
|
|
112
|
|
113 static void
|
|
114 print_device (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
115 {
|
|
116 struct device *d = XDEVICE (obj);
|
|
117 char buf[256];
|
|
118
|
|
119 if (print_readably)
|
|
120 error ("printing unreadable object #<device %s 0x%x>",
|
14
|
121 XSTRING_DATA (d->name), d->header.uid);
|
0
|
122
|
|
123 sprintf (buf, "#<%s-device", !DEVICE_LIVE_P (d) ? "dead" :
|
|
124 DEVICE_TYPE_NAME (d));
|
|
125 write_c_string (buf, printcharfun);
|
|
126 if (DEVICE_LIVE_P (d))
|
|
127 {
|
|
128 write_c_string (" on ", printcharfun);
|
|
129 print_internal (DEVICE_CONNECTION (d), printcharfun, 1);
|
|
130 }
|
|
131 sprintf (buf, " 0x%x>", d->header.uid);
|
|
132 write_c_string (buf, printcharfun);
|
|
133 }
|
|
134
|
272
|
135 DEFINE_LRECORD_IMPLEMENTATION ("device", device,
|
|
136 mark_device, print_device, 0, 0, 0,
|
|
137 struct device);
|
0
|
138
|
|
139 int
|
|
140 valid_device_class_p (Lisp_Object class)
|
|
141 {
|
|
142 return !NILP (memq_no_quit (class, Vdevice_class_list));
|
|
143 }
|
|
144
|
20
|
145 DEFUN ("valid-device-class-p", Fvalid_device_class_p, 1, 1, 0, /*
|
0
|
146 Given a DEVICE-CLASS, return t if it is valid.
|
|
147 Valid classes are 'color, 'grayscale, and 'mono.
|
20
|
148 */
|
|
149 (device_class))
|
0
|
150 {
|
185
|
151 return valid_device_class_p (device_class) ? Qt : Qnil;
|
0
|
152 }
|
|
153
|
20
|
154 DEFUN ("device-class-list", Fdevice_class_list, 0, 0, 0, /*
|
0
|
155 Return a list of valid device classes.
|
20
|
156 */
|
|
157 ())
|
0
|
158 {
|
|
159 return Fcopy_sequence (Vdevice_class_list);
|
|
160 }
|
|
161
|
|
162 static struct device *
|
|
163 allocate_device (Lisp_Object console)
|
|
164 {
|
185
|
165 Lisp_Object device;
|
|
166 struct device *d = alloc_lcrecord_type (struct device, lrecord_device);
|
0
|
167 struct gcpro gcpro1;
|
|
168
|
|
169 zero_lcrecord (d);
|
|
170
|
|
171 XSETDEVICE (device, d);
|
|
172 GCPRO1 (device);
|
|
173
|
|
174 d->name = Qnil;
|
|
175 d->console = console;
|
|
176 d->connection = Qnil;
|
|
177 d->canon_connection = Qnil;
|
|
178 d->frame_list = Qnil;
|
|
179 d->_selected_frame = Qnil;
|
|
180 d->frame_with_focus_real = Qnil;
|
|
181 d->frame_with_focus_for_hooks = Qnil;
|
|
182 d->frame_that_ought_to_have_focus = Qnil;
|
|
183 d->device_class = Qnil;
|
|
184 d->user_defined_tags = Qnil;
|
|
185 d->pixel_to_glyph_cache.obj1 = Qnil;
|
|
186 d->pixel_to_glyph_cache.obj2 = Qnil;
|
|
187
|
|
188 d->infd = d->outfd = -1;
|
|
189
|
|
190 /* #### is 20 reasonable? */
|
|
191 d->color_instance_cache = make_lisp_hashtable (20, HASHTABLE_KEY_WEAK,
|
|
192 HASHTABLE_EQUAL);
|
|
193 d->font_instance_cache = make_lisp_hashtable (20, HASHTABLE_KEY_WEAK,
|
|
194 HASHTABLE_EQUAL);
|
70
|
195 #ifdef MULE
|
|
196 /* Note that the following table is bi-level. */
|
|
197 d->charset_font_cache = make_lisp_hashtable (20, HASHTABLE_NONWEAK,
|
|
198 HASHTABLE_EQ);
|
|
199 #endif
|
0
|
200 /*
|
|
201 Note that the image instance cache is actually bi-level.
|
|
202 See device.h. We use a low number here because most of the
|
|
203 time there aren't very many diferent masks that will be used.
|
|
204 */
|
|
205 d->image_instance_cache = make_lisp_hashtable (5, HASHTABLE_NONWEAK,
|
|
206 HASHTABLE_EQ);
|
|
207
|
|
208 UNGCPRO;
|
|
209 return d;
|
|
210 }
|
|
211
|
|
212 struct device *
|
|
213 decode_device (Lisp_Object device)
|
|
214 {
|
|
215 if (NILP (device))
|
|
216 device = Fselected_device (Qnil);
|
|
217 /* quietly accept frames for the device arg */
|
|
218 if (FRAMEP (device))
|
|
219 device = FRAME_DEVICE (decode_frame (device));
|
|
220 CHECK_LIVE_DEVICE (device);
|
|
221 return XDEVICE (device);
|
|
222 }
|
|
223
|
20
|
224 DEFUN ("dfw-device", Fdfw_device, 1, 1, 0, /*
|
0
|
225 Given a device, frame, or window, return the associated device.
|
|
226 Return nil otherwise.
|
20
|
227 */
|
|
228 (obj))
|
0
|
229 {
|
|
230 return DFW_DEVICE (obj);
|
|
231 }
|
|
232
|
|
233
|
20
|
234 DEFUN ("selected-device", Fselected_device, 0, 1, 0, /*
|
0
|
235 Return the device which is currently active.
|
|
236 If optional CONSOLE is non-nil, return the device that would be currently
|
|
237 active if CONSOLE were the selected console.
|
20
|
238 */
|
|
239 (console))
|
0
|
240 {
|
|
241 if (NILP (console) && NILP (Vselected_console))
|
|
242 return Qnil; /* happens early in temacs */
|
|
243 return CONSOLE_SELECTED_DEVICE (decode_console (console));
|
|
244 }
|
|
245
|
|
246 /* Called from selected_frame_1(), called from Fselect_window() */
|
|
247 void
|
|
248 select_device_1 (Lisp_Object device)
|
|
249 {
|
|
250 struct device *dev = XDEVICE (device);
|
|
251 Lisp_Object old_selected_device = Fselected_device (Qnil);
|
185
|
252
|
0
|
253 if (EQ (device, old_selected_device))
|
|
254 return;
|
|
255
|
|
256 /* now select the device's console */
|
|
257 CONSOLE_SELECTED_DEVICE (XCONSOLE (DEVICE_CONSOLE (dev))) = device;
|
|
258 select_console_1 (DEVICE_CONSOLE (dev));
|
|
259 }
|
|
260
|
20
|
261 DEFUN ("select-device", Fselect_device, 1, 1, 0, /*
|
0
|
262 Select the device DEVICE.
|
|
263 Subsequent editing commands apply to its console, selected frame,
|
|
264 and selected window.
|
|
265 The selection of DEVICE lasts until the next time the user does
|
|
266 something to select a different device, or until the next time this
|
|
267 function is called.
|
20
|
268 */
|
|
269 (device))
|
0
|
270 {
|
|
271 CHECK_LIVE_DEVICE (device);
|
|
272
|
|
273 /* select the device's selected frame's selected window. This will call
|
|
274 selected_frame_1()->selected_device_1()->selected_console_1(). */
|
|
275 if (!NILP (DEVICE_SELECTED_FRAME (XDEVICE (device))))
|
|
276 Fselect_window (FRAME_SELECTED_WINDOW
|
282
|
277 (XFRAME (DEVICE_SELECTED_FRAME (XDEVICE (device)))),
|
|
278 Qnil);
|
0
|
279 else
|
|
280 error ("Can't select a device with no frames");
|
|
281 return Qnil;
|
|
282 }
|
|
283
|
|
284 void
|
|
285 set_device_selected_frame (struct device *d, Lisp_Object frame)
|
|
286 {
|
|
287 if (!NILP (frame) && !FRAME_MINIBUF_ONLY_P (XFRAME (frame)))
|
|
288 set_console_last_nonminibuf_frame (XCONSOLE (DEVICE_CONSOLE (d)), frame);
|
|
289 d->_selected_frame = frame;
|
|
290 }
|
|
291
|
20
|
292 DEFUN ("set-device-selected-frame", Fset_device_selected_frame, 2, 2, 0, /*
|
0
|
293 Set the selected frame of device object DEVICE to FRAME.
|
|
294 If DEVICE is nil, the selected device is used.
|
|
295 If DEVICE is the selected device, this makes FRAME the selected frame.
|
20
|
296 */
|
|
297 (device, frame))
|
0
|
298 {
|
272
|
299 XSETDEVICE (device, decode_device (device));
|
0
|
300 CHECK_LIVE_FRAME (frame);
|
|
301
|
|
302 if (! EQ (device, FRAME_DEVICE (XFRAME (frame))))
|
|
303 error ("In `set-device-selected-frame', FRAME is not on DEVICE");
|
|
304
|
|
305 if (EQ (device, Fselected_device (Qnil)))
|
|
306 return Fselect_frame (frame);
|
|
307
|
|
308 set_device_selected_frame (XDEVICE (device), frame);
|
|
309 return frame;
|
|
310 }
|
|
311
|
20
|
312 DEFUN ("devicep", Fdevicep, 1, 1, 0, /*
|
0
|
313 Return non-nil if OBJECT is a device.
|
20
|
314 */
|
|
315 (object))
|
0
|
316 {
|
185
|
317 return DEVICEP (object) ? Qt : Qnil;
|
0
|
318 }
|
|
319
|
20
|
320 DEFUN ("device-live-p", Fdevice_live_p, 1, 1, 0, /*
|
0
|
321 Return non-nil if OBJECT is a device that has not been deleted.
|
20
|
322 */
|
|
323 (object))
|
0
|
324 {
|
185
|
325 return DEVICEP (object) && DEVICE_LIVE_P (XDEVICE (object)) ? Qt : Qnil;
|
0
|
326 }
|
|
327
|
20
|
328 DEFUN ("device-name", Fdevice_name, 0, 1, 0, /*
|
0
|
329 Return the name of the specified device.
|
|
330 DEVICE defaults to the selected device if omitted.
|
20
|
331 */
|
|
332 (device))
|
0
|
333 {
|
|
334 return DEVICE_NAME (decode_device (device));
|
|
335 }
|
|
336
|
20
|
337 DEFUN ("device-connection", Fdevice_connection, 0, 1, 0, /*
|
0
|
338 Return the connection of the specified device.
|
|
339 DEVICE defaults to the selected device if omitted.
|
20
|
340 */
|
|
341 (device))
|
0
|
342 {
|
|
343 return DEVICE_CONNECTION (decode_device (device));
|
|
344 }
|
|
345
|
20
|
346 DEFUN ("device-console", Fdevice_console, 0, 1, 0, /*
|
0
|
347 Return the console of the specified device.
|
|
348 DEVICE defaults to the selected device if omitted.
|
20
|
349 */
|
|
350 (device))
|
0
|
351 {
|
|
352 return DEVICE_CONSOLE (decode_device (device));
|
|
353 }
|
|
354
|
263
|
355 #ifdef HAVE_WINDOW_SYSTEM
|
0
|
356
|
|
357 static void
|
|
358 init_global_resources (struct device *d)
|
|
359 {
|
|
360 init_global_faces (d);
|
|
361 #ifdef HAVE_SCROLLBARS
|
|
362 init_global_scrollbars (d);
|
|
363 #endif
|
|
364 #ifdef HAVE_TOOLBARS
|
|
365 init_global_toolbars (d);
|
|
366 #endif
|
|
367 }
|
|
368
|
|
369 #endif
|
|
370
|
|
371 static void
|
|
372 init_device_resources (struct device *d)
|
|
373 {
|
|
374 init_device_faces (d);
|
|
375 #ifdef HAVE_SCROLLBARS
|
|
376 init_device_scrollbars (d);
|
|
377 #endif
|
|
378 #ifdef HAVE_TOOLBARS
|
|
379 init_device_toolbars (d);
|
|
380 #endif
|
|
381 }
|
|
382
|
|
383 static Lisp_Object
|
|
384 semi_canonicalize_device_connection (struct console_methods *meths,
|
|
385 Lisp_Object name, Error_behavior errb)
|
|
386 {
|
|
387 return CONTYPE_METH_OR_GIVEN (meths, semi_canonicalize_device_connection,
|
|
388 (name, errb), name);
|
|
389 }
|
|
390
|
|
391 static Lisp_Object
|
|
392 canonicalize_device_connection (struct console_methods *meths,
|
|
393 Lisp_Object name, Error_behavior errb)
|
|
394 {
|
|
395 return CONTYPE_METH_OR_GIVEN (meths, canonicalize_device_connection,
|
|
396 (name, errb), name);
|
|
397 }
|
|
398
|
|
399 static Lisp_Object
|
|
400 find_device_of_type (struct console_methods *meths, Lisp_Object canon)
|
|
401 {
|
|
402 Lisp_Object devcons, concons;
|
|
403
|
|
404 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
405 {
|
|
406 Lisp_Object device = XCAR (devcons);
|
|
407
|
|
408 if (EQ (CONMETH_TYPE (meths), DEVICE_TYPE (XDEVICE (device)))
|
195
|
409 && internal_equal (DEVICE_CANON_CONNECTION (XDEVICE (device)),
|
|
410 canon, 0))
|
0
|
411 return device;
|
|
412 }
|
|
413
|
|
414 return Qnil;
|
|
415 }
|
|
416
|
20
|
417 DEFUN ("find-device", Ffind_device, 1, 2, 0, /*
|
0
|
418 Look for an existing device attached to connection CONNECTION.
|
|
419 Return the device if found; otherwise, return nil.
|
|
420
|
|
421 If TYPE is specified, only return devices of that type; otherwise,
|
|
422 return devices of any type. (It is possible, although unlikely,
|
|
423 that two devices of different types could have the same connection
|
|
424 name; in such a case, the first device found is returned.)
|
20
|
425 */
|
|
426 (connection, type))
|
0
|
427 {
|
|
428 Lisp_Object canon = Qnil;
|
|
429 struct gcpro gcpro1;
|
|
430
|
|
431 GCPRO1 (canon);
|
|
432
|
|
433 if (!NILP (type))
|
|
434 {
|
|
435 struct console_methods *conmeths = decode_console_type (type, ERROR_ME);
|
|
436 canon = canonicalize_device_connection (conmeths, connection,
|
|
437 ERROR_ME_NOT);
|
|
438 if (UNBOUNDP (canon))
|
|
439 RETURN_UNGCPRO (Qnil);
|
|
440
|
|
441 RETURN_UNGCPRO (find_device_of_type (conmeths, canon));
|
|
442 }
|
|
443 else
|
|
444 {
|
|
445 int i;
|
|
446
|
|
447 for (i = 0; i < Dynarr_length (the_console_type_entry_dynarr); i++)
|
|
448 {
|
|
449 struct console_methods *conmeths =
|
|
450 Dynarr_at (the_console_type_entry_dynarr, i).meths;
|
|
451 canon = canonicalize_device_connection (conmeths, connection,
|
|
452 ERROR_ME_NOT);
|
|
453 if (!UNBOUNDP (canon))
|
|
454 {
|
|
455 Lisp_Object device = find_device_of_type (conmeths, canon);
|
|
456 if (!NILP (device))
|
|
457 RETURN_UNGCPRO (device);
|
|
458 }
|
|
459 }
|
|
460
|
|
461 RETURN_UNGCPRO (Qnil);
|
|
462 }
|
|
463 }
|
|
464
|
20
|
465 DEFUN ("get-device", Fget_device, 1, 2, 0, /*
|
0
|
466 Look for an existing device attached to connection CONNECTION.
|
|
467 Return the device if found; otherwise, signal an error.
|
|
468
|
|
469 If TYPE is specified, only return devices of that type; otherwise,
|
|
470 return devices of any type. (It is possible, although unlikely,
|
|
471 that two devices of different types could have the same connection
|
|
472 name; in such a case, the first device found is returned.)
|
20
|
473 */
|
|
474 (connection, type))
|
0
|
475 {
|
|
476 Lisp_Object device = Ffind_device (connection, type);
|
|
477 if (NILP (device))
|
|
478 {
|
|
479 if (NILP (type))
|
|
480 signal_simple_error ("No such device", connection);
|
|
481 else
|
|
482 signal_simple_error_2 ("No such device", type, connection);
|
|
483 }
|
|
484 return device;
|
|
485 }
|
|
486
|
155
|
487 static Lisp_Object
|
272
|
488 delete_deviceless_console (Lisp_Object console)
|
155
|
489 {
|
|
490 if (NILP (XCONSOLE (console)->device_list))
|
185
|
491 Fdelete_console (console, Qnil);
|
155
|
492 return Qnil;
|
|
493 }
|
|
494
|
20
|
495 DEFUN ("make-device", Fmake_device, 2, 3, 0, /*
|
272
|
496 Return a new device of type TYPE, attached to connection CONNECTION.
|
0
|
497
|
|
498 The valid values for CONNECTION are device-specific; however,
|
|
499 CONNECTION is generally a string. (Specifically, for X devices,
|
|
500 CONNECTION should be a display specification such as "foo:0", and
|
|
501 for TTY devices, CONNECTION should be the filename of a TTY device
|
|
502 file, such as "/dev/ttyp4", or nil to refer to XEmacs' standard
|
|
503 input/output.)
|
|
504
|
|
505 PROPS, if specified, should be a plist of properties controlling
|
|
506 device creation.
|
|
507
|
|
508 If CONNECTION specifies an already-existing device connection, that
|
|
509 device is simply returned; no new device is created, and PROPS
|
|
510 have no effect.
|
20
|
511 */
|
|
512 (type, connection, props))
|
0
|
513 {
|
|
514 /* This function can GC */
|
|
515 struct device *d;
|
|
516 struct console *con;
|
|
517 Lisp_Object device = Qnil;
|
|
518 Lisp_Object console = Qnil;
|
|
519 Lisp_Object name = Qnil;
|
|
520 struct console_methods *conmeths;
|
155
|
521 int speccount = specpdl_depth();
|
0
|
522
|
|
523 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
524 #ifdef HAVE_X_WINDOWS
|
|
525 /* #### icky-poo. If this is the first X device we are creating,
|
|
526 then retrieve the global face resources. We have to do it
|
|
527 here, at the same time as (or just before) the device face
|
|
528 resources are retrieved; specifically, it needs to be done
|
|
529 after the device has been created but before any frames have
|
|
530 been popped up or much anything else has been done. It's
|
|
531 possible for other devices to specify different global
|
|
532 resources (there's a property on each X server's root window
|
|
533 that holds some resources); tough luck for the moment.
|
|
534
|
|
535 This is a nasty violation of device independence, but
|
|
536 there's not a whole lot I can figure out to do about it.
|
|
537 The real problem is that the concept of resources is not
|
|
538 generalized away from X. Similar resource-related
|
|
539 device-independence violations occur in faces.el. */
|
|
540 int first_x_device = NILP (Vdefault_x_device) && EQ (type, Qx);
|
|
541 #endif
|
|
542
|
|
543 GCPRO3 (device, console, name);
|
|
544
|
|
545 conmeths = decode_console_type (type, ERROR_ME_NOT);
|
|
546 if (!conmeths)
|
|
547 signal_simple_error ("Invalid device type", type);
|
|
548
|
|
549 device = Ffind_device (connection, type);
|
|
550 if (!NILP (device))
|
|
551 RETURN_UNGCPRO (device);
|
|
552
|
|
553 name = Fplist_get (props, Qname, Qnil);
|
|
554
|
|
555 {
|
|
556 Lisp_Object conconnect =
|
272
|
557 (HAS_CONTYPE_METH_P (conmeths, device_to_console_connection)) ?
|
|
558 CONTYPE_METH (conmeths, device_to_console_connection,
|
|
559 (connection, ERROR_ME)) :
|
|
560 connection;
|
0
|
561 console = create_console (name, type, conconnect, props);
|
|
562 }
|
|
563
|
155
|
564 record_unwind_protect(delete_deviceless_console, console);
|
|
565
|
0
|
566 con = XCONSOLE (console);
|
|
567 d = allocate_device (console);
|
|
568 XSETDEVICE (device, d);
|
|
569
|
|
570 d->devmeths = con->conmeths;
|
|
571
|
|
572 DEVICE_NAME (d) = name;
|
272
|
573 DEVICE_CONNECTION (d) =
|
|
574 semi_canonicalize_device_connection (conmeths, connection, ERROR_ME);
|
|
575 DEVICE_CANON_CONNECTION (d) =
|
|
576 canonicalize_device_connection (conmeths, connection, ERROR_ME);
|
0
|
577
|
|
578 MAYBE_DEVMETH (d, init_device, (d, props));
|
|
579
|
|
580 /* Do it this way so that the device list is in order of creation */
|
|
581 con->device_list = nconc2 (con->device_list, Fcons (device, Qnil));
|
|
582 RESET_CHANGED_SET_FLAGS;
|
|
583 if (NILP (Vdefault_device) || DEVICE_STREAM_P (XDEVICE (Vdefault_device)))
|
|
584 Vdefault_device = device;
|
|
585
|
|
586 init_device_sound (d);
|
|
587 #ifdef HAVE_X_WINDOWS
|
|
588 if (first_x_device)
|
|
589 init_global_resources (d);
|
|
590 #endif
|
|
591 init_device_resources (d);
|
|
592
|
|
593 MAYBE_DEVMETH (d, finish_init_device, (d, props));
|
|
594
|
|
595 /* If this is the first device on the console, make it the selected one. */
|
|
596 if (NILP (CONSOLE_SELECTED_DEVICE (con)))
|
|
597 CONSOLE_SELECTED_DEVICE (con) = device;
|
|
598
|
|
599 /* #### the following should trap errors. */
|
|
600 setup_device_initial_specifier_tags (d);
|
|
601
|
|
602 UNGCPRO;
|
155
|
603 unbind_to(speccount, Qnil);
|
0
|
604 return device;
|
|
605 }
|
|
606
|
|
607 /* find a device other than the selected one. Prefer non-stream
|
|
608 devices over stream devices. Maybe stay on the same console. */
|
|
609
|
|
610 static Lisp_Object
|
|
611 find_other_device (Lisp_Object device, int on_same_console)
|
|
612 {
|
272
|
613 Lisp_Object devcons = Qnil, concons;
|
0
|
614 Lisp_Object console = DEVICE_CONSOLE (XDEVICE (device));
|
|
615
|
|
616 /* look for a non-stream device */
|
|
617 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
618 {
|
|
619 Lisp_Object dev = XCAR (devcons);
|
|
620 if (on_same_console && !EQ (console, DEVICE_CONSOLE (XDEVICE (dev))))
|
|
621 continue;
|
|
622 if (!DEVICE_STREAM_P (XDEVICE (dev)) && !EQ (dev, device) &&
|
|
623 !NILP (DEVICE_SELECTED_FRAME (XDEVICE (dev))))
|
|
624 goto double_break_1;
|
|
625 }
|
|
626
|
|
627 double_break_1:
|
|
628 if (!NILP (devcons))
|
|
629 return XCAR (devcons);
|
|
630
|
|
631 /* OK, now look for a stream device */
|
|
632 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
633 {
|
|
634 Lisp_Object dev = XCAR (devcons);
|
|
635 if (on_same_console && !EQ (console, DEVICE_CONSOLE (XDEVICE (dev))))
|
|
636 continue;
|
|
637 if (!EQ (dev, device) && !NILP (DEVICE_SELECTED_FRAME (XDEVICE (dev))))
|
|
638 goto double_break_2;
|
|
639 }
|
|
640 double_break_2:
|
|
641 if (!NILP (devcons))
|
|
642 return XCAR (devcons);
|
|
643
|
|
644 /* Sorry, there ain't none */
|
|
645 return Qnil;
|
|
646 }
|
|
647
|
|
648 static int
|
|
649 find_nonminibuffer_frame_not_on_device_predicate (Lisp_Object frame,
|
|
650 void *closure)
|
|
651 {
|
|
652 Lisp_Object device;
|
|
653
|
|
654 VOID_TO_LISP (device, closure);
|
|
655 if (FRAME_MINIBUF_ONLY_P (XFRAME (frame)))
|
|
656 return 0;
|
|
657 if (EQ (device, FRAME_DEVICE (XFRAME (frame))))
|
|
658 return 0;
|
|
659 return 1;
|
|
660 }
|
|
661
|
|
662 Lisp_Object
|
|
663 find_nonminibuffer_frame_not_on_device (Lisp_Object device)
|
|
664 {
|
|
665 return find_some_frame (find_nonminibuffer_frame_not_on_device_predicate,
|
|
666 LISP_TO_VOID (device));
|
|
667 }
|
|
668
|
|
669
|
|
670 /* Delete device D.
|
|
671
|
|
672 If FORCE is non-zero, allow deletion of the only frame.
|
|
673
|
|
674 If CALLED_FROM_DELETE_CONSOLE is non-zero, then, if
|
|
675 deleting the last device on a console, just delete it,
|
|
676 instead of calling `delete-console'.
|
|
677
|
|
678 If FROM_IO_ERROR is non-zero, then the device is gone due
|
|
679 to an I/O error. This affects what happens if we exit
|
|
680 (we do an emergency exit instead of `save-buffers-kill-emacs'.)
|
|
681 */
|
|
682
|
|
683 void
|
|
684 delete_device_internal (struct device *d, int force,
|
|
685 int called_from_delete_console,
|
|
686 int from_io_error)
|
|
687 {
|
|
688 /* This function can GC */
|
|
689 struct console *c;
|
272
|
690 Lisp_Object device;
|
0
|
691 struct gcpro gcpro1;
|
|
692
|
|
693 /* OK to delete an already-deleted device. */
|
|
694 if (!DEVICE_LIVE_P (d))
|
|
695 return;
|
|
696
|
|
697 XSETDEVICE (device, d);
|
|
698 GCPRO1 (device);
|
|
699
|
|
700 c = XCONSOLE (DEVICE_CONSOLE (d));
|
|
701
|
|
702 if (!called_from_delete_console)
|
|
703 {
|
|
704 int delete_console = 0;
|
|
705 /* If we're deleting the only device on the console,
|
|
706 delete the console. */
|
|
707 if ((XINT (Flength (CONSOLE_DEVICE_LIST (c))) == 1)
|
|
708 /* if we just created the device, it might not be listed,
|
|
709 or something ... */
|
|
710 && !NILP (memq_no_quit (device, CONSOLE_DEVICE_LIST (c))))
|
|
711 delete_console = 1;
|
|
712 /* Or if there aren't any nonminibuffer frames that would be
|
|
713 left, delete the console (this will make XEmacs exit). */
|
|
714 else if (NILP (find_nonminibuffer_frame_not_on_device (device)))
|
|
715 delete_console = 1;
|
|
716
|
|
717 if (delete_console)
|
|
718 {
|
|
719 delete_console_internal (c, force, 0, from_io_error);
|
|
720 UNGCPRO;
|
|
721 return;
|
|
722 }
|
|
723 }
|
|
724
|
|
725 reset_one_device (d);
|
|
726
|
|
727 {
|
|
728 Lisp_Object frmcons;
|
|
729
|
|
730 /* First delete all frames without their own minibuffers,
|
|
731 to avoid errors coming from attempting to delete a frame
|
|
732 that is a surrogate for another frame. */
|
|
733 DEVICE_FRAME_LOOP (frmcons, d)
|
|
734 {
|
|
735 struct frame *f = XFRAME (XCAR (frmcons));
|
|
736 /* delete_frame_internal() might do anything such as run hooks,
|
|
737 so be defensive. */
|
|
738 if (FRAME_LIVE_P (f) && !FRAME_HAS_MINIBUF_P (f))
|
|
739 delete_frame_internal (f, 1, 1, from_io_error);
|
|
740
|
|
741 if (!DEVICE_LIVE_P (d)) /* make sure the delete-*-hook didn't
|
|
742 go ahead and delete anything */
|
|
743 {
|
|
744 UNGCPRO;
|
|
745 return;
|
|
746 }
|
|
747 }
|
|
748
|
|
749 /* #### This should probably be a device method but it is time for
|
|
750 19.14 to go out the door. */
|
|
751 #ifdef HAVE_X_WINDOWS
|
|
752 /* Next delete all frames which have the popup property to avoid
|
|
753 deleting a child after its parent. */
|
|
754 DEVICE_FRAME_LOOP (frmcons, d)
|
|
755 {
|
|
756 struct frame *f = XFRAME (XCAR (frmcons));
|
|
757
|
|
758 if (FRAME_LIVE_P (f))
|
|
759 {
|
|
760 Lisp_Object popup = Fframe_property (XCAR (frmcons), Qpopup, Qnil);
|
|
761 if (!NILP (popup))
|
|
762 delete_frame_internal (f, 1, 1, from_io_error);
|
|
763
|
|
764 if (!DEVICE_LIVE_P (d)) /* make sure the delete-*-hook didn't
|
|
765 go ahead and delete anything */
|
|
766 {
|
|
767 UNGCPRO;
|
|
768 return;
|
|
769 }
|
|
770 }
|
|
771 }
|
|
772 #endif /* HAVE_X_WINDOWS */
|
|
773
|
|
774 DEVICE_FRAME_LOOP (frmcons, d)
|
|
775 {
|
|
776 struct frame *f = XFRAME (XCAR (frmcons));
|
|
777 /* delete_frame_internal() might do anything such as run hooks,
|
|
778 so be defensive. */
|
|
779 if (FRAME_LIVE_P (f))
|
|
780 delete_frame_internal (f, 1, 1, from_io_error);
|
|
781
|
|
782 if (!DEVICE_LIVE_P (d)) /* make sure the delete-*-hook didn't
|
|
783 go ahead and delete anything */
|
|
784 {
|
|
785 UNGCPRO;
|
|
786 return;
|
|
787 }
|
|
788 }
|
|
789 }
|
|
790
|
|
791 set_device_selected_frame (d, Qnil);
|
|
792
|
|
793 /* try to select another device */
|
|
794
|
|
795 if (EQ (device, Fselected_device (DEVICE_CONSOLE (d))))
|
|
796 {
|
|
797 Lisp_Object other_dev = find_other_device (device, 1);
|
|
798 if (!NILP (other_dev))
|
|
799 Fselect_device (other_dev);
|
|
800 }
|
|
801
|
|
802 if (EQ (device, Vdefault_device))
|
|
803 Vdefault_device = find_other_device (device, 0);
|
|
804
|
|
805 MAYBE_DEVMETH (d, delete_device, (d));
|
|
806
|
|
807 CONSOLE_DEVICE_LIST (c) = delq_no_quit (device, CONSOLE_DEVICE_LIST (c));
|
|
808 RESET_CHANGED_SET_FLAGS;
|
|
809 d->devmeths = dead_console_methods;
|
|
810 UNGCPRO;
|
|
811 }
|
|
812
|
|
813 /* delete a device as a result of an I/O error. Called from
|
|
814 an enqueued magic-eval event. */
|
|
815
|
|
816 void
|
|
817 io_error_delete_device (Lisp_Object device)
|
|
818 {
|
|
819 delete_device_internal (XDEVICE (device), 1, 0, 1);
|
|
820 }
|
|
821
|
20
|
822 DEFUN ("delete-device", Fdelete_device, 1, 2, 0, /*
|
0
|
823 Delete DEVICE, permanently eliminating it from use.
|
|
824 Normally, you cannot delete the last non-minibuffer-only frame (you must
|
|
825 use `save-buffers-kill-emacs' or `kill-emacs'). However, if optional
|
|
826 second argument FORCE is non-nil, you can delete the last frame. (This
|
|
827 will automatically call `save-buffers-kill-emacs'.)
|
20
|
828 */
|
|
829 (device, force))
|
0
|
830 {
|
|
831 CHECK_DEVICE (device);
|
|
832 delete_device_internal (XDEVICE (device), !NILP (force), 0, 0);
|
|
833 return Qnil;
|
|
834 }
|
|
835
|
20
|
836 DEFUN ("device-frame-list", Fdevice_frame_list, 0, 1, 0, /*
|
0
|
837 Return a list of all frames on DEVICE.
|
|
838 If DEVICE is nil, the selected device will be used.
|
20
|
839 */
|
|
840 (device))
|
0
|
841 {
|
|
842 return Fcopy_sequence (DEVICE_FRAME_LIST (decode_device (device)));
|
|
843 }
|
|
844
|
20
|
845 DEFUN ("device-class", Fdevice_class, 0, 1, 0, /*
|
0
|
846 Return the class (color behavior) of DEVICE.
|
|
847 This will be one of 'color, 'grayscale, or 'mono.
|
20
|
848 */
|
|
849 (device))
|
0
|
850 {
|
|
851 return DEVICE_CLASS (decode_device (device));
|
|
852 }
|
|
853
|
20
|
854 DEFUN ("set-device-class", Fset_device_class, 2, 2, 0, /*
|
0
|
855 Set the class (color behavior) of DEVICE.
|
|
856 CLASS should be one of 'color, 'grayscale, or 'mono.
|
|
857 This is only allowed on device such as TTY devices, where the color
|
|
858 behavior cannot necessarily be determined automatically.
|
20
|
859 */
|
|
860 (device, class))
|
0
|
861 {
|
|
862 struct device *d = decode_device (device);
|
|
863 XSETDEVICE (device, d);
|
|
864 if (!DEVICE_TTY_P (d))
|
|
865 signal_simple_error ("Cannot change the class of this device", device);
|
|
866 if (!EQ (class, Qcolor) && !EQ (class, Qmono) && !EQ (class, Qgrayscale))
|
|
867 signal_simple_error ("Must be color, mono, or grayscale", class);
|
272
|
868 if (! EQ (DEVICE_CLASS (d), class))
|
|
869 {
|
|
870 Lisp_Object frmcons;
|
|
871 DEVICE_CLASS (d) = class;
|
|
872 DEVICE_FRAME_LOOP (frmcons, d)
|
|
873 {
|
|
874 struct frame *f = XFRAME (XCAR (frmcons));
|
|
875
|
|
876 recompute_all_cached_specifiers_in_frame (f);
|
|
877 MARK_FRAME_FACES_CHANGED (f);
|
|
878 MARK_FRAME_GLYPHS_CHANGED (f);
|
|
879 MARK_FRAME_TOOLBARS_CHANGED (f);
|
|
880 f->menubar_changed = 1;
|
|
881 }
|
|
882 }
|
0
|
883 return Qnil;
|
|
884 }
|
|
885
|
20
|
886 DEFUN ("set-device-baud-rate", Fset_device_baud_rate, 2, 2, 0, /*
|
0
|
887 Set the output baud rate of DEVICE to RATE.
|
|
888 On most systems, changing this value will affect the amount of padding
|
|
889 and other strategic decisions made during redisplay.
|
20
|
890 */
|
|
891 (device, rate))
|
0
|
892 {
|
|
893 CHECK_INT (rate);
|
|
894
|
|
895 DEVICE_BAUD_RATE (decode_device (device)) = XINT (rate);
|
|
896
|
|
897 return rate;
|
|
898 }
|
|
899
|
20
|
900 DEFUN ("device-baud-rate", Fdevice_baud_rate, 0, 1, 0, /*
|
0
|
901 Return the output baud rate of DEVICE.
|
20
|
902 */
|
|
903 (device))
|
0
|
904 {
|
|
905 return make_int (DEVICE_BAUD_RATE (decode_device (device)));
|
|
906 }
|
|
907
|
282
|
908 DEFUN ("device-system-metrics", Fdevice_system_metrics, 2, 2, 0, /*
|
|
909 Get metrics for DEVICE as provided by the system.
|
|
910
|
|
911 METRIC must be a symbol specifying requested metric. Note that
|
|
912 the metrics returned are these provided by the system internally,
|
|
913 not read from resources, so obtained from the mostly internal level.
|
|
914
|
|
915 If a metric is not provided by the system, return value is nil.
|
|
916 Boolean values are returned as zero and non-zero integers.
|
|
917
|
|
918 Metrics, by group, are:
|
|
919
|
|
920 COLORS. Colors are returned as valid color instantiators. No other
|
|
921 assumption on the returned valie should be made (i.e. it can be a
|
|
922 string on one system but a color instance on another). For colors,
|
|
923 returned value is a cons of foreground and background colors. Note
|
|
924 that if the system provides only one color of the pair, the second
|
|
925 one may be nil.
|
|
926
|
|
927 'color-default Standard window text foreground and background.
|
|
928 'color-select Selection highligh text and backgroun colors.
|
|
929 'color-balloon Ballon popup text and background colors.
|
|
930 'color-3d-face 3-D object (button, modeline) text and surface colors.
|
|
931 'color-3d-light Fore and back colors for 3-D edges facing light source.
|
|
932 'color-3d-dark Fore and back colors for 3-D edges facing away from
|
|
933 light source.
|
|
934 'color-menu Text and background for menus
|
|
935 'color-menu-high Selected menu item colors
|
|
936 'color-menu-button Menu button colors
|
|
937 'color-menu-unsel Unselectable menu item colors
|
|
938 'color-toolbar Toolbar foreground and background colors
|
|
939 'color-scrollbar Scrollbar foreground and background colors
|
|
940 'color-desktop Desktop window colors
|
|
941 'color-workspace Workspace window colors
|
|
942
|
|
943 FONTS. Fonts are returned as valid font instantiators. No other
|
|
944 assumption on the returned value should be made (i.e. it can be a
|
|
945 string on one system but font instance on another).
|
|
946
|
|
947 'font-default Default fixed width font.
|
|
948 'font-menubar Menubar font
|
|
949 'font-dialog Dialog boxes font
|
|
950
|
|
951 GEOMETRY. These metrics are returned as conses of (X . Y). As with colors,
|
|
952 either car or cdr of the cons may be nil if the system does not provide one
|
|
953 of corresponding dimensions.
|
|
954 'size-cursor Mouse cursor size.
|
|
955 'size-scrollbar Scrollbars (WIDTH . HEIGHT)
|
|
956 'size-menu Menubar height, as (nil . HEIGHT)
|
|
957 'size-toolbar Toolbar width and height.
|
|
958 'size-tbbutton Toolbar button size.
|
|
959 'size-tbborder Toolbar border width and height.
|
|
960 'size-icon Icon dimensions.
|
|
961 'size-icon-small Small icon dimensions.
|
|
962 'size-device Device screen size in pixels.
|
|
963 'size-workspace Workspace size in pixels. This can be less than the above
|
|
964 if window manager has decorations which effectively shrink
|
|
965 the area remaining for application windows.
|
|
966 'size-device-mm Device screen size in millimeters.
|
|
967 'device-dpi Device resolution, in dots per inch.
|
|
968
|
|
969 'num-bit-planes Integer, number of deive bit planes.
|
|
970 'num-color-cells Integer, number of device color cells.
|
|
971
|
|
972 FEATURES. This group reports various device features. Boolean values retuned
|
|
973 as integer 1 for true and zero for false, or nil if the feature is unknown
|
|
974 for the system.
|
|
975
|
|
976 'mouse-buttons Number of mouse buttons, or zero if no mouse (integer).
|
|
977 'swap-buttons Non-zero if left and right mouse buttons are swapped
|
|
978 'show-sounds User preference for visual over audible bell (boolean).
|
|
979 'slow-device Device is slow, avoid animation (boolean).
|
|
980 'security Non-zero if user environment is secure.
|
|
981 'dbcs Window system supports DBCS (boolean).
|
|
982 'ime Device embeds an input method editor (boolean).
|
|
983 'mid-east Non-zero if the window system is enabled for Hebrew
|
|
984 and Arabic (left-to-right reading) languages.
|
|
985 */
|
|
986 (device, metric))
|
|
987 {
|
|
988 struct device *d = decode_device (device);
|
|
989 enum device_metrics m;
|
|
990
|
|
991 /* Decode metric */
|
|
992 if (EQ (metric, Qcolor_default)) m = color_default;
|
|
993 else if (EQ (metric, Qcolor_select)) m = color_select;
|
|
994 else if (EQ (metric, Qcolor_balloon)) m = color_balloon;
|
|
995 else if (EQ (metric, Qcolor_3d_face)) m = color_3d_face;
|
|
996 else if (EQ (metric, Qcolor_3d_light)) m = color_3d_light;
|
|
997 else if (EQ (metric, Qcolor_3d_dark)) m = color_3d_dark;
|
|
998 else if (EQ (metric, Qcolor_menu)) m = color_menu;
|
|
999 else if (EQ (metric, Qcolor_menu_high)) m = color_menu_high;
|
|
1000 else if (EQ (metric, Qcolor_menu_button)) m = color_menu_button;
|
|
1001 else if (EQ (metric, Qcolor_menu_unsel)) m = color_menu_unsel;
|
|
1002 else if (EQ (metric, Qcolor_toolbar)) m = color_toolbar;
|
|
1003 else if (EQ (metric, Qcolor_scrollbar)) m = color_scrollbar;
|
|
1004 else if (EQ (metric, Qcolor_desktop)) m = color_desktop;
|
|
1005 else if (EQ (metric, Qcolor_workspace)) m = color_workspace;
|
|
1006 else if (EQ (metric, Qfont_default)) m = font_default;
|
|
1007 else if (EQ (metric, Qfont_menubar)) m = font_menubar;
|
|
1008 else if (EQ (metric, Qfont_dialog)) m = font_dialog;
|
|
1009 else if (EQ (metric, Qsize_cursor)) m = size_cursor;
|
|
1010 else if (EQ (metric, Qsize_scrollbar)) m = size_scrollbar;
|
|
1011 else if (EQ (metric, Qsize_menu)) m = size_menu;
|
|
1012 else if (EQ (metric, Qsize_toolbar)) m = size_toolbar;
|
|
1013 else if (EQ (metric, Qsize_tbbutton)) m = size_tbbutton;
|
|
1014 else if (EQ (metric, Qsize_tbborder)) m = size_tbborder;
|
|
1015 else if (EQ (metric, Qsize_icon)) m = size_icon;
|
|
1016 else if (EQ (metric, Qsize_icon_small)) m = size_icon_small;
|
|
1017 else if (EQ (metric, Qsize_device)) m = size_device;
|
|
1018 else if (EQ (metric, Qsize_workspace)) m = size_workspace;
|
|
1019 else if (EQ (metric, Qsize_device_mm)) m = size_device_mm;
|
|
1020 else if (EQ (metric, Qdevice_dpi)) m = device_dpi;
|
|
1021 else if (EQ (metric, Qnum_bit_planes)) m = num_bit_planes;
|
|
1022 else if (EQ (metric, Qnum_color_cells)) m = num_color_cells;
|
|
1023 else if (EQ (metric, Qmouse_buttons)) m = mouse_buttons;
|
|
1024 else if (EQ (metric, Qswap_buttons)) m = swap_buttons;
|
|
1025 else if (EQ (metric, Qshow_sounds)) m = show_sounds;
|
|
1026 else if (EQ (metric, Qslow_device)) m = slow_device;
|
|
1027 else if (EQ (metric, Qsecurity)) m = security;
|
|
1028 else if (EQ (metric, Qdbcs)) m = dbcs;
|
|
1029 else if (EQ (metric, Qime)) m = ime;
|
|
1030 else if (EQ (metric, Qmid_east)) m = mid_east;
|
|
1031 else
|
|
1032 signal_simple_error ("Invalid device metric symbol", metric);
|
|
1033
|
|
1034 return DEVMETH_OR_GIVEN (d, device_system_metrics, (d, m), Qnil);
|
|
1035 }
|
|
1036
|
269
|
1037 Lisp_Object
|
|
1038 domain_device_type (Lisp_Object domain)
|
|
1039 {
|
|
1040 /* This cannot GC */
|
|
1041 assert (WINDOWP (domain) || FRAMEP (domain)
|
|
1042 || DEVICEP (domain) || CONSOLEP (domain));
|
|
1043
|
|
1044 if (WINDOWP (domain))
|
|
1045 {
|
|
1046 if (!WINDOW_LIVE_P (XWINDOW (domain)))
|
|
1047 return Qdead;
|
|
1048 domain = WINDOW_FRAME (XWINDOW (domain));
|
|
1049 }
|
|
1050 if (FRAMEP (domain))
|
|
1051 {
|
|
1052 if (!FRAME_LIVE_P (XFRAME (domain)))
|
|
1053 return Qdead;
|
|
1054 domain = FRAME_DEVICE (XFRAME (domain));
|
|
1055 }
|
|
1056 if (DEVICEP (domain))
|
|
1057 {
|
|
1058 if (!DEVICE_LIVE_P (XDEVICE (domain)))
|
|
1059 return Qdead;
|
|
1060 domain = DEVICE_CONSOLE (XDEVICE (domain));
|
|
1061 }
|
|
1062 return CONSOLE_TYPE (XCONSOLE (domain));
|
|
1063 }
|
|
1064
|
|
1065 /*
|
|
1066 * Determine whether window system bases window geometry on character
|
|
1067 * or pixel counts.
|
|
1068 * Return non-zero for pixel-based geometry, zero for character-based.
|
|
1069 */
|
|
1070 int
|
|
1071 window_system_pixelated_geometry (Lisp_Object domain)
|
|
1072 {
|
|
1073 /* This cannot GC */
|
|
1074 Lisp_Object winsy = domain_device_type (domain);
|
|
1075 struct console_methods *meth = decode_console_type (winsy, ERROR_ME_NOT);
|
|
1076 assert (meth);
|
|
1077 return (MAYBE_INT_CONTYPE_METH (meth, device_implementation_flags, ())
|
|
1078 & XDEVIMPF_PIXEL_GEOMETRY);
|
|
1079 }
|
|
1080
|
|
1081 DEFUN ("domain-device-type", Fdomain_device_type, 0, 1, 0, /*
|
|
1082 Return the device type symbol for a DOMAIN, e.g. 'x or 'tty.
|
|
1083 DOMAIN can be either a window, frame, device or console.
|
|
1084 */
|
|
1085 (domain))
|
|
1086 {
|
|
1087 if (!WINDOWP (domain) && !FRAMEP (domain)
|
|
1088 && !DEVICEP (domain) && !CONSOLEP (domain))
|
|
1089 signal_simple_error
|
|
1090 ("Domain must be either a window, frame, device or console", domain);
|
|
1091
|
|
1092 return domain_device_type (domain);
|
|
1093 }
|
|
1094
|
0
|
1095 void
|
|
1096 handle_asynch_device_change (void)
|
|
1097 {
|
|
1098 int i;
|
|
1099 int old_asynch_device_change_pending = asynch_device_change_pending;
|
|
1100 for (i = 0; i < Dynarr_length (the_console_type_entry_dynarr); i++)
|
|
1101 {
|
|
1102 if (Dynarr_at (the_console_type_entry_dynarr, i).meths->
|
|
1103 asynch_device_change_method)
|
|
1104 (Dynarr_at (the_console_type_entry_dynarr, i).meths->
|
|
1105 asynch_device_change_method) ();
|
|
1106 }
|
|
1107 /* reset the flag to 0 unless another notification occurred while
|
|
1108 we were processing this one. Block SIGWINCH during this
|
|
1109 check to prevent a possible race condition. */
|
100
|
1110 #ifndef WINDOWSNT
|
0
|
1111 EMACS_BLOCK_SIGNAL (SIGWINCH);
|
100
|
1112 #endif
|
0
|
1113 if (old_asynch_device_change_pending == asynch_device_change_pending)
|
|
1114 asynch_device_change_pending = 0;
|
100
|
1115 #ifndef WINDOWSNT
|
0
|
1116 EMACS_UNBLOCK_SIGNAL (SIGWINCH);
|
100
|
1117 #endif
|
0
|
1118 }
|
|
1119
|
|
1120 void
|
|
1121 call_critical_lisp_code (struct device *d, Lisp_Object function,
|
|
1122 Lisp_Object object)
|
|
1123 {
|
|
1124 int old_gc_currently_forbidden = gc_currently_forbidden;
|
|
1125 Lisp_Object old_inhibit_quit = Vinhibit_quit;
|
|
1126
|
|
1127 /* There's no reason to bother doing specbinds here, because if
|
|
1128 initialize-*-faces signals an error, emacs is going to crash
|
|
1129 immediately.
|
|
1130 */
|
|
1131 gc_currently_forbidden = 1;
|
|
1132 Vinhibit_quit = Qt;
|
|
1133 LOCK_DEVICE (d);
|
|
1134
|
|
1135 /* But it's useful to have an error handler; otherwise an infinite
|
|
1136 loop may result. */
|
|
1137 if (!NILP (object))
|
|
1138 call1_with_handler (Qreally_early_error_handler, function, object);
|
|
1139 else
|
|
1140 call0_with_handler (Qreally_early_error_handler, function);
|
185
|
1141
|
0
|
1142 UNLOCK_DEVICE (d);
|
|
1143 Vinhibit_quit = old_inhibit_quit;
|
|
1144 gc_currently_forbidden = old_gc_currently_forbidden;
|
|
1145 }
|
|
1146
|
|
1147
|
|
1148 /************************************************************************/
|
|
1149 /* initialization */
|
|
1150 /************************************************************************/
|
|
1151
|
|
1152 void
|
|
1153 syms_of_device (void)
|
|
1154 {
|
20
|
1155 DEFSUBR (Fvalid_device_class_p);
|
|
1156 DEFSUBR (Fdevice_class_list);
|
0
|
1157
|
20
|
1158 DEFSUBR (Fdfw_device);
|
|
1159 DEFSUBR (Fselected_device);
|
|
1160 DEFSUBR (Fselect_device);
|
|
1161 DEFSUBR (Fset_device_selected_frame);
|
|
1162 DEFSUBR (Fdevicep);
|
|
1163 DEFSUBR (Fdevice_live_p);
|
|
1164 DEFSUBR (Fdevice_name);
|
|
1165 DEFSUBR (Fdevice_connection);
|
|
1166 DEFSUBR (Fdevice_console);
|
|
1167 DEFSUBR (Ffind_device);
|
|
1168 DEFSUBR (Fget_device);
|
|
1169 DEFSUBR (Fmake_device);
|
|
1170 DEFSUBR (Fdelete_device);
|
|
1171 DEFSUBR (Fdevice_frame_list);
|
|
1172 DEFSUBR (Fdevice_class);
|
|
1173 DEFSUBR (Fset_device_class);
|
282
|
1174 DEFSUBR (Fdevice_system_metrics);
|
20
|
1175 DEFSUBR (Fset_device_baud_rate);
|
|
1176 DEFSUBR (Fdevice_baud_rate);
|
269
|
1177 DEFSUBR (Fdomain_device_type);
|
0
|
1178
|
|
1179 defsymbol (&Qdevicep, "devicep");
|
|
1180 defsymbol (&Qdevice_live_p, "device-live-p");
|
|
1181 defsymbol (&Qdelete_device, "delete-device");
|
|
1182
|
|
1183 defsymbol (&Qcreate_device_hook, "create-device-hook");
|
|
1184 defsymbol (&Qdelete_device_hook, "delete-device-hook");
|
|
1185
|
|
1186 /* Qcolor defined in general.c */
|
|
1187 defsymbol (&Qgrayscale, "grayscale");
|
|
1188 defsymbol (&Qmono, "mono");
|
282
|
1189
|
|
1190 /* Device metrics symbols */
|
|
1191 defsymbol (&Qcolor_default, "color-default");
|
|
1192 defsymbol (&Qcolor_select, "color-select");
|
|
1193 defsymbol (&Qcolor_balloon, "color-balloon");
|
|
1194 defsymbol (&Qcolor_3d_face, "color-3d-face");
|
|
1195 defsymbol (&Qcolor_3d_light, "color-3d-light");
|
|
1196 defsymbol (&Qcolor_3d_dark, "color-3d-dark");
|
|
1197 defsymbol (&Qcolor_menu, "color-menu");
|
|
1198 defsymbol (&Qcolor_menu_high, "color-menu-high");
|
|
1199 defsymbol (&Qcolor_menu_button, "color-menu-button");
|
|
1200 defsymbol (&Qcolor_menu_unsel, "color-menu-unsel");
|
|
1201 defsymbol (&Qcolor_toolbar, "color-toolbar");
|
|
1202 defsymbol (&Qcolor_scrollbar, "color-scrollbar");
|
|
1203 defsymbol (&Qcolor_desktop, "color-desktop");
|
|
1204 defsymbol (&Qcolor_workspace, "color-workspace");
|
|
1205 defsymbol (&Qfont_default, "font-default");
|
|
1206 defsymbol (&Qfont_menubar, "font-menubar");
|
|
1207 defsymbol (&Qfont_dialog, "font-dialog");
|
|
1208 defsymbol (&Qsize_cursor, "size-cursor");
|
|
1209 defsymbol (&Qsize_scrollbar, "size-scrollbar");
|
|
1210 defsymbol (&Qsize_menu, "size-menu");
|
|
1211 defsymbol (&Qsize_toolbar, "size-toolbar");
|
|
1212 defsymbol (&Qsize_tbbutton, "size-tbbutton");
|
|
1213 defsymbol (&Qsize_tbborder, "size-tbborder");
|
|
1214 defsymbol (&Qsize_icon, "size-icon");
|
|
1215 defsymbol (&Qsize_icon_small, "size-icon-small");
|
|
1216 defsymbol (&Qsize_device, "size-device");
|
|
1217 defsymbol (&Qsize_workspace, "size-workspace");
|
|
1218 defsymbol (&Qsize_device_mm, "size-device-mm");
|
|
1219 defsymbol (&Qnum_bit_planes, "num-bit-planes");
|
|
1220 defsymbol (&Qnum_color_cells, "num-color-cells");
|
|
1221 defsymbol (&Qdevice_dpi, "device-dpi");
|
|
1222 defsymbol (&Qmouse_buttons, "mouse-buttons");
|
|
1223 defsymbol (&Qswap_buttons, "swap-buttons");
|
|
1224 defsymbol (&Qshow_sounds, "show-sounds");
|
|
1225 defsymbol (&Qslow_device, "slow-device");
|
|
1226 defsymbol (&Qsecurity, "security");
|
|
1227 defsymbol (&Qdbcs, "dbcs");
|
|
1228 defsymbol (&Qime, "ime");
|
|
1229 defsymbol (&Qmid_east, "mid-east");
|
0
|
1230 }
|
|
1231
|
|
1232 void
|
|
1233 vars_of_device (void)
|
|
1234 {
|
|
1235 DEFVAR_LISP ("create-device-hook", &Vcreate_device_hook /*
|
|
1236 Function or functions to call when a device is created.
|
|
1237 One argument, the newly-created device.
|
|
1238 This is called after the first frame has been created, but before
|
|
1239 calling the `create-frame-hook'.
|
|
1240 Note that in general the device will not be selected.
|
|
1241 */ );
|
|
1242 Vcreate_device_hook = Qnil;
|
|
1243
|
|
1244 DEFVAR_LISP ("delete-device-hook", &Vdelete_device_hook /*
|
|
1245 Function or functions to call when a device is deleted.
|
|
1246 One argument, the to-be-deleted device.
|
|
1247 */ );
|
|
1248 Vdelete_device_hook = Qnil;
|
|
1249
|
|
1250 staticpro (&Vdefault_device);
|
|
1251 Vdefault_device = Qnil;
|
|
1252
|
|
1253 asynch_device_change_pending = 0;
|
|
1254
|
|
1255 Vdevice_class_list = list3 (Qcolor, Qgrayscale, Qmono);
|
|
1256 staticpro (&Vdevice_class_list);
|
229
|
1257
|
|
1258 /* Death to devices.el !!! */
|
|
1259 Fprovide(intern("devices"));
|
0
|
1260 }
|