Do not update current size when there is only geometry change and not head structure...
[clfswm.git] / src / clfswm-second-mode.lisp
blob50029f2c2499429c4ecfbf0ada04aecd1a8bcda2
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 (setf *in-second-mode* nil)
131 (when *sm-gc*
132 (xlib:free-gcontext *sm-gc*)
133 (setf *sm-gc* nil))
134 (when *sm-font*
135 (xlib:close-font *sm-font*)
136 (setf *sm-font* nil))
137 (when *sm-window*
138 (xlib:destroy-window *sm-window*)
139 (setf *sm-window* nil))
140 (xungrab-keyboard)
141 (xungrab-pointer)
142 (grab-main-keys)
143 (show-all-children)
144 (display-all-frame-info)
145 (raise-notify-window)
146 (wait-no-key-or-button-press))
148 (defun second-key-mode ()
149 "Switch to editing mode (second mode)"
150 (generic-mode 'second-mode
151 'exit-second-loop
152 :enter-function #'sm-enter-function
153 :loop-function #'sm-loop-function
154 :leave-function #'sm-leave-function)
155 (when *second-mode-leave-function*
156 (funcall *second-mode-leave-function*)
157 (setf *second-mode-leave-function* nil)))
159 (defun leave-second-mode ()
160 "Leave second mode"
161 (cond (*in-second-mode*
162 (setf *in-second-mode* nil)
163 (throw 'exit-second-loop nil))
164 (t (setf *in-second-mode* nil)
165 (show-all-children))))
168 (defun sm-delete-focus-window ()
169 "Close focus window: Delete the focus window in all frames and workspaces"
170 (setf *second-mode-leave-function* 'delete-focus-window)
171 (leave-second-mode))
173 (defun sm-ask-close/kill-current-window ()
174 "Close or kill the current window (ask before doing anything)"
175 (setf *second-mode-leave-function* #'ask-close/kill-current-window)
176 (leave-second-mode))