annotate lisp/w3/devices.el @ 144:318232e2a3f0 r20-2b6

Import from CVS: tag r20-2b6
author cvs
date Mon, 13 Aug 2007 09:34:14 +0200
parents 6608ceec7cf8
children 489f57a838ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
1 ;;; devices.el -- XEmacs device API emulation
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
2 ;; Author: wmperry
144
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 138
diff changeset
3 ;; Created: 1997/04/25 21:27:01
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 138
diff changeset
4 ;; Version: 1.4
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
5 ;; Keywords:
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
6
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
8 ;;; Copyright (c) 1996 by William M. Perry (wmperry@cs.indiana.edu)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
10 ;;;
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
11 ;;; This file is not part of GNU Emacs, but the same permissions apply.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
12 ;;;
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
13 ;;; GNU Emacs is free software; you can redistribute it and/or modify
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
14 ;;; it under the terms of the GNU General Public License as published by
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
15 ;;; the Free Software Foundation; either version 2, or (at your option)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
16 ;;; any later version.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
17 ;;;
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
18 ;;; GNU Emacs is distributed in the hope that it will be useful,
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
21 ;;; GNU General Public License for more details.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
22 ;;;
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
23 ;;; You should have received a copy of the GNU General Public License
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
24 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
25 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
26 ;;; Boston, MA 02111-1307, USA.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
27 ;;;
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
29
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
30 ;; This is a complete implementation of all the device-* functions found in
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
31 ;; XEmacs 19.14. A 'device' for Emacs 19 is just a frame, from which we can
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
32 ;; determine the connection to an X display, etc.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
33
144
318232e2a3f0 Import from CVS: tag r20-2b6
cvs
parents: 138
diff changeset
34 (require 'cl)
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
35 (eval-when-compile
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
36 (if (string-match "XEmacs" (emacs-version))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
37 (set 'byte-optimize nil)))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
38
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
39 (if (string-match "XEmacs" (emacs-version))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
40 nil
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
41 '()
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
42 (defalias 'selected-device 'ignore)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
43 (defalias 'device-or-frame-p 'framep)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
44 (defalias 'device-console 'ignore)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
45 (defalias 'device-sound-enabled-p 'ignore)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
46 (defalias 'device-live-p 'frame-live-p)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
47 (defalias 'devicep 'framep)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
48 (defalias 'frame-device 'identity)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
49 (defalias 'redisplay-device 'redraw-frame)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
50 (defalias 'redraw-device 'redraw-frame)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
51 (defalias 'select-device 'select-frame)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
52 (defalias 'set-device-class 'ignore)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
53
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
54 (defun make-device (type connection &optional props)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
55 "Create a new device of type TYPE, attached to connection CONNECTION.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
56
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
57 The valid values for CONNECTION are device-specific; however,
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
58 CONNECTION is generally a string. (Specifically, for X devices,
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
59 CONNECTION should be a display specification such as \"foo:0\", and
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
60 for TTY devices, CONNECTION should be the filename of a TTY device
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
61 file, such as \"/dev/ttyp4\", or nil to refer to XEmacs' standard
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
62 input/output.)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
63
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
64 PROPS, if specified, should be a plist of properties controlling
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
65 device creation.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
66
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
67 If CONNECTION specifies an already-existing device connection, that
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
68 device is simply returned; no new device is created, and PROPS
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
69 have no effect."
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
70 (cond
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
71 ((and (eq type 'x) connection)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
72 (make-frame-on-display connection props))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
73 ((eq type 'x)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
74 (make-frame props))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
75 ((eq type 'tty)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
76 nil)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
77 (t
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
78 (error "Unsupported device-type: %s" type))))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
79
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
80 (defun make-frame-on-device (type connection &optional props)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
81 "Create a frame of type TYPE on CONNECTION.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
82 TYPE should be a symbol naming the device type, i.e. one of
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
83
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
84 x An X display. CONNECTION should be a standard display string
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
85 such as \"unix:0\", or nil for the display specified on the
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
86 command line or in the DISPLAY environment variable. Only if
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
87 support for X was compiled into XEmacs.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
88 tty A standard TTY connection or terminal. CONNECTION should be
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
89 a TTY device name such as \"/dev/ttyp2\" (as determined by
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
90 the Unix command `tty') or nil for XEmacs' standard input
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
91 and output (usually the TTY in which XEmacs started). Only
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
92 if support for TTY's was compiled into XEmacs.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
93 ns A connection to a machine running the NeXTstep windowing
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
94 system. Not currently implemented.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
95 win32 A connection to a machine running Microsoft Windows NT or
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
96 Windows 95. Not currently implemented.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
97 pc A direct-write MS-DOS frame. Not currently implemented.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
98
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
99 PROPS should be an plist of properties, as in the call to `make-frame'.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
100
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
101 If a connection to CONNECTION already exists, it is reused; otherwise,
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
102 a new connection is opened."
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
103 (make-device type connection props))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
104
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
105 (defun make-tty-device (&optional tty terminal-type)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
106 "Create a new device on TTY.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
107 TTY should be the name of a tty device file (e.g. \"/dev/ttyp3\" under
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
108 SunOS et al.), as returned by the `tty' command. A value of nil means
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
109 use the stdin and stdout as passed to XEmacs from the shell.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
110 If TERMINAL-TYPE is non-nil, it should be a string specifying the
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
111 type of the terminal attached to the specified tty. If it is nil,
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
112 the terminal type will be inferred from the TERM environment variable."
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
113 (make-device 'tty tty (list 'terminal-type terminal-type)))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
114
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
115 (defun make-x-device (&optional display)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
116 (make-device 'x display))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
117
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 136
diff changeset
118 (defun set-device-selected-frame (device frame)
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
119 "Set the selected frame of device object DEVICE to FRAME.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
120 If DEVICE is nil, the selected device is used.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
121 If DEVICE is the selected device, this makes FRAME the selected frame."
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
122 (select-frame frame))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
123
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 136
diff changeset
124 (defun set-device-baud-rate (device rate)
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
125 "Set the output baud rate of DEVICE to RATE.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
126 On most systems, changing this value will affect the amount of padding
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
127 and other strategic decisions made during redisplay."
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
128 (setq baud-rate rate))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
129
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
130 (defun dfw-device (obj)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
131 "Given a device, frame, or window, return the associated device.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
132 Return nil otherwise."
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
133 (cond
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
134 ((windowp obj)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
135 (window-frame obj))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
136 ((framep obj)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
137 obj)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
138 (t
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
139 nil)))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
140
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 136
diff changeset
141 (defun event-device (event)
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
142 "Return the device that EVENT occurred on.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
143 This will be nil for some types of events (e.g. keyboard and eval events)."
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
144 (dfw-device (posn-window (event-start event))))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
145
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 136
diff changeset
146 (defun device-connection (&optional device)
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
147 "Return the connection of the specified device.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
148 DEVICE defaults to the selected device if omitted"
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
149 (or (cdr-safe (assq 'display (frame-parameters device))) "stdio"))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
150
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
151 (defun find-device (connection &optional type)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
152 "Look for an existing device attached to connection CONNECTION.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
153 Return the device if found; otherwise, return nil.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
154
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
155 If TYPE is specified, only return devices of that type; otherwise,
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
156 return devices of any type. (It is possible, although unlikely,
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
157 that two devices of different types could have the same connection
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
158 name; in such a case, the first device found is returned.)"
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
159 (let ((devices (device-list))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
160 (retval nil))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
161 (while (and devices (not nil))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
162 (if (equal connection (device-connection (car devices)))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
163 (setq retval (car devices)))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
164 (setq devices (cdr devices)))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
165 retval))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
166
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
167 (defalias 'get-device 'find-device)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
168
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
169 (defmacro device-baud-rate (&optional device)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
170 "Return the output baud rate of DEVICE."
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
171 'baud-rate)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
172
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 136
diff changeset
173 (defun device-on-window-system-p (&optional device)
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
174 "Return non-nil if DEVICE is on a window system.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
175 This generally means that there is support for the mouse, the menubar,
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
176 the toolbar, glyphs, etc."
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
177 (and (cdr-safe (assq 'display (frame-parameters device))) t))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
178
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 136
diff changeset
179 (defun device-name (&optional device)
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
180 "Return the name of the specified device."
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
181 (or (cdr-safe (assq 'display (frame-parameters device))) "stdio"))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
182
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
183 (defun device-frame-list (&optional device)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
184 "Return a list of all frames on DEVICE.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
185 If DEVICE is nil, the selected device will be used."
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
186 (let ((desired (device-connection device)))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
187 (filtered-frame-list (function (lambda (x) (equal (device-connection x)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
188 desired))))))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
189 (defun device-list ()
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
190 "Return a list of all devices"
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
191 (let ((seen nil)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
192 (cur nil)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
193 (conn nil)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
194 (retval nil)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
195 (not-heard (frame-list)))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
196 (while not-heard
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
197 (setq cur (car not-heard)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
198 conn (device-connection cur)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
199 not-heard (cdr not-heard))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
200 (if (member conn seen)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
201 nil ; Already got it
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
202 (setq seen (cons conn seen) ; Whoo hoo, a new one!
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
203 retval (cons cur retval))))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
204 retval))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
205
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
206 (defvar delete-device-hook nil
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
207 "Function or functions to call when a device is deleted.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
208 One argument, the to-be-deleted device.")
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
209
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
210 (defun delete-device (device &optional force)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
211 "Delete DEVICE, permanently eliminating it from use.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
212 Normally, you cannot delete the last non-minibuffer-only frame (you must
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
213 use `save-buffers-kill-emacs' or `kill-emacs'). However, if optional
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
214 second argument FORCE is non-nil, you can delete the last frame. (This
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
215 will automatically call `save-buffers-kill-emacs'.)"
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
216 (let ((frames (device-frame-list device)))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
217 (run-hook-with-args 'delete-device-hook device)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
218 (while frames
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
219 (delete-frame (car frames) force)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
220 (setq frames (cdr frames)))))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
221
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 136
diff changeset
222 (defun device-color-cells (&optional device)
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
223 (case window-system
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
224 ((x win32 pm) (x-display-color-cells device))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
225 (ns (ns-display-color-cells device))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
226 (otherwise 1)))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
227
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 136
diff changeset
228 (defun device-pixel-width (&optional device)
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
229 (case window-system
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
230 ((x win32 pm) (x-display-pixel-width device))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
231 (ns (ns-display-pixel-width device))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
232 (otherwise (frame-width device))))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
233
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 136
diff changeset
234 (defun device-pixel-height (&optional device)
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
235 (case window-system
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
236 ((x win32 pm) (x-display-pixel-height device))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
237 (ns (ns-display-pixel-height device))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
238 (otherwise (frame-height device))))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
239
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 136
diff changeset
240 (defun device-mm-width (&optional device)
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
241 (case window-system
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
242 ((x win32 pm) (x-display-mm-width device))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
243 (ns (ns-display-mm-width device))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
244 (otherwise nil)))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
245
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 136
diff changeset
246 (defun device-mm-height (&optional device)
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
247 (case window-system
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
248 ((x win32 pm) (x-display-mm-height device))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
249 (ns (ns-display-mm-height device))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
250 (otherwise nil)))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
251
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 136
diff changeset
252 (defun device-bitplanes (&optional device)
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
253 (case window-system
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
254 ((x win32 pm) (x-display-planes device))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
255 (ns (ns-display-planes device))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
256 (otherwise 2)))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
257
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 136
diff changeset
258 (defun device-class (&optional device)
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
259 (case window-system
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
260 (x ; X11
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
261 (cond
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
262 ((fboundp 'x-display-visual-class)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
263 (let ((val (symbol-name (x-display-visual-class device))))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
264 (cond
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
265 ((string-match "color" val) 'color)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
266 ((string-match "gray-scale" val) 'grayscale)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
267 (t 'mono))))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
268 ((fboundp 'x-display-color-p)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
269 (if (x-display-color-p device)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
270 'color
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
271 'mono))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
272 (t 'color)))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
273 (pm ; OS/2 Presentation Manager
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
274 (cond
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
275 ((fboundp 'pm-display-visual-class)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
276 (let ((val (symbol-name (pm-display-visual-class device))))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
277 (cond
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
278 ((string-match "color" val) 'color)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
279 ((string-match "gray-scale" val) 'grayscale)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
280 (t 'mono))))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
281 ((fboundp 'pm-display-color-p)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
282 (if (pm-display-color-p device)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
283 'color
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
284 'mono))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
285 (t 'color)))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
286 (ns
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
287 (cond
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
288 ((fboundp 'ns-display-visual-class)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
289 (let ((val (symbol-name (ns-display-visual-class device))))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
290 (cond
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
291 ((string-match "color" val) 'color)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
292 ((string-match "gray-scale" val) 'grayscale)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
293 (t 'mono))))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
294 ((fboundp 'ns-display-color-p)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
295 (if (ns-display-color-p device)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
296 'color
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
297 'mono))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
298 (t 'mono)))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
299 (otherwise 'color)))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
300
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 136
diff changeset
301 (defun device-class-list ()
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
302 "Returns a list of valid device classes."
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
303 (list 'color 'grayscale 'mono))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
304
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 136
diff changeset
305 (defun valid-device-class-p (class)
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
306 "Given a CLASS, return t if it is valid.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
307 Valid classes are 'color, 'grayscale, and 'mono."
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
308 (memq class (device-class-list)))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
309
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 136
diff changeset
310 (defun device-or-frame-type (device-or-frame)
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
311 "Return the type (e.g. `x' or `tty') of DEVICE-OR-FRAME.
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
312 DEVICE-OR-FRAME should be a device or a frame object. See `device-type'
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
313 for a description of the possible types."
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
314 (or window-system 'tty))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
315
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 136
diff changeset
316 (defun device-type (&optional device)
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
317 "Return the type of the specified device (e.g. `x' or `tty').
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
318 Value is `tty' for a tty device (a character-only terminal),
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
319 `x' for a device which is a connection to an X server,
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
320 'ns' for a device which is a connection to a NeXTStep dps server,
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
321 'win32' for a Windows-NT window,
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
322 'pm' for an OS/2 Presentation Manager window,
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
323 'intuition' for an Amiga screen"
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
324 (device-or-frame-type device))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
325
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 136
diff changeset
326 (defun device-type-list ()
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
327 "Return a list of valid console types."
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
328 (if window-system
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
329 (list window-system 'tty)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
330 (list 'tty)))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
331
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 136
diff changeset
332 (defun valid-device-type-p (type)
136
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
333 "Given a TYPE, return t if it is valid."
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
334 (memq type (device-type-list)))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
335
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
336 ) ; This closes the conditional on whether we are in XEmacs or not
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
337
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
338 (provide 'devices)
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
339
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
340 (eval-when-compile
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
341 (if (string-match "XEmacs" (emacs-version))
b980b6286996 Import from CVS: tag r20-2b2
cvs
parents:
diff changeset
342 (set 'byte-optimize t)))