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