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