Followup to 2011-10-19T09:48:35Z!eliz@gnu.org.
[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
20d385d6 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
68 "Toggle gpm-mouse mode to use the mouse in GNU/Linux consoles.
69With prefix arg, turn gpm-mouse mode on if arg is positive,
70otherwise turn it off.
eff05ea1 71
0e2806fa
SM
72This allows the use of the mouse when operating on a GNU/Linux console,
73in the same way as you can use the mouse under X11.
74It relies on the `gpm' daemon being activated."
3c5a7a3c
SM
75 :global t :group 'mouse :init-value t
76 (dolist (terminal (terminal-list))
77 (when (and (eq t (terminal-live-p terminal))
78 (not (eq gpm-mouse-mode
79 (terminal-parameter terminal 'gpm-mouse-active))))
80 ;; Simulate selecting a terminal by selecting one of its frames ;-(
81 (with-selected-frame (car (frames-on-display-list terminal))
82 (if gpm-mouse-mode (gpm-mouse-enable) (gpm-mouse-disable))))))
9efe4a2d
NR
83
84(provide 't-mouse)
85
86;;; t-mouse.el ends here