src/clfswm-expose-mode.lisp (expose-query-key-press-hook): Add an option to immediate...
[clfswm.git] / src / clfswm-second-mode.lisp
blob49b528acce97efb5b977d977c6f7017cb5c520c8
1 ;;; --------------------------------------------------------------------------
2 ;;; CLFSWM - FullScreen Window Manager
3 ;;;
4 ;;; --------------------------------------------------------------------------
5 ;;; Documentation: Second mode functions
6 ;;; --------------------------------------------------------------------------
7 ;;;
8 ;;; (C) 2012 Philippe Brochard <pbrochard@common-lisp.net>
9 ;;;
10 ;;; This program is free software; you can redistribute it and/or modify
11 ;;; it under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or
13 ;;; (at your option) any later version.
14 ;;;
15 ;;; This program is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
19 ;;;
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with this program; if not, write to the Free Software
22 ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 ;;;
24 ;;; --------------------------------------------------------------------------
26 (in-package :clfswm)
28 (defparameter *sm-window* nil)
29 (defparameter *sm-font* nil)
30 (defparameter *sm-gc* nil)
32 (defparameter *second-mode-leave-function* nil
33 "Execute the function if not nil")
36 (defun draw-second-mode-window ()
37 (raise-window *sm-window*)
38 (clear-pixmap-buffer *sm-window* *sm-gc*)
39 (let* ((text (format nil "Second mode"))
40 (len (length text)))
41 (xlib:draw-glyphs *pixmap-buffer* *sm-gc*
42 (truncate (/ (- *sm-width* (* (xlib:max-char-width *sm-font*) len)) 2))
43 (truncate (/ (+ *sm-height* (- (xlib:font-ascent *sm-font*) (xlib:font-descent *sm-font*))) 2))
44 text))
45 (copy-pixmap-buffer *sm-window* *sm-gc*))
50 ;;; Second mode handlers
51 (define-handler second-mode :key-press (code state)
52 (funcall-key-from-code *second-keys* code state)
53 (draw-second-mode-window))
55 (define-handler second-mode :enter-notify ()
56 (draw-second-mode-window))
58 (define-handler second-mode :motion-notify (window root-x root-y)
59 (unless (compress-motion-notify)
60 (funcall-button-from-code *second-mouse* 'motion
61 (modifiers->state *default-modifiers*)
62 window root-x root-y *fun-press*)))
64 (define-handler second-mode :button-press (window root-x root-y code state)
65 (funcall-button-from-code *second-mouse* code state window root-x root-y *fun-press*)
66 (draw-second-mode-window))
68 (define-handler second-mode :button-release (window root-x root-y code state)
69 (funcall-button-from-code *second-mouse* code state window root-x root-y *fun-release*)
70 (draw-second-mode-window))
72 (define-handler second-mode :configure-request ()
73 (apply #'handle-event-fun-main-mode-configure-request event-slots)
74 (draw-second-mode-window))
77 (define-handler second-mode :configure-notify ()
78 (draw-second-mode-window))
81 (define-handler second-mode :destroy-notify ()
82 (apply #'handle-event-fun-main-mode-destroy-notify event-slots)
83 (draw-second-mode-window))
85 (define-handler second-mode :map-request ()
86 (apply #'handle-event-fun-main-mode-map-request event-slots)
87 (draw-second-mode-window))
89 (define-handler second-mode :unmap-notify ()
90 (apply #'handle-event-fun-main-mode-unmap-notify event-slots)
91 (draw-second-mode-window))
93 (define-handler second-mode :exposure ()
94 (apply #'handle-event-fun-main-mode-exposure event-slots)
95 (draw-second-mode-window))
100 (defun sm-enter-function ()
101 (with-placement (*second-mode-placement* x y *sm-width* *sm-height*)
102 (setf *in-second-mode* t
103 *sm-window* (xlib:create-window :parent *root*
104 :x x :y y
105 :width *sm-width* :height *sm-height*
106 :background (get-color *sm-background-color*)
107 :border-width *border-size*
108 :border (get-color *sm-border-color*)
109 :colormap (xlib:screen-default-colormap *screen*)
110 :event-mask '(:exposure))
111 *sm-font* (xlib:open-font *display* *sm-font-string*)
112 *sm-gc* (xlib:create-gcontext :drawable *sm-window*
113 :foreground (get-color *sm-foreground-color*)
114 :background (get-color *sm-background-color*)
115 :font *sm-font*
116 :line-style :solid)))
117 (setf (window-transparency *sm-window*) *sm-transparency*)
118 (map-window *sm-window*)
119 (draw-second-mode-window)
120 (no-focus)
121 (ungrab-main-keys)
122 (xgrab-keyboard *root*)
123 (xgrab-pointer *root* 66 67)
124 (speed-mouse-reset))
126 (defun sm-loop-function ()
127 (raise-window *sm-window*))
129 (defun sm-leave-function ()
130 (xlib:free-gcontext *sm-gc*)
131 (xlib:close-font *sm-font*)
132 (xlib:destroy-window *sm-window*)
133 (xungrab-keyboard)
134 (xungrab-pointer)
135 (grab-main-keys)
136 (show-all-children)
137 (display-all-frame-info)
138 (raise-notify-window)
139 (wait-no-key-or-button-press)
140 (setf *in-second-mode* nil))
142 (defun second-key-mode ()
143 "Switch to editing mode (second mode)"
144 (generic-mode 'second-mode
145 'exit-second-loop
146 :enter-function #'sm-enter-function
147 :loop-function #'sm-loop-function
148 :leave-function #'sm-leave-function)
149 (when *second-mode-leave-function*
150 (funcall *second-mode-leave-function*)
151 (setf *second-mode-leave-function* nil)))
153 (defun leave-second-mode ()
154 "Leave second mode"
155 (cond (*in-second-mode*
156 (setf *in-second-mode* nil)
157 (throw 'exit-second-loop nil))
158 (t (setf *in-second-mode* nil)
159 (show-all-children))))
162 (defun sm-delete-focus-window ()
163 "Close focus window: Delete the focus window in all frames and workspaces"
164 (setf *second-mode-leave-function* 'delete-focus-window)
165 (leave-second-mode))
167 (defun sm-ask-close/kill-current-window ()
168 "Close or kill the current window (ask before doing anything)"
169 (setf *second-mode-leave-function* #'ask-close/kill-current-window)
170 (leave-second-mode))