e1ca00ac88fc05072af46482031c81c158a93047
[clfswm.git] / src / bindings-second-mode.lisp
blobe1ca00ac88fc05072af46482031c81c158a93047
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)
115 (define-second-key ("Down" :mod-1) 'select-previous-level)
116 (define-second-key ("Up" :mod-1) 'select-next-level)
117 (define-second-key ("Left" :control :mod-1) 'select-brother-spatial-move-left)
118 (define-second-key ("Right" :control :mod-1) 'select-brother-spatial-move-right)
119 (define-second-key ("Up" :control :mod-1) 'select-brother-spatial-move-up)
120 (define-second-key ("Down" :control :mod-1) 'select-brother-spatial-move-down)
121 (define-second-key ("j") 'swap-frame-geometry)
122 (define-second-key ("h") 'rotate-frame-geometry)
123 (define-second-key ("h" :shift) 'anti-rotate-frame-geometry)
125 (define-second-key ("Page_Up") 'select-next-root)
126 (define-second-key ("Page_Down") 'select-previous-root)
127 (define-second-key ("Page_Up" :control) 'rotate-root-geometry-next)
128 (define-second-key ("Page_Down" :control) 'rotate-root-geometry-previous)
130 (define-second-key ("Right") 'speed-mouse-right)
131 (define-second-key ("Left") 'speed-mouse-left)
132 (define-second-key ("Down") 'speed-mouse-down)
133 (define-second-key ("Up") 'speed-mouse-up)
134 (define-second-key ("Left" :control) 'speed-mouse-undo)
135 (define-second-key ("Up" :control) 'speed-mouse-first-history)
136 (define-second-key ("Down" :control) 'speed-mouse-reset)
138 (define-second-key ("Tab" :mod-1) 'select-next-child)
139 (define-second-key ("Tab" :mod-1 :shift) 'select-previous-child)
140 (define-second-key ("Tab" :mod-1 :control) 'select-next-subchild)
141 (define-second-key ("Tab") 'switch-to-last-child)
142 (define-second-key ("Return" :mod-1) 'enter-frame)
143 (define-second-key ("Return" :mod-1 :shift) 'leave-frame)
144 (define-second-key ("Return" :mod-1 :control) 'frame-toggle-maximize)
145 (define-second-key ("Return" :mod-5) 'frame-toggle-maximize)
146 (define-second-key ("Page_Up" :mod-1) 'frame-lower-child)
147 (define-second-key ("Page_Down" :mod-1) 'frame-raise-child)
148 (define-second-key ("Home" :mod-1) 'switch-to-root-frame)
149 (define-second-key ("Home" :mod-1 :shift) 'switch-and-select-root-frame)
150 (define-second-key ("Menu") 'toggle-show-root-frame)
151 (define-second-key ("b" :mod-1) 'banish-pointer)
152 (define-second-key ("o") 'set-open-in-new-frame-in-parent-frame-nw-hook)
153 (define-second-key ("o" :control) 'set-open-in-new-frame-in-root-frame-nw-hook)
154 (define-second-key ("a") 'add-default-frame)
155 (define-second-key ("a" :control) 'add-frame-in-parent-frame)
156 (define-second-key ("plus") 'inc-tile-layout-size)
157 (define-second-key ("minus") 'dec-tile-layout-size)
158 (define-second-key ("plus" :control) 'inc-slow-tile-layout-size)
159 (define-second-key ("minus" :control) 'dec-slow-tile-layout-size)
160 ;; Escape
161 (define-second-key ("Escape" :control) 'ask-close/kill-current-window)
162 ;; Selection
163 (define-second-key ("x" :control) 'cut-current-child)
164 (define-second-key ("x" :control :mod-1) 'clear-selection)
165 (define-second-key ("c" :control) 'copy-current-child)
166 (define-second-key ("v" :control) 'paste-selection)
167 (define-second-key ("v" :control :shift) 'paste-selection-no-clear)
168 (define-second-key ("Delete" :control) 'remove-current-child)
169 (define-second-key ("Delete") 'delete-current-child)
170 (define-shell ("t") b-start-xterm "start an xterm" "cd $HOME && exec xterm")
171 (define-shell ("e") b-start-emacs "start emacs" "cd $HOME && exec emacs")
172 (define-shell ("e" :control) b-start-emacsremote
173 "start an emacs for another user"
174 "exec xterm -e emacsremote")
175 (define-second-key ("F10" :mod-1) 'fast-layout-switch)
176 (define-second-key ("F10" :shift :control) 'toggle-show-root-frame)
177 (define-second-key ("F10") 'expose-windows-mode)
178 (define-second-key ("F10" :control) 'expose-all-windows-mode)
179 (define-second-key ("L2" :shift) 'show-all-frames-info-key)
180 (define-second-key ("L2" :shift :mod-1) 'show-all-frames-info)
181 ;; Bind or jump functions
182 (define-second-key ("1" :mod-1) 'bind-or-jump 1)
183 (define-second-key ("2" :mod-1) 'bind-or-jump 2)
184 (define-second-key ("3" :mod-1) 'bind-or-jump 3)
185 (define-second-key ("4" :mod-1) 'bind-or-jump 4)
186 (define-second-key ("5" :mod-1) 'bind-or-jump 5)
187 (define-second-key ("6" :mod-1) 'bind-or-jump 6)
188 (define-second-key ("7" :mod-1) 'bind-or-jump 7)
189 (define-second-key ("8" :mod-1) 'bind-or-jump 8)
190 (define-second-key ("9" :mod-1) 'bind-or-jump 9)
191 (define-second-key ("0" :mod-1) 'bind-or-jump 10)
192 ;;; Transparency
193 (define-second-key ("t" :control :shift) 'key-inc-transparency)
194 (define-second-key ("t" :control) 'key-dec-transparency))
196 (add-hook *binding-hook* 'set-default-second-keys)
201 ;;; Mouse action
202 (defun sm-mouse-click-to-focus-and-move (window root-x root-y)
203 "Move and focus the current child - Create a new frame on the root window.
204 Or do corners actions"
205 (declare (ignore window))
206 (or (do-corner-action root-x root-y *corner-second-mode-left-button*)
207 (mouse-focus-move/resize-generic root-x root-y #'move-frame nil)))
209 (defun sm-mouse-click-to-focus-and-resize (window root-x root-y)
210 "Resize and focus the current child - Create a new frame on the root window.
211 Or do corners actions"
212 (declare (ignore window))
213 (or (do-corner-action root-x root-y *corner-second-mode-right-button*)
214 (mouse-focus-move/resize-generic root-x root-y #'resize-frame nil)))
217 (defun sm-mouse-middle-click (window root-x root-y)
218 "Do actions on corners"
219 (declare (ignore window))
220 (or (do-corner-action root-x root-y *corner-second-mode-middle-button*)
221 (replay-button-event)))
226 (defun sm-mouse-select-next-level (window root-x root-y)
227 "Select the next level in frame"
228 (declare (ignore window root-x root-y))
229 (select-next-level))
234 (defun sm-mouse-select-previous-level (window root-x root-y)
235 "Select the previous level in frame"
236 (declare (ignore window root-x root-y))
237 (select-previous-level))
241 (defun sm-mouse-enter-frame (window root-x root-y)
242 "Enter in the selected frame - ie make it the root frame"
243 (declare (ignore window root-x root-y))
244 (enter-frame))
248 (defun sm-mouse-leave-frame (window root-x root-y)
249 "Leave the selected frame - ie make its parent the root frame"
250 (declare (ignore window root-x root-y))
251 (leave-frame))
254 (defun sm-mouse-click-to-focus-and-move-window (window root-x root-y)
255 "Move and focus the current child - Create a new frame on the root window"
256 (declare (ignore window))
257 (mouse-focus-move/resize-generic root-x root-y #'move-frame t))
260 (defun sm-mouse-click-to-focus-and-resize-window (window root-x root-y)
261 "Resize and focus the current child - Create a new frame on the root window"
262 (declare (ignore window))
263 (mouse-focus-move/resize-generic root-x root-y #'resize-frame t))
266 (defun sm-mouse-click-to-focus-and-move-window-constrained (window root-x root-y)
267 "Move (constrained by other frames) and focus the current child - Create a new frame on the root window"
268 (declare (ignore window))
269 (mouse-focus-move/resize-generic root-x root-y #'move-frame-constrained t))
272 (defun sm-mouse-click-to-focus-and-resize-window-constrained (window root-x root-y)
273 "Resize (constrained by other frames) and focus the current child - Create a new frame on the root window"
274 (declare (ignore window))
275 (mouse-focus-move/resize-generic root-x root-y #'resize-frame-constrained t))
279 (defun set-default-second-mouse ()
280 (define-second-mouse (1) 'sm-mouse-click-to-focus-and-move)
281 (define-second-mouse (2) 'sm-mouse-middle-click)
282 (define-second-mouse (3) 'sm-mouse-click-to-focus-and-resize)
283 (define-second-mouse (1 :mod-1) 'sm-mouse-click-to-focus-and-move-window)
284 (define-second-mouse (3 :mod-1) 'sm-mouse-click-to-focus-and-resize-window)
285 (define-second-mouse (1 :mod-1 :shift) 'sm-mouse-click-to-focus-and-move-window-constrained)
286 (define-second-mouse (3 :mod-1 :shift) 'sm-mouse-click-to-focus-and-resize-window-constrained)
287 (define-second-mouse (1 :control :mod-1) 'mouse-move-child-over-frame)
288 (define-second-mouse (4) 'sm-mouse-select-next-level)
289 (define-second-mouse (5) 'sm-mouse-select-previous-level)
290 (define-second-mouse (4 :mod-1) 'sm-mouse-enter-frame)
291 (define-second-mouse (5 :mod-1) 'sm-mouse-leave-frame))
293 (add-hook *binding-hook* 'set-default-second-mouse)