]> code.delx.au - gnu-emacs/blobdiff - lisp/xt-mouse.el
Merged in changes from CVS trunk.
[gnu-emacs] / lisp / xt-mouse.el
index b03539532c3596a8e1dee85457ddbda6de21be2e..a261d3d36c8ec87e6fe5c7c757eea586cd5dacfe 100644 (file)
@@ -65,7 +65,7 @@
                                            (vector down-where down-command)
                                          (vector down-command))))
             (is-click (string-match "^mouse" (symbol-name (car down)))))
-           
+
        (unless is-click
          (unless (and (eq (read-char) ?\e)
                       (eq (read-char) ?\[)
   "Position of last xterm mouse event relative to the frame.")
 
 ;; Indicator for the xterm-mouse mode.
-(defvar xterm-mouse-mode nil)
 
 (defun xterm-mouse-position-function (pos)
   "Bound to `mouse-position-function' in XTerm mouse mode."
   (setcdr pos (cons xterm-mouse-x xterm-mouse-y))
   pos)
 
+;; read xterm sequences above ascii 127 (#x7f)
+(defun xterm-mouse-event-read ()
+  (let ((c (read-char)))
+    (if (< c 0)
+        (+ c #x8000000 128)
+      c)))
+
 (defun xterm-mouse-event ()
   "Convert XTerm mouse event to Emacs mouse event."
-  (let* ((type (- (read-char) #o40))
-        (x (- (read-char) #o40 1))
-        (y (- (read-char) #o40 1))
+  (let* ((type (- (xterm-mouse-event-read) #o40))
+        (x (- (xterm-mouse-event-read) #o40 1))
+        (y (- (xterm-mouse-event-read) #o40 1))
         (point (cons x y))
         (window (window-at x y))
         (where (if window
                                       (max 0 (1- (window-hscroll)))))
                    (point))
                where))
-        (mouse (intern 
+        (mouse (intern
                 ;; For buttons > 3, the release-event looks
                 ;; differently (see xc/programs/xterm/button.c,
                 ;; function EditorButton), and there seems to come in
          (list window pos point
                (/ (nth 2 (current-time)) 1000)))))
 
-(or (assq 'xterm-mouse-mode minor-mode-alist)
-    (setq minor-mode-alist
-         (cons '(xterm-mouse-mode (" Mouse")) minor-mode-alist)))
-
 ;;;###autoload
-(defun xterm-mouse-mode (arg)
+(define-minor-mode xterm-mouse-mode
   "Toggle XTerm mouse mode.
 With prefix arg, turn XTerm mouse mode on iff arg is positive.
 
 Turn it on to use emacs mouse commands, and off to use xterm mouse commands."
-  (interactive "P")
-  (if (or (and (null arg) xterm-mouse-mode)
-         (<= (prefix-numeric-value arg) 0))
-      ;; Turn it off
-      (if xterm-mouse-mode
-         (progn
-           (turn-off-xterm-mouse-tracking)
-           (setq xterm-mouse-mode nil
-                 mouse-position-function nil)
-           (set-buffer-modified-p (buffer-modified-p))))
-    ;;Turn it on
-    (unless (or window-system xterm-mouse-mode)
-      (setq xterm-mouse-mode t
-           mouse-position-function #'xterm-mouse-position-function)
-      (turn-on-xterm-mouse-tracking)
-      (set-buffer-modified-p (buffer-modified-p)))))
+  nil " Mouse" nil :global t
+  (if xterm-mouse-mode
+      ;; Turn it on
+      (unless window-system
+       (setq mouse-position-function #'xterm-mouse-position-function)
+       (turn-on-xterm-mouse-tracking))
+    ;; Turn it off
+    (turn-off-xterm-mouse-tracking 'force)
+    (setq mouse-position-function nil)))
 
 (defun turn-on-xterm-mouse-tracking ()
   "Enable Emacs mouse tracking in xterm."
   (if xterm-mouse-mode
       (send-string-to-terminal "\e[?1000h")))
 
-(defun turn-off-xterm-mouse-tracking ()
+(defun turn-off-xterm-mouse-tracking (&optional force)
   "Disable Emacs mouse tracking in xterm."
-  (if xterm-mouse-mode
+  (if (or force xterm-mouse-mode)
       (send-string-to-terminal "\e[?1000l")))
 
 ;; Restore normal mouse behaviour outside Emacs.
@@ -203,4 +198,5 @@ Turn it on to use emacs mouse commands, and off to use xterm mouse commands."
 
 (provide 'xt-mouse)
 
+;;; arch-tag: 84962d4e-fae9-4c13-a9d7-ef4925a4ac03
 ;;; xt-mouse.el ends here