Newer
Older
;;; --------------------------------------------------------------------------
;;; CLFSWM - FullScreen Window Manager
;;;
;;; --------------------------------------------------------------------------
;;; Documentation: Second mode functions
;;; --------------------------------------------------------------------------
;;;
;;; (C) 2012 Philippe Brochard <pbrochard@common-lisp.net>
;;;
;;; 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)
Philippe Brochard
committed
(defparameter *second-mode-leave-function* nil
"Execute the function if not nil")
(defun draw-second-mode-window ()
(raise-window *sm-window*)
(clear-pixmap-buffer *sm-window* *sm-gc*)
(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))
Philippe Brochard
committed
(copy-pixmap-buffer *sm-window* *sm-gc*)
(no-focus))
Philippe Brochard
committed
;;; Second mode handlers
(define-handler second-mode :key-press (code state)
(funcall-key-from-code *second-keys* code state)
(draw-second-mode-window))
Philippe Brochard
committed
(define-handler second-mode :enter-notify ()
Philippe Brochard
committed
(define-handler second-mode :motion-notify (window root-x root-y)
Philippe Brochard
committed
(funcall-button-from-code *second-mouse* 'motion
(modifiers->state *default-modifiers*)
window root-x root-y *fun-press*)))
Philippe Brochard
committed
(define-handler second-mode :button-press (window root-x root-y code state)
(funcall-button-from-code *second-mouse* code state window root-x root-y *fun-press*)
(draw-second-mode-window))
Philippe Brochard
committed
(define-handler second-mode :button-release (window root-x root-y code state)
(funcall-button-from-code *second-mouse* code state window root-x root-y *fun-release*)
(draw-second-mode-window))
Philippe Brochard
committed
(define-handler second-mode :configure-request ()
(apply #'handle-event-fun-main-mode-configure-request event-slots)
Philippe Brochard
committed
(define-handler second-mode :configure-notify ()
Philippe Brochard
committed
(define-handler second-mode :destroy-notify ()
(apply #'handle-event-fun-main-mode-destroy-notify event-slots)
Philippe Brochard
committed
(define-handler second-mode :map-request ()
(apply #'handle-event-fun-main-mode-map-request event-slots)
Philippe Brochard
committed
(define-handler second-mode :unmap-notify ()
(apply #'handle-event-fun-main-mode-unmap-notify event-slots)
Philippe Brochard
committed
(define-handler second-mode :exposure ()
(apply #'handle-event-fun-main-mode-exposure event-slots)
(defun sm-enter-function ()
Philippe Brochard
committed
(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*)
Philippe Brochard
committed
:border-width *border-size*
Philippe Brochard
committed
: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
committed
:font *sm-font*
:line-style :solid)))
(setf (window-transparency *sm-window*) *sm-transparency*)
(map-window *sm-window*)
(draw-second-mode-window)
(no-focus)
(ungrab-main-keys)
(xgrab-keyboard *root*)
Philippe Brochard
committed
(xgrab-pointer *root* 66 67)
(defun sm-loop-function ()
(raise-window *sm-window*))
(defun sm-leave-function ()
Philippe Brochard
committed
(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
committed
(raise-notify-window)
Philippe Brochard
committed
(wait-no-key-or-button-press))
(defun second-key-mode ()
Philippe Brochard
committed
"Switch to editing mode (second mode)"
Philippe Brochard
committed
(generic-mode 'second-mode
'exit-second-loop
:enter-function #'sm-enter-function
:loop-function #'sm-loop-function
Philippe Brochard
committed
:leave-function #'sm-leave-function)
(when *second-mode-leave-function*
(funcall *second-mode-leave-function*)
(setf *second-mode-leave-function* nil)))
Philippe Brochard
committed
(cond (*in-second-mode*
Philippe Brochard
committed
(throw 'exit-second-loop nil))
(t (setf *in-second-mode* nil)
(show-all-children))))
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))