Skip to content
clfswm-second-mode.lisp 5.81 KiB
Newer Older
Philippe Brochard's avatar
Philippe Brochard committed
;;; --------------------------------------------------------------------------
;;; CLFSWM - FullScreen Window Manager
;;;
;;; --------------------------------------------------------------------------
;;; Documentation: Second mode functions
;;; --------------------------------------------------------------------------
;;;
;;; (C) 2012 Philippe Brochard <pbrochard@common-lisp.net>
Philippe Brochard's avatar
Philippe Brochard committed
;;;
;;; This program 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 3 of the License, or
;;; (at your option) any later version.
;;;
;;; This program 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 this program; if not, write to the Free Software
;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
;;;
;;; --------------------------------------------------------------------------

(in-package :clfswm)

(defparameter *sm-window* nil)
(defparameter *sm-font* nil)
(defparameter *sm-gc* nil)

(defparameter *second-mode-leave-function* nil
  "Execute the function if not nil")

Philippe Brochard's avatar
Philippe Brochard committed

(defun draw-second-mode-window ()
  (raise-window *sm-window*)
  (clear-pixmap-buffer *sm-window* *sm-gc*)
Philippe Brochard's avatar
Philippe Brochard committed
  (let* ((text (format nil "Second mode"))
	 (len (length text)))
    (xlib:draw-glyphs *pixmap-buffer* *sm-gc*
		      (truncate (/ (- *sm-width* (* (xlib:max-char-width *sm-font*) len)) 2))
		      (truncate (/ (+ *sm-height* (- (xlib:font-ascent *sm-font*) (xlib:font-descent *sm-font*))) 2))
		      text))
  (copy-pixmap-buffer *sm-window* *sm-gc*)
  (no-focus))
;;; Second mode handlers
(define-handler second-mode :key-press (code state)
Philippe Brochard's avatar
Philippe Brochard committed
  (funcall-key-from-code *second-keys* code state)
  (draw-second-mode-window))

(define-handler second-mode :enter-notify ()
Philippe Brochard's avatar
Philippe Brochard committed
  (draw-second-mode-window))

(define-handler second-mode :motion-notify (window root-x root-y)
Philippe Brochard's avatar
Philippe Brochard committed
  (unless (compress-motion-notify)
    (funcall-button-from-code *second-mouse* 'motion
			      (modifiers->state *default-modifiers*)
			      window root-x root-y *fun-press*)))
Philippe Brochard's avatar
Philippe Brochard committed

(define-handler second-mode :button-press (window root-x root-y code state)
Philippe Brochard's avatar
Philippe Brochard committed
  (funcall-button-from-code *second-mouse* code state window root-x root-y *fun-press*)
  (draw-second-mode-window))

(define-handler second-mode :button-release (window root-x root-y code state)
Philippe Brochard's avatar
Philippe Brochard committed
  (funcall-button-from-code *second-mouse* code state window root-x root-y *fun-release*)
  (draw-second-mode-window))

(define-handler second-mode :configure-request ()
  (apply #'handle-event-fun-main-mode-configure-request event-slots)
Philippe Brochard's avatar
Philippe Brochard committed
  (draw-second-mode-window))


(define-handler second-mode :configure-notify ()
Philippe Brochard's avatar
Philippe Brochard committed
  (draw-second-mode-window))


(define-handler second-mode :destroy-notify ()
  (apply #'handle-event-fun-main-mode-destroy-notify event-slots)
Philippe Brochard's avatar
Philippe Brochard committed
  (draw-second-mode-window))

(define-handler second-mode :map-request ()
  (apply #'handle-event-fun-main-mode-map-request event-slots)
Philippe Brochard's avatar
Philippe Brochard committed
  (draw-second-mode-window))

(define-handler second-mode :unmap-notify ()
  (apply #'handle-event-fun-main-mode-unmap-notify event-slots)
Philippe Brochard's avatar
Philippe Brochard committed
  (draw-second-mode-window))

(define-handler second-mode :exposure ()
  (apply #'handle-event-fun-main-mode-exposure event-slots)
Philippe Brochard's avatar
Philippe Brochard committed
  (draw-second-mode-window))




(defun sm-enter-function ()
  (with-placement (*second-mode-placement* x y *sm-width* *sm-height*)
    (setf *in-second-mode* t
	  *sm-window* (xlib:create-window :parent *root*
					  :x x :y y
					  :width *sm-width* :height *sm-height*
					  :background (get-color *sm-background-color*)
					  :border (get-color *sm-border-color*)
					  :colormap (xlib:screen-default-colormap *screen*)
					  :event-mask '(:exposure))
	  *sm-font* (xlib:open-font *display* *sm-font-string*)
	  *sm-gc* (xlib:create-gcontext :drawable *sm-window*
					:foreground (get-color *sm-foreground-color*)
Philippe Brochard's avatar
Philippe Brochard committed
					:background (get-color *sm-background-color*)
  (setf (window-transparency *sm-window*) *sm-transparency*)
Philippe Brochard's avatar
Philippe Brochard committed
  (draw-second-mode-window)
  (no-focus)
  (ungrab-main-keys)
  (xgrab-keyboard *root*)
Philippe Brochard's avatar
Philippe Brochard committed
  (speed-mouse-reset))

(defun sm-loop-function ()
  (raise-window *sm-window*))

(defun sm-leave-function ()
  (setf *in-second-mode* nil)
  (when *sm-gc*
    (xlib:free-gcontext *sm-gc*)
    (setf *sm-gc* nil))
  (when *sm-font*
    (xlib:close-font *sm-font*)
    (setf *sm-font* nil))
  (when *sm-window*
    (xlib:destroy-window *sm-window*)
    (setf *sm-window* nil))
  (xungrab-keyboard)
  (xungrab-pointer)
  (grab-main-keys)
  (show-all-children)
  (display-all-frame-info)
Philippe Brochard's avatar
Philippe Brochard committed

(defun second-key-mode ()
  (generic-mode 'second-mode
		'exit-second-loop
		:enter-function #'sm-enter-function
		:loop-function #'sm-loop-function
		:leave-function #'sm-leave-function)
  (when *second-mode-leave-function*
    (funcall *second-mode-leave-function*)
    (setf *second-mode-leave-function* nil)))
Philippe Brochard's avatar
Philippe Brochard committed

(defun leave-second-mode ()
  "Leave second mode"
Philippe Brochard's avatar
Philippe Brochard committed
	 (setf *in-second-mode* nil)
Philippe Brochard's avatar
Philippe Brochard committed
	(t (setf *in-second-mode* nil)
	   (show-all-children))))
Philippe Brochard's avatar
Philippe Brochard committed

(defun sm-delete-focus-window ()
  "Close focus window: Delete the focus window in all frames and workspaces"
  (setf *second-mode-leave-function* 'delete-focus-window)
  (leave-second-mode))

(defun sm-ask-close/kill-current-window ()
  "Close or kill the current window (ask before doing anything)"
  (setf *second-mode-leave-function* #'ask-close/kill-current-window)
  (leave-second-mode))