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