annotate lisp/emacs-lisp/levents.el @ 11882:8b3575269610

(hack_wm_protocols): Cast args of XGetWindowProperty. (x_set_border_pixel): Cast args of XSetWindowBorder.
author Karl Heuer <kwzh@gnu.org>
date Tue, 23 May 1995 03:02:53 +0000
parents ec432bd5d5b9
children 44f42e36b529
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2232
4f9d60f7de9d Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2066
diff changeset
1 ;;; levents.el --- emulate the Lucid event data type and associated functions.
4f9d60f7de9d Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2066
diff changeset
2
2034
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1993 Free Software Foundation, Inc.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; This file is part of GNU Emacs.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; it under the terms of the GNU General Public License as published by
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; the Free Software Foundation; either version 2, or (at your option)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; any later version.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is distributed in the hope that it will be useful,
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; GNU General Public License for more details.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; You should have received a copy of the GNU General Public License
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
2232
4f9d60f7de9d Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2066
diff changeset
21 ;;; Commentary:
2034
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; Things we cannot emulate in Lisp:
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; It is not possible to emulate current-mouse-event as a variable,
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; though it is not hard to obtain the data from (this-command-keys).
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; We do not have a variable unread-command-event;
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; instead, we have the more general unread-command-events.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29
2039
e062b4567dc6 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2034
diff changeset
30 ;; Our read-key-sequence and read-char are not precisely
e062b4567dc6 *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2034
diff changeset
31 ;; compatible with those in Lucid Emacs, but they should work ok.
2034
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;;; Code:
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34
2057
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
35 (defun next-command-event (event)
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
36 (error "You must rewrite to use `read-command-event' instead of `next-command-event'"))
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
37
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
38 (defun next-event (event)
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
39 (error "You must rewrite to use `read-event' instead of `next-event'"))
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
40
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
41 (defun dispatch-event (event)
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
42 (error "`dispatch-event' not supported"))
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
43
2034
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; Make events of type eval, menu and timeout
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;; execute properly.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 (define-key global-map [menu] 'execute-eval-event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 (define-key global-map [timeout] 'execute-eval-event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 (define-key global-map [eval] 'execute-eval-event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 (defun execute-eval-event (event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 (interactive "e")
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (funcall (nth 1 event) (nth 2 event)))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 (put 'eval 'event-symbol-elements '(eval))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 (put 'menu 'event-symbol-elements '(eval))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (put 'timeout 'event-symbol-elements '(eval))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 (defsubst eventp (obj)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 "True if the argument is an event object."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 (or (integerp obj)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (and (symbolp obj)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 (get obj 'event-symbol-elements))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (and (consp obj)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (symbolp (car obj))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (get (car obj) 'event-symbol-elements))))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (defun allocate-event ()
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 "Returns an empty event structure.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 In this emulation, it returns nil."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 nil)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (defun button-press-event-p (obj)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 "True if the argument is a mouse-button-press event object."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (and (consp obj) (symbolp (car obj))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (memq 'down (get (car obj) 'event-symbol-elements))))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 (defun button-release-event-p (obj)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 "True if the argument is a mouse-button-release event object."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (and (consp obj) (symbolp (car obj))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 (or (memq 'click (get (car obj) 'event-symbol-elements))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (memq 'drag (get (car obj) 'event-symbol-elements)))))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 (defun character-to-event (ch &optional event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 "Converts a numeric ASCII value to an event structure, replete with
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 bucky bits. The character is the first argument, and the event to fill
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 in is the second. This function contains knowledge about what the codes
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 mean -- for example, the number 9 is converted to the character Tab,
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 not the distinct character Control-I.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 Beware that character-to-event and event-to-character are not strictly
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 inverse functions, since events contain much more information than the
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 ASCII character set can encode."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ch)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (defun copy-event (event1 &optional event2)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 "Make a copy of the given event object.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 In this emulation, `copy-event' just returns its argument."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 event1)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (defun deallocate-event (event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 "Allow the given event structure to be reused.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 In actual Lucid Emacs, you MUST NOT use this event object after
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 calling this function with it. You will lose. It is not necessary to
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 call this function, as event objects are garbage- collected like all
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 other objects; however, it may be more efficient to explicitly
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 deallocate events when you are sure that that is safe.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 This emulation does not actually deallocate or reuse events
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 except via garbage collection and `cons'."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 nil)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (defun enqueue-eval-event: (function object)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 "Add an eval event to the back of the queue.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 It will be the next event read after all pending events."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (setq unread-command-events
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (nconc unread-command-events
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (list (list 'eval function object)))))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (defun eval-event-p (obj)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 "True if the argument is an eval or menu event object."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (eq (car-safe obj) 'eval))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (defun event-button (event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 "Return the button-number of the given mouse-button-press event."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (let ((sym (car (get (car event) 'event-symbol-elements))))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (cdr (assq sym '((mouse-1 . 1) (mouse-2 . 2) (mouse-3 . 3)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (mouse-4 . 4) (mouse-5 . 5))))))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (defun event-function (event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 "Return the callback function of the given timeout, menu, or eval event."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (nth 1 event))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (defun event-key (event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 "Returns the KeySym of the given key-press event.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 The value is an ASCII printing character (not upper case) or a symbol."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (if (symbolp event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (car (get event 'event-symbol-elements))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (let ((base (logand event (1- (lsh 1 18)))))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (downcase (if (< base 32) (logior base 64) base)))))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (defun event-object (event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 "Returns the function argument of the given timeout, menu, or eval event."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (nth 2 event))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (defun event-point (event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 "Returns the character position of the given mouse-related event.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 If the event did not occur over a window, or did
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 not occur over text, then this returns nil. Otherwise, it returns an index
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 into the buffer visible in the event's window."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (posn-point (event-end event)))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (defun event-process (event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 "Returns the process of the given process-output event."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (nth 1 event))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (defun event-timestamp (event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 "Returns the timestamp of the given event object.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 In Lucid Emacs, this works for any kind of event.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 In this emulation, it returns nil for non-mouse-related events."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (and (listp event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (posn-timestamp (event-end event))))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (defun event-to-character (event &optional lenient)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 "Returns the closest ASCII approximation to the given event object.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 If the event isn't a keypress, this returns nil.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 If the second argument is non-nil, then this is lenient in its
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 translation; it will ignore modifier keys other than control and meta,
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 and will ignore the shift modifier on those characters which have no
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 shifted ASCII equivalent (Control-Shift-A for example, will be mapped to
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 the same ASCII code as Control-A.) If the second arg is nil, then nil
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 will be returned for events which have no direct ASCII equivalent."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (if (symbolp event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (and lenient
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (cdr (assq event '((backspace . 8) (delete . 127) (tab . 9)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (return . 10) (enter . 10)))))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 ;; Our interpretation is, ASCII means anything a number can represent.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (if (integerp event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 event nil)))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (defun event-window (event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 "Returns the window of the given mouse-related event object."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (posn-window (event-end event)))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (defun event-x (event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 "Returns the X position in characters of the given mouse-related event."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (/ (car (posn-col-row (event-end event)))
2066
9b4cb6b6d474 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2057
diff changeset
188 (frame-char-width (window-frame (event-window event)))))
2034
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (defun event-x-pixel (event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 "Returns the X position in pixels of the given mouse-related event."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (car (posn-col-row (event-end event))))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (defun event-y (event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 "Returns the Y position in characters of the given mouse-related event."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (/ (cdr (posn-col-row (event-end event)))
2066
9b4cb6b6d474 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 2057
diff changeset
197 (frame-char-height (window-frame (event-window event)))))
2034
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (defun event-y-pixel (event)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 "Returns the Y position in pixels of the given mouse-related event."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (cdr (posn-col-row (event-end event))))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (defun key-press-event-p (obj)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 "True if the argument is a keyboard event object."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (or (integerp obj)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (and (symbolp obj)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (get obj 'event-symbol-elements))))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (defun menu-event-p (obj)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 "True if the argument is a menu event object."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (eq (car-safe obj) 'menu))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (defun motion-event-p (obj)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 "True if the argument is a mouse-motion event object."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (eq (car-safe obj) 'mouse-movement))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216
2057
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
217 (defun read-command-event ()
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
218 "Return the next keyboard or mouse event; execute other events.
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
219 This is similar to the function `next-command-event' of Lucid Emacs,
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
220 but different in that it returns the event rather than filling in
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
221 an existing event object."
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
222 (let (event)
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
223 (while (progn
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
224 (setq event (read-event))
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
225 (not (or (key-press-event-p event)
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
226 (button-press-event-p event)
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
227 (button-release-event-p event)
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
228 (menu-event-p event))))
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
229 (let ((type (car-safe event)))
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
230 (cond ((eq type 'eval)
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
231 (funcall (nth 1 event) (nth 2 event)))
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
232 ((eq type 'switch-frame)
2957
ec432bd5d5b9 (event-modifiers): Function deleted.
Richard M. Stallman <rms@gnu.org>
parents: 2232
diff changeset
233 (select-frame (nth 1 event))))))
2057
265b81ff7eee *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 2039
diff changeset
234 event))
2034
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (defun process-event-p (obj)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 "True if the argument is a process-output event object.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 GNU Emacs 19 does not currently generate process-output events."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (eq (car-safe obj) 'process))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (defun timeout-event-p (obj)
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 "True if the argument is a timeout event object.
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 GNU Emacs 19 does not currently generate timeout events."
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (eq (car-safe obj) 'timeout))
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245
8f940ad51dd0 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 ;;; levents.el ends here