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