.config/msmtp/config: Update TLS fingerprints for shemshak and gnu
[~bandali/configs] / .emacs.d / lisp / bandali-exwm.el
1 ;;; bandali-exwm.el --- bandali's EXWM configuration -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2018-2021 Amin Bandali
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
27 (add-to-list 'load-path (b/lisp "xelb"))
28 (add-to-list 'load-path (b/lisp "exwm"))
29 (require 'exwm)
30 (csetq ;; exwm-replace t
31 exwm-workspace-show-all-buffers t)
32 ;; make class name the buffer name, truncating beyond 60 characters
33 (defun b/exwm-rename-buffer ()
34 (interactive)
35 (exwm-workspace-rename-buffer
36 (concat exwm-class-name ":"
37 (if (<= (length exwm-title) 60) exwm-title
38 (concat (substring exwm-title 0 59) "...")))))
39 ;; Enable EXWM
40 (exwm-enable)
41 (add-hook 'exwm-update-class-hook #'b/exwm-rename-buffer)
42 (add-hook 'exwm-update-title-hook #'b/exwm-rename-buffer)
43
44 (require 'exwm-config)
45 (add-hook 'exwm-init-hook #'exwm-config--fix/ido-buffer-window-other-frame)
46
47 (require 'exwm-input)
48 (defun b/exwm-ws-prev-index ()
49 "Return the index for the previous EXWM workspace, wrapping
50 around if needed."
51 (if (= exwm-workspace-current-index 0)
52 (1- exwm-workspace-number)
53 (1- exwm-workspace-current-index)))
54
55 (defun b/exwm-ws-next-index ()
56 "Return the index for the next EXWM workspace, wrapping
57 around if needed."
58 (if (= exwm-workspace-current-index
59 (1- exwm-workspace-number))
60 0
61 (1+ exwm-workspace-current-index)))
62
63 (defun b/exwm-ws-prev ()
64 "Switch to previous EXWM workspace, wrapping around if needed."
65 (interactive)
66 (exwm-workspace-switch-create
67 (b/exwm-ws-prev-index)))
68
69 (defun b/exwm-ws-next ()
70 "Switch to next EXWM workspace, wrapping around if needed."
71 (interactive)
72 (exwm-workspace-switch-create
73 (b/exwm-ws-next-index)))
74
75 ;; shorten 'C-c C-q' to 'C-q'
76 (define-key exwm-mode-map [?\C-q] #'exwm-input-send-next-key)
77
78 ;; scroll up/down/left/right on the echo area
79 (define-key minibuffer-inactive-mode-map [mouse-4] #'b/exwm-ws-prev)
80 (define-key minibuffer-inactive-mode-map [mouse-5] #'b/exwm-ws-next)
81 (define-key minibuffer-inactive-mode-map [mouse-6] #'b/exwm-ws-prev)
82 (define-key minibuffer-inactive-mode-map [mouse-7] #'b/exwm-ws-next)
83
84 (defvar b/shifted-ws-names
85 '(0 \) 1 \! 2 \@ 3 \# 4 \$
86 5 \% 6 \^ 7 \& 8 \* 9 \()
87 "Mapping of shifted numbers on my keyboard.")
88
89 (csetq exwm-workspace-number 10
90 exwm-input-global-keys
91 `(([?\s-R] . exwm-reset)
92 ([?\s-b] . exwm-workspace-switch-to-buffer)
93 ([?\s-\\] . exwm-workspace-switch)
94 ([?\s-\s] . dmenu)
95 ;; ([?\s-\s] . (lambda ()
96 ;; (interactive)
97 ;; (start-process-shell-command
98 ;; "rofi" nil "rofi -show run")))
99 ([?\S-\s-\s] . (lambda (command) ; doesn't work in X windows
100 (interactive
101 (list (read-shell-command "➜ ")))
102 (start-process-shell-command
103 command nil command)))
104 ([s-return] . (lambda ()
105 (interactive)
106 (start-process "" nil "urxvt")))
107 ([S-s-return] . (lambda ()
108 (interactive)
109 (start-process "" nil "urxvt"
110 "-name" "floating")))
111 ([?\C-\s-\s] . counsel-linux-app)
112 ([?\M-\s-\s] . (lambda ()
113 (interactive)
114 (start-process-shell-command
115 "rofi-pass" nil "rofi-pass")))
116 ([?\s-h] . windmove-left)
117 ([?\s-j] . windmove-down)
118 ([?\s-k] . windmove-up)
119 ([?\s-l] . windmove-right)
120 ([?\s-H] . windmove-swap-states-left)
121 ([?\s-J] . windmove-swap-states-down)
122 ([?\s-K] . windmove-swap-states-up)
123 ([?\s-L] . windmove-swap-states-right)
124 ([?\s-N ?d] . (lambda ()
125 (interactive)
126 (start-process
127 "" nil "dunstctl" "close")))
128 ([?\s-N ?D] . (lambda ()
129 (interactive)
130 (start-process
131 "" nil "dunstctl" "close-all")))
132 ([?\s-N ?h] . (lambda ()
133 (interactive)
134 (start-process
135 "" nil "dunstctl" "history-pop")))
136 ([?\s-N return] . (lambda ()
137 (interactive)
138 (start-process
139 "" nil "dunstctl" "context")))
140 ([?\M-\s-h] . shrink-window-horizontally)
141 ([?\M-\s-l] . enlarge-window-horizontally)
142 ([?\M-\s-k] . shrink-window)
143 ([?\M-\s-j] . enlarge-window)
144 ([?\s-\[] . b/exwm-ws-prev)
145 ([?\s-\]] . b/exwm-ws-next)
146 ([mode-line mouse-4] . b/exwm-ws-prev) ; up
147 ([mode-line mouse-5] . b/exwm-ws-next) ; down
148 ([mode-line mouse-6] . b/exwm-ws-prev) ; left
149 ([mode-line mouse-7] . b/exwm-ws-next) ; right
150 ([?\s-{] . (lambda ()
151 (interactive)
152 (exwm-workspace-move-window
153 (b/exwm-ws-prev-index))))
154 ([?\s-}] . (lambda ()
155 (interactive)
156 (exwm-workspace-move-window
157 (b/exwm-ws-next-index))))
158 ,@(mapcar (lambda (i)
159 `(,(kbd (format "s-%d" i)) .
160 (lambda ()
161 (interactive)
162 (exwm-workspace-switch-create ,i))))
163 (number-sequence 0 (1- exwm-workspace-number)))
164 ,@(mapcar
165 (lambda (i)
166 `(,(kbd (format "s-%s"
167 (plist-get b/shifted-ws-names i)))
168 .
169 (lambda ()
170 (interactive)
171 (exwm-workspace-move-window ,i))))
172 (number-sequence 0 (1- exwm-workspace-number)))
173 ([?\s-F] . exwm-floating-toggle-floating)
174 ([?\s-f] . exwm-layout-toggle-fullscreen)
175 ([?\s-W] . (lambda ()
176 (interactive)
177 (kill-buffer (current-buffer))))
178 ([?\s-Q] . (lambda ()
179 (interactive)
180 (exwm-manage--kill-client)))
181 ([?\s-\'] . (lambda ()
182 (interactive)
183 (start-process-shell-command
184 "rofi-light" nil "rofi-light")))
185 ([XF86AudioMute] . ; borken on my X200 :-(
186 (lambda ()
187 (interactive)
188 (start-process "" nil "pamixer" "--toggle-mute")))
189 ([XF86Launch1] .
190 (lambda ()
191 (interactive)
192 (start-process "" nil "pamixer" "--toggle-mute")))
193 ([\s-XF86Launch1] . ; toggle mic mute
194 (lambda ()
195 (interactive)
196 (start-process
197 "" nil "pamixer" "--default-source" "--toggle-mute")))
198 ([XF86AudioLowerVolume] .
199 (lambda ()
200 (interactive)
201 (start-process
202 "" nil "pamixer" "--allow-boost" "--decrease" "5")))
203 ([XF86AudioRaiseVolume] .
204 (lambda ()
205 (interactive)
206 (start-process
207 "" nil "pamixer" "--allow-boost" "--increase" "5")))
208 ([XF86AudioPlay] .
209 (lambda ()
210 (interactive)
211 (start-process "" nil "mpc" "toggle")))
212 ([XF86AudioPrev] .
213 (lambda ()
214 (interactive)
215 (start-process "" nil "mpc" "prev")))
216 ([XF86AudioNext] .
217 (lambda ()
218 (interactive)
219 (start-process "" nil "mpc" "next")))
220 ([XF86MonBrightnessDown] .
221 (lambda ()
222 (interactive)
223 (start-process "" nil "light" "-U" "5")))
224 ([XF86MonBrightnessUp] .
225 (lambda ()
226 (interactive)
227 (start-process "" nil "light" "-A" "5")))
228 ([XF86ScreenSaver] .
229 (lambda ()
230 (interactive)
231 (start-process "" nil "dm-tool" "lock")))
232 ([\s-XF86Back] . previous-buffer)
233 ([\s-XF86Forward] . next-buffer)))
234
235 ;; Line-editing shortcuts
236 (csetq exwm-input-simulation-keys
237 '(;; movement
238 ([?\C-b] . [left])
239 ([?\M-b] . [C-left])
240 ([?\C-f] . [right])
241 ([?\M-f] . [C-right])
242 ([?\C-p] . [up])
243 ([?\C-n] . [down])
244 ([?\C-a] . [home])
245 ([?\C-e] . [end])
246 ([?\M-v] . [prior])
247 ([?\C-v] . [next])
248 ([?\C-d] . [delete])
249 ([?\C-k] . [S-end ?\C-x])
250 ([?\M-<] . C-home)
251 ([?\M->] . C-end)
252 ;; cut/copy/paste
253 ([?\C-w] . [?\C-x])
254 ([?\M-w] . [?\C-c])
255 ([?\C-y] . [?\C-v])
256 ([?\M-d] . [C-S-right ?\C-x])
257 ([?\M-\d] . [C-S-left ?\C-x])
258 ;; window
259 ([?\s-w] . [?\C-w])
260 ([?\s-q] . [?\C-q])
261 ;; misc
262 ([?\C-s] . [?\C-f])
263 ([?\s-s] . [?\C-s])
264 ([?\C-g] . [escape])))
265
266 (require 'exwm-manage)
267 (csetq
268 exwm-manage-configurations
269 '(((equal exwm-instance-name "floating")
270 floating t
271 floating-mode-line nil)))
272 (add-hook 'exwm-manage-finish-hook
273 (lambda ()
274 (when exwm-class-name
275 (cond
276 ((member exwm-class-name '("Abrowser" "IceCat" "Iceweasel"))
277 (exwm-input-set-local-simulation-keys
278 `(,@exwm-input-simulation-keys
279 ([?\C-\S-d] . [?\C-d]))))
280 ((member exwm-class-name '("URxvt" "Mate-terminal"))
281 (exwm-input-set-local-simulation-keys
282 '(([?\C-c ?\C-c] . [?\C-c])
283 ([?\C-c ?\C-u] . [?\C-u]))))
284 ((string= exwm-class-name "Zathura")
285 (exwm-input-set-local-simulation-keys
286 '(([?\C-p] . [C-up])
287 ([?\C-n] . [C-down]))))))))
288
289 (require 'exwm-randr)
290 (csetq
291 exwm-randr-workspace-monitor-plist
292 '(0 "eDP-1"
293 1 "eDP-1" 2 "eDP-1" 3 "eDP-1"
294 4 "eDP-1" 5 "eDP-1" 6 "eDP-1"
295 7 "HDMI-1" 8 "HDMI-1" 9 "HDMI-1"))
296 ;; (add-hook
297 ;; 'exwm-randr-screen-change-hook
298 ;; (lambda ()
299 ;; (start-process-shell-command
300 ;; "xrandr" nil
301 ;; "xrandr --output HDMI-1 --mode 1280x720 --above eDP-1 --auto")))
302 (exwm-randr-enable)
303
304 (require 'exwm-systemtray)
305 (exwm-systemtray-enable)
306
307 (add-to-list 'load-path (b/lisp "exwm-edit"))
308 (require 'exwm-edit)
309
310 (provide 'bandali-exwm)
311 ;;; bandali-exwm.el ends here