aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2014-05-07 21:46:15 -0400
committerStefan Monnier2014-05-07 21:46:15 -0400
commitb406487f5227bb0f26844aea233a7b8d4a3709db (patch)
treef9a9cf527402cf7451e6326efddebb63d3bd54e7
parent76377e461836419770c548872e5d88c6e111439c (diff)
downloademacs-b406487f5227bb0f26844aea233a7b8d4a3709db.tar.gz
emacs-b406487f5227bb0f26844aea233a7b8d4a3709db.zip
* lisp/xt-mouse.el: Drop spurious/oddly shaped events.
(xterm-mouse--read-event-sequence-1000): Return nil if something looks fishy. (xterm-mouse-event): Propagate it. (xterm-mouse-translate-1): Handle it. Fixes: debbugs:17378
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/xt-mouse.el103
2 files changed, 62 insertions, 49 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index f8502bd35bb..333bc7fcf90 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12014-05-08 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * xt-mouse.el: Drop spurious/oddly shaped events (bug#17378).
4 (xterm-mouse--read-event-sequence-1000): Return nil if something
5 looks fishy.
6 (xterm-mouse-event): Propagate it.
7 (xterm-mouse-translate-1): Handle it.
8
12014-05-07 Stephen Berman <stephen.berman@gmx.net> 92014-05-07 Stephen Berman <stephen.berman@gmx.net>
2 10
3 * calendar/todo-mode.el (todo-insert-item--apply-args): When all 11 * calendar/todo-mode.el (todo-insert-item--apply-args): When all
diff --git a/lisp/xt-mouse.el b/lisp/xt-mouse.el
index 87e65f7e117..5b34612c2e7 100644
--- a/lisp/xt-mouse.el
+++ b/lisp/xt-mouse.el
@@ -63,8 +63,8 @@ http://invisible-island.net/xterm/ctlseqs/ctlseqs.html)."
63 63
64(defun xterm-mouse-translate-1 (&optional extension) 64(defun xterm-mouse-translate-1 (&optional extension)
65 (save-excursion 65 (save-excursion
66 (save-window-excursion 66 (save-window-excursion ;FIXME: Why?
67 (deactivate-mark) 67 (deactivate-mark) ;FIXME: Why?
68 (let* ((xterm-mouse-last nil) 68 (let* ((xterm-mouse-last nil)
69 (down (xterm-mouse-event extension)) 69 (down (xterm-mouse-event extension))
70 (down-command (nth 0 down)) 70 (down-command (nth 0 down))
@@ -73,10 +73,10 @@ http://invisible-island.net/xterm/ctlseqs/ctlseqs.html)."
73 (down-binding (key-binding (if (symbolp down-where) 73 (down-binding (key-binding (if (symbolp down-where)
74 (vector down-where down-command) 74 (vector down-where down-command)
75 (vector down-command)))) 75 (vector down-command))))
76 (is-click (string-match "^mouse" (symbol-name (car down))))) 76 (is-down (string-match "down" (symbol-name (car down)))))
77 77
78 ;; Retrieve the expected preface for the up-event. 78 ;; Retrieve the expected preface for the up-event.
79 (unless is-click 79 (unless is-down
80 (unless (cond ((null extension) 80 (unless (cond ((null extension)
81 (and (eq (read-event) ?\e) 81 (and (eq (read-event) ?\e)
82 (eq (read-event) ?\[) 82 (eq (read-event) ?\[)
@@ -88,14 +88,17 @@ http://invisible-island.net/xterm/ctlseqs/ctlseqs.html)."
88 (error "Unexpected escape sequence from XTerm"))) 88 (error "Unexpected escape sequence from XTerm")))
89 89
90 ;; Process the up-event. 90 ;; Process the up-event.
91 (let* ((click (if is-click down (xterm-mouse-event extension))) 91 (let* ((click (if is-down (xterm-mouse-event extension) down))
92 (click-data (nth 1 click)) 92 (click-data (nth 1 click))
93 (click-where (nth 1 click-data))) 93 (click-where (nth 1 click-data)))
94 (if (memq down-binding '(nil ignore)) 94 (cond
95 (if (and (symbolp click-where) 95 ((null down) nil)
96 (consp click-where)) 96 ((memq down-binding '(nil ignore))
97 (vector (list click-where click-data) click) 97 (if (and (symbolp click-where)
98 (vector click)) 98 (consp click-where))
99 (vector (list click-where click-data) click)
100 (vector click)))
101 (t
99 (setq unread-command-events 102 (setq unread-command-events
100 (append (if (eq down-where click-where) 103 (append (if (eq down-where click-where)
101 (list click) 104 (list click)
@@ -114,7 +117,7 @@ http://invisible-island.net/xterm/ctlseqs/ctlseqs.html)."
114 (if (and (symbolp down-where) 117 (if (and (symbolp down-where)
115 (consp down-where)) 118 (consp down-where))
116 (vector (list down-where down-data) down) 119 (vector (list down-where down-data) down)
117 (vector down)))))))) 120 (vector down)))))))))
118 121
119;; These two variables have been converted to terminal parameters. 122;; These two variables have been converted to terminal parameters.
120;; 123;;
@@ -153,7 +156,8 @@ http://invisible-island.net/xterm/ctlseqs/ctlseqs.html)."
153;; Normal terminal mouse click reporting: expect three bytes, of the 156;; Normal terminal mouse click reporting: expect three bytes, of the
154;; form <BUTTON+32> <X+32> <Y+32>. Return a list (EVENT-TYPE X Y). 157;; form <BUTTON+32> <X+32> <Y+32>. Return a list (EVENT-TYPE X Y).
155(defun xterm-mouse--read-event-sequence-1000 () 158(defun xterm-mouse--read-event-sequence-1000 ()
156 (list (let ((code (- (read-event) 32))) 159 (let* ((code (- (read-event) 32))
160 (type
157 (intern 161 (intern
158 ;; For buttons > 3, the release-event looks differently 162 ;; For buttons > 3, the release-event looks differently
159 ;; (see xc/programs/xterm/button.c, function EditorButton), 163 ;; (see xc/programs/xterm/button.c, function EditorButton),
@@ -163,19 +167,19 @@ http://invisible-island.net/xterm/ctlseqs/ctlseqs.html)."
163 ((memq code '(8 9 10)) 167 ((memq code '(8 9 10))
164 (setq xterm-mouse-last (- code 8)) 168 (setq xterm-mouse-last (- code 8))
165 (format "M-down-mouse-%d" (- code 7))) 169 (format "M-down-mouse-%d" (- code 7)))
166 ((= code 11) 170 ((and (= code 11) xterm-mouse-last)
167 (format "M-mouse-%d" (+ 1 (or xterm-mouse-last 0)))) 171 (format "M-mouse-%d" (1+ xterm-mouse-last)))
168 ((= code 3) 172 ((and (= code 3) xterm-mouse-last)
169 ;; For buttons > 5 xterm only reports a 173 ;; For buttons > 5 xterm only reports a button-release event.
170 ;; button-release event. Avoid error by mapping 174 ;; Drop them since they're not usable and can be spurious.
171 ;; them all to mouse-1. 175 (format "mouse-%d" (1+ xterm-mouse-last)))
172 (format "mouse-%d" (+ 1 (or xterm-mouse-last 0)))) 176 ((memq code '(0 1 2))
173 (t
174 (setq xterm-mouse-last code) 177 (setq xterm-mouse-last code)
175 (format "down-mouse-%d" (+ 1 code)))))) 178 (format "down-mouse-%d" (+ 1 code))))))
176 ;; x and y coordinates 179 (x (- (read-event) 33))
177 (max 0 (- (read-event) 33)) 180 (y (- (read-event) 33)))
178 (max 0 (- (read-event) 33)))) 181 (and type (wholenump x) (wholenump y)
182 (list type x y))))
179 183
180;; XTerm's 1006-mode terminal mouse click reporting has the form 184;; XTerm's 1006-mode terminal mouse click reporting has the form
181;; <BUTTON> ; <X> ; <Y> <M or m>, where the button and ordinates are 185;; <BUTTON> ; <X> ; <Y> <M or m>, where the button and ordinates are
@@ -222,32 +226,33 @@ which is the \"1006\" extension implemented in Xterm >= 277."
222 ((eq extension 1006) 226 ((eq extension 1006)
223 (xterm-mouse--read-event-sequence-1006)) 227 (xterm-mouse--read-event-sequence-1006))
224 (t 228 (t
225 (error "Unsupported XTerm mouse protocol")))) 229 (error "Unsupported XTerm mouse protocol")))))
226 (type (nth 0 click)) 230 (when click
227 (x (nth 1 click)) 231 (let* ((type (nth 0 click))
228 (y (nth 2 click)) 232 (x (nth 1 click))
229 ;; Emulate timestamp information. This is accurate enough 233 (y (nth 2 click))
230 ;; for default value of mouse-1-click-follows-link (450msec). 234 ;; Emulate timestamp information. This is accurate enough
231 (timestamp (xterm-mouse-truncate-wrap 235 ;; for default value of mouse-1-click-follows-link (450msec).
232 (* 1000 236 (timestamp (xterm-mouse-truncate-wrap
233 (- (float-time) 237 (* 1000
234 (or xt-mouse-epoch 238 (- (float-time)
235 (setq xt-mouse-epoch (float-time))))))) 239 (or xt-mouse-epoch
236 (w (window-at x y)) 240 (setq xt-mouse-epoch (float-time)))))))
237 (ltrb (window-edges w)) 241 (w (window-at x y))
238 (left (nth 0 ltrb)) 242 (ltrb (window-edges w))
239 (top (nth 1 ltrb))) 243 (left (nth 0 ltrb))
240 (set-terminal-parameter nil 'xterm-mouse-x x) 244 (top (nth 1 ltrb)))
241 (set-terminal-parameter nil 'xterm-mouse-y y) 245 (set-terminal-parameter nil 'xterm-mouse-x x)
242 (setq 246 (set-terminal-parameter nil 'xterm-mouse-y y)
243 last-input-event 247 (setq
244 (list type 248 last-input-event
245 (let ((event (if w 249 (list type
246 (posn-at-x-y (- x left) (- y top) w t) 250 (let ((event (if w
247 (append (list nil 'menu-bar) 251 (posn-at-x-y (- x left) (- y top) w t)
248 (nthcdr 2 (posn-at-x-y x y)))))) 252 (append (list nil 'menu-bar)
249 (setcar (nthcdr 3 event) timestamp) 253 (nthcdr 2 (posn-at-x-y x y))))))
250 event))))) 254 (setcar (nthcdr 3 event) timestamp)
255 event)))))))
251 256
252;;;###autoload 257;;;###autoload
253(define-minor-mode xterm-mouse-mode 258(define-minor-mode xterm-mouse-mode