view lisp/gpm.el @ 5361:62b9ef1ed4ac

Change "special form" to "special operator" in the manuals, too 2011-03-01 Aidan Kehoe <kehoea@parhasard.net> * lispref/commands.texi (Using Interactive): * lispref/compile.texi (Eval During Compile): * lispref/compile.texi (Compiled-Function Objects): * lispref/control.texi (Sequencing): * lispref/control.texi (Conditionals): * lispref/control.texi (Combining Conditions): * lispref/control.texi (Iteration): * lispref/control.texi (Catch and Throw): * lispref/control.texi (Handling Errors): * lispref/control.texi (Cleanups): * lispref/display.texi (Temporary Displays): * lispref/eval.texi (Quoting): * lispref/eval.texi (Multiple values): * lispref/frames.texi (Input Focus): * lispref/functions.texi (Argument List): * lispref/functions.texi (Defining Functions): * lispref/functions.texi (Anonymous Functions): * lispref/internationalization.texi (Level 3 Primitives): * lispref/internationalization.texi (Domain Specification): * lispref/intro.texi (A Sample Function Description): * lispref/intro.texi (A Sample Variable Description): * lispref/lists.texi (Sets And Lists): * lispref/macros.texi (Defining Macros): * lispref/macros.texi (Backquote): * lispref/positions.texi (Excursions): * lispref/positions.texi (Narrowing): * lispref/searching.texi (Saving Match Data): * lispref/sequences.texi (Sequence Functions): * lispref/sequences.texi (Array Functions): * lispref/specifiers.texi (Adding Specifications): * lispref/variables.texi (Local Variables): * lispref/variables.texi (Defining Variables): * lispref/variables.texi (Setting Variables): * lispref/variables.texi (Default Value): * lispref/windows.texi (Selecting Windows): * lispref/windows.texi (Window Configurations): No longer use @defspec, since we no longer use the term "special form"; instead use @deffn {Special Operator}. Unfortunately there's no way in texinfo to redefine @defspec in one place.
author Aidan Kehoe <kehoea@parhasard.net>
date Tue, 01 Mar 2011 14:18:45 +0000
parents 023b83f4e54b
children 308d34e9f07d
line wrap: on
line source

;;; gpm.el --- Support the mouse when emacs run on a Linux console.

;; Copyright (C) 1999 Free Software Foundation

;; Author: William Perry <wmperry@gnu.org>
;; Keywords: mouse, terminals

;; This file is part of XEmacs.

;; XEmacs 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)
;; any later version.

;; XEmacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with XEmacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

(defvar gpm-enabled-devices (make-hash-table :test 'eq
					     :size 13
					     :weakness 'key)
  "A hash table of devices with GPM currently turned on.")
 
(defun gpm-mode (&optional arg device)
  "Toggle GPM mouse mode.
With prefix arg, turn GPM mouse mode on if and only if arg is positive."
  (interactive (list current-prefix-arg (selected-device)))
  (with-fboundp 'gpm-enable
    (cond
     ((null arg)				; Toggle
      (if (gethash device gpm-enabled-devices)
	  (progn
	    (gpm-enable device nil)
	    (remhash device gpm-enabled-devices))
	(gpm-enable device t)
	(puthash device t gpm-enabled-devices)))
     ((> arg 0)				; Turn on
      (gpm-enable device t)
      (puthash device t gpm-enabled-devices))
     ((gethash device gpm-enabled-devices) ; Turn off
      (gpm-enable device nil)
      (remhash device gpm-enabled-devices)))))

(defun turn-on-gpm-mouse-tracking (&optional device)
  ;; Enable mouse tracking on linux console
  (gpm-mode 5 device))

(defun turn-off-gpm-mouse-tracking (&optional device)
  ;; Disable mouse tracking on linux console
  (gpm-mode -5 device))

(defun gpm-is-supported-p (device)
  "Returns non-nil if GPM is usable right now on DEVICE in this XEmacs session.
This checks whether GPM support was compiled in, TTY support was
compiled in, XEmacs is running on Linux, the current console/device is
TTY, and its terminal type has been set to `linux'."
  (and (not noninteractive)	; Don't want to do this in batch mode
       (fboundp 'gpm-enable)	; Must have C-level GPM support
       (eq system-type 'linux)	; Must be running linux
       (eq (device-type device) 'tty) ; on a tty
       (equal "linux" (declare-fboundp ; an a linux terminal type
		       (console-tty-terminal-type (device-console device))))))
  
(defun gpm-create-device-hook (device)
  (if (gpm-is-supported-p device)
      (turn-on-gpm-mouse-tracking device)))

(defun gpm-delete-device-hook (device)
  (if (gpm-is-supported-p device)
      (turn-off-gpm-mouse-tracking device)))

;; Restore normal mouse behavior outside Emacs

(add-hook 'suspend-hook 'turn-off-gpm-mouse-tracking)
(add-hook 'suspend-resume-hook 'turn-on-gpm-mouse-tracking)
(add-hook 'create-device-hook 'gpm-create-device-hook)
(add-hook 'delete-device-hook 'gpm-delete-device-hook)

(provide 'gpm)