442
|
1 /* Generic device functions.
|
428
|
2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
|
|
3 Copyright (C) 1994, 1995 Free Software Foundation, Inc.
|
853
|
4 Copyright (C) 1995, 1996, 2002 Ben Wing.
|
428
|
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
|
853
|
25 /* Written by Ben Wing, late 1995?
|
|
26 Based on prototype by Chuck Thompson.
|
|
27 device-system-metric stuff added 1998? by Kirill Katsnelson.
|
|
28 */
|
428
|
29
|
|
30 #include <config.h>
|
|
31 #include "lisp.h"
|
|
32
|
|
33 #include "buffer.h"
|
|
34 #include "console.h"
|
872
|
35 #include "device-impl.h"
|
428
|
36 #include "elhash.h"
|
|
37 #include "events.h"
|
|
38 #include "faces.h"
|
872
|
39 #include "frame-impl.h"
|
428
|
40 #include "keymap.h"
|
872
|
41 #include "objects.h"
|
428
|
42 #include "redisplay.h"
|
|
43 #include "specifier.h"
|
|
44 #include "sysdep.h"
|
800
|
45 #include "toolbar.h"
|
428
|
46 #include "window.h"
|
|
47
|
934
|
48 #ifdef USE_KKCC
|
|
49 #include "console-tty-impl.h"
|
|
50 #ifdef HAVE_MS_WINDOWS
|
|
51 #include "console-msw-impl.h"
|
|
52 #endif
|
|
53 #ifdef HAVE_X_WINDOWS
|
|
54 #include "console-x-impl.h"
|
|
55 #endif
|
|
56 #ifdef HAVE_GTK
|
|
57 #include "console-gtk-impl.h"
|
|
58 #endif
|
|
59 #endif /* USE_KKCC */
|
|
60
|
428
|
61 #ifdef HAVE_SCROLLBARS
|
|
62 #include "scrollbar.h"
|
|
63 #endif
|
|
64
|
|
65 #include "syssignal.h"
|
|
66
|
|
67 /* Vdefault_device is the firstly-created non-stream device that's still
|
|
68 around. We don't really use it anywhere currently, but it might
|
|
69 be used for resourcing at some point. (Currently we use
|
872
|
70 the default X device -- see Vdefault_device_plist.) */
|
428
|
71 Lisp_Object Vdefault_device;
|
|
72
|
|
73 Lisp_Object Vcreate_device_hook, Vdelete_device_hook;
|
|
74
|
872
|
75 static Lisp_Object Vdefault_device_plist;
|
|
76
|
428
|
77 /* Device classes */
|
|
78 /* Qcolor defined in general.c */
|
|
79 Lisp_Object Qgrayscale, Qmono;
|
|
80
|
|
81 /* Device metrics symbols */
|
|
82 Lisp_Object
|
|
83 Qcolor_default, Qcolor_select, Qcolor_balloon, Qcolor_3d_face,
|
|
84 Qcolor_3d_light, Qcolor_3d_dark, Qcolor_menu, Qcolor_menu_highlight,
|
|
85 Qcolor_menu_button, Qcolor_menu_disabled, Qcolor_toolbar,
|
|
86 Qcolor_scrollbar, Qcolor_desktop, Qcolor_workspace, Qfont_default,
|
|
87 Qfont_menubar, Qfont_dialog, Qsize_cursor, Qsize_scrollbar,
|
|
88 Qsize_menu, Qsize_toolbar, Qsize_toolbar_button,
|
|
89 Qsize_toolbar_border, Qsize_icon, Qsize_icon_small, Qsize_device,
|
440
|
90 Qsize_workspace, Qoffset_workspace, Qsize_device_mm, Qdevice_dpi,
|
|
91 Qnum_bit_planes, Qnum_color_cells, Qmouse_buttons, Qswap_buttons,
|
|
92 Qshow_sounds, Qslow_device, Qsecurity;
|
428
|
93
|
|
94 Lisp_Object Qdevicep, Qdevice_live_p;
|
|
95 Lisp_Object Qcreate_device_hook;
|
|
96 Lisp_Object Qdelete_device_hook;
|
|
97 Lisp_Object Vdevice_class_list;
|
|
98
|
|
99
|
934
|
100
|
|
101 #ifdef USE_KKCC
|
|
102
|
|
103 static const struct lrecord_description empty_devdata_description [] = {
|
|
104 { XD_END }
|
|
105 };
|
|
106
|
|
107 static const struct lrecord_description mswindows_devdata_description [] = {
|
|
108 #ifdef HAVE_MS_WINDOWS
|
|
109 { XD_LISP_OBJECT, offsetof (struct mswindows_device, fontlist) },
|
|
110 #endif
|
|
111 { XD_END }
|
|
112 };
|
|
113
|
|
114 static const struct lrecord_description gtk_devdata_description [] = {
|
|
115 #ifdef HAVE_GTK
|
|
116 { XD_LISP_OBJECT, offsetof (struct gtk_device, x_keysym_map_hash_table) },
|
|
117 { XD_LISP_OBJECT, offsetof (struct gtk_device, WM_COMMAND_frame) },
|
|
118 #endif
|
|
119 { XD_END }
|
|
120 };
|
|
121
|
|
122 static const struct lrecord_description x_devdata_description [] = {
|
|
123 #ifdef HAVE_X_WINDOWS
|
|
124 { XD_LISP_OBJECT, offsetof (struct x_device, x_keysym_map_hash_table) },
|
|
125 { XD_LISP_OBJECT, offsetof (struct x_device, WM_COMMAND_frame) },
|
|
126 #endif
|
|
127 { XD_END }
|
|
128 };
|
|
129
|
|
130 static const struct struct_description devdata_description []= {
|
|
131 { dead_console, empty_devdata_description},
|
|
132 { tty_console, empty_devdata_description},
|
|
133 { gtk_console, gtk_devdata_description},
|
|
134 { x_console, x_devdata_description},
|
|
135 { mswindows_console, mswindows_devdata_description},
|
|
136 { stream_console, empty_devdata_description},
|
|
137 { XD_END }
|
|
138 };
|
|
139
|
|
140 static const struct lrecord_description conmeths_description_1 [] = {
|
|
141 { XD_LISP_OBJECT, offsetof (struct console_methods, symbol) },
|
|
142 { XD_END }
|
|
143 };
|
|
144
|
|
145 static const struct struct_description conmeths_description = {
|
|
146 sizeof (struct console_methods),
|
|
147 conmeths_description_1
|
|
148 };
|
|
149
|
|
150 static const struct lrecord_description device_description [] = {
|
|
151 { XD_INT, offsetof (struct device, devtype) },
|
|
152 { XD_LISP_OBJECT, offsetof (struct device, name) },
|
|
153 { XD_LISP_OBJECT, offsetof (struct device, connection) },
|
|
154 { XD_LISP_OBJECT, offsetof (struct device, canon_connection) },
|
|
155 { XD_LISP_OBJECT, offsetof (struct device, frame_list) },
|
|
156 { XD_LISP_OBJECT, offsetof (struct device, console) },
|
|
157 { XD_LISP_OBJECT, offsetof (struct device, selected_frame) },
|
|
158 { XD_LISP_OBJECT, offsetof (struct device, frame_with_focus_real) },
|
|
159 { XD_LISP_OBJECT, offsetof (struct device, frame_with_focus_for_hooks) },
|
|
160 { XD_LISP_OBJECT, offsetof (struct device, frame_that_ought_to_have_focus) },
|
|
161 { XD_LISP_OBJECT, offsetof (struct device, device_class) },
|
|
162 { XD_LISP_OBJECT, offsetof (struct device, user_defined_tags) },
|
|
163 { XD_LISP_OBJECT, offsetof (struct device, color_instance_cache) },
|
|
164 { XD_LISP_OBJECT, offsetof (struct device, font_instance_cache) },
|
|
165 #ifdef MULE
|
|
166 { XD_LISP_OBJECT, offsetof (struct device, charset_font_cache_stage_1) },
|
|
167 { XD_LISP_OBJECT, offsetof (struct device, charset_font_cache_stage_2) },
|
|
168 #endif
|
|
169 { XD_LISP_OBJECT, offsetof (struct device, image_instance_cache) },
|
|
170 { XD_LISP_OBJECT, offsetof (struct device, frame_list) },
|
|
171 { XD_STRUCT_PTR, offsetof (struct device, devmeths), 1, &conmeths_description },
|
|
172 { XD_UNION, offsetof (struct device, device_data),
|
|
173 XD_INDIRECT (0, 0), devdata_description },
|
|
174 { XD_END }
|
|
175 };
|
|
176 #endif /* USE_KKCC */
|
|
177
|
428
|
178 static Lisp_Object
|
|
179 mark_device (Lisp_Object obj)
|
|
180 {
|
|
181 struct device *d = XDEVICE (obj);
|
|
182
|
617
|
183 #define MARKED_SLOT(x) mark_object (d->x)
|
|
184 #include "devslots.h"
|
428
|
185
|
|
186 if (d->devmeths)
|
|
187 {
|
|
188 mark_object (d->devmeths->symbol);
|
|
189 MAYBE_DEVMETH (d, mark_device, (d));
|
|
190 }
|
|
191
|
|
192 return (d->frame_list);
|
|
193 }
|
|
194
|
|
195 static void
|
|
196 print_device (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
197 {
|
|
198 struct device *d = XDEVICE (obj);
|
|
199
|
|
200 if (print_readably)
|
563
|
201 printing_unreadable_object ("#<device %s 0x%x>",
|
|
202 XSTRING_DATA (d->name), d->header.uid);
|
428
|
203
|
800
|
204 write_fmt_string (printcharfun, "#<%s-device", !DEVICE_LIVE_P (d) ? "dead" :
|
|
205 DEVICE_TYPE_NAME (d));
|
440
|
206 if (DEVICE_LIVE_P (d) && !NILP (DEVICE_CONNECTION (d)))
|
800
|
207 write_fmt_string_lisp (printcharfun, " on %S", 1, DEVICE_CONNECTION (d));
|
|
208 write_fmt_string (printcharfun, " 0x%x>", d->header.uid);
|
428
|
209 }
|
|
210
|
934
|
211 #ifdef USE_KKCC
|
|
212 DEFINE_LRECORD_IMPLEMENTATION ("device", device,
|
|
213 0, /*dumpable-flag*/
|
|
214 mark_device, print_device, 0, 0, 0,
|
|
215 device_description,
|
|
216 struct device);
|
|
217 #else /* not USE_KKCC */
|
428
|
218 DEFINE_LRECORD_IMPLEMENTATION ("device", device,
|
|
219 mark_device, print_device, 0, 0, 0, 0,
|
|
220 struct device);
|
934
|
221 #endif /* not USE_KKCC */
|
428
|
222
|
|
223 int
|
|
224 valid_device_class_p (Lisp_Object class)
|
|
225 {
|
|
226 return !NILP (memq_no_quit (class, Vdevice_class_list));
|
|
227 }
|
|
228
|
|
229 DEFUN ("valid-device-class-p", Fvalid_device_class_p, 1, 1, 0, /*
|
|
230 Given a DEVICE-CLASS, return t if it is valid.
|
|
231 Valid classes are 'color, 'grayscale, and 'mono.
|
|
232 */
|
|
233 (device_class))
|
|
234 {
|
|
235 return valid_device_class_p (device_class) ? Qt : Qnil;
|
|
236 }
|
|
237
|
|
238 DEFUN ("device-class-list", Fdevice_class_list, 0, 0, 0, /*
|
|
239 Return a list of valid device classes.
|
|
240 */
|
|
241 ())
|
|
242 {
|
|
243 return Fcopy_sequence (Vdevice_class_list);
|
|
244 }
|
|
245
|
617
|
246 static void
|
|
247 nuke_all_device_slots (struct device *d, Lisp_Object zap)
|
|
248 {
|
|
249 zero_lcrecord (d);
|
|
250
|
|
251 #define MARKED_SLOT(x) d->x = zap
|
|
252 #include "devslots.h"
|
|
253 }
|
|
254
|
428
|
255 static struct device *
|
|
256 allocate_device (Lisp_Object console)
|
|
257 {
|
|
258 Lisp_Object device;
|
|
259 struct device *d = alloc_lcrecord_type (struct device, &lrecord_device);
|
|
260 struct gcpro gcpro1;
|
|
261
|
853
|
262 zero_lcrecord (d);
|
|
263
|
793
|
264 device = wrap_device (d);
|
428
|
265 GCPRO1 (device);
|
|
266
|
617
|
267 nuke_all_device_slots (d, Qnil);
|
|
268
|
428
|
269 d->console = console;
|
|
270 d->infd = d->outfd = -1;
|
|
271
|
|
272 /* #### is 20 reasonable? */
|
|
273 d->color_instance_cache =
|
|
274 make_lisp_hash_table (20, HASH_TABLE_KEY_WEAK, HASH_TABLE_EQUAL);
|
|
275 d->font_instance_cache =
|
|
276 make_lisp_hash_table (20, HASH_TABLE_KEY_WEAK, HASH_TABLE_EQUAL);
|
|
277 #ifdef MULE
|
872
|
278 initialize_charset_font_caches (d);
|
428
|
279 #endif
|
|
280 /*
|
|
281 Note that the image instance cache is actually bi-level.
|
|
282 See device.h. We use a low number here because most of the
|
|
283 time there aren't very many different masks that will be used.
|
|
284 */
|
|
285 d->image_instance_cache =
|
|
286 make_lisp_hash_table (5, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
|
|
287
|
|
288 UNGCPRO;
|
|
289 return d;
|
|
290 }
|
|
291
|
|
292 struct device *
|
|
293 decode_device (Lisp_Object device)
|
|
294 {
|
|
295 if (NILP (device))
|
|
296 device = Fselected_device (Qnil);
|
|
297 /* quietly accept frames for the device arg */
|
|
298 else if (FRAMEP (device))
|
|
299 device = FRAME_DEVICE (decode_frame (device));
|
|
300 CHECK_LIVE_DEVICE (device);
|
|
301 return XDEVICE (device);
|
|
302 }
|
|
303
|
|
304 DEFUN ("dfw-device", Fdfw_device, 1, 1, 0, /*
|
|
305 Given a device, frame, or window, return the associated device.
|
|
306 Return nil otherwise.
|
|
307 */
|
444
|
308 (object))
|
428
|
309 {
|
444
|
310 return DFW_DEVICE (object);
|
428
|
311 }
|
|
312
|
872
|
313 Lisp_Object
|
|
314 device_console (struct device *d)
|
|
315 {
|
|
316 return DEVICE_CONSOLE (d);
|
|
317 }
|
|
318
|
|
319 int
|
|
320 device_live_p (struct device *d)
|
|
321 {
|
|
322 return DEVICE_LIVE_P (d);
|
|
323 }
|
|
324
|
|
325 Lisp_Object
|
|
326 device_frame_list (struct device *d)
|
|
327 {
|
|
328 return DEVICE_FRAME_LIST (d);
|
|
329 }
|
|
330
|
428
|
331
|
|
332 DEFUN ("selected-device", Fselected_device, 0, 1, 0, /*
|
|
333 Return the device which is currently active.
|
|
334 If optional CONSOLE is non-nil, return the device that would be currently
|
|
335 active if CONSOLE were the selected console.
|
|
336 */
|
|
337 (console))
|
|
338 {
|
|
339 if (NILP (console) && NILP (Vselected_console))
|
|
340 return Qnil; /* happens early in temacs */
|
|
341 return CONSOLE_SELECTED_DEVICE (decode_console (console));
|
|
342 }
|
|
343
|
|
344 /* Called from selected_frame_1(), called from Fselect_window() */
|
|
345 void
|
|
346 select_device_1 (Lisp_Object device)
|
|
347 {
|
|
348 struct device *dev = XDEVICE (device);
|
|
349 Lisp_Object old_selected_device = Fselected_device (Qnil);
|
|
350
|
|
351 if (EQ (device, old_selected_device))
|
|
352 return;
|
|
353
|
|
354 /* now select the device's console */
|
|
355 CONSOLE_SELECTED_DEVICE (XCONSOLE (DEVICE_CONSOLE (dev))) = device;
|
|
356 select_console_1 (DEVICE_CONSOLE (dev));
|
|
357 }
|
|
358
|
|
359 DEFUN ("select-device", Fselect_device, 1, 1, 0, /*
|
|
360 Select the device DEVICE.
|
|
361 Subsequent editing commands apply to its console, selected frame,
|
|
362 and selected window.
|
|
363 The selection of DEVICE lasts until the next time the user does
|
|
364 something to select a different device, or until the next time this
|
|
365 function is called.
|
|
366 */
|
|
367 (device))
|
|
368 {
|
|
369 CHECK_LIVE_DEVICE (device);
|
|
370
|
|
371 /* select the device's selected frame's selected window. This will call
|
|
372 selected_frame_1()->selected_device_1()->selected_console_1(). */
|
|
373 if (!NILP (DEVICE_SELECTED_FRAME (XDEVICE (device))))
|
|
374 Fselect_window (FRAME_SELECTED_WINDOW
|
|
375 (XFRAME (DEVICE_SELECTED_FRAME (XDEVICE (device)))),
|
|
376 Qnil);
|
|
377 else
|
563
|
378 invalid_operation ("Can't select a device with no frames", Qunbound);
|
428
|
379 return Qnil;
|
|
380 }
|
|
381
|
|
382 void
|
|
383 set_device_selected_frame (struct device *d, Lisp_Object frame)
|
|
384 {
|
|
385 if (!NILP (frame) && !FRAME_MINIBUF_ONLY_P (XFRAME (frame)))
|
|
386 set_console_last_nonminibuf_frame (XCONSOLE (DEVICE_CONSOLE (d)), frame);
|
|
387 d->selected_frame = frame;
|
|
388 }
|
|
389
|
|
390 DEFUN ("set-device-selected-frame", Fset_device_selected_frame, 2, 2, 0, /*
|
|
391 Set the selected frame of device object DEVICE to FRAME.
|
|
392 If DEVICE is nil, the selected device is used.
|
|
393 If DEVICE is the selected device, this makes FRAME the selected frame.
|
|
394 */
|
|
395 (device, frame))
|
|
396 {
|
793
|
397 device = wrap_device (decode_device (device));
|
428
|
398 CHECK_LIVE_FRAME (frame);
|
|
399
|
|
400 if (! EQ (device, FRAME_DEVICE (XFRAME (frame))))
|
617
|
401 invalid_argument ("In `set-device-selected-frame', FRAME is not on DEVICE",
|
|
402 Qunbound);
|
428
|
403
|
|
404 if (EQ (device, Fselected_device (Qnil)))
|
|
405 return Fselect_frame (frame);
|
|
406
|
|
407 set_device_selected_frame (XDEVICE (device), frame);
|
|
408 return frame;
|
|
409 }
|
|
410
|
|
411 DEFUN ("devicep", Fdevicep, 1, 1, 0, /*
|
|
412 Return non-nil if OBJECT is a device.
|
|
413 */
|
|
414 (object))
|
|
415 {
|
|
416 return DEVICEP (object) ? Qt : Qnil;
|
|
417 }
|
|
418
|
|
419 DEFUN ("device-live-p", Fdevice_live_p, 1, 1, 0, /*
|
|
420 Return non-nil if OBJECT is a device that has not been deleted.
|
|
421 */
|
|
422 (object))
|
|
423 {
|
|
424 return DEVICEP (object) && DEVICE_LIVE_P (XDEVICE (object)) ? Qt : Qnil;
|
|
425 }
|
|
426
|
|
427 DEFUN ("device-name", Fdevice_name, 0, 1, 0, /*
|
|
428 Return the name of the specified device.
|
|
429 DEVICE defaults to the selected device if omitted.
|
|
430 */
|
|
431 (device))
|
|
432 {
|
|
433 return DEVICE_NAME (decode_device (device));
|
|
434 }
|
|
435
|
|
436 DEFUN ("device-connection", Fdevice_connection, 0, 1, 0, /*
|
|
437 Return the connection of the specified device.
|
|
438 DEVICE defaults to the selected device if omitted.
|
|
439 */
|
|
440 (device))
|
|
441 {
|
|
442 return DEVICE_CONNECTION (decode_device (device));
|
|
443 }
|
|
444
|
|
445 DEFUN ("device-console", Fdevice_console, 0, 1, 0, /*
|
|
446 Return the console of the specified device.
|
|
447 DEVICE defaults to the selected device if omitted.
|
|
448 */
|
|
449 (device))
|
|
450 {
|
|
451 return DEVICE_CONSOLE (decode_device (device));
|
|
452 }
|
|
453
|
|
454 static void
|
|
455 init_global_resources (struct device *d)
|
|
456 {
|
|
457 init_global_faces (d);
|
|
458 #ifdef HAVE_SCROLLBARS
|
|
459 init_global_scrollbars (d);
|
|
460 #endif
|
|
461 #ifdef HAVE_TOOLBARS
|
|
462 init_global_toolbars (d);
|
|
463 #endif
|
|
464 }
|
|
465
|
|
466 static void
|
|
467 init_device_resources (struct device *d)
|
|
468 {
|
|
469 init_device_faces (d);
|
|
470 #ifdef HAVE_SCROLLBARS
|
|
471 init_device_scrollbars (d);
|
|
472 #endif
|
|
473 #ifdef HAVE_TOOLBARS
|
|
474 init_device_toolbars (d);
|
|
475 #endif
|
|
476 }
|
|
477
|
872
|
478 DEFUN ("default-device", Fdefault_device, 0, 1, 0, /*
|
|
479 Return the default device of type TYPE.
|
|
480 This is generally the first-created device of that TYPE that still exists.
|
|
481 It is used for resourcing and certain other things. On MS Windows, it
|
|
482 is not very useful because there is generally only one device.
|
|
483 If TYPE is omitted, it is derived from the selected device.
|
|
484 If there is no default device of TYPE, nil is returned.
|
|
485 */
|
|
486 (type))
|
|
487 {
|
|
488 if (NILP (type))
|
|
489 type = XDEVICE_TYPE (Fselected_device (Qnil));
|
|
490 else
|
|
491 /* For errors */
|
|
492 decode_console_type (type, ERROR_ME);
|
|
493
|
|
494 return Fplist_get (Vdefault_device_plist, type, Qnil);
|
|
495 }
|
|
496
|
|
497 /* Return the default device for a device type. */
|
|
498 Lisp_Object
|
|
499 get_default_device (Lisp_Object type)
|
|
500 {
|
|
501 return Fplist_get (Vdefault_device_plist, type, Qnil);
|
|
502 }
|
|
503
|
|
504 /* Set the default device for a device type. */
|
|
505 void
|
|
506 set_default_device (Lisp_Object type, Lisp_Object device)
|
|
507 {
|
|
508 Vdefault_device_plist = Fplist_put (Vdefault_device_plist, type, device);
|
|
509 }
|
|
510
|
|
511 void
|
|
512 clear_default_devices (void)
|
|
513 {
|
|
514 Vdefault_device_plist = Qnil;
|
|
515 }
|
|
516
|
428
|
517 static Lisp_Object
|
|
518 semi_canonicalize_device_connection (struct console_methods *meths,
|
578
|
519 Lisp_Object name, Error_Behavior errb)
|
428
|
520 {
|
440
|
521 if (HAS_CONTYPE_METH_P (meths, semi_canonicalize_device_connection))
|
|
522 return CONTYPE_METH (meths, semi_canonicalize_device_connection,
|
|
523 (name, errb));
|
|
524 else
|
|
525 return CONTYPE_METH_OR_GIVEN (meths, canonicalize_device_connection,
|
|
526 (name, errb), name);
|
428
|
527 }
|
|
528
|
|
529 static Lisp_Object
|
|
530 canonicalize_device_connection (struct console_methods *meths,
|
578
|
531 Lisp_Object name, Error_Behavior errb)
|
428
|
532 {
|
440
|
533 if (HAS_CONTYPE_METH_P (meths, canonicalize_device_connection))
|
|
534 return CONTYPE_METH (meths, canonicalize_device_connection,
|
|
535 (name, errb));
|
|
536 else
|
|
537 return CONTYPE_METH_OR_GIVEN (meths, semi_canonicalize_device_connection,
|
|
538 (name, errb), name);
|
428
|
539 }
|
|
540
|
|
541 static Lisp_Object
|
|
542 find_device_of_type (struct console_methods *meths, Lisp_Object canon)
|
|
543 {
|
|
544 Lisp_Object devcons, concons;
|
|
545
|
|
546 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
547 {
|
|
548 Lisp_Object device = XCAR (devcons);
|
|
549
|
|
550 if (EQ (CONMETH_TYPE (meths), DEVICE_TYPE (XDEVICE (device)))
|
|
551 && internal_equal (DEVICE_CANON_CONNECTION (XDEVICE (device)),
|
|
552 canon, 0))
|
|
553 return device;
|
|
554 }
|
|
555
|
|
556 return Qnil;
|
|
557 }
|
|
558
|
|
559 DEFUN ("find-device", Ffind_device, 1, 2, 0, /*
|
|
560 Look for an existing device attached to connection CONNECTION.
|
|
561 Return the device if found; otherwise, return nil.
|
|
562
|
|
563 If TYPE is specified, only return devices of that type; otherwise,
|
|
564 return devices of any type. (It is possible, although unlikely,
|
|
565 that two devices of different types could have the same connection
|
|
566 name; in such a case, the first device found is returned.)
|
|
567 */
|
|
568 (connection, type))
|
|
569 {
|
|
570 Lisp_Object canon = Qnil;
|
|
571 struct gcpro gcpro1;
|
|
572
|
|
573 GCPRO1 (canon);
|
|
574
|
|
575 if (!NILP (type))
|
|
576 {
|
|
577 struct console_methods *conmeths = decode_console_type (type, ERROR_ME);
|
|
578 canon = canonicalize_device_connection (conmeths, connection,
|
|
579 ERROR_ME_NOT);
|
|
580 if (UNBOUNDP (canon))
|
|
581 RETURN_UNGCPRO (Qnil);
|
|
582
|
|
583 RETURN_UNGCPRO (find_device_of_type (conmeths, canon));
|
|
584 }
|
|
585 else
|
|
586 {
|
|
587 int i;
|
|
588
|
|
589 for (i = 0; i < Dynarr_length (the_console_type_entry_dynarr); i++)
|
|
590 {
|
|
591 struct console_methods *conmeths =
|
|
592 Dynarr_at (the_console_type_entry_dynarr, i).meths;
|
|
593 canon = canonicalize_device_connection (conmeths, connection,
|
|
594 ERROR_ME_NOT);
|
|
595 if (!UNBOUNDP (canon))
|
|
596 {
|
|
597 Lisp_Object device = find_device_of_type (conmeths, canon);
|
|
598 if (!NILP (device))
|
|
599 RETURN_UNGCPRO (device);
|
|
600 }
|
|
601 }
|
|
602
|
|
603 RETURN_UNGCPRO (Qnil);
|
|
604 }
|
|
605 }
|
|
606
|
|
607 DEFUN ("get-device", Fget_device, 1, 2, 0, /*
|
|
608 Look for an existing device attached to connection CONNECTION.
|
|
609 Return the device if found; otherwise, signal an error.
|
|
610
|
|
611 If TYPE is specified, only return devices of that type; otherwise,
|
|
612 return devices of any type. (It is possible, although unlikely,
|
|
613 that two devices of different types could have the same connection
|
|
614 name; in such a case, the first device found is returned.)
|
|
615 */
|
|
616 (connection, type))
|
|
617 {
|
|
618 Lisp_Object device = Ffind_device (connection, type);
|
|
619 if (NILP (device))
|
|
620 {
|
|
621 if (NILP (type))
|
563
|
622 invalid_argument ("No such device", connection);
|
428
|
623 else
|
563
|
624 invalid_argument_2 ("No such device", type, connection);
|
428
|
625 }
|
|
626 return device;
|
|
627 }
|
|
628
|
|
629 static Lisp_Object
|
|
630 delete_deviceless_console (Lisp_Object console)
|
|
631 {
|
|
632 if (NILP (XCONSOLE (console)->device_list))
|
|
633 Fdelete_console (console, Qnil);
|
|
634 return Qnil;
|
|
635 }
|
|
636
|
|
637 DEFUN ("make-device", Fmake_device, 2, 3, 0, /*
|
|
638 Return a new device of type TYPE, attached to connection CONNECTION.
|
|
639
|
|
640 The valid values for CONNECTION are device-specific; however,
|
|
641 CONNECTION is generally a string. (Specifically, for X devices,
|
|
642 CONNECTION should be a display specification such as "foo:0", and
|
|
643 for TTY devices, CONNECTION should be the filename of a TTY device
|
|
644 file, such as "/dev/ttyp4", or nil to refer to XEmacs' standard
|
|
645 input/output.)
|
|
646
|
|
647 PROPS, if specified, should be a plist of properties controlling
|
|
648 device creation.
|
|
649
|
|
650 If CONNECTION specifies an already-existing device connection, that
|
|
651 device is simply returned; no new device is created, and PROPS
|
|
652 have no effect.
|
|
653 */
|
|
654 (type, connection, props))
|
|
655 {
|
|
656 /* This function can GC */
|
|
657 struct device *d;
|
|
658 struct console *con;
|
|
659 Lisp_Object device = Qnil;
|
|
660 Lisp_Object console = Qnil;
|
|
661 Lisp_Object name = Qnil;
|
|
662 struct console_methods *conmeths;
|
|
663 int speccount = specpdl_depth();
|
|
664
|
|
665 struct gcpro gcpro1, gcpro2, gcpro3;
|
872
|
666 /* If this is the first device we are creating of a particular type
|
|
667 (e.g. X), then retrieve the global face resources. We have to do it
|
|
668 here, at the same time as (or just before) the device face resources
|
|
669 are retrieved; specifically, it needs to be done after the device has
|
|
670 been created but before any frames have been popped up or much
|
|
671 anything else has been done. It's possible for other devices to
|
|
672 specify different global resources (there's a property on each X
|
|
673 server's root window that holds some resources); tough luck for the
|
|
674 moment. */
|
|
675 int first = NILP (get_default_device (type));
|
428
|
676
|
|
677 GCPRO3 (device, console, name);
|
|
678
|
|
679 conmeths = decode_console_type (type, ERROR_ME_NOT);
|
|
680 if (!conmeths)
|
563
|
681 invalid_constant ("Invalid device type", type);
|
428
|
682
|
|
683 device = Ffind_device (connection, type);
|
|
684 if (!NILP (device))
|
|
685 RETURN_UNGCPRO (device);
|
|
686
|
|
687 name = Fplist_get (props, Qname, Qnil);
|
|
688
|
|
689 {
|
|
690 Lisp_Object conconnect =
|
|
691 (HAS_CONTYPE_METH_P (conmeths, device_to_console_connection)) ?
|
|
692 CONTYPE_METH (conmeths, device_to_console_connection,
|
|
693 (connection, ERROR_ME)) :
|
|
694 connection;
|
|
695 console = create_console (name, type, conconnect, props);
|
|
696 }
|
|
697
|
872
|
698 record_unwind_protect (delete_deviceless_console, console);
|
428
|
699
|
|
700 con = XCONSOLE (console);
|
|
701 d = allocate_device (console);
|
793
|
702 device = wrap_device (d);
|
428
|
703
|
|
704 d->devmeths = con->conmeths;
|
934
|
705 #ifdef USE_KKCC
|
|
706 d->devtype = get_console_variant (type);
|
|
707 #endif /* USE_KKCC */
|
428
|
708
|
|
709 DEVICE_NAME (d) = name;
|
|
710 DEVICE_CONNECTION (d) =
|
|
711 semi_canonicalize_device_connection (conmeths, connection, ERROR_ME);
|
|
712 DEVICE_CANON_CONNECTION (d) =
|
|
713 canonicalize_device_connection (conmeths, connection, ERROR_ME);
|
|
714
|
|
715 MAYBE_DEVMETH (d, init_device, (d, props));
|
|
716
|
|
717 /* Do it this way so that the device list is in order of creation */
|
|
718 con->device_list = nconc2 (con->device_list, Fcons (device, Qnil));
|
872
|
719
|
|
720 if (NILP (get_default_device (type)))
|
|
721 set_default_device (type, device);
|
|
722
|
853
|
723 note_object_created (device);
|
|
724
|
428
|
725 RESET_CHANGED_SET_FLAGS;
|
|
726 if (NILP (Vdefault_device) || DEVICE_STREAM_P (XDEVICE (Vdefault_device)))
|
|
727 Vdefault_device = device;
|
|
728
|
|
729 init_device_sound (d);
|
|
730
|
|
731 /* If this is the first device on the console, make it the selected one. */
|
|
732 if (NILP (CONSOLE_SELECTED_DEVICE (con)))
|
|
733 CONSOLE_SELECTED_DEVICE (con) = device;
|
|
734
|
872
|
735 /* Needed before initialization of resources because they may do things
|
|
736 with the tags, esp. the face code. For example,
|
|
737 init-other-random-faces calls face-property-instance, and the
|
|
738 specifier code checks inst-pairs by seeing if the device matches the
|
|
739 tag; this fails for tags such as `default', if we haven't set up the
|
|
740 tags yet. */
|
428
|
741 setup_device_initial_specifier_tags (d);
|
|
742
|
872
|
743 if (!EQ (type, Qstream))
|
|
744 {
|
|
745 if (first)
|
|
746 init_global_resources (d);
|
|
747 init_device_resources (d);
|
|
748 }
|
|
749
|
|
750 MAYBE_DEVMETH (d, finish_init_device, (d, props));
|
|
751
|
428
|
752 UNGCPRO;
|
771
|
753 unbind_to (speccount);
|
428
|
754 return device;
|
|
755 }
|
|
756
|
|
757 /* find a device other than the selected one. Prefer non-stream
|
|
758 devices over stream devices. Maybe stay on the same console. */
|
|
759
|
|
760 static Lisp_Object
|
|
761 find_other_device (Lisp_Object device, int on_same_console)
|
|
762 {
|
|
763 Lisp_Object devcons = Qnil, concons;
|
|
764 Lisp_Object console = DEVICE_CONSOLE (XDEVICE (device));
|
|
765
|
|
766 /* look for a non-stream device */
|
|
767 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
768 {
|
|
769 Lisp_Object dev = XCAR (devcons);
|
|
770 if (on_same_console && !EQ (console, DEVICE_CONSOLE (XDEVICE (dev))))
|
|
771 continue;
|
|
772 if (!DEVICE_STREAM_P (XDEVICE (dev)) && !EQ (dev, device) &&
|
|
773 !NILP (DEVICE_SELECTED_FRAME (XDEVICE (dev))))
|
|
774 goto double_break_1;
|
|
775 }
|
|
776
|
|
777 double_break_1:
|
|
778 if (!NILP (devcons))
|
|
779 return XCAR (devcons);
|
|
780
|
|
781 /* OK, now look for a stream device */
|
|
782 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
783 {
|
|
784 Lisp_Object dev = XCAR (devcons);
|
|
785 if (on_same_console && !EQ (console, DEVICE_CONSOLE (XDEVICE (dev))))
|
|
786 continue;
|
|
787 if (!EQ (dev, device) && !NILP (DEVICE_SELECTED_FRAME (XDEVICE (dev))))
|
|
788 goto double_break_2;
|
|
789 }
|
|
790 double_break_2:
|
|
791 if (!NILP (devcons))
|
|
792 return XCAR (devcons);
|
|
793
|
|
794 /* Sorry, there ain't none */
|
|
795 return Qnil;
|
|
796 }
|
|
797
|
|
798 static int
|
|
799 find_nonminibuffer_frame_not_on_device_predicate (Lisp_Object frame,
|
|
800 void *closure)
|
|
801 {
|
|
802 Lisp_Object device;
|
|
803
|
826
|
804 device = VOID_TO_LISP (closure);
|
428
|
805 if (FRAME_MINIBUF_ONLY_P (XFRAME (frame)))
|
|
806 return 0;
|
|
807 if (EQ (device, FRAME_DEVICE (XFRAME (frame))))
|
|
808 return 0;
|
|
809 return 1;
|
|
810 }
|
|
811
|
|
812 Lisp_Object
|
|
813 find_nonminibuffer_frame_not_on_device (Lisp_Object device)
|
|
814 {
|
|
815 return find_some_frame (find_nonminibuffer_frame_not_on_device_predicate,
|
|
816 LISP_TO_VOID (device));
|
|
817 }
|
|
818
|
|
819
|
|
820 /* Delete device D.
|
|
821
|
|
822 If FORCE is non-zero, allow deletion of the only frame.
|
|
823
|
|
824 If CALLED_FROM_DELETE_CONSOLE is non-zero, then, if
|
|
825 deleting the last device on a console, just delete it,
|
|
826 instead of calling `delete-console'.
|
|
827
|
|
828 If FROM_IO_ERROR is non-zero, then the device is gone due
|
|
829 to an I/O error. This affects what happens if we exit
|
|
830 (we do an emergency exit instead of `save-buffers-kill-emacs'.)
|
|
831 */
|
|
832
|
|
833 void
|
|
834 delete_device_internal (struct device *d, int force,
|
|
835 int called_from_delete_console,
|
|
836 int from_io_error)
|
|
837 {
|
|
838 /* This function can GC */
|
|
839 struct console *c;
|
|
840 Lisp_Object device;
|
|
841 struct gcpro gcpro1;
|
|
842
|
|
843 /* OK to delete an already-deleted device. */
|
|
844 if (!DEVICE_LIVE_P (d))
|
|
845 return;
|
|
846
|
793
|
847 device = wrap_device (d);
|
853
|
848
|
|
849 if (!force)
|
|
850 check_allowed_operation (OPERATION_DELETE_OBJECT, device, Qnil);
|
|
851
|
428
|
852 GCPRO1 (device);
|
|
853
|
|
854 c = XCONSOLE (DEVICE_CONSOLE (d));
|
|
855
|
|
856 if (!called_from_delete_console)
|
|
857 {
|
|
858 int delete_console = 0;
|
|
859 /* If we're deleting the only device on the console,
|
|
860 delete the console. */
|
|
861 if ((XINT (Flength (CONSOLE_DEVICE_LIST (c))) == 1)
|
|
862 /* if we just created the device, it might not be listed,
|
|
863 or something ... */
|
|
864 && !NILP (memq_no_quit (device, CONSOLE_DEVICE_LIST (c))))
|
|
865 delete_console = 1;
|
|
866 /* Or if there aren't any nonminibuffer frames that would be
|
|
867 left, delete the console (this will make XEmacs exit). */
|
|
868 else if (NILP (find_nonminibuffer_frame_not_on_device (device)))
|
|
869 delete_console = 1;
|
|
870
|
|
871 if (delete_console)
|
|
872 {
|
|
873 delete_console_internal (c, force, 0, from_io_error);
|
|
874 UNGCPRO;
|
|
875 return;
|
|
876 }
|
|
877 }
|
|
878
|
|
879 reset_one_device (d);
|
|
880
|
|
881 {
|
|
882 Lisp_Object frmcons;
|
|
883
|
|
884 /* First delete all frames without their own minibuffers,
|
|
885 to avoid errors coming from attempting to delete a frame
|
|
886 that is a surrogate for another frame. */
|
|
887 DEVICE_FRAME_LOOP (frmcons, d)
|
|
888 {
|
|
889 struct frame *f = XFRAME (XCAR (frmcons));
|
|
890 /* delete_frame_internal() might do anything such as run hooks,
|
|
891 so be defensive. */
|
|
892 if (FRAME_LIVE_P (f) && !FRAME_HAS_MINIBUF_P (f))
|
|
893 delete_frame_internal (f, 1, 1, from_io_error);
|
|
894
|
|
895 if (!DEVICE_LIVE_P (d)) /* make sure the delete-*-hook didn't
|
|
896 go ahead and delete anything */
|
|
897 {
|
|
898 UNGCPRO;
|
|
899 return;
|
|
900 }
|
|
901 }
|
|
902
|
|
903 /* #### This should probably be a device method but it is time for
|
|
904 19.14 to go out the door. */
|
462
|
905 /* #### BILL!!! Should this deal with HAVE_MSWINDOWS as well? */
|
|
906 #if defined (HAVE_X_WINDOWS) || defined (HAVE_GTK)
|
428
|
907 /* Next delete all frames which have the popup property to avoid
|
|
908 deleting a child after its parent. */
|
|
909 DEVICE_FRAME_LOOP (frmcons, d)
|
|
910 {
|
|
911 struct frame *f = XFRAME (XCAR (frmcons));
|
|
912
|
|
913 if (FRAME_LIVE_P (f))
|
|
914 {
|
|
915 Lisp_Object popup = Fframe_property (XCAR (frmcons), Qpopup, Qnil);
|
|
916 if (!NILP (popup))
|
|
917 delete_frame_internal (f, 1, 1, from_io_error);
|
|
918
|
|
919 if (!DEVICE_LIVE_P (d)) /* make sure the delete-*-hook didn't
|
|
920 go ahead and delete anything */
|
|
921 {
|
|
922 UNGCPRO;
|
|
923 return;
|
|
924 }
|
|
925 }
|
|
926 }
|
|
927 #endif /* HAVE_X_WINDOWS */
|
|
928
|
|
929 DEVICE_FRAME_LOOP (frmcons, d)
|
|
930 {
|
|
931 struct frame *f = XFRAME (XCAR (frmcons));
|
|
932 /* delete_frame_internal() might do anything such as run hooks,
|
|
933 so be defensive. */
|
|
934 if (FRAME_LIVE_P (f))
|
|
935 delete_frame_internal (f, 1, 1, from_io_error);
|
|
936
|
|
937 if (!DEVICE_LIVE_P (d)) /* make sure the delete-*-hook didn't
|
|
938 go ahead and delete anything */
|
|
939 {
|
|
940 UNGCPRO;
|
|
941 return;
|
|
942 }
|
|
943 }
|
|
944 }
|
|
945
|
|
946 set_device_selected_frame (d, Qnil);
|
|
947
|
|
948 /* try to select another device */
|
|
949
|
|
950 if (EQ (device, Fselected_device (DEVICE_CONSOLE (d))))
|
|
951 {
|
|
952 Lisp_Object other_dev = find_other_device (device, 1);
|
|
953 if (!NILP (other_dev))
|
|
954 Fselect_device (other_dev);
|
|
955 }
|
|
956
|
|
957 if (EQ (device, Vdefault_device))
|
|
958 Vdefault_device = find_other_device (device, 0);
|
|
959
|
|
960 MAYBE_DEVMETH (d, delete_device, (d));
|
|
961
|
872
|
962 /* Now see if we're the default device, and thus need to be changed. */
|
|
963 {
|
|
964 /* Device type still OK, not set to null till down below. */
|
|
965 Lisp_Object dt = DEVICE_TYPE (d);
|
|
966
|
|
967 if (EQ (device, get_default_device (dt)))
|
|
968 {
|
|
969 Lisp_Object devcons, concons;
|
|
970 /* #### handle deleting last device */
|
|
971 set_default_device (dt, Qnil);
|
|
972 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
973 {
|
|
974 if (EQ (dt, XDEVICE_TYPE (XCAR (devcons))) &&
|
|
975 !EQ (device, XCAR (devcons)))
|
|
976 {
|
|
977 set_default_device (dt, XCAR (devcons));
|
|
978 goto double_break;
|
|
979 }
|
|
980 }
|
|
981 }
|
|
982 }
|
|
983 double_break:
|
|
984
|
428
|
985 CONSOLE_DEVICE_LIST (c) = delq_no_quit (device, CONSOLE_DEVICE_LIST (c));
|
617
|
986
|
428
|
987 RESET_CHANGED_SET_FLAGS;
|
617
|
988
|
|
989 /* Nobody should be accessing anything in this object any more, and
|
|
990 making all Lisp_Objects Qnil allows for better GC'ing in case a
|
|
991 pointer to the dead device continues to hang around. Zero all
|
|
992 other structs in case someone tries to access something through
|
|
993 them. */
|
|
994 nuke_all_device_slots (d, Qnil);
|
428
|
995 d->devmeths = dead_console_methods;
|
853
|
996 note_object_deleted (device);
|
617
|
997
|
428
|
998 UNGCPRO;
|
|
999 }
|
|
1000
|
|
1001 /* delete a device as a result of an I/O error. Called from
|
|
1002 an enqueued magic-eval event. */
|
|
1003
|
|
1004 void
|
|
1005 io_error_delete_device (Lisp_Object device)
|
|
1006 {
|
|
1007 /* Note: it's the console that should get deleted, but
|
|
1008 delete_device_internal() contains a hack that also deletes the
|
|
1009 console when called from this function. */
|
|
1010 delete_device_internal (XDEVICE (device), 1, 0, 1);
|
|
1011 }
|
|
1012
|
|
1013 DEFUN ("delete-device", Fdelete_device, 1, 2, 0, /*
|
|
1014 Delete DEVICE, permanently eliminating it from use.
|
|
1015 Normally, you cannot delete the last non-minibuffer-only frame (you must
|
|
1016 use `save-buffers-kill-emacs' or `kill-emacs'). However, if optional
|
|
1017 second argument FORCE is non-nil, you can delete the last frame. (This
|
|
1018 will automatically call `save-buffers-kill-emacs'.)
|
|
1019 */
|
|
1020 (device, force))
|
|
1021 {
|
|
1022 CHECK_DEVICE (device);
|
|
1023 delete_device_internal (XDEVICE (device), !NILP (force), 0, 0);
|
|
1024 return Qnil;
|
|
1025 }
|
|
1026
|
|
1027 DEFUN ("device-frame-list", Fdevice_frame_list, 0, 1, 0, /*
|
|
1028 Return a list of all frames on DEVICE.
|
|
1029 If DEVICE is nil, the selected device will be used.
|
|
1030 */
|
|
1031 (device))
|
|
1032 {
|
|
1033 return Fcopy_sequence (DEVICE_FRAME_LIST (decode_device (device)));
|
|
1034 }
|
|
1035
|
|
1036 DEFUN ("device-class", Fdevice_class, 0, 1, 0, /*
|
|
1037 Return the class (color behavior) of DEVICE.
|
|
1038 This will be one of 'color, 'grayscale, or 'mono.
|
|
1039 */
|
|
1040 (device))
|
|
1041 {
|
|
1042 return DEVICE_CLASS (decode_device (device));
|
|
1043 }
|
|
1044
|
|
1045 DEFUN ("set-device-class", Fset_device_class, 2, 2, 0, /*
|
|
1046 Set the class (color behavior) of DEVICE.
|
|
1047 CLASS should be one of 'color, 'grayscale, or 'mono.
|
|
1048 This is only allowed on device such as TTY devices, where the color
|
|
1049 behavior cannot necessarily be determined automatically.
|
|
1050 */
|
|
1051 (device, class))
|
|
1052 {
|
|
1053 struct device *d = decode_device (device);
|
793
|
1054 device = wrap_device (d);
|
428
|
1055 if (!DEVICE_TTY_P (d))
|
563
|
1056 gui_error ("Cannot change the class of this device", device);
|
428
|
1057 if (!EQ (class, Qcolor) && !EQ (class, Qmono) && !EQ (class, Qgrayscale))
|
563
|
1058 invalid_constant ("Must be color, mono, or grayscale", class);
|
428
|
1059 if (! EQ (DEVICE_CLASS (d), class))
|
|
1060 {
|
|
1061 Lisp_Object frmcons;
|
|
1062 DEVICE_CLASS (d) = class;
|
|
1063 DEVICE_FRAME_LOOP (frmcons, d)
|
|
1064 {
|
|
1065 struct frame *f = XFRAME (XCAR (frmcons));
|
|
1066
|
|
1067 recompute_all_cached_specifiers_in_frame (f);
|
|
1068 MARK_FRAME_FACES_CHANGED (f);
|
|
1069 MARK_FRAME_GLYPHS_CHANGED (f);
|
|
1070 MARK_FRAME_SUBWINDOWS_CHANGED (f);
|
|
1071 MARK_FRAME_TOOLBARS_CHANGED (f);
|
442
|
1072 MARK_FRAME_GUTTERS_CHANGED (f);
|
428
|
1073 f->menubar_changed = 1;
|
|
1074 }
|
|
1075 }
|
|
1076 return Qnil;
|
|
1077 }
|
|
1078
|
|
1079 DEFUN ("set-device-baud-rate", Fset_device_baud_rate, 2, 2, 0, /*
|
|
1080 Set the output baud rate of DEVICE to RATE.
|
|
1081 On most systems, changing this value will affect the amount of padding
|
|
1082 and other strategic decisions made during redisplay.
|
|
1083 */
|
|
1084 (device, rate))
|
|
1085 {
|
|
1086 CHECK_INT (rate);
|
|
1087
|
|
1088 DEVICE_BAUD_RATE (decode_device (device)) = XINT (rate);
|
|
1089
|
|
1090 return rate;
|
|
1091 }
|
|
1092
|
|
1093 DEFUN ("device-baud-rate", Fdevice_baud_rate, 0, 1, 0, /*
|
|
1094 Return the output baud rate of DEVICE.
|
|
1095 */
|
|
1096 (device))
|
|
1097 {
|
|
1098 return make_int (DEVICE_BAUD_RATE (decode_device (device)));
|
|
1099 }
|
|
1100
|
440
|
1101 DEFUN ("device-printer-p", Fdevice_printer_p, 0, 1, 0, /*
|
|
1102 Return t if DEVICE is a printer, nil if it is a display. DEVICE defaults
|
|
1103 to selected device if omitted, and must be live if specified.
|
|
1104 */
|
|
1105 (device))
|
|
1106 {
|
442
|
1107 return DEVICE_PRINTER_P (decode_device (device)) ? Qt : Qnil;
|
440
|
1108 }
|
|
1109
|
428
|
1110 DEFUN ("device-system-metric", Fdevice_system_metric, 1, 3, 0, /*
|
|
1111 Get a metric for DEVICE as provided by the system.
|
|
1112
|
|
1113 METRIC must be a symbol specifying requested metric. Note that the metrics
|
|
1114 returned are these provided by the system internally, not read from resources,
|
|
1115 so obtained from the most internal level.
|
|
1116
|
|
1117 If a metric is not provided by the system, then DEFAULT is returned.
|
|
1118
|
|
1119 When DEVICE is nil, selected device is assumed
|
|
1120
|
|
1121 Metrics, by group, are:
|
|
1122
|
|
1123 COLORS. Colors are returned as valid color instantiators. No other assumption
|
|
1124 on the returned value should be made (i.e. it can be a string on one system but
|
|
1125 a color instance on another). For colors, returned value is a cons of
|
|
1126 foreground and background colors. Note that if the system provides only one
|
|
1127 color of the pair, the second one may be nil.
|
|
1128
|
|
1129 color-default Standard window text foreground and background.
|
|
1130 color-select Selection highlight text and background colors.
|
|
1131 color-balloon Balloon popup text and background colors.
|
|
1132 color-3d-face 3-D object (button, modeline) text and surface colors.
|
|
1133 color-3d-light Fore and back colors for 3-D edges facing light source.
|
|
1134 color-3d-dark Fore and back colors for 3-D edges facing away from
|
|
1135 light source.
|
|
1136 color-menu Text and background for menus
|
|
1137 color-menu-highlight Selected menu item colors
|
|
1138 color-menu-button Menu button colors
|
|
1139 color-menu-disabled Unselectable menu item colors
|
|
1140 color-toolbar Toolbar foreground and background colors
|
|
1141 color-scrollbar Scrollbar foreground and background colors
|
|
1142 color-desktop Desktop window colors
|
|
1143 color-workspace Workspace window colors
|
|
1144
|
|
1145 FONTS. Fonts are returned as valid font instantiators. No other assumption on
|
|
1146 the returned value should be made (i.e. it can be a string on one system but
|
|
1147 font instance on another).
|
|
1148
|
|
1149 font-default Default fixed width font.
|
|
1150 font-menubar Menubar font
|
|
1151 font-dialog Dialog boxes font
|
|
1152
|
|
1153 GEOMETRY. These metrics are returned as conses of (X . Y). As with colors,
|
|
1154 either car or cdr of the cons may be nil if the system does not provide one
|
|
1155 of the corresponding dimensions.
|
|
1156
|
|
1157 size-cursor Mouse cursor size.
|
|
1158 size-scrollbar Scrollbars (WIDTH . HEIGHT)
|
|
1159 size-menu Menubar height, as (nil . HEIGHT)
|
|
1160 size-toolbar Toolbar width and height.
|
|
1161 size-toolbar-button Toolbar button size.
|
|
1162 size-toolbar-border Toolbar border width and height.
|
|
1163 size-icon Icon dimensions.
|
|
1164 size-icon-small Small icon dimensions.
|
440
|
1165 size-device Device screen or paper size in pixels.
|
|
1166 size-workspace Workspace size in pixels. This can be less than or
|
442
|
1167 equal to the above. For displays, this is the area
|
|
1168 available to applications less window manager
|
440
|
1169 decorations. For printers, this is the size of
|
|
1170 printable area.
|
|
1171 offset-workspace Offset of workspace area from the top left corner
|
442
|
1172 of screen or paper, in pixels.
|
428
|
1173 size-device-mm Device screen size in millimeters.
|
|
1174 device-dpi Device resolution, in dots per inch.
|
|
1175 num-bit-planes Integer, number of device bit planes.
|
|
1176 num-color-cells Integer, number of device color cells.
|
|
1177
|
|
1178 FEATURES. This group reports various device features. If a feature is
|
|
1179 present, integer 1 (one) is returned, if it is not present, then integer
|
|
1180 0 (zero) is returned. If the system is unaware of the feature, then
|
|
1181 DEFAULT is returned.
|
|
1182
|
|
1183 mouse-buttons Integer, number of mouse buttons, or zero if no mouse.
|
|
1184 swap-buttons Non-zero if left and right mouse buttons are swapped.
|
|
1185 show-sounds User preference for visual over audible bell.
|
|
1186 slow-device Device is slow, avoid animation.
|
|
1187 security Non-zero if user environment is secure.
|
|
1188 */
|
|
1189 (device, metric, default_))
|
|
1190 {
|
|
1191 struct device *d = decode_device (device);
|
|
1192 enum device_metrics m;
|
|
1193 Lisp_Object res;
|
|
1194
|
|
1195 /* Decode metric */
|
|
1196 #define FROB(met) \
|
|
1197 else if (EQ (metric, Q##met)) \
|
|
1198 m = DM_##met
|
|
1199
|
|
1200 if (0)
|
|
1201 ;
|
|
1202 FROB (color_default);
|
|
1203 FROB (color_select);
|
|
1204 FROB (color_balloon);
|
|
1205 FROB (color_3d_face);
|
|
1206 FROB (color_3d_light);
|
|
1207 FROB (color_3d_dark);
|
|
1208 FROB (color_menu);
|
|
1209 FROB (color_menu_highlight);
|
|
1210 FROB (color_menu_button);
|
|
1211 FROB (color_menu_disabled);
|
|
1212 FROB (color_toolbar);
|
|
1213 FROB (color_scrollbar);
|
|
1214 FROB (color_desktop);
|
|
1215 FROB (color_workspace);
|
|
1216 FROB (font_default);
|
|
1217 FROB (font_menubar);
|
|
1218 FROB (font_dialog);
|
|
1219 FROB (size_cursor);
|
|
1220 FROB (size_scrollbar);
|
|
1221 FROB (size_menu);
|
|
1222 FROB (size_toolbar);
|
|
1223 FROB (size_toolbar_button);
|
|
1224 FROB (size_toolbar_border);
|
|
1225 FROB (size_icon);
|
|
1226 FROB (size_icon_small);
|
|
1227 FROB (size_device);
|
|
1228 FROB (size_workspace);
|
440
|
1229 FROB (offset_workspace);
|
428
|
1230 FROB (size_device_mm);
|
|
1231 FROB (device_dpi);
|
|
1232 FROB (num_bit_planes);
|
|
1233 FROB (num_color_cells);
|
|
1234 FROB (mouse_buttons);
|
|
1235 FROB (swap_buttons);
|
|
1236 FROB (show_sounds);
|
|
1237 FROB (slow_device);
|
|
1238 FROB (security);
|
|
1239 else
|
563
|
1240 invalid_constant ("Invalid device metric symbol", metric);
|
428
|
1241
|
|
1242 res = DEVMETH_OR_GIVEN (d, device_system_metrics, (d, m), Qunbound);
|
|
1243 return UNBOUNDP(res) ? default_ : res;
|
|
1244
|
|
1245 #undef FROB
|
|
1246 }
|
|
1247
|
|
1248 DEFUN ("device-system-metrics", Fdevice_system_metrics, 0, 1, 0, /*
|
|
1249 Get a property list of device metric for DEVICE.
|
|
1250
|
|
1251 See `device-system-metric' for the description of available metrics.
|
|
1252 DEVICE defaults to selected device when omitted.
|
|
1253 */
|
|
1254 (device))
|
|
1255 {
|
|
1256 struct device *d = decode_device (device);
|
|
1257 Lisp_Object plist = Qnil, one_metric;
|
|
1258
|
|
1259 #define FROB(m) \
|
|
1260 if (!UNBOUNDP ((one_metric = \
|
|
1261 DEVMETH_OR_GIVEN (d, device_system_metrics, \
|
|
1262 (d, DM_##m), Qunbound)))) \
|
|
1263 plist = Fcons (Q##m, Fcons (one_metric, plist));
|
|
1264
|
|
1265 FROB (color_default);
|
|
1266 FROB (color_select);
|
|
1267 FROB (color_balloon);
|
|
1268 FROB (color_3d_face);
|
|
1269 FROB (color_3d_light);
|
|
1270 FROB (color_3d_dark);
|
|
1271 FROB (color_menu);
|
|
1272 FROB (color_menu_highlight);
|
|
1273 FROB (color_menu_button);
|
|
1274 FROB (color_menu_disabled);
|
|
1275 FROB (color_toolbar);
|
|
1276 FROB (color_scrollbar);
|
|
1277 FROB (color_desktop);
|
|
1278 FROB (color_workspace);
|
|
1279 FROB (font_default);
|
|
1280 FROB (font_menubar);
|
|
1281 FROB (font_dialog);
|
|
1282 FROB (size_cursor);
|
|
1283 FROB (size_scrollbar);
|
|
1284 FROB (size_menu);
|
|
1285 FROB (size_toolbar);
|
|
1286 FROB (size_toolbar_button);
|
|
1287 FROB (size_toolbar_border);
|
|
1288 FROB (size_icon);
|
|
1289 FROB (size_icon_small);
|
|
1290 FROB (size_device);
|
|
1291 FROB (size_workspace);
|
440
|
1292 FROB (offset_workspace);
|
428
|
1293 FROB (size_device_mm);
|
|
1294 FROB (device_dpi);
|
|
1295 FROB (num_bit_planes);
|
|
1296 FROB (num_color_cells);
|
|
1297 FROB (mouse_buttons);
|
|
1298 FROB (swap_buttons);
|
|
1299 FROB (show_sounds);
|
|
1300 FROB (slow_device);
|
|
1301 FROB (security);
|
|
1302
|
|
1303 return plist;
|
|
1304
|
|
1305 #undef FROB
|
|
1306 }
|
|
1307
|
|
1308 Lisp_Object
|
|
1309 domain_device_type (Lisp_Object domain)
|
|
1310 {
|
|
1311 /* This cannot GC */
|
|
1312 assert (WINDOWP (domain) || FRAMEP (domain)
|
|
1313 || DEVICEP (domain) || CONSOLEP (domain));
|
|
1314
|
|
1315 if (WINDOWP (domain))
|
|
1316 {
|
|
1317 if (!WINDOW_LIVE_P (XWINDOW (domain)))
|
|
1318 return Qdead;
|
|
1319 domain = WINDOW_FRAME (XWINDOW (domain));
|
|
1320 }
|
|
1321 if (FRAMEP (domain))
|
|
1322 {
|
|
1323 if (!FRAME_LIVE_P (XFRAME (domain)))
|
|
1324 return Qdead;
|
|
1325 domain = FRAME_DEVICE (XFRAME (domain));
|
|
1326 }
|
|
1327 if (DEVICEP (domain))
|
|
1328 {
|
|
1329 if (!DEVICE_LIVE_P (XDEVICE (domain)))
|
|
1330 return Qdead;
|
|
1331 domain = DEVICE_CONSOLE (XDEVICE (domain));
|
|
1332 }
|
|
1333 return CONSOLE_TYPE (XCONSOLE (domain));
|
|
1334 }
|
|
1335
|
|
1336 /*
|
|
1337 * Determine whether window system bases window geometry on character
|
|
1338 * or pixel counts.
|
|
1339 * Return non-zero for pixel-based geometry, zero for character-based.
|
|
1340 */
|
|
1341 int
|
|
1342 window_system_pixelated_geometry (Lisp_Object domain)
|
|
1343 {
|
|
1344 /* This cannot GC */
|
|
1345 Lisp_Object winsy = domain_device_type (domain);
|
|
1346 struct console_methods *meth = decode_console_type (winsy, ERROR_ME_NOT);
|
|
1347 assert (meth);
|
545
|
1348 return CONMETH_IMPL_FLAG (meth, XDEVIMPF_PIXEL_GEOMETRY);
|
428
|
1349 }
|
|
1350
|
|
1351 DEFUN ("domain-device-type", Fdomain_device_type, 0, 1, 0, /*
|
|
1352 Return the device type symbol for a DOMAIN, e.g. 'x or 'tty.
|
|
1353 DOMAIN can be either a window, frame, device or console.
|
|
1354 */
|
|
1355 (domain))
|
|
1356 {
|
|
1357 if (!WINDOWP (domain) && !FRAMEP (domain)
|
|
1358 && !DEVICEP (domain) && !CONSOLEP (domain))
|
563
|
1359 invalid_argument
|
428
|
1360 ("Domain must be either a window, frame, device or console", domain);
|
|
1361
|
|
1362 return domain_device_type (domain);
|
|
1363 }
|
|
1364
|
|
1365 void
|
|
1366 handle_asynch_device_change (void)
|
|
1367 {
|
|
1368 int i;
|
|
1369 int old_asynch_device_change_pending = asynch_device_change_pending;
|
|
1370 for (i = 0; i < Dynarr_length (the_console_type_entry_dynarr); i++)
|
|
1371 {
|
|
1372 if (Dynarr_at (the_console_type_entry_dynarr, i).meths->
|
|
1373 asynch_device_change_method)
|
|
1374 (Dynarr_at (the_console_type_entry_dynarr, i).meths->
|
|
1375 asynch_device_change_method) ();
|
|
1376 }
|
|
1377 /* reset the flag to 0 unless another notification occurred while
|
|
1378 we were processing this one. Block SIGWINCH during this
|
|
1379 check to prevent a possible race condition. */
|
442
|
1380 #ifdef SIGWINCH
|
428
|
1381 EMACS_BLOCK_SIGNAL (SIGWINCH);
|
|
1382 #endif
|
|
1383 if (old_asynch_device_change_pending == asynch_device_change_pending)
|
|
1384 asynch_device_change_pending = 0;
|
442
|
1385 #ifdef SIGWINCH
|
428
|
1386 EMACS_UNBLOCK_SIGNAL (SIGWINCH);
|
|
1387 #endif
|
|
1388 }
|
|
1389
|
771
|
1390 static Lisp_Object
|
|
1391 unlock_device (Lisp_Object d)
|
|
1392 {
|
|
1393 UNLOCK_DEVICE (XDEVICE (d));
|
|
1394 return Qnil;
|
|
1395 }
|
|
1396
|
872
|
1397 Lisp_Object
|
428
|
1398 call_critical_lisp_code (struct device *d, Lisp_Object function,
|
|
1399 Lisp_Object object)
|
|
1400 {
|
853
|
1401 /* This function cannot GC */
|
771
|
1402 int count = begin_gc_forbidden ();
|
853
|
1403 struct gcpro gcpro1;
|
|
1404 Lisp_Object args[3];
|
872
|
1405 Lisp_Object retval;
|
853
|
1406
|
771
|
1407 specbind (Qinhibit_quit, Qt);
|
|
1408 record_unwind_protect (unlock_device, wrap_device (d));
|
428
|
1409
|
771
|
1410 /* [[There's no real reason to bother doing unwind-protects, because if
|
428
|
1411 initialize-*-faces signals an error, emacs is going to crash
|
771
|
1412 immediately.]] But this sucks! This code is called not only during
|
|
1413 the initial device, but for other devices as well! #### When dealing
|
|
1414 with non-initial devices, we should signal an error but NOT kill
|
|
1415 ourselves! --ben
|
428
|
1416 */
|
|
1417 LOCK_DEVICE (d);
|
|
1418
|
853
|
1419 args[0] = Qreally_early_error_handler;
|
|
1420 args[1] = function;
|
|
1421 args[2] = object;
|
|
1422
|
|
1423 GCPRO1_ARRAY (args, 3);
|
|
1424
|
|
1425 /* It's useful to have an error handler; otherwise an infinite
|
428
|
1426 loop may result. */
|
872
|
1427 retval = Fcall_with_condition_handler (!NILP (object) ? 3 : 2, args);
|
853
|
1428
|
|
1429 UNGCPRO;
|
428
|
1430
|
872
|
1431 return unbind_to_1 (count, retval);
|
428
|
1432 }
|
|
1433
|
|
1434
|
|
1435 /************************************************************************/
|
|
1436 /* initialization */
|
|
1437 /************************************************************************/
|
|
1438
|
|
1439 void
|
|
1440 syms_of_device (void)
|
|
1441 {
|
442
|
1442 INIT_LRECORD_IMPLEMENTATION (device);
|
|
1443
|
428
|
1444 DEFSUBR (Fvalid_device_class_p);
|
|
1445 DEFSUBR (Fdevice_class_list);
|
|
1446
|
|
1447 DEFSUBR (Fdfw_device);
|
|
1448 DEFSUBR (Fselected_device);
|
|
1449 DEFSUBR (Fselect_device);
|
|
1450 DEFSUBR (Fset_device_selected_frame);
|
|
1451 DEFSUBR (Fdevicep);
|
|
1452 DEFSUBR (Fdevice_live_p);
|
|
1453 DEFSUBR (Fdevice_name);
|
|
1454 DEFSUBR (Fdevice_connection);
|
|
1455 DEFSUBR (Fdevice_console);
|
|
1456 DEFSUBR (Ffind_device);
|
|
1457 DEFSUBR (Fget_device);
|
|
1458 DEFSUBR (Fmake_device);
|
872
|
1459 DEFSUBR (Fdefault_device);
|
428
|
1460 DEFSUBR (Fdelete_device);
|
|
1461 DEFSUBR (Fdevice_frame_list);
|
|
1462 DEFSUBR (Fdevice_class);
|
|
1463 DEFSUBR (Fset_device_class);
|
|
1464 DEFSUBR (Fdevice_system_metrics);
|
|
1465 DEFSUBR (Fdevice_system_metric);
|
|
1466 DEFSUBR (Fset_device_baud_rate);
|
|
1467 DEFSUBR (Fdevice_baud_rate);
|
|
1468 DEFSUBR (Fdomain_device_type);
|
440
|
1469 DEFSUBR (Fdevice_printer_p);
|
428
|
1470
|
563
|
1471 DEFSYMBOL (Qdevicep);
|
|
1472 DEFSYMBOL (Qdevice_live_p);
|
428
|
1473
|
563
|
1474 DEFSYMBOL (Qcreate_device_hook);
|
|
1475 DEFSYMBOL (Qdelete_device_hook);
|
428
|
1476
|
|
1477 /* Qcolor defined in general.c */
|
563
|
1478 DEFSYMBOL (Qgrayscale);
|
|
1479 DEFSYMBOL (Qmono);
|
428
|
1480
|
|
1481 /* Device metrics symbols */
|
563
|
1482 DEFSYMBOL (Qcolor_default);
|
|
1483 DEFSYMBOL (Qcolor_select);
|
|
1484 DEFSYMBOL (Qcolor_balloon);
|
|
1485 DEFSYMBOL (Qcolor_3d_face);
|
|
1486 DEFSYMBOL (Qcolor_3d_light);
|
|
1487 DEFSYMBOL (Qcolor_3d_dark);
|
|
1488 DEFSYMBOL (Qcolor_menu);
|
|
1489 DEFSYMBOL (Qcolor_menu_highlight);
|
|
1490 DEFSYMBOL (Qcolor_menu_button);
|
|
1491 DEFSYMBOL (Qcolor_menu_disabled);
|
|
1492 DEFSYMBOL (Qcolor_toolbar);
|
|
1493 DEFSYMBOL (Qcolor_scrollbar);
|
|
1494 DEFSYMBOL (Qcolor_desktop);
|
|
1495 DEFSYMBOL (Qcolor_workspace);
|
|
1496 DEFSYMBOL (Qfont_default);
|
|
1497 DEFSYMBOL (Qfont_menubar);
|
|
1498 DEFSYMBOL (Qfont_dialog);
|
|
1499 DEFSYMBOL (Qsize_cursor);
|
|
1500 DEFSYMBOL (Qsize_scrollbar);
|
|
1501 DEFSYMBOL (Qsize_menu);
|
|
1502 DEFSYMBOL (Qsize_toolbar);
|
|
1503 DEFSYMBOL (Qsize_toolbar_button);
|
|
1504 DEFSYMBOL (Qsize_toolbar_border);
|
|
1505 DEFSYMBOL (Qsize_icon);
|
|
1506 DEFSYMBOL (Qsize_icon_small);
|
|
1507 DEFSYMBOL (Qsize_device);
|
|
1508 DEFSYMBOL (Qsize_workspace);
|
|
1509 DEFSYMBOL (Qoffset_workspace);
|
|
1510 DEFSYMBOL (Qsize_device_mm);
|
|
1511 DEFSYMBOL (Qnum_bit_planes);
|
|
1512 DEFSYMBOL (Qnum_color_cells);
|
|
1513 DEFSYMBOL (Qdevice_dpi);
|
|
1514 DEFSYMBOL (Qmouse_buttons);
|
|
1515 DEFSYMBOL (Qswap_buttons);
|
|
1516 DEFSYMBOL (Qshow_sounds);
|
|
1517 DEFSYMBOL (Qslow_device);
|
|
1518 DEFSYMBOL (Qsecurity);
|
428
|
1519 }
|
|
1520
|
|
1521 void
|
|
1522 reinit_vars_of_device (void)
|
|
1523 {
|
|
1524 staticpro_nodump (&Vdefault_device);
|
|
1525 Vdefault_device = Qnil;
|
|
1526 asynch_device_change_pending = 0;
|
|
1527 }
|
|
1528
|
|
1529 void
|
|
1530 vars_of_device (void)
|
|
1531 {
|
|
1532 reinit_vars_of_device ();
|
|
1533
|
|
1534 DEFVAR_LISP ("create-device-hook", &Vcreate_device_hook /*
|
|
1535 Function or functions to call when a device is created.
|
|
1536 One argument, the newly-created device.
|
|
1537 This is called after the first frame has been created, but before
|
|
1538 calling the `create-frame-hook'.
|
|
1539 Note that in general the device will not be selected.
|
|
1540 */ );
|
|
1541 Vcreate_device_hook = Qnil;
|
|
1542
|
|
1543 DEFVAR_LISP ("delete-device-hook", &Vdelete_device_hook /*
|
|
1544 Function or functions to call when a device is deleted.
|
|
1545 One argument, the to-be-deleted device.
|
|
1546 */ );
|
|
1547 Vdelete_device_hook = Qnil;
|
|
1548
|
872
|
1549 /* Plist of device types and their default devices. */
|
|
1550 Vdefault_device_plist = Qnil;
|
|
1551 staticpro (&Vdefault_device_plist);
|
|
1552
|
428
|
1553 Vdevice_class_list = list3 (Qcolor, Qgrayscale, Qmono);
|
|
1554 staticpro (&Vdevice_class_list);
|
|
1555
|
|
1556 /* Death to devices.el !!! */
|
617
|
1557 Fprovide (intern ("devices"));
|
428
|
1558 }
|