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