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