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