0
|
1 /* Generic device functions.
|
|
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 "scrollbar.h"
|
|
41 #include "specifier.h"
|
|
42 #include "sysdep.h"
|
|
43 #include "window.h"
|
|
44
|
|
45 #include "syssignal.h"
|
|
46
|
|
47 /* Vdefault_device is the firstly-created non-stream device that's still
|
|
48 around. We don't really use it anywhere currently, but it might
|
|
49 be used for resourcing at some point. (Currently we use
|
|
50 Vdefault_x_device.) */
|
|
51 Lisp_Object Vdefault_device;
|
|
52
|
|
53 Lisp_Object Vcreate_device_hook, Vdelete_device_hook;
|
|
54
|
|
55 /* Device classes */
|
|
56 /* Qcolor defined in general.c */
|
|
57 Lisp_Object Qgrayscale, Qmono;
|
|
58
|
|
59 Lisp_Object Qdevicep, Qdevice_live_p;
|
|
60 Lisp_Object Qdelete_device;
|
|
61 Lisp_Object Qcreate_device_hook;
|
|
62 Lisp_Object Qdelete_device_hook;
|
|
63
|
|
64 Lisp_Object Vdevice_class_list;
|
|
65
|
|
66 MAC_DEFINE (struct device *, MTdevice_data)
|
|
67
|
|
68
|
|
69 static Lisp_Object mark_device (Lisp_Object, void (*) (Lisp_Object));
|
|
70 static void print_device (Lisp_Object, Lisp_Object, int);
|
|
71 DEFINE_LRECORD_IMPLEMENTATION ("device", device,
|
|
72 mark_device, print_device, 0, 0, 0,
|
|
73 struct device);
|
|
74
|
|
75 static Lisp_Object
|
|
76 mark_device (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
77 {
|
|
78 struct device *d = XDEVICE (obj);
|
|
79
|
|
80 ((markobj) (d->name));
|
|
81 ((markobj) (d->connection));
|
|
82 ((markobj) (d->canon_connection));
|
|
83 ((markobj) (d->console));
|
|
84 ((markobj) (d->_selected_frame));
|
|
85 ((markobj) (d->frame_with_focus_real));
|
|
86 ((markobj) (d->frame_with_focus_for_hooks));
|
|
87 ((markobj) (d->frame_that_ought_to_have_focus));
|
|
88 ((markobj) (d->device_class));
|
|
89 ((markobj) (d->user_defined_tags));
|
|
90 ((markobj) (d->pixel_to_glyph_cache.obj1));
|
|
91 ((markobj) (d->pixel_to_glyph_cache.obj2));
|
|
92
|
|
93 ((markobj) (d->color_instance_cache));
|
|
94 ((markobj) (d->font_instance_cache));
|
|
95 ((markobj) (d->image_instance_cache));
|
|
96
|
|
97 if (d->devmeths)
|
|
98 {
|
|
99 ((markobj) (d->devmeths->symbol));
|
|
100 MAYBE_DEVMETH (d, mark_device, (d, markobj));
|
|
101 }
|
|
102
|
|
103 return (d->frame_list);
|
|
104 }
|
|
105
|
|
106 static void
|
|
107 print_device (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
108 {
|
|
109 struct device *d = XDEVICE (obj);
|
|
110 char buf[256];
|
|
111
|
|
112 if (print_readably)
|
|
113 error ("printing unreadable object #<device %s 0x%x>",
|
14
|
114 XSTRING_DATA (d->name), d->header.uid);
|
0
|
115
|
|
116 sprintf (buf, "#<%s-device", !DEVICE_LIVE_P (d) ? "dead" :
|
|
117 DEVICE_TYPE_NAME (d));
|
|
118 write_c_string (buf, printcharfun);
|
|
119 if (DEVICE_LIVE_P (d))
|
|
120 {
|
|
121 write_c_string (" on ", printcharfun);
|
|
122 print_internal (DEVICE_CONNECTION (d), printcharfun, 1);
|
|
123 }
|
|
124 sprintf (buf, " 0x%x>", d->header.uid);
|
|
125 write_c_string (buf, printcharfun);
|
|
126 }
|
|
127
|
|
128
|
|
129 int
|
|
130 valid_device_class_p (Lisp_Object class)
|
|
131 {
|
|
132 return !NILP (memq_no_quit (class, Vdevice_class_list));
|
|
133 }
|
|
134
|
20
|
135 DEFUN ("valid-device-class-p", Fvalid_device_class_p, 1, 1, 0, /*
|
0
|
136 Given a DEVICE-CLASS, return t if it is valid.
|
|
137 Valid classes are 'color, 'grayscale, and 'mono.
|
20
|
138 */
|
|
139 (device_class))
|
0
|
140 {
|
|
141 if (valid_device_class_p (device_class))
|
|
142 return Qt;
|
|
143 else
|
|
144 return Qnil;
|
|
145 }
|
|
146
|
20
|
147 DEFUN ("device-class-list", Fdevice_class_list, 0, 0, 0, /*
|
0
|
148 Return a list of valid device classes.
|
20
|
149 */
|
|
150 ())
|
0
|
151 {
|
|
152 return Fcopy_sequence (Vdevice_class_list);
|
|
153 }
|
|
154
|
|
155 static struct device *
|
|
156 allocate_device (Lisp_Object console)
|
|
157 {
|
|
158 Lisp_Object device = Qnil;
|
|
159 struct device *d = alloc_lcrecord (sizeof (struct device), lrecord_device);
|
|
160 struct gcpro gcpro1;
|
|
161
|
|
162 zero_lcrecord (d);
|
|
163
|
|
164 XSETDEVICE (device, d);
|
|
165 GCPRO1 (device);
|
|
166
|
|
167 d->name = Qnil;
|
|
168 d->console = console;
|
|
169 d->connection = Qnil;
|
|
170 d->canon_connection = Qnil;
|
|
171 d->frame_list = Qnil;
|
|
172 d->_selected_frame = Qnil;
|
|
173 d->frame_with_focus_real = Qnil;
|
|
174 d->frame_with_focus_for_hooks = Qnil;
|
|
175 d->frame_that_ought_to_have_focus = Qnil;
|
|
176 d->device_class = Qnil;
|
|
177 d->user_defined_tags = Qnil;
|
|
178 d->pixel_to_glyph_cache.obj1 = Qnil;
|
|
179 d->pixel_to_glyph_cache.obj2 = Qnil;
|
|
180
|
|
181 d->infd = d->outfd = -1;
|
|
182
|
|
183 /* #### is 20 reasonable? */
|
|
184 d->color_instance_cache = make_lisp_hashtable (20, HASHTABLE_KEY_WEAK,
|
|
185 HASHTABLE_EQUAL);
|
|
186 d->font_instance_cache = make_lisp_hashtable (20, HASHTABLE_KEY_WEAK,
|
|
187 HASHTABLE_EQUAL);
|
|
188 /*
|
|
189 Note that the image instance cache is actually bi-level.
|
|
190 See device.h. We use a low number here because most of the
|
|
191 time there aren't very many diferent masks that will be used.
|
|
192 */
|
|
193 d->image_instance_cache = make_lisp_hashtable (5, HASHTABLE_NONWEAK,
|
|
194 HASHTABLE_EQ);
|
|
195
|
|
196 UNGCPRO;
|
|
197 return d;
|
|
198 }
|
|
199
|
|
200 struct device *
|
|
201 decode_device (Lisp_Object device)
|
|
202 {
|
|
203 if (NILP (device))
|
|
204 device = Fselected_device (Qnil);
|
|
205 /* quietly accept frames for the device arg */
|
|
206 if (FRAMEP (device))
|
|
207 device = FRAME_DEVICE (decode_frame (device));
|
|
208 CHECK_LIVE_DEVICE (device);
|
|
209 return XDEVICE (device);
|
|
210 }
|
|
211
|
|
212 Lisp_Object
|
|
213 make_device (struct device *d)
|
|
214 {
|
|
215 Lisp_Object device = Qnil;
|
|
216 XSETDEVICE (device, d);
|
|
217 return device;
|
|
218 }
|
|
219
|
20
|
220 DEFUN ("dfw-device", Fdfw_device, 1, 1, 0, /*
|
0
|
221 Given a device, frame, or window, return the associated device.
|
|
222 Return nil otherwise.
|
20
|
223 */
|
|
224 (obj))
|
0
|
225 {
|
|
226 return DFW_DEVICE (obj);
|
|
227 }
|
|
228
|
|
229
|
20
|
230 DEFUN ("selected-device", Fselected_device, 0, 1, 0, /*
|
0
|
231 Return the device which is currently active.
|
|
232 If optional CONSOLE is non-nil, return the device that would be currently
|
|
233 active if CONSOLE were the selected console.
|
20
|
234 */
|
|
235 (console))
|
0
|
236 {
|
|
237 if (NILP (console) && NILP (Vselected_console))
|
|
238 return Qnil; /* happens early in temacs */
|
|
239 return CONSOLE_SELECTED_DEVICE (decode_console (console));
|
|
240 }
|
|
241
|
|
242 /* Called from selected_frame_1(), called from Fselect_window() */
|
|
243 void
|
|
244 select_device_1 (Lisp_Object device)
|
|
245 {
|
|
246 struct device *dev = XDEVICE (device);
|
|
247 Lisp_Object old_selected_device = Fselected_device (Qnil);
|
|
248
|
|
249 if (EQ (device, old_selected_device))
|
|
250 return;
|
|
251
|
|
252 /* now select the device's console */
|
|
253 CONSOLE_SELECTED_DEVICE (XCONSOLE (DEVICE_CONSOLE (dev))) = device;
|
|
254 select_console_1 (DEVICE_CONSOLE (dev));
|
|
255 }
|
|
256
|
20
|
257 DEFUN ("select-device", Fselect_device, 1, 1, 0, /*
|
0
|
258 Select the device DEVICE.
|
|
259 Subsequent editing commands apply to its console, selected frame,
|
|
260 and selected window.
|
|
261 The selection of DEVICE lasts until the next time the user does
|
|
262 something to select a different device, or until the next time this
|
|
263 function is called.
|
20
|
264 */
|
|
265 (device))
|
0
|
266 {
|
|
267 CHECK_LIVE_DEVICE (device);
|
|
268
|
|
269 /* select the device's selected frame's selected window. This will call
|
|
270 selected_frame_1()->selected_device_1()->selected_console_1(). */
|
|
271 if (!NILP (DEVICE_SELECTED_FRAME (XDEVICE (device))))
|
|
272 Fselect_window (FRAME_SELECTED_WINDOW
|
|
273 (XFRAME (DEVICE_SELECTED_FRAME (XDEVICE (device)))));
|
|
274 else
|
|
275 error ("Can't select a device with no frames");
|
|
276 return Qnil;
|
|
277 }
|
|
278
|
|
279 void
|
|
280 set_device_selected_frame (struct device *d, Lisp_Object frame)
|
|
281 {
|
|
282 if (!NILP (frame) && !FRAME_MINIBUF_ONLY_P (XFRAME (frame)))
|
|
283 set_console_last_nonminibuf_frame (XCONSOLE (DEVICE_CONSOLE (d)), frame);
|
|
284 d->_selected_frame = frame;
|
|
285 }
|
|
286
|
20
|
287 DEFUN ("set-device-selected-frame", Fset_device_selected_frame, 2, 2, 0, /*
|
0
|
288 Set the selected frame of device object DEVICE to FRAME.
|
|
289 If DEVICE is nil, the selected device is used.
|
|
290 If DEVICE is the selected device, this makes FRAME the selected frame.
|
20
|
291 */
|
|
292 (device, frame))
|
0
|
293 {
|
|
294 XSETDEVICE (device, decode_device (device));
|
|
295 CHECK_LIVE_FRAME (frame);
|
|
296
|
|
297 if (! EQ (device, FRAME_DEVICE (XFRAME (frame))))
|
|
298 error ("In `set-device-selected-frame', FRAME is not on DEVICE");
|
|
299
|
|
300 if (EQ (device, Fselected_device (Qnil)))
|
|
301 return Fselect_frame (frame);
|
|
302
|
|
303 set_device_selected_frame (XDEVICE (device), frame);
|
|
304 return frame;
|
|
305 }
|
|
306
|
20
|
307 DEFUN ("devicep", Fdevicep, 1, 1, 0, /*
|
0
|
308 Return non-nil if OBJECT is a device.
|
20
|
309 */
|
|
310 (object))
|
0
|
311 {
|
|
312 if (!DEVICEP (object))
|
|
313 return Qnil;
|
|
314 return Qt;
|
|
315 }
|
|
316
|
20
|
317 DEFUN ("device-live-p", Fdevice_live_p, 1, 1, 0, /*
|
0
|
318 Return non-nil if OBJECT is a device that has not been deleted.
|
20
|
319 */
|
|
320 (object))
|
0
|
321 {
|
|
322 if (!DEVICEP (object) || !DEVICE_LIVE_P (XDEVICE (object)))
|
|
323 return Qnil;
|
|
324 return Qt;
|
|
325 }
|
|
326
|
20
|
327 DEFUN ("device-name", Fdevice_name, 0, 1, 0, /*
|
0
|
328 Return the name of the specified device.
|
|
329 DEVICE defaults to the selected device if omitted.
|
20
|
330 */
|
|
331 (device))
|
0
|
332 {
|
|
333 return DEVICE_NAME (decode_device (device));
|
|
334 }
|
|
335
|
20
|
336 DEFUN ("device-connection", Fdevice_connection, 0, 1, 0, /*
|
0
|
337 Return the connection of the specified device.
|
|
338 DEVICE defaults to the selected device if omitted.
|
20
|
339 */
|
|
340 (device))
|
0
|
341 {
|
|
342 return DEVICE_CONNECTION (decode_device (device));
|
|
343 }
|
|
344
|
20
|
345 DEFUN ("device-console", Fdevice_console, 0, 1, 0, /*
|
0
|
346 Return the console of the specified device.
|
|
347 DEVICE defaults to the selected device if omitted.
|
20
|
348 */
|
|
349 (device))
|
0
|
350 {
|
|
351 return DEVICE_CONSOLE (decode_device (device));
|
|
352 }
|
|
353
|
|
354 #ifdef HAVE_X_WINDOWS
|
|
355 extern Lisp_Object Vdefault_x_device;
|
|
356 #endif
|
|
357 #ifdef HAVE_NEXTSTEP
|
|
358 extern Lisp_Object Vdefault_ns_device;
|
|
359 #endif
|
|
360
|
|
361 #ifdef HAVE_X_WINDOWS
|
|
362
|
|
363 static void
|
|
364 init_global_resources (struct device *d)
|
|
365 {
|
|
366 init_global_faces (d);
|
|
367 #ifdef HAVE_SCROLLBARS
|
|
368 init_global_scrollbars (d);
|
|
369 #endif
|
|
370 #ifdef HAVE_TOOLBARS
|
|
371 init_global_toolbars (d);
|
|
372 #endif
|
|
373 }
|
|
374
|
|
375 #endif
|
|
376
|
|
377 static void
|
|
378 init_device_resources (struct device *d)
|
|
379 {
|
|
380 init_device_faces (d);
|
|
381 #ifdef HAVE_SCROLLBARS
|
|
382 init_device_scrollbars (d);
|
|
383 #endif
|
|
384 #ifdef HAVE_TOOLBARS
|
|
385 init_device_toolbars (d);
|
|
386 #endif
|
|
387 }
|
|
388
|
|
389 static Lisp_Object
|
|
390 semi_canonicalize_device_connection (struct console_methods *meths,
|
|
391 Lisp_Object name, Error_behavior errb)
|
|
392 {
|
|
393 return CONTYPE_METH_OR_GIVEN (meths, semi_canonicalize_device_connection,
|
|
394 (name, errb), name);
|
|
395 }
|
|
396
|
|
397 static Lisp_Object
|
|
398 canonicalize_device_connection (struct console_methods *meths,
|
|
399 Lisp_Object name, Error_behavior errb)
|
|
400 {
|
|
401 return CONTYPE_METH_OR_GIVEN (meths, canonicalize_device_connection,
|
|
402 (name, errb), name);
|
|
403 }
|
|
404
|
|
405 static Lisp_Object
|
|
406 find_device_of_type (struct console_methods *meths, Lisp_Object canon)
|
|
407 {
|
|
408 Lisp_Object devcons, concons;
|
|
409
|
|
410 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
411 {
|
|
412 Lisp_Object device = XCAR (devcons);
|
|
413
|
|
414 if (EQ (CONMETH_TYPE (meths), DEVICE_TYPE (XDEVICE (device)))
|
|
415 && !NILP (Fequal (DEVICE_CANON_CONNECTION (XDEVICE (device)),
|
|
416 canon)))
|
|
417 return device;
|
|
418 }
|
|
419
|
|
420 return Qnil;
|
|
421 }
|
|
422
|
20
|
423 DEFUN ("find-device", Ffind_device, 1, 2, 0, /*
|
0
|
424 Look for an existing device attached to connection CONNECTION.
|
|
425 Return the device if found; otherwise, return nil.
|
|
426
|
|
427 If TYPE is specified, only return devices of that type; otherwise,
|
|
428 return devices of any type. (It is possible, although unlikely,
|
|
429 that two devices of different types could have the same connection
|
|
430 name; in such a case, the first device found is returned.)
|
20
|
431 */
|
|
432 (connection, type))
|
0
|
433 {
|
|
434 Lisp_Object canon = Qnil;
|
|
435 struct gcpro gcpro1;
|
|
436
|
|
437 GCPRO1 (canon);
|
|
438
|
|
439 if (!NILP (type))
|
|
440 {
|
|
441 struct console_methods *conmeths = decode_console_type (type, ERROR_ME);
|
|
442 canon = canonicalize_device_connection (conmeths, connection,
|
|
443 ERROR_ME_NOT);
|
|
444 if (UNBOUNDP (canon))
|
|
445 RETURN_UNGCPRO (Qnil);
|
|
446
|
|
447 RETURN_UNGCPRO (find_device_of_type (conmeths, canon));
|
|
448 }
|
|
449 else
|
|
450 {
|
|
451 int i;
|
|
452
|
|
453 for (i = 0; i < Dynarr_length (the_console_type_entry_dynarr); i++)
|
|
454 {
|
|
455 struct console_methods *conmeths =
|
|
456 Dynarr_at (the_console_type_entry_dynarr, i).meths;
|
|
457 canon = canonicalize_device_connection (conmeths, connection,
|
|
458 ERROR_ME_NOT);
|
|
459 if (!UNBOUNDP (canon))
|
|
460 {
|
|
461 Lisp_Object device = find_device_of_type (conmeths, canon);
|
|
462 if (!NILP (device))
|
|
463 RETURN_UNGCPRO (device);
|
|
464 }
|
|
465 }
|
|
466
|
|
467 RETURN_UNGCPRO (Qnil);
|
|
468 }
|
|
469 }
|
|
470
|
20
|
471 DEFUN ("get-device", Fget_device, 1, 2, 0, /*
|
0
|
472 Look for an existing device attached to connection CONNECTION.
|
|
473 Return the device if found; otherwise, signal an error.
|
|
474
|
|
475 If TYPE is specified, only return devices of that type; otherwise,
|
|
476 return devices of any type. (It is possible, although unlikely,
|
|
477 that two devices of different types could have the same connection
|
|
478 name; in such a case, the first device found is returned.)
|
20
|
479 */
|
|
480 (connection, type))
|
0
|
481 {
|
|
482 Lisp_Object device = Ffind_device (connection, type);
|
|
483 if (NILP (device))
|
|
484 {
|
|
485 if (NILP (type))
|
|
486 signal_simple_error ("No such device", connection);
|
|
487 else
|
|
488 signal_simple_error_2 ("No such device", type, connection);
|
|
489 }
|
|
490 return device;
|
|
491 }
|
|
492
|
20
|
493 DEFUN ("make-device", Fmake_device, 2, 3, 0, /*
|
0
|
494 Create a new device of type TYPE, attached to connection CONNECTION.
|
|
495
|
|
496 The valid values for CONNECTION are device-specific; however,
|
|
497 CONNECTION is generally a string. (Specifically, for X devices,
|
|
498 CONNECTION should be a display specification such as "foo:0", and
|
|
499 for TTY devices, CONNECTION should be the filename of a TTY device
|
|
500 file, such as "/dev/ttyp4", or nil to refer to XEmacs' standard
|
|
501 input/output.)
|
|
502
|
|
503 PROPS, if specified, should be a plist of properties controlling
|
|
504 device creation.
|
|
505
|
|
506 If CONNECTION specifies an already-existing device connection, that
|
|
507 device is simply returned; no new device is created, and PROPS
|
|
508 have no effect.
|
20
|
509 */
|
|
510 (type, connection, props))
|
0
|
511 {
|
|
512 /* This function can GC */
|
|
513 struct device *d;
|
|
514 struct console *con;
|
|
515 Lisp_Object device = Qnil;
|
|
516 Lisp_Object console = Qnil;
|
|
517 Lisp_Object name = Qnil;
|
|
518 struct console_methods *conmeths;
|
|
519
|
|
520 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
521 #ifdef HAVE_X_WINDOWS
|
|
522 /* #### icky-poo. If this is the first X device we are creating,
|
|
523 then retrieve the global face resources. We have to do it
|
|
524 here, at the same time as (or just before) the device face
|
|
525 resources are retrieved; specifically, it needs to be done
|
|
526 after the device has been created but before any frames have
|
|
527 been popped up or much anything else has been done. It's
|
|
528 possible for other devices to specify different global
|
|
529 resources (there's a property on each X server's root window
|
|
530 that holds some resources); tough luck for the moment.
|
|
531
|
|
532 This is a nasty violation of device independence, but
|
|
533 there's not a whole lot I can figure out to do about it.
|
|
534 The real problem is that the concept of resources is not
|
|
535 generalized away from X. Similar resource-related
|
|
536 device-independence violations occur in faces.el. */
|
|
537 int first_x_device = NILP (Vdefault_x_device) && EQ (type, Qx);
|
|
538 #endif
|
|
539
|
|
540 GCPRO3 (device, console, name);
|
|
541
|
|
542 conmeths = decode_console_type (type, ERROR_ME_NOT);
|
|
543 if (!conmeths)
|
|
544 signal_simple_error ("Invalid device type", type);
|
|
545
|
|
546 device = Ffind_device (connection, type);
|
|
547 if (!NILP (device))
|
|
548 RETURN_UNGCPRO (device);
|
|
549
|
|
550 name = Fplist_get (props, Qname, Qnil);
|
|
551
|
|
552 {
|
|
553 Lisp_Object conconnect =
|
|
554 CONTYPE_METH_OR_GIVEN (conmeths,
|
|
555 device_to_console_connection,
|
|
556 (connection, ERROR_ME),
|
|
557 connection);
|
|
558 console = create_console (name, type, conconnect, props);
|
|
559 }
|
|
560
|
|
561 con = XCONSOLE (console);
|
|
562 d = allocate_device (console);
|
|
563 XSETDEVICE (device, d);
|
|
564
|
|
565 d->devmeths = con->conmeths;
|
|
566
|
|
567 DEVICE_NAME (d) = name;
|
|
568 DEVICE_CONNECTION (d) = semi_canonicalize_device_connection (conmeths,
|
|
569 connection,
|
|
570 ERROR_ME);
|
|
571 DEVICE_CANON_CONNECTION (d) = canonicalize_device_connection (conmeths,
|
|
572 connection,
|
|
573 ERROR_ME);
|
|
574
|
|
575 MAYBE_DEVMETH (d, init_device, (d, props));
|
|
576
|
|
577 /* Do it this way so that the device list is in order of creation */
|
|
578 con->device_list = nconc2 (con->device_list, Fcons (device, Qnil));
|
|
579 RESET_CHANGED_SET_FLAGS;
|
|
580 if (NILP (Vdefault_device) || DEVICE_STREAM_P (XDEVICE (Vdefault_device)))
|
|
581 Vdefault_device = device;
|
|
582
|
|
583 init_device_sound (d);
|
|
584 #ifdef HAVE_X_WINDOWS
|
|
585 if (first_x_device)
|
|
586 init_global_resources (d);
|
|
587 #endif
|
|
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;
|
|
600 return device;
|
|
601 }
|
|
602
|
|
603 /* find a device other than the selected one. Prefer non-stream
|
|
604 devices over stream devices. Maybe stay on the same console. */
|
|
605
|
|
606 static Lisp_Object
|
|
607 find_other_device (Lisp_Object device, int on_same_console)
|
|
608 {
|
|
609 Lisp_Object devcons = Qnil, concons = Qnil;
|
|
610 Lisp_Object console = DEVICE_CONSOLE (XDEVICE (device));
|
|
611
|
|
612 /* look for a non-stream device */
|
|
613 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
614 {
|
|
615 Lisp_Object dev = XCAR (devcons);
|
|
616 if (on_same_console && !EQ (console, DEVICE_CONSOLE (XDEVICE (dev))))
|
|
617 continue;
|
|
618 if (!DEVICE_STREAM_P (XDEVICE (dev)) && !EQ (dev, device) &&
|
|
619 !NILP (DEVICE_SELECTED_FRAME (XDEVICE (dev))))
|
|
620 goto double_break_1;
|
|
621 }
|
|
622
|
|
623 double_break_1:
|
|
624 if (!NILP (devcons))
|
|
625 return XCAR (devcons);
|
|
626
|
|
627 /* OK, now look for a stream device */
|
|
628 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
629 {
|
|
630 Lisp_Object dev = XCAR (devcons);
|
|
631 if (on_same_console && !EQ (console, DEVICE_CONSOLE (XDEVICE (dev))))
|
|
632 continue;
|
|
633 if (!EQ (dev, device) && !NILP (DEVICE_SELECTED_FRAME (XDEVICE (dev))))
|
|
634 goto double_break_2;
|
|
635 }
|
|
636 double_break_2:
|
|
637 if (!NILP (devcons))
|
|
638 return XCAR (devcons);
|
|
639
|
|
640 /* Sorry, there ain't none */
|
|
641 return Qnil;
|
|
642 }
|
|
643
|
|
644 static int
|
|
645 find_nonminibuffer_frame_not_on_device_predicate (Lisp_Object frame,
|
|
646 void *closure)
|
|
647 {
|
|
648 Lisp_Object device;
|
|
649
|
|
650 VOID_TO_LISP (device, closure);
|
|
651 if (FRAME_MINIBUF_ONLY_P (XFRAME (frame)))
|
|
652 return 0;
|
|
653 if (EQ (device, FRAME_DEVICE (XFRAME (frame))))
|
|
654 return 0;
|
|
655 return 1;
|
|
656 }
|
|
657
|
|
658 Lisp_Object
|
|
659 find_nonminibuffer_frame_not_on_device (Lisp_Object device)
|
|
660 {
|
|
661 return find_some_frame (find_nonminibuffer_frame_not_on_device_predicate,
|
|
662 LISP_TO_VOID (device));
|
|
663 }
|
|
664
|
|
665
|
|
666 /* Delete device D.
|
|
667
|
|
668 If FORCE is non-zero, allow deletion of the only frame.
|
|
669
|
|
670 If CALLED_FROM_DELETE_CONSOLE is non-zero, then, if
|
|
671 deleting the last device on a console, just delete it,
|
|
672 instead of calling `delete-console'.
|
|
673
|
|
674 If FROM_IO_ERROR is non-zero, then the device is gone due
|
|
675 to an I/O error. This affects what happens if we exit
|
|
676 (we do an emergency exit instead of `save-buffers-kill-emacs'.)
|
|
677 */
|
|
678
|
|
679 void
|
|
680 delete_device_internal (struct device *d, int force,
|
|
681 int called_from_delete_console,
|
|
682 int from_io_error)
|
|
683 {
|
|
684 /* This function can GC */
|
|
685 struct console *c;
|
|
686 Lisp_Object device = Qnil;
|
|
687 struct gcpro gcpro1;
|
|
688
|
|
689 /* OK to delete an already-deleted device. */
|
|
690 if (!DEVICE_LIVE_P (d))
|
|
691 return;
|
|
692
|
|
693 XSETDEVICE (device, d);
|
|
694 GCPRO1 (device);
|
|
695
|
|
696 c = XCONSOLE (DEVICE_CONSOLE (d));
|
|
697
|
|
698 if (!called_from_delete_console)
|
|
699 {
|
|
700 int delete_console = 0;
|
|
701 /* If we're deleting the only device on the console,
|
|
702 delete the console. */
|
|
703 if ((XINT (Flength (CONSOLE_DEVICE_LIST (c))) == 1)
|
|
704 /* if we just created the device, it might not be listed,
|
|
705 or something ... */
|
|
706 && !NILP (memq_no_quit (device, CONSOLE_DEVICE_LIST (c))))
|
|
707 delete_console = 1;
|
|
708 /* Or if there aren't any nonminibuffer frames that would be
|
|
709 left, delete the console (this will make XEmacs exit). */
|
|
710 else if (NILP (find_nonminibuffer_frame_not_on_device (device)))
|
|
711 delete_console = 1;
|
|
712
|
|
713 if (delete_console)
|
|
714 {
|
|
715 delete_console_internal (c, force, 0, from_io_error);
|
|
716 UNGCPRO;
|
|
717 return;
|
|
718 }
|
|
719 }
|
|
720
|
|
721 reset_one_device (d);
|
|
722
|
|
723 {
|
|
724 Lisp_Object frmcons;
|
|
725
|
|
726 /* First delete all frames without their own minibuffers,
|
|
727 to avoid errors coming from attempting to delete a frame
|
|
728 that is a surrogate for another frame. */
|
|
729 DEVICE_FRAME_LOOP (frmcons, d)
|
|
730 {
|
|
731 struct frame *f = XFRAME (XCAR (frmcons));
|
|
732 /* delete_frame_internal() might do anything such as run hooks,
|
|
733 so be defensive. */
|
|
734 if (FRAME_LIVE_P (f) && !FRAME_HAS_MINIBUF_P (f))
|
|
735 delete_frame_internal (f, 1, 1, from_io_error);
|
|
736
|
|
737 if (!DEVICE_LIVE_P (d)) /* make sure the delete-*-hook didn't
|
|
738 go ahead and delete anything */
|
|
739 {
|
|
740 UNGCPRO;
|
|
741 return;
|
|
742 }
|
|
743 }
|
|
744
|
|
745 /* #### This should probably be a device method but it is time for
|
|
746 19.14 to go out the door. */
|
|
747 #ifdef HAVE_X_WINDOWS
|
|
748 /* Next delete all frames which have the popup property to avoid
|
|
749 deleting a child after its parent. */
|
|
750 DEVICE_FRAME_LOOP (frmcons, d)
|
|
751 {
|
|
752 struct frame *f = XFRAME (XCAR (frmcons));
|
|
753
|
|
754 if (FRAME_LIVE_P (f))
|
|
755 {
|
|
756 Lisp_Object popup = Fframe_property (XCAR (frmcons), Qpopup, Qnil);
|
|
757 if (!NILP (popup))
|
|
758 delete_frame_internal (f, 1, 1, from_io_error);
|
|
759
|
|
760 if (!DEVICE_LIVE_P (d)) /* make sure the delete-*-hook didn't
|
|
761 go ahead and delete anything */
|
|
762 {
|
|
763 UNGCPRO;
|
|
764 return;
|
|
765 }
|
|
766 }
|
|
767 }
|
|
768 #endif /* HAVE_X_WINDOWS */
|
|
769
|
|
770 DEVICE_FRAME_LOOP (frmcons, d)
|
|
771 {
|
|
772 struct frame *f = XFRAME (XCAR (frmcons));
|
|
773 /* delete_frame_internal() might do anything such as run hooks,
|
|
774 so be defensive. */
|
|
775 if (FRAME_LIVE_P (f))
|
|
776 delete_frame_internal (f, 1, 1, from_io_error);
|
|
777
|
|
778 if (!DEVICE_LIVE_P (d)) /* make sure the delete-*-hook didn't
|
|
779 go ahead and delete anything */
|
|
780 {
|
|
781 UNGCPRO;
|
|
782 return;
|
|
783 }
|
|
784 }
|
|
785 }
|
|
786
|
|
787 set_device_selected_frame (d, Qnil);
|
|
788
|
|
789 /* try to select another device */
|
|
790
|
|
791 if (EQ (device, Fselected_device (DEVICE_CONSOLE (d))))
|
|
792 {
|
|
793 Lisp_Object other_dev = find_other_device (device, 1);
|
|
794 if (!NILP (other_dev))
|
|
795 Fselect_device (other_dev);
|
|
796 }
|
|
797
|
|
798 if (EQ (device, Vdefault_device))
|
|
799 Vdefault_device = find_other_device (device, 0);
|
|
800
|
|
801 MAYBE_DEVMETH (d, delete_device, (d));
|
|
802
|
|
803 CONSOLE_DEVICE_LIST (c) = delq_no_quit (device, CONSOLE_DEVICE_LIST (c));
|
|
804 RESET_CHANGED_SET_FLAGS;
|
|
805 d->devmeths = dead_console_methods;
|
|
806 UNGCPRO;
|
|
807 }
|
|
808
|
|
809 /* delete a device as a result of an I/O error. Called from
|
|
810 an enqueued magic-eval event. */
|
|
811
|
|
812 void
|
|
813 io_error_delete_device (Lisp_Object device)
|
|
814 {
|
|
815 delete_device_internal (XDEVICE (device), 1, 0, 1);
|
|
816 }
|
|
817
|
20
|
818 DEFUN ("delete-device", Fdelete_device, 1, 2, 0, /*
|
0
|
819 Delete DEVICE, permanently eliminating it from use.
|
|
820 Normally, you cannot delete the last non-minibuffer-only frame (you must
|
|
821 use `save-buffers-kill-emacs' or `kill-emacs'). However, if optional
|
|
822 second argument FORCE is non-nil, you can delete the last frame. (This
|
|
823 will automatically call `save-buffers-kill-emacs'.)
|
20
|
824 */
|
|
825 (device, force))
|
0
|
826 {
|
|
827 CHECK_DEVICE (device);
|
|
828 delete_device_internal (XDEVICE (device), !NILP (force), 0, 0);
|
|
829 return Qnil;
|
|
830 }
|
|
831
|
20
|
832 DEFUN ("device-frame-list", Fdevice_frame_list, 0, 1, 0, /*
|
0
|
833 Return a list of all frames on DEVICE.
|
|
834 If DEVICE is nil, the selected device will be used.
|
20
|
835 */
|
|
836 (device))
|
0
|
837 {
|
|
838 return Fcopy_sequence (DEVICE_FRAME_LIST (decode_device (device)));
|
|
839 }
|
|
840
|
20
|
841 DEFUN ("device-class", Fdevice_class, 0, 1, 0, /*
|
0
|
842 Return the class (color behavior) of DEVICE.
|
|
843 This will be one of 'color, 'grayscale, or 'mono.
|
20
|
844 */
|
|
845 (device))
|
0
|
846 {
|
|
847 return DEVICE_CLASS (decode_device (device));
|
|
848 }
|
|
849
|
20
|
850 DEFUN ("set-device-class", Fset_device_class, 2, 2, 0, /*
|
0
|
851 Set the class (color behavior) of DEVICE.
|
|
852 CLASS should be one of 'color, 'grayscale, or 'mono.
|
|
853 This is only allowed on device such as TTY devices, where the color
|
|
854 behavior cannot necessarily be determined automatically.
|
20
|
855 */
|
|
856 (device, class))
|
0
|
857 {
|
|
858 struct device *d = decode_device (device);
|
|
859 XSETDEVICE (device, d);
|
|
860 if (!DEVICE_TTY_P (d))
|
|
861 signal_simple_error ("Cannot change the class of this device", device);
|
|
862 if (!EQ (class, Qcolor) && !EQ (class, Qmono) && !EQ (class, Qgrayscale))
|
|
863 signal_simple_error ("Must be color, mono, or grayscale", class);
|
|
864 DEVICE_CLASS (d) = class;
|
|
865 return Qnil;
|
|
866 }
|
|
867
|
20
|
868 DEFUN ("device-pixel-width", Fdevice_pixel_width, 0, 1, 0, /*
|
0
|
869 Return the width in pixels of DEVICE, or nil if unknown.
|
20
|
870 */
|
|
871 (device))
|
0
|
872 {
|
|
873 struct device *d = decode_device (device);
|
|
874 int retval;
|
|
875
|
|
876 retval = DEVMETH_OR_GIVEN (d, device_pixel_width, (d), 0);
|
|
877 if (retval <= 0)
|
|
878 return Qnil;
|
|
879
|
|
880 return make_int (retval);
|
|
881 }
|
|
882
|
20
|
883 DEFUN ("device-pixel-height", Fdevice_pixel_height, 0, 1, 0, /*
|
0
|
884 Return the height in pixels of DEVICE, or nil if unknown.
|
20
|
885 */
|
|
886 (device))
|
0
|
887 {
|
|
888 struct device *d = decode_device (device);
|
|
889 int retval;
|
|
890
|
|
891 retval = DEVMETH_OR_GIVEN (d, device_pixel_height, (d), 0);
|
|
892 if (retval <= 0)
|
|
893 return Qnil;
|
|
894
|
|
895 return make_int (retval);
|
|
896 }
|
|
897
|
20
|
898 DEFUN ("device-mm-width", Fdevice_mm_width, 0, 1, 0, /*
|
0
|
899 Return the width in millimeters of DEVICE, or nil if unknown.
|
20
|
900 */
|
|
901 (device))
|
0
|
902 {
|
|
903 struct device *d = decode_device (device);
|
|
904 int retval;
|
|
905
|
|
906 retval = DEVMETH_OR_GIVEN (d, device_mm_width, (d), 0);
|
|
907 if (retval <= 0)
|
|
908 return Qnil;
|
|
909
|
|
910 return make_int (retval);
|
|
911 }
|
|
912
|
20
|
913 DEFUN ("device-mm-height", Fdevice_mm_height, 0, 1, 0, /*
|
0
|
914 Return the height in millimeters of DEVICE, or nil if unknown.
|
20
|
915 */
|
|
916 (device))
|
0
|
917 {
|
|
918 struct device *d = decode_device (device);
|
|
919 int retval;
|
|
920
|
|
921 retval = DEVMETH_OR_GIVEN (d, device_mm_height, (d), 0);
|
|
922 if (retval <= 0)
|
|
923 return Qnil;
|
|
924
|
|
925 return make_int (retval);
|
|
926 }
|
|
927
|
20
|
928 DEFUN ("device-bitplanes", Fdevice_bitplanes, 0, 1, 0, /*
|
0
|
929 Return the number of bitplanes of DEVICE, or nil if unknown.
|
20
|
930 */
|
|
931 (device))
|
0
|
932 {
|
|
933 struct device *d = decode_device (device);
|
|
934 int retval;
|
|
935
|
|
936 retval = DEVMETH_OR_GIVEN (d, device_bitplanes, (d), 0);
|
|
937 if (retval <= 0)
|
|
938 return Qnil;
|
|
939
|
|
940 return make_int (retval);
|
|
941 }
|
|
942
|
20
|
943 DEFUN ("device-color-cells", Fdevice_color_cells, 0, 1, 0, /*
|
0
|
944 Return the number of color cells of DEVICE, or nil if unknown.
|
20
|
945 */
|
|
946 (device))
|
0
|
947 {
|
|
948 struct device *d = decode_device (device);
|
|
949 int retval;
|
|
950
|
|
951 retval = DEVMETH_OR_GIVEN (d, device_color_cells, (d), 0);
|
|
952 if (retval <= 0)
|
|
953 return Qnil;
|
|
954
|
|
955 return make_int (retval);
|
|
956 }
|
|
957
|
20
|
958 DEFUN ("set-device-baud-rate", Fset_device_baud_rate, 2, 2, 0, /*
|
0
|
959 Set the output baud rate of DEVICE to RATE.
|
|
960 On most systems, changing this value will affect the amount of padding
|
|
961 and other strategic decisions made during redisplay.
|
20
|
962 */
|
|
963 (device, rate))
|
0
|
964 {
|
|
965 CHECK_INT (rate);
|
|
966
|
|
967 DEVICE_BAUD_RATE (decode_device (device)) = XINT (rate);
|
|
968
|
|
969 return rate;
|
|
970 }
|
|
971
|
20
|
972 DEFUN ("device-baud-rate", Fdevice_baud_rate, 0, 1, 0, /*
|
0
|
973 Return the output baud rate of DEVICE.
|
20
|
974 */
|
|
975 (device))
|
0
|
976 {
|
|
977 return make_int (DEVICE_BAUD_RATE (decode_device (device)));
|
|
978 }
|
|
979
|
|
980 void
|
|
981 handle_asynch_device_change (void)
|
|
982 {
|
|
983 int i;
|
|
984 int old_asynch_device_change_pending = asynch_device_change_pending;
|
|
985 for (i = 0; i < Dynarr_length (the_console_type_entry_dynarr); i++)
|
|
986 {
|
|
987 if (Dynarr_at (the_console_type_entry_dynarr, i).meths->
|
|
988 asynch_device_change_method)
|
|
989 (Dynarr_at (the_console_type_entry_dynarr, i).meths->
|
|
990 asynch_device_change_method) ();
|
|
991 }
|
|
992 /* reset the flag to 0 unless another notification occurred while
|
|
993 we were processing this one. Block SIGWINCH during this
|
|
994 check to prevent a possible race condition. */
|
|
995 EMACS_BLOCK_SIGNAL (SIGWINCH);
|
|
996 if (old_asynch_device_change_pending == asynch_device_change_pending)
|
|
997 asynch_device_change_pending = 0;
|
|
998 EMACS_UNBLOCK_SIGNAL (SIGWINCH);
|
|
999 }
|
|
1000
|
|
1001 void
|
|
1002 call_critical_lisp_code (struct device *d, Lisp_Object function,
|
|
1003 Lisp_Object object)
|
|
1004 {
|
|
1005 int old_gc_currently_forbidden = gc_currently_forbidden;
|
|
1006 Lisp_Object old_inhibit_quit = Vinhibit_quit;
|
|
1007
|
|
1008 /* There's no reason to bother doing specbinds here, because if
|
|
1009 initialize-*-faces signals an error, emacs is going to crash
|
|
1010 immediately.
|
|
1011 */
|
|
1012 gc_currently_forbidden = 1;
|
|
1013 Vinhibit_quit = Qt;
|
|
1014 LOCK_DEVICE (d);
|
|
1015
|
|
1016 /* But it's useful to have an error handler; otherwise an infinite
|
|
1017 loop may result. */
|
|
1018 if (!NILP (object))
|
|
1019 call1_with_handler (Qreally_early_error_handler, function, object);
|
|
1020 else
|
|
1021 call0_with_handler (Qreally_early_error_handler, function);
|
|
1022
|
|
1023 UNLOCK_DEVICE (d);
|
|
1024 Vinhibit_quit = old_inhibit_quit;
|
|
1025 gc_currently_forbidden = old_gc_currently_forbidden;
|
|
1026 }
|
|
1027
|
|
1028
|
|
1029 /************************************************************************/
|
|
1030 /* initialization */
|
|
1031 /************************************************************************/
|
|
1032
|
|
1033 void
|
|
1034 syms_of_device (void)
|
|
1035 {
|
20
|
1036 DEFSUBR (Fvalid_device_class_p);
|
|
1037 DEFSUBR (Fdevice_class_list);
|
0
|
1038
|
20
|
1039 DEFSUBR (Fdfw_device);
|
|
1040 DEFSUBR (Fselected_device);
|
|
1041 DEFSUBR (Fselect_device);
|
|
1042 DEFSUBR (Fset_device_selected_frame);
|
|
1043 DEFSUBR (Fdevicep);
|
|
1044 DEFSUBR (Fdevice_live_p);
|
|
1045 DEFSUBR (Fdevice_name);
|
|
1046 DEFSUBR (Fdevice_connection);
|
|
1047 DEFSUBR (Fdevice_console);
|
|
1048 DEFSUBR (Ffind_device);
|
|
1049 DEFSUBR (Fget_device);
|
|
1050 DEFSUBR (Fmake_device);
|
|
1051 DEFSUBR (Fdelete_device);
|
|
1052 DEFSUBR (Fdevice_frame_list);
|
|
1053 DEFSUBR (Fdevice_class);
|
|
1054 DEFSUBR (Fset_device_class);
|
|
1055 DEFSUBR (Fdevice_pixel_width);
|
|
1056 DEFSUBR (Fdevice_pixel_height);
|
|
1057 DEFSUBR (Fdevice_mm_width);
|
|
1058 DEFSUBR (Fdevice_mm_height);
|
|
1059 DEFSUBR (Fdevice_bitplanes);
|
|
1060 DEFSUBR (Fdevice_color_cells);
|
|
1061 DEFSUBR (Fset_device_baud_rate);
|
|
1062 DEFSUBR (Fdevice_baud_rate);
|
0
|
1063
|
|
1064 defsymbol (&Qdevicep, "devicep");
|
|
1065 defsymbol (&Qdevice_live_p, "device-live-p");
|
|
1066 defsymbol (&Qdelete_device, "delete-device");
|
|
1067
|
|
1068 defsymbol (&Qcreate_device_hook, "create-device-hook");
|
|
1069 defsymbol (&Qdelete_device_hook, "delete-device-hook");
|
|
1070
|
|
1071 /* Qcolor defined in general.c */
|
|
1072 defsymbol (&Qgrayscale, "grayscale");
|
|
1073 defsymbol (&Qmono, "mono");
|
|
1074 }
|
|
1075
|
|
1076 void
|
|
1077 vars_of_device (void)
|
|
1078 {
|
|
1079 DEFVAR_LISP ("create-device-hook", &Vcreate_device_hook /*
|
|
1080 Function or functions to call when a device is created.
|
|
1081 One argument, the newly-created device.
|
|
1082 This is called after the first frame has been created, but before
|
|
1083 calling the `create-frame-hook'.
|
|
1084 Note that in general the device will not be selected.
|
|
1085 */ );
|
|
1086 Vcreate_device_hook = Qnil;
|
|
1087
|
|
1088 DEFVAR_LISP ("delete-device-hook", &Vdelete_device_hook /*
|
|
1089 Function or functions to call when a device is deleted.
|
|
1090 One argument, the to-be-deleted device.
|
|
1091 */ );
|
|
1092 Vdelete_device_hook = Qnil;
|
|
1093
|
|
1094 staticpro (&Vdefault_device);
|
|
1095 Vdefault_device = Qnil;
|
|
1096
|
|
1097 asynch_device_change_pending = 0;
|
|
1098
|
|
1099 Vdevice_class_list = list3 (Qcolor, Qgrayscale, Qmono);
|
|
1100 staticpro (&Vdevice_class_list);
|
|
1101 }
|