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