Fix minor mode docstrings for the new meaning of a nil ARG.
[bpt/emacs.git] / lisp / t-mouse.el
CommitLineData
9efe4a2d
NR
1;;; t-mouse.el --- mouse support within the text terminal
2
20d385d6
NR
3;; Author: Nick Roberts <nickrob@gnu.org>
4;; Maintainer: FSF
9efe4a2d
NR
5;; Keywords: mouse gpm linux
6
95df8112 7;; Copyright (C) 1994-1995, 1998, 2006-2011 Free Software Foundation, Inc.
eff05ea1
NR
8
9;; This file is part of GNU Emacs.
10
eb3fa2cf 11;; GNU Emacs is free software: you can redistribute it and/or modify
eff05ea1 12;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
eff05ea1
NR
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
9efe4a2d 20
eff05ea1 21;; You should have received a copy of the GNU General Public License
eb3fa2cf 22;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
9efe4a2d
NR
23
24;;; Commentary:
25
20d385d6
NR
26;; This package provides access to mouse event as reported by the gpm-Linux
27;; package. It tries to reproduce the functionality offered by Emacs under X.
9efe4a2d
NR
28;; The "gpm" server runs under Linux, so this package is rather
29;; Linux-dependent.
30
43180aff
NR
31;; The file, t-mouse.el was originally written by Alessandro Rubini and Ian T
32;; Zimmerman, and Emacs communicated with gpm through a client program called
33;; mev. Now the interface with gpm is directly through a Unix socket, so this
34;; file is reduced to a single minor mode macro call.
9efe4a2d 35
06e21633 36;;
9efe4a2d
NR
37\f
38;;; Code:
39
478975a9
GM
40;; Prevent warning when compiling in an Emacs without gpm support.
41(declare-function gpm-mouse-start "term.c" ())
42
3c5a7a3c
SM
43(defun gpm-mouse-enable ()
44 "Try to enable gpm mouse support on the current terminal."
45 (let ((activated nil))
46 (unwind-protect
47 (progn
48 (unless (fboundp 'gpm-mouse-start)
49 (error "Emacs must be built with Gpm to use this mode"))
50 (when gpm-mouse-mode
51 (gpm-mouse-start)
52 (set-terminal-parameter nil 'gpm-mouse-active t)
53 (setq activated t)))
54 ;; If something failed to turn it on, try to turn it off as well,
55 ;; just in case.
56 (unless activated (gpm-mouse-disable)))))
57
58(defun gpm-mouse-disable ()
59 "Try to disable gpm mouse support on the current terminal."
60 (when (fboundp 'gpm-mouse-stop)
61 (gpm-mouse-stop))
62 (set-terminal-parameter nil 'gpm-mouse-active nil))
63
eff05ea1 64;;;###autoload
0e2806fa
SM
65(define-obsolete-function-alias 't-mouse-mode 'gpm-mouse-mode "23.1")
66;;;###autoload
67(define-minor-mode gpm-mouse-mode
06e21633
CY
68 "Toggle mouse support in GNU/Linux consoles (GPM Mouse mode).
69With a prefix argument ARG, enable GPM Mouse mode if ARG is
70positive, and disable it otherwise. If called from Lisp, enable
71the mode if ARG is omitted or nil.
eff05ea1 72
0e2806fa
SM
73This allows the use of the mouse when operating on a GNU/Linux console,
74in the same way as you can use the mouse under X11.
75It relies on the `gpm' daemon being activated."
3c5a7a3c
SM
76 :global t :group 'mouse :init-value t
77 (dolist (terminal (terminal-list))
78 (when (and (eq t (terminal-live-p terminal))
79 (not (eq gpm-mouse-mode
80 (terminal-parameter terminal 'gpm-mouse-active))))
81 ;; Simulate selecting a terminal by selecting one of its frames ;-(
82 (with-selected-frame (car (frames-on-display-list terminal))
83 (if gpm-mouse-mode (gpm-mouse-enable) (gpm-mouse-disable))))))
9efe4a2d
NR
84
85(provide 't-mouse)
86
87;;; t-mouse.el ends here