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