src/clfswm-expose-mode.lisp (expose-query-key-press-hook): Add an option to immediate...
[clfswm.git] / src / clfswm-corner.lisp
blob4d89b816458e2634557d158989f8dc1a31f92db9
1 ;;; --------------------------------------------------------------------------
2 ;;; CLFSWM - FullScreen Window Manager
3 ;;;
4 ;;; --------------------------------------------------------------------------
5 ;;; Documentation: Corner 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)
30 (symbol-macrolet ((sw (xlib:screen-width *screen*))
31 (sh (xlib:screen-height *screen*))
32 (cs *corner-size*))
33 (defun in-corner (corner x y)
34 "Return t if (x, y) is in corner.
35 Corner is one of :bottom-right :bottom-left :top-right :top-left"
36 (multiple-value-bind (xmin ymin xmax ymax)
37 (case corner
38 (:bottom-right (values (- sw cs) (- sh cs) sw sh))
39 (:bottom-left (values 0 (- sh cs) cs sh))
40 (:top-left (values 0 0 cs cs))
41 (:top-right (values (- sw cs) 0 sw cs))
42 (t (values 10 10 0 0)))
43 (and (<= xmin x xmax)
44 (<= ymin y ymax)))))
47 (symbol-macrolet ((sw (xlib:screen-width *screen*))
48 (sh (xlib:screen-height *screen*))
49 (cs *corner-size*))
50 (defun find-corner (x y)
51 (cond ((and (< cs x (- sw cs)) (< cs y (- sh cs))) nil)
52 ((and (<= 0 x cs) (<= 0 y cs)) :top-left)
53 ((and (<= (- sw cs) x sw) (<= 0 y cs)) :top-right)
54 ((and (<= 0 x cs) (<= (- sh cs) y sh)) :bottom-left)
55 ((and (<= (- sw cs) x sw) (<= (- sh cs) y sh)) :bottom-right)
56 (t nil))))
61 (defun do-corner-action (x y corner-list)
62 "Do the action associated with corner. The corner function must return T to
63 stop the button event"
64 (when (frame-p (find-current-root))
65 (let ((corner (find-corner x y)))
66 (when corner
67 (let ((fun (second (assoc corner corner-list))))
68 (when fun
69 (funcall fun)))))))
75 ;;;***************************************;;;
76 ;;; CONFIG - Corner actions definitions: ;;;
77 ;;;***************************************;;;
78 (defun find-window-in-query-tree (target-win)
79 (when target-win
80 (dolist (win (xlib:query-tree *root*))
81 (when (child-equal-p win target-win)
82 (return t)))))
84 (defun wait-window-in-query-tree (wait-test)
85 (dotimes (try *corner-command-try-number*)
86 (dolist (win (xlib:query-tree *root*))
87 (when (funcall wait-test win)
88 (return-from wait-window-in-query-tree win)))
89 (sleep *corner-command-try-delay*)))
92 (defun generic-present-body (cmd wait-test win &optional focus-p)
93 (stop-button-event)
94 (unless (find-window-in-query-tree win)
95 (do-shell cmd)
96 (setf win (wait-window-in-query-tree wait-test))
97 (if win
98 (progn
99 (grab-all-buttons win)
100 (hide-window win))
101 (notify-message *corner-error-message-delay*
102 (list (format nil "Error with command ~S" cmd)
103 *corner-error-message-color*))))
104 (when win
105 (cond ((window-hidden-p win)
106 (unhide-window win)
107 (when focus-p
108 (focus-window win))
109 (raise-window win))
110 (t (hide-window win)
111 (show-all-children))))
112 win)
116 (let (win)
117 (defun close-virtual-keyboard ()
118 (when win
119 (xlib:destroy-window win)
120 (xlib:display-finish-output *display*)
121 (setf win nil)))
122 (defun present-virtual-keyboard ()
123 "Present a virtual keyboard"
124 (setf win (generic-present-body *virtual-keyboard-cmd*
125 (lambda (win)
126 (string-equal (xlib:get-wm-class win) "xvkbd"))
127 win))
131 (let (win)
132 (defun equal-clfswm-terminal (window)
133 (when win
134 (xlib:window-equal window win)))
135 (defun close-clfswm-terminal ()
136 (when win
137 (xlib:destroy-window win)
138 (xlib:display-finish-output *display*)
139 (setf win nil)))
140 (defun present-clfswm-terminal ()
141 "Hide/Unhide a terminal"
142 (setf win (generic-present-body *clfswm-terminal-cmd*
143 (lambda (win)
144 (string-equal (xlib:wm-name win) *clfswm-terminal-name*))