]> code.delx.au - gnu-emacs/blobdiff - lisp/t-mouse.el
Merge from emacs--rel--22
[gnu-emacs] / lisp / t-mouse.el
index c48b56d620053d26a253ab3643f60a785653c22b..e88067b7fe511322f083583238532f0cc2a480f7 100644 (file)
@@ -10,7 +10,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;;; Code:
 
 ;;;###autoload
-(define-minor-mode t-mouse-mode
-  "Toggle t-mouse mode to use the mouse in Linux consoles.
-With prefix arg, turn t-mouse mode on iff arg is positive.
+(define-obsolete-function-alias 't-mouse-mode 'gpm-mouse-mode "23.1")
+;;;###autoload
+(define-minor-mode gpm-mouse-mode
+  "Toggle gpm-mouse mode to use the mouse in GNU/Linux consoles.
+With prefix arg, turn gpm-mouse mode on if arg is positive,
+otherwise turn it off.
 
-This allows the use of the mouse when operating on a Linux console, in the
-same way as you can use the mouse under X11.
-It requires the `mev' program, part of the `gpm' utilities."
+This allows the use of the mouse when operating on a GNU/Linux console,
+in the same way as you can use the mouse under X11.
+It relies on the `gpm' daemon being activated."
   :global t :group 'mouse
-  (if window-system
-      (error "t-mouse only works in the console on GNU/Linux")
-    (if t-mouse-mode
-       (progn
-         (unless (fboundp 'term-open-connection)
-           (progn
-             (setq t-mouse-mode nil)
-             (error "Emacs must be built with Gpm to use this mode")))
-         (unless (term-open-connection)
-           (progn
-             (setq t-mouse-mode nil)
-             (error "Can't open mouse connection"))))
-      ;; Turn it off
-      (term-close-connection))))
+  (let ((activated nil))
+    (unwind-protect
+        (progn
+          (unless (fboundp 'gpm-mouse-start)
+            (error "Emacs must be built with Gpm to use this mode"))
+          (when gpm-mouse-mode
+            (gpm-mouse-start)
+            (setq activated t)))
+      ;; If the user asked to turn it off do that.
+      ;; If something failed to turn it on, try to turn it off as well,
+      ;; just in case.
+      (when (and (fboundp 'gpm-mouse-stop) (not activated))
+        (setq gpm-mouse-mode nil)
+        (gpm-mouse-stop)))))
 
 (provide 't-mouse)