t-mouse.el 3.3 KB

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