summaryrefslogtreecommitdiff
path: root/lisp/xt-mouse.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2007-10-18 19:06:44 +0000
committerStefan Monnier <monnier@iro.umontreal.ca>2007-10-18 19:06:44 +0000
commitaf020a0464b03976a56041e25087f132e7d38160 (patch)
tree30a723de42bc99bb8dd9f77e93d5b6bbbddec550 /lisp/xt-mouse.el
parent8782c744ef0c1732c513e29f260b0e73263deffd (diff)
downloademacs-af020a0464b03976a56041e25087f132e7d38160.tar.gz
Don't change the global function-key-map anny more.
(xterm-mouse-mode): Use terminal-init-xterm-hook. Don't use after-make-frame-functions now that term/xterm.el calls us directly. (turn-on-xterm-mouse-tracking, turn-off-xterm-mouse-tracking): Use turn-*-xterm-mouse-tracking-on-terminal. Only once per terminal. (turn-on-xterm-mouse-tracking-on-terminal): Make param optional. Setup input-decode-map and remember that xterm-mouse-mode was enabled in this terminal. (turn-off-xterm-mouse-tracking-on-terminal): Only disable on those terminals where it has been enabled.
Diffstat (limited to 'lisp/xt-mouse.el')
-rw-r--r--lisp/xt-mouse.el45
1 files changed, 24 insertions, 21 deletions
diff --git a/lisp/xt-mouse.el b/lisp/xt-mouse.el
index 15aebb08ab2..adb6f08943c 100644
--- a/lisp/xt-mouse.el
+++ b/lisp/xt-mouse.el
@@ -45,9 +45,6 @@
(defvar xterm-mouse-debug-buffer nil)
-;; XXX Perhaps this should be terminal-local instead. --lorentey
-(define-key function-key-map "\e[M" 'xterm-mouse-translate)
-
(defvar xterm-mouse-last)
;; Mouse events symbols must have an 'event-kind property with
@@ -78,7 +75,7 @@
(error "Unexpected escape sequence from XTerm")))
(let* ((click (if is-click down (xterm-mouse-event)))
- (click-command (nth 0 click))
+ ;; (click-command (nth 0 click))
(click-data (nth 1 click))
(click-where (nth 1 click-data)))
(if (memq down-binding '(nil ignore))
@@ -209,14 +206,15 @@ down the SHIFT key while pressing the mouse button."
;; Turn it on
(progn
;; Frame creation and deletion.
- (add-hook 'after-make-frame-functions
- 'turn-on-xterm-mouse-tracking-on-terminal)
+ (add-hook 'terminal-init-xterm-hook
+ 'turn-on-xterm-mouse-tracking-on-terminal)
+
(add-hook 'delete-frame-functions 'xterm-mouse-handle-delete-frame)
;; Restore normal mouse behaviour outside Emacs.
(add-hook 'suspend-tty-functions
'turn-off-xterm-mouse-tracking-on-terminal)
- (add-hook 'resume-tty-functions
+ (add-hook 'resume-tty-functions
'turn-on-xterm-mouse-tracking-on-terminal)
(add-hook 'suspend-hook 'turn-off-xterm-mouse-tracking)
(add-hook 'suspend-resume-hook 'turn-on-xterm-mouse-tracking)
@@ -224,8 +222,6 @@ down the SHIFT key while pressing the mouse button."
(setq mouse-position-function #'xterm-mouse-position-function)
(turn-on-xterm-mouse-tracking))
;; Turn it off
- (remove-hook 'after-make-frame-functions
- 'turn-on-xterm-mouse-tracking-on-terminal)
(remove-hook 'delete-frame-functions 'xterm-mouse-handle-delete-frame)
(remove-hook 'suspend-tty-functions
'turn-off-xterm-mouse-tracking-on-terminal)
@@ -239,28 +235,35 @@ down the SHIFT key while pressing the mouse button."
(defun turn-on-xterm-mouse-tracking ()
"Enable Emacs mouse tracking in xterm."
- (dolist (f (frame-list))
- (when (eq t (frame-live-p f))
- (with-selected-frame f
- (when xterm-mouse-mode
- (send-string-to-terminal "\e[?1000h"))))))
+ (dolist (terminal (delete-dups (mapcar 'frame-terminal (frame-list))))
+ (turn-on-xterm-mouse-tracking-on-terminal terminal)))
(defun turn-off-xterm-mouse-tracking (&optional force)
"Disable Emacs mouse tracking in xterm."
- (dolist (f (frame-list))
- (when (eq t (frame-live-p f))
- (with-selected-frame f
- (when (or force xterm-mouse-mode)
- (send-string-to-terminal "\e[?1000l"))))))
+ (dolist (terminal (delete-dups (mapcar 'frame-terminal (frame-list))))
+ (turn-off-xterm-mouse-tracking-on-terminal terminal)))
-(defun turn-on-xterm-mouse-tracking-on-terminal (terminal)
+(defun turn-on-xterm-mouse-tracking-on-terminal (&optional terminal)
"Enable xterm mouse tracking on TERMINAL."
(when (and xterm-mouse-mode (eq t (terminal-live-p terminal)))
+ (unless (terminal-parameter terminal 'xterm-mouse-mode)
+ ;; Simulate selecting a terminal by selecting one of its frames ;-(
+ (with-selected-frame (car (frames-on-display-list terminal))
+ (define-key input-decode-map "\e[M" 'xterm-mouse-translate))
+ (set-terminal-parameter terminal 'xterm-mouse-mode t))
(send-string-to-terminal "\e[?1000h" terminal)))
(defun turn-off-xterm-mouse-tracking-on-terminal (terminal)
"Disable xterm mouse tracking on TERMINAL."
- (when (and xterm-mouse-mode (eq t (terminal-live-p terminal)))
+ ;; Only send the disable command to those terminals to which we've already
+ ;; sent the enable command.
+ (when (and (terminal-parameter terminal 'xterm-mouse-mode)
+ (eq t (terminal-live-p terminal)))
+ ;; We could remove the key-binding and unset the `xterm-mouse-mode'
+ ;; terminal parameter, but it seems less harmful to send this escape
+ ;; command too many times (or to catch an unintended key sequence), than
+ ;; to send it too few times (or to fail to let xterm-mouse events
+ ;; pass by untranslated).
(send-string-to-terminal "\e[?1000l" terminal)))
(defun xterm-mouse-handle-delete-frame (frame)