* .emacs.d/init.el: Show system volumes in mode-line.
[~bandali/configs] / .emacs.d / lisp / bandali-exwm.el
CommitLineData
4c05c418
AB
1;;; bandali-exwm.el --- bandali's EXWM configuration -*- lexical-binding: t; -*-
2
78d731e1 3;; Copyright (C) 2018-2022 Amin Bandali
4c05c418
AB
4
5;; Author: Amin Bandali <bandali@gnu.org>
6;; Keywords: tools
7
8;; This program is free software; you can redistribute it and/or modify
9;; it under the terms of the GNU General Public License as published by
10;; the Free Software Foundation, either version 3 of the License, or
11;; (at your option) any later version.
12
13;; This program is distributed in the hope that it will be useful,
14;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16;; GNU General Public License for more details.
17
18;; You should have received a copy of the GNU General Public License
19;; along with this program. If not, see <https://www.gnu.org/licenses/>.
20
21;;; Commentary:
22
23;; My EXWM setup. Makes good use of its simulation keys.
24
25;;; Code:
26
1f5c92ff
AB
27(add-to-list 'load-path (b/lisp "xelb"))
28(add-to-list 'load-path (b/lisp "exwm"))
29(require 'exwm)
a567a327 30;; (setq exwm-replace t)
1f5c92ff
AB
31;; make class name the buffer name, truncating beyond 60 characters
32(defun b/exwm-rename-buffer ()
33 (interactive)
34 (exwm-workspace-rename-buffer
35 (concat exwm-class-name ":"
36 (if (<= (length exwm-title) 60) exwm-title
37 (concat (substring exwm-title 0 59) "...")))))
38;; Enable EXWM
39(exwm-enable)
40(add-hook 'exwm-update-class-hook #'b/exwm-rename-buffer)
41(add-hook 'exwm-update-title-hook #'b/exwm-rename-buffer)
42
43(require 'exwm-config)
44(add-hook 'exwm-init-hook #'exwm-config--fix/ido-buffer-window-other-frame)
45
46(require 'exwm-input)
47(defun b/exwm-ws-prev-index ()
48 "Return the index for the previous EXWM workspace, wrapping
8b1a2f32 49around if needed."
1f5c92ff
AB
50 (if (= exwm-workspace-current-index 0)
51 (1- exwm-workspace-number)
52 (1- exwm-workspace-current-index)))
8b1a2f32 53
1f5c92ff
AB
54(defun b/exwm-ws-next-index ()
55 "Return the index for the next EXWM workspace, wrapping
8b1a2f32 56around if needed."
1f5c92ff
AB
57 (if (= exwm-workspace-current-index
58 (1- exwm-workspace-number))
59 0
60 (1+ exwm-workspace-current-index)))
61
9867e4bb
AB
62(defun b/exwm-ws-prev ()
63 "Switch to previous EXWM workspace, wrapping around if needed."
64 (interactive)
65 (exwm-workspace-switch-create
66 (b/exwm-ws-prev-index)))
67
68(defun b/exwm-ws-next ()
69 "Switch to next EXWM workspace, wrapping around if needed."
70 (interactive)
71 (exwm-workspace-switch-create
72 (b/exwm-ws-next-index)))
73
1f5c92ff
AB
74;; shorten 'C-c C-q' to 'C-q'
75(define-key exwm-mode-map [?\C-q] #'exwm-input-send-next-key)
76
9867e4bb
AB
77;; scroll up/down/left/right on the echo area
78(define-key minibuffer-inactive-mode-map [mouse-4] #'b/exwm-ws-prev)
79(define-key minibuffer-inactive-mode-map [mouse-5] #'b/exwm-ws-next)
80(define-key minibuffer-inactive-mode-map [mouse-6] #'b/exwm-ws-prev)
81(define-key minibuffer-inactive-mode-map [mouse-7] #'b/exwm-ws-next)
82
83(defvar b/shifted-ws-names
84 '(0 \) 1 \! 2 \@ 3 \# 4 \$
85 5 \% 6 \^ 7 \& 8 \* 9 \()
86 "Mapping of shifted numbers on my keyboard.")
87
78d731e1
AB
88(setq
89 exwm-workspace-number 10
90 exwm-input-global-keys
91 `(([?\s-R] . exwm-reset)
5d40c938
AB
92 ;; ([?\s-b] . exwm-workspace-switch-to-buffer)
93 ([?\s-/] . exwm-workspace-switch)
78d731e1 94 ([?\s-\s] . dmenu)
5d40c938
AB
95 ([?\s-\\] . (lambda ()
96 (interactive)
97 (start-process-shell-command
98 "passmenu" nil "passmenu --type")))
99 ([?\S-\s-\s] . (lambda (command)
78d731e1
AB
100 (interactive
101 (list (read-shell-command "➜ ")))
102 (start-process-shell-command
103 command nil command)))
104 ([s-return] . (lambda ()
105 (interactive)
188c64b5 106 (start-process "" nil "xterm")))
78d731e1
AB
107 ([S-s-return] . (lambda ()
108 (interactive)
188c64b5 109 (start-process "" nil "xterm"
78d731e1
AB
110 "-name" "floating")))
111 ([?\C-\s-\s] . counsel-linux-app)
78d731e1
AB
112 ([?\s-h] . windmove-left)
113 ([?\s-j] . windmove-down)
114 ([?\s-k] . windmove-up)
115 ([?\s-l] . windmove-right)
116 ([?\s-H] . windmove-swap-states-left)
117 ([?\s-J] . windmove-swap-states-down)
118 ([?\s-K] . windmove-swap-states-up)
119 ([?\s-L] . windmove-swap-states-right)
120 ([?\s-N ?d] . (lambda ()
121 (interactive)
122 (start-process
123 "" nil "dunstctl" "close")))
124 ([?\s-N ?D] . (lambda ()
125 (interactive)
126 (start-process
127 "" nil "dunstctl" "close-all")))
128 ([?\s-N ?h] . (lambda ()
129 (interactive)
130 (start-process
131 "" nil "dunstctl" "history-pop")))
132 ([?\s-N return] . (lambda ()
8b1a2f32 133 (interactive)
78d731e1
AB
134 (start-process
135 "" nil "dunstctl" "context")))
136 ([?\M-\s-h] . shrink-window-horizontally)
137 ([?\M-\s-l] . enlarge-window-horizontally)
138 ([?\M-\s-k] . shrink-window)
139 ([?\M-\s-j] . enlarge-window)
140 ([?\s-\[] . b/exwm-ws-prev)
141 ([?\s-\]] . b/exwm-ws-next)
142 ([mode-line mouse-4] . b/exwm-ws-prev) ; up
143 ([mode-line mouse-5] . b/exwm-ws-next) ; down
144 ([mode-line mouse-6] . b/exwm-ws-prev) ; left
145 ([mode-line mouse-7] . b/exwm-ws-next) ; right
146 ([?\s-{] . (lambda ()
147 (interactive)
148 (exwm-workspace-move-window
149 (b/exwm-ws-prev-index))))
150 ([?\s-}] . (lambda ()
151 (interactive)
152 (exwm-workspace-move-window
153 (b/exwm-ws-next-index))))
154 ,@(mapcar (lambda (i)
155 `(,(kbd (format "s-%d" i)) .
156 (lambda ()
157 (interactive)
158 (exwm-workspace-switch-create ,i))))
159 (number-sequence 0 (1- exwm-workspace-number)))
160 ,@(mapcar
161 (lambda (i)
162 `(,(kbd (format "s-%s"
163 (plist-get b/shifted-ws-names i)))
164 .
1f5c92ff
AB
165 (lambda ()
166 (interactive)
78d731e1
AB
167 (exwm-workspace-move-window ,i))))
168 (number-sequence 0 (1- exwm-workspace-number)))
5d40c938 169 ([?\s-.] . exwm-floating-toggle-floating)
78d731e1
AB
170 ([?\s-f] . exwm-layout-toggle-fullscreen)
171 ([?\s-W] . (lambda ()
172 (interactive)
173 (kill-buffer (current-buffer))))
174 ([?\s-Q] . (lambda ()
175 (interactive)
176 (exwm-manage--kill-client)))
177 ([?\s-\'] . (lambda ()
178 (interactive)
179 (start-process-shell-command
188c64b5 180 "dmneu-light" nil "dmenu-light")))
5d40c938
AB
181 ([?\s-\;] . (lambda ()
182 (interactive)
183 (start-process-shell-command
20b58f4d
AB
184 "dmneu-pamixer" nil "dmenu-pamixer")
185 (b/set-volume-level (b/get-volume-level))
186 (force-mode-line-update)))
78d731e1
AB
187 ([XF86AudioMute] . ; borken on my X200 :-(
188 (lambda ()
189 (interactive)
20b58f4d
AB
190 (start-process "" nil "pamixer" "--toggle-mute")
191 (b/set-volume-mute (b/get-volume-mute))
192 (force-mode-line-update)))
193 ([\s-XF86AudioMute] . ; toggle mic mute
194 (lambda ()
195 (interactive)
196 (start-process
197 "" nil "pamixer" "--default-source" "--toggle-mute")
198 (b/set-volume-mute (b/get-volume-mute 'mic) 'mic)
199 (force-mode-line-update)))
78d731e1
AB
200 ([XF86Launch1] .
201 (lambda ()
202 (interactive)
20b58f4d
AB
203 (start-process "" nil "pamixer" "--toggle-mute")
204 (b/set-volume-mute (b/get-volume-mute))
205 (force-mode-line-update)))
78d731e1
AB
206 ([\s-XF86Launch1] . ; toggle mic mute
207 (lambda ()
208 (interactive)
209 (start-process
20b58f4d
AB
210 "" nil "pamixer" "--default-source" "--toggle-mute")
211 (b/set-volume-mute (b/get-volume-mute 'mic) 'mic)
212 (force-mode-line-update)))
78d731e1
AB
213 ([XF86AudioLowerVolume] .
214 (lambda ()
215 (interactive)
216 (start-process
20b58f4d
AB
217 "" nil "pamixer" "--allow-boost" "--decrease" "5")
218 (b/set-volume-level (b/get-volume-level))
219 (force-mode-line-update)))
78d731e1
AB
220 ([XF86AudioRaiseVolume] .
221 (lambda ()
222 (interactive)
223 (start-process
20b58f4d
AB
224 "" nil "pamixer" "--allow-boost" "--increase" "5")
225 (b/set-volume-level (b/get-volume-level))
226 (force-mode-line-update)))
227 ([\s-XF86AudioLowerVolume] .
228 (lambda ()
229 (interactive)
230 (start-process
231 "" nil "pamixer" "--default-source" "--decrease" "5")
232 (b/set-volume-level (b/get-volume-level 'mic) 'mic)
233 (force-mode-line-update)))
234 ([\s-XF86AudioRaiseVolume] .
235 (lambda ()
236 (interactive)
237 (start-process
238 "" nil "pamixer" "--default-source" "--increase" "5")
239 (b/set-volume-level (b/get-volume-level 'mic) 'mic)
240 (force-mode-line-update)))
78d731e1
AB
241 ([XF86AudioPlay] .
242 (lambda ()
243 (interactive)
244 (start-process "" nil "mpc" "toggle")))
245 ([XF86AudioPrev] .
246 (lambda ()
247 (interactive)
248 (start-process "" nil "mpc" "prev")))
249 ([XF86AudioNext] .
250 (lambda ()
251 (interactive)
252 (start-process "" nil "mpc" "next")))
253 ([XF86MonBrightnessDown] .
254 (lambda ()
255 (interactive)
256 (start-process "" nil "light" "-U" "5")))
257 ([XF86MonBrightnessUp] .
258 (lambda ()
259 (interactive)
260 (start-process "" nil "light" "-A" "5")))
261 ([XF86ScreenSaver] .
262 (lambda ()
ca72d745
AB
263 (interactive)
264 (start-process "" nil "dm-tool" "lock")))
78d731e1
AB
265 ([\s-XF86Back] . previous-buffer)
266 ([\s-XF86Forward] . next-buffer)))
1f5c92ff
AB
267
268;; Line-editing shortcuts
78d731e1
AB
269(setq
270 exwm-input-simulation-keys
271 '(;; movement
272 ([?\C-b] . [left])
273 ([?\M-b] . [C-left])
274 ([?\C-f] . [right])
275 ([?\M-f] . [C-right])
276 ([?\C-p] . [up])
277 ([?\C-n] . [down])
278 ([?\C-a] . [home])
279 ([?\C-e] . [end])
280 ([?\M-v] . [prior])
281 ([?\C-v] . [next])
282 ([?\C-d] . [delete])
283 ([?\C-k] . [S-end ?\C-x])
284 ([?\M-<] . C-home)
285 ([?\M->] . C-end)
286 ;; cut/copy/paste
287 ([?\C-w] . [?\C-x])
288 ([?\M-w] . [?\C-c])
289 ([?\C-y] . [?\C-v])
290 ([?\M-d] . [C-S-right ?\C-x])
291 ([?\M-\d] . [C-S-left ?\C-x])
292 ;; window
293 ([?\s-w] . [?\C-w])
294 ([?\s-q] . [?\C-q])
295 ;; misc
296 ([?\C-s] . [?\C-f])
5d40c938 297 ([?\s-g] . [?\C-g])
78d731e1 298 ([?\s-s] . [?\C-s])
5d40c938
AB
299 ([?\C-g] . [escape])
300 ([?\C-/] . [?\C-z])))
1f5c92ff
AB
301
302(require 'exwm-manage)
78d731e1 303(setq
9867e4bb
AB
304 exwm-manage-configurations
305 '(((equal exwm-instance-name "floating")
306 floating t
307 floating-mode-line nil)))
1f5c92ff
AB
308(add-hook 'exwm-manage-finish-hook
309 (lambda ()
310 (when exwm-class-name
311 (cond
9867e4bb 312 ((member exwm-class-name '("Abrowser" "IceCat" "Iceweasel"))
1f5c92ff
AB
313 (exwm-input-set-local-simulation-keys
314 `(,@exwm-input-simulation-keys
315 ([?\C-\S-d] . [?\C-d]))))
188c64b5 316 ((member exwm-class-name '("XTerm" "Mate-terminal"))
1f5c92ff
AB
317 (exwm-input-set-local-simulation-keys
318 '(([?\C-c ?\C-c] . [?\C-c])
319 ([?\C-c ?\C-u] . [?\C-u]))))
320 ((string= exwm-class-name "Zathura")
321 (exwm-input-set-local-simulation-keys
322 '(([?\C-p] . [C-up])
323 ([?\C-n] . [C-down]))))))))
324
325(require 'exwm-randr)
78d731e1 326(setq
9867e4bb
AB
327 exwm-randr-workspace-monitor-plist
328 '(0 "eDP-1"
329 1 "eDP-1" 2 "eDP-1" 3 "eDP-1"
330 4 "eDP-1" 5 "eDP-1" 6 "eDP-1"
331 7 "HDMI-1" 8 "HDMI-1" 9 "HDMI-1"))
332;; (add-hook
333;; 'exwm-randr-screen-change-hook
334;; (lambda ()
335;; (start-process-shell-command
336;; "xrandr" nil
337;; "xrandr --output HDMI-1 --mode 1280x720 --above eDP-1 --auto")))
1f5c92ff 338(exwm-randr-enable)
1f5c92ff
AB
339
340(require 'exwm-systemtray)
341(exwm-systemtray-enable)
342
343(add-to-list 'load-path (b/lisp "exwm-edit"))
344(require 'exwm-edit)
8b1a2f32 345
78619ba4 346(with-eval-after-load 'exwm-workspace
a567a327 347 (setq exwm-workspace-show-all-buffers t)
78619ba4
AB
348 (setq-default
349 mode-line-format
350 (append
351 mode-line-format
352 '((:eval
353 (format
354 " [%s]" (number-to-string
20b58f4d 355 exwm-workspace-current-index)))))))
78619ba4 356
a567a327
AB
357(with-eval-after-load 'exwm-layout
358 (setq exwm-layout-show-all-buffers t))
359
8b1a2f32 360(provide 'bandali-exwm)
4c05c418 361;;; bandali-exwm.el ends here