Source

xwem / lisp / xwem-mouse.el

Full commit
;;; xwem-mouse.el --- Mouse support for XWEM.

;; Copyright (C) 2003 by Free Software Foundation, Inc.

;; Author: Zajcev Evgeny <zevlg@yandex.ru>
;; Created: 21 Mar 2003
;; Keywords: xlib, xwem
;; X-CVS: $Id$

;; This file is part of XWEM.

;; XWEM 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.

;; XWEM 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.

;;; Synched up with: Not in FSF

;;; Commentary:
;;

;; TODO:
;;   * Add item here.
;;

;;; Code:
;;

(defcustom xwem-popup-menu-function 'popup-menu
  "*Function used to popup menus."
  :type 'function
  :group 'xwem)


(defun xwem-mouse-change-cursor (cursor )
  (XChangeActivePointerGrab (xwem-dpy) cursor
			    (Xmask-or XM-ButtonPress XM-ButtonRelease)))

;;;###autoload
(defun xwem-mouse-grab (cursor &optional win mask)
  "Begin to grab mouse from root window with cursor typ CURSOR.."
  ;; TODO: install custom events handlers?
  (XGrabPointer (xwem-dpy)
		(or win (xwem-rootwin))
		(or mask (Xmask-or XM-ButtonPress XM-ButtonRelease))
		cursor)
  )

;;;###autoload
(defun xwem-mouse-ungrab ()
  "Stop grabing mouse."
  (XUngrabPointer (xwem-dpy))
  )

;;; Menus
(defvar xwem-applications-submenu
  '("Applications"
     ["XEmacs" (make-frame)]
     ["xterm" (xwem-execute-program "xterm")]
     ["gv" (xwem-execute-program "gv")]
     ["xfontsel" (xwem-execute-program "xfontsel")]
     )
  "Submenu with applications.")

(defvar xwem-menu
  (list "XWEM Menu"
	xwem-applications-submenu
	'("Windows"
	  ["Vertical Split" (xwem-frame-split-vert nil)]
	  ["Horizontal Split" (xwem-frame-split-horiz nil)]
	  ["Delete Window" (xwem-window-delete)]
	  ["Delete Others" (xwem-window-delete-others)]
	  ["Balance" (xwem-balance-windows (xwem-frame-selected))])
	)
  "Popup menu to be used by xwem."
  )

(defun xwem-menu-generate ()
  "Generates xwem menu on fly."
  (list "XWEM Menu"
        '("xwem-frames" :filter
          (lambda (not-used)
            (mapcar (lambda (el)
                      (let ((fn (xwem-frame-num el)))
                        (vector 
                         (concat "Frame " (int-to-string fn) ": " (xwem-frame-name el))
                         `(xwem-frame-switch-nth ,fn))))
                    xwem-frames-list)))

        '("xwem-clients" :filter
          (lambda (not-used)
            (mapcar (lambda (el)
                      (let ((nam (xwem-hints-wm-name (xwem-cl-hints el))))
                        (vector nam `(xwem-cl-pop-to-client ,el)
                                :active (if (xwem-cl-exclude-p el) nil t))))
                    xwem-clients)))
        "--"
	xwem-applications-submenu
        
        ;; XXX - it is just demo of popup menus
        ))

(defun xwem-popup-menu (menu &optional event)
  "Popup MENU.
MENU and EVENT is same as for `popup-menu'."
  (funcall xwem-popup-menu-function menu event))

(define-xwem-command xwem-popup-function-menu (arg)
  "Just popup `xwem-menu'."
  (xwem-interactive "_P")

  ;; TODO:
  ;;   * use ARG
  (xwem-popup-menu xwem-menu))

(define-xwem-command xwem-popup-auto-menu (arg)
  "Popup menu generated by `xwem-menu-generate'."
  (xwem-interactive "_P")

  (xwem-popup-menu (xwem-menu-generate)))


(provide 'xwem-mouse)

;;; xwem-mouse.el ends here