Allow to move the current focused child when circulating over brothers (new bindings)
[clfswm.git] / src / bindings-second-mode.lisp
blob93620a24cc1d799f4d0233b992ab0666be7b53c7
1 ;;; --------------------------------------------------------------------------
2 ;;; CLFSWM - FullScreen Window Manager
3 ;;;
4 ;;; --------------------------------------------------------------------------
5 ;;; Documentation: Bindings keys and mouse for second mode
6 ;;;
7 ;;; Note: Mod-1 is the Alt or Meta key, Mod-2 is the Numlock key.
8 ;;; --------------------------------------------------------------------------
9 ;;;
10 ;;; (C) 2012 Philippe Brochard <pbrochard@common-lisp.net>
11 ;;;
12 ;;; This program is free software; you can redistribute it and/or modify
13 ;;; it under the terms of the GNU General Public License as published by
14 ;;; the Free Software Foundation; either version 3 of the License, or
15 ;;; (at your option) any later version.
16 ;;;
17 ;;; This program is distributed in the hope that it will be useful,
18 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;;; GNU General Public License for more details.
21 ;;;
22 ;;; You should have received a copy of the GNU General Public License
23 ;;; along with this program; if not, write to the Free Software
24 ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 ;;;
26 ;;; --------------------------------------------------------------------------
28 (in-package :clfswm)
30 ;;;,-----
31 ;;;| Second keys
32 ;;;|
33 ;;;| CONFIG - Second mode bindings
34 ;;;`-----
35 (add-hook *binding-hook* 'init-*second-keys* 'init-*second-mouse*)
38 (defun open-frame-menu ()
39 "Open the frame menu"
40 (open-menu (find-menu 'frame-menu)))
42 (defun open-window-menu ()
43 "Open the window menu"
44 (open-menu (find-menu 'window-menu)))
46 (defun open-action-by-name-menu ()
47 "Open the action by name menu"
48 (open-menu (find-menu 'action-by-name-menu)))
50 (defun open-action-by-number-menu ()
51 "Open the action by number menu"
52 (open-menu (find-menu 'action-by-number-menu)))
54 (defun open-frame-movement-menu ()
55 "Open the frame movement menu (pack/fill/resize)"
56 (open-menu (find-menu 'frame-movement-menu)))
58 (defun open-root-menu ()
59 "Open the root menu"
60 (open-menu (find-menu 'root-menu)))
62 (defun open-child-menu ()
63 "Open the child menu"
64 (open-menu (find-menu 'child-menu)))
66 (defun tile-current-frame ()
67 "Tile the current frame"
68 (set-layout-once #'tile-layout)
69 (leave-second-mode))
72 (defun stop-all-pending-actions ()
73 "Stop all pending actions"
74 (clear-all-nw-hooks)
75 (leave-second-mode))
78 ;;; default shell programs
79 (defmacro define-shell (key name docstring cmd)
80 "Define a second key to start a shell command"
81 `(define-second-key ,key
82 (defun ,name ()
83 ,docstring
84 (setf *second-mode-leave-function* (let ((cmd ,cmd))
85 (lambda ()
86 (do-shell cmd))))
87 (leave-second-mode))))
90 (defun set-default-second-keys ()
91 (define-second-key ("F1" :mod-1) 'help-on-clfswm)
92 (define-second-key ("m") 'open-menu)
93 (define-second-key ("less") 'open-menu)
94 (define-second-key ("less" :control) 'open-menu)
95 (define-second-key ("f") 'open-frame-menu)
96 (define-second-key ("w") 'open-window-menu)
97 (define-second-key ("n") 'open-action-by-name-menu)
98 (define-second-key ("u") 'open-action-by-number-menu)
99 (define-second-key ("p") 'open-frame-movement-menu)
100 (define-second-key ("r") 'open-root-menu)
101 (define-second-key ("c") 'open-child-menu)
102 (define-second-key ("x") 'update-layout-managed-children-position)
103 (define-second-key ("g" :control) 'stop-all-pending-actions)
104 (define-second-key ("q") 'sm-delete-focus-window)
105 (define-second-key ("k") 'sm-ask-close/kill-current-window)
106 (define-second-key ("i") 'identify-key)
107 (define-second-key ("colon") 'eval-from-query-string)
108 (define-second-key ("exclam") 'run-program-from-query-string)
109 (define-second-key ("Return") 'leave-second-mode)
110 (define-second-key ("Escape") 'leave-second-mode)
111 (define-second-key ("t" :shift) 'tile-current-frame)
112 (define-second-key ("Home" :mod-1 :control :shift) 'exit-clfswm)
113 (define-second-key ("Right" :mod-1) 'select-next-brother)
114 (define-second-key ("Left" :mod-1) 'select-previous-brother)
116 (define-second-key ("Right" :mod-1 :shift) 'select-next-brother-take-current)
117 (define-second-key ("Left" :mod-1 :shift) 'select-previous-brother-take-current)
119 (define-second-key ("Down" :mod-1) 'select-previous-level)
120 (define-second-key ("Up" :mod-1) 'select-next-level)
122 (define-second-key ("Left" :control :mod-1) 'select-brother-spatial-move-left)
123 (define-second-key ("Right" :control :mod-1) 'select-brother-spatial-move-right)
124 (define-second-key ("Up" :control :mod-1) 'select-brother-spatial-move-up)
125 (define-second-key ("Down" :control :mod-1) 'select-brother-spatial-move-down)
127 (define-second-key ("Left" :control :mod-1 :shift) 'select-brother-spatial-move-left-take-current)
128 (define-second-key ("Right" :control :mod-1 :shift) 'select-brother-spatial-move-right-take-current)
129 (define-second-key ("Up" :control :mod-1 :shift) 'select-brother-spatial-move-up-take-current)
130 (define-second-key ("Down" :control :mod-1 :shift) 'select-brother-spatial-move-down-take-current)
132 (define-second-key ("j") 'swap-frame-geometry)
133 (define-second-key ("h") 'rotate-frame-geometry)
134 (define-second-key ("h" :shift) 'anti-rotate-frame-geometry)
136 (define-second-key ("Page_Up") 'select-next-root)
137 (define-second-key ("Page_Down") 'select-previous-root)
138 (define-second-key ("Page_Up" :control) 'rotate-root-geometry-next)
139 (define-second-key ("Page_Down" :control) 'rotate-root-geometry-previous)
141 (define-second-key ("Right") 'speed-mouse-right)
142 (define-second-key ("Left") 'speed-mouse-left)
143 (define-second-key ("Down") 'speed-mouse-down)
144 (define-second-key ("Up") 'speed-mouse-up)
145 (define-second-key ("Left" :control) 'speed-mouse-undo)
146 (define-second-key ("Up" :control) 'speed-mouse-first-history)
147 (define-second-key ("Down" :control) 'speed-mouse-reset)
149 (define-second-key ("Tab" :mod-1) 'select-next-child)
150 (define-second-key ("Tab" :mod-1 :shift) 'select-previous-child)
151 (define-second-key ("Tab" :mod-1 :control) 'select-next-subchild)
152 (define-second-key ("Tab") 'switch-to-last-child)
153 (define-second-key ("Return" :mod-1) 'enter-frame)
154 (define-second-key ("Return" :mod-1 :shift) 'leave-frame)
155 (define-second-key ("Return" :mod-1 :control) 'frame-toggle-maximize)
156 (define-second-key ("Return" :mod-5) 'frame-toggle-maximize)
157 (define-second-key ("Page_Up" :mod-1) 'frame-lower-child)
158 (define-second-key ("Page_Down" :mod-1) 'frame-raise-child)
159 (define-second-key ("Home" :mod-1) 'switch-to-root-frame)
160 (define-second-key ("Home" :mod-1 :shift) 'switch-and-select-root-frame)
161 (define-second-key ("Menu") 'toggle-show-root-frame)
162 (define-second-key ("b" :mod-1) 'banish-pointer)
163 (define-second-key ("o") 'set-open-in-new-frame-in-parent-frame-nw-hook)
164 (define-second-key ("o" :control) 'set-open-in-new-frame-in-root-frame-nw-hook)
165 (define-second-key ("a") 'add-default-frame)
166 (define-second-key ("a" :control) 'add-frame-in-parent-frame)
167 (define-second-key ("plus") 'inc-tile-layout-size)
168 (define-second-key ("minus") 'dec-tile-layout-size)
169 (define-second-key ("plus" :control) 'inc-slow-tile-layout-size)
170 (define-second-key ("minus" :control) 'dec-slow-tile-layout-size)
171 ;; Escape
172 (define-second-key ("Escape" :control) 'ask-close/kill-current-window)
173 ;; Selection
174 (define-second-key ("x" :control) 'cut-current-child)
175 (define-second-key ("x" :control :mod-1) 'clear-selection)
176 (define-second-key ("c" :control) 'copy-current-child)
177 (define-second-key ("v" :control) 'paste-selection)
178 (define-second-key ("v" :control :shift) 'paste-selection-no-clear)
179 (define-second-key ("Delete" :control) 'remove-current-child)
180 (define-second-key ("Delete") 'delete-current-child)
181 (define-shell ("t") b-start-xterm "start an xterm" "cd $HOME && exec xterm")
182 (define-shell ("e") b-start-emacs "start emacs" "cd $HOME && exec emacs")
183 (define-shell ("e" :control) b-start-emacsremote
184 "start an emacs for another user"
185 "exec xterm -e emacsremote")
186 (define-second-key ("F10" :mod-1) 'fast-layout-switch)
187 (define-second-key ("F10" :shift :control) 'toggle-show-root-frame)
188 (define-second-key ("F10") 'expose-windows-mode)
189 (define-second-key ("F10" :control) 'expose-all-windows-mode)
190 (define-second-key ("F12" :shift) 'show-all-frames-info-key)
191 (define-second-key ("F12" :shift :mod-1) 'show-all-frames-info)
192 ;; Bind or jump functions
193 (define-second-key ("1" :mod-1) 'bind-or-jump 1)
194 (define-second-key ("2" :mod-1) 'bind-or-jump 2)
195 (define-second-key ("3" :mod-1) 'bind-or-jump 3)
196 (define-second-key ("4" :mod-1) 'bind-or-jump 4)
197 (define-second-key ("5" :mod-1) 'bind-or-jump 5)
198 (define-second-key ("6" :mod-1) 'bind-or-jump 6)
199 (define-second-key ("7" :mod-1) 'bind-or-jump 7)
200 (define-second-key ("8" :mod-1) 'bind-or-jump 8)
201 (define-second-key ("9" :mod-1) 'bind-or-jump 9)
202 (define-second-key ("0" :mod-1) 'bind-or-jump 10)
203 ;;; Transparency
204 (define-second-key ("t" :control :shift) 'key-inc-transparency)
205 (define-second-key ("t" :control) 'key-dec-transparency))
207 (add-hook *binding-hook* 'set-default-second-keys)
212 ;;; Mouse action
213 (defun sm-mouse-click-to-focus-and-move (window root-x root-y)
214 "Move and focus the current child - Create a new frame on the root window.
215 Or do corners actions"
216 (declare (ignore window))
217 (or (do-corner-action root-x root-y *corner-second-mode-left-button*)
218 (mouse-focus-move/resize-generic root-x root-y #'move-frame nil)))
220 (defun sm-mouse-click-to-focus-and-resize (window root-x root-y)
221 "Resize and focus the current child - Create a new frame on the root window.
222 Or do corners actions"
223 (declare (ignore window))
224 (or (do-corner-action root-x root-y *corner-second-mode-right-button*)
225 (mouse-focus-move/resize-generic root-x root-y #'resize-frame nil)))
228 (defun sm-mouse-middle-click (window root-x root-y)
229 "Do actions on corners"
230 (declare (ignore window))
231 (or (do-corner-action root-x root-y *corner-second-mode-middle-button*)
232 (replay-button-event)))
237 (defun sm-mouse-select-next-level (window root-x root-y)
238 "Select the next level in frame"
239 (declare (ignore window root-x root-y))
240 (select-next-level))
245 (defun sm-mouse-select-previous-level (window root-x root-y)
246 "Select the previous level in frame"
247 (declare (ignore window root-x root-y))
248 (select-previous-level))
252 (defun sm-mouse-enter-frame (window root-x root-y)
253 "Enter in the selected frame - ie make it the root frame"
254 (declare (ignore window root-x root-y))
255 (enter-frame))
259 (defun sm-mouse-leave-frame (window root-x root-y)
260 "Leave the selected frame - ie make its parent the root frame"
261 (declare (ignore window root-x root-y))
262 (leave-frame))
265 (defun sm-mouse-click-to-focus-and-move-window (window root-x root-y)
266 "Move and focus the current child - Create a new frame on the root window"
267 (declare (ignore window))
268 (mouse-focus-move/resize-generic root-x root-y #'move-frame t))
271 (defun sm-mouse-click-to-focus-and-resize-window (window root-x root-y)
272 "Resize and focus the current child - Create a new frame on the root window"
273 (declare (ignore window))
274 (mouse-focus-move/resize-generic root-x root-y #'resize-frame t))
277 (defun sm-mouse-click-to-focus-and-move-window-constrained (window root-x root-y)
278 "Move (constrained by other frames) and focus the current child - Create a new frame on the root window"
279 (declare (ignore window))
280 (mouse-focus-move/resize-generic root-x root-y #'move-frame-constrained t))
283 (defun sm-mouse-click-to-focus-and-resize-window-constrained (window root-x root-y)
284 "Resize (constrained by other frames) and focus the current child - Create a new frame on the root window"
285 (declare (ignore window))
286 (mouse-focus-move/resize-generic root-x root-y #'resize-frame-constrained t))
290 (defun set-default-second-mouse ()
291 (define-second-mouse (1) 'sm-mouse-click-to-focus-and-move)
292 (define-second-mouse (2) 'sm-mouse-middle-click)
293 (define-second-mouse (3) 'sm-mouse-click-to-focus-and-resize)
294 (define-second-mouse (1 :mod-1) 'sm-mouse-click-to-focus-and-move-window)
295 (define-second-mouse (3 :mod-1) 'sm-mouse-click-to-focus-and-resize-window)
296 (define-second-mouse (1 :mod-1 :shift) 'sm-mouse-click-to-focus-and-move-window-constrained)
297 (define-second-mouse (3 :mod-1 :shift) 'sm-mouse-click-to-focus-and-resize-window-constrained)
298 (define-second-mouse (1 :control :mod-1) 'mouse-move-child-over-frame)
299 (define-second-mouse (4) 'sm-mouse-select-next-level)
300 (define-second-mouse (5) 'sm-mouse-select-previous-level)
301 (define-second-mouse (4 :mod-1) 'sm-mouse-enter-frame)
302 (define-second-mouse (5 :mod-1) 'sm-mouse-leave-frame))
304 (add-hook *binding-hook* 'set-default-second-mouse)