Move Org setup to lisp/bandali-org.el and fix time & battery display
[~bandali/configs] / lisp / bandali-exwm.el
CommitLineData
8b1a2f32
AB
1(use-package exwm
2 :if b/exwm-p
3 :demand
4 :config
5 ;; make class name the buffer name, truncating beyond 60 characters
6 (defun b/exwm-rename-buffer ()
7 (interactive)
8 (exwm-workspace-rename-buffer
9 (concat exwm-class-name ":"
10 (if (<= (length exwm-title) 60) exwm-title
11 (concat (substring exwm-title 0 59) "...")))))
12 ;; Enable EXWM
13 (exwm-enable)
14 :hook ((exwm-update-class . b/exwm-rename-buffer)
15 (exwm-update-title . b/exwm-rename-buffer)))
16
17(use-package exwm-config
18 :demand
19 :after exwm
20 :hook (exwm-init . exwm-config--fix/ido-buffer-window-other-frame))
21
22(use-package exwm-input
23 :demand
24 :after exwm
25 :config
26 (defun b/exwm-ws-prev-index ()
27 "Return the index for the previous EXWM workspace, wrapping
28around if needed."
29 (if (= exwm-workspace-current-index 0)
30 (1- exwm-workspace-number)
31 (1- exwm-workspace-current-index)))
32
33 (defun b/exwm-ws-next-index ()
34 "Return the index for the next EXWM workspace, wrapping
35around if needed."
36 (if (= exwm-workspace-current-index
37 (1- exwm-workspace-number))
38 0
39 (1+ exwm-workspace-current-index)))
40
41 ;; shorten 'C-c C-q' to 'C-q'
42 (define-key exwm-mode-map [?\C-q] #'exwm-input-send-next-key)
43
44 (setq exwm-workspace-number 4
45 exwm-input-global-keys
46 `(([?\s-R] . exwm-reset)
47 ([?\s-\\] . exwm-workspace-switch)
48 ([?\s-\s] . dmenu)
49 ([?\S-\s-\s] . (lambda (command)
50 (interactive
51 (list (read-shell-command "➜ ")))
52 (start-process-shell-command
53 command nil command)))
54 ([s-return] . (lambda ()
55 (interactive)
56 (start-process "" nil "urxvt")))
57 ([?\C-\s-\s] . counsel-linux-app)
58 ([?\M-\s-\s] . (lambda ()
59 (interactive)
60 (start-process-shell-command
61 "rofi-pass" nil "rofi-pass")))
62 ([?\s-h] . windmove-left)
63 ([?\s-j] . windmove-down)
64 ([?\s-k] . windmove-up)
65 ([?\s-l] . windmove-right)
66 ([?\s-H] . windmove-swap-states-left)
67 ([?\s-J] . windmove-swap-states-down)
68 ([?\s-K] . windmove-swap-states-up)
69 ([?\s-L] . windmove-swap-states-right)
70 ([?\M-\s-h] . shrink-window-horizontally)
71 ([?\M-\s-l] . enlarge-window-horizontally)
72 ([?\M-\s-k] . shrink-window)
73 ([?\M-\s-j] . enlarge-window)
74 ([?\s-\[] . (lambda ()
75 (interactive)
76 (exwm-workspace-switch-create
77 (b/exwm-ws-prev-index))))
78 ([?\s-\]] . (lambda ()
79 (interactive)
80 (exwm-workspace-switch-create
81 (b/exwm-ws-next-index))))
82 ([?\s-{] . (lambda ()
83 (interactive)
84 (exwm-workspace-move-window
85 (b/exwm-ws-prev-index))))
86 ([?\s-}] . (lambda ()
87 (interactive)
88 (exwm-workspace-move-window
89 (b/exwm-ws-next-index))))
90 ,@(mapcar (lambda (i)
91 `(,(kbd (format "s-%d" i)) .
92 (lambda ()
93 (interactive)
94 (exwm-workspace-switch-create ,i))))
95 (number-sequence 0 (1- exwm-workspace-number)))
96 ([?\s-t] . exwm-floating-toggle-floating)
97 ([?\s-f] . exwm-layout-toggle-fullscreen)
98 ([?\s-W] . (lambda ()
99 (interactive)
100 (kill-buffer (current-buffer))))
101 ([?\s-Q] . (lambda ()
102 (interactive)
103 (exwm-manage--kill-client)))
104 ([?\s-\'] . (lambda ()
105 (interactive)
106 (start-process-shell-command
107 "rofi-light" nil "rofi-light")))
108 ([XF86AudioMute] .
109 (lambda ()
110 (interactive)
111 (start-process "" nil "amixer" "set" "'Master',0" "toggle")))
112 ([XF86AudioLowerVolume] .
113 (lambda ()
114 (interactive)
115 (start-process
116 "" nil "amixer" "set" "'Master',0" "5%-")))
117 ([XF86AudioRaiseVolume] .
118 (lambda ()
119 (interactive)
120 (start-process
121 "" nil "amixer" "set" "'Master',0" "5%+")))
122 ([XF86AudioPlay] .
123 (lambda ()
124 (interactive)
125 (start-process "" nil "mpc" "toggle")))
126 ([XF86AudioPrev] .
127 (lambda ()
128 (interactive)
129 (start-process "" nil "mpc" "prev")))
130 ([XF86AudioNext] .
131 (lambda ()
132 (interactive)
133 (start-process "" nil "mpc" "next")))
134 ([XF86ScreenSaver] .
135 (lambda ()
136 (interactive)
137 (start-process "" nil "dm-tool" "lock")))
138 ([\s-XF86Back] . previous-buffer)
139 ([\s-XF86Forward] . next-buffer)))
140
141 ;; Line-editing shortcuts
142 (setq exwm-input-simulation-keys
143 '(;; movement
144 ([?\C-b] . [left])
145 ([?\M-b] . [C-left])
146 ([?\C-f] . [right])
147 ([?\M-f] . [C-right])
148 ([?\C-p] . [up])
149 ([?\C-n] . [down])
150 ([?\C-a] . [home])
151 ([?\C-e] . [end])
152 ([?\M-v] . [prior])
153 ([?\C-v] . [next])
154 ([?\C-d] . [delete])
155 ([?\C-k] . [S-end ?\C-x])
156 ([?\M-<] . C-home)
157 ([?\M->] . C-end)
158 ;; cut/copy/paste
159 ([?\C-w] . [?\C-x])
160 ([?\M-w] . [?\C-c])
161 ([?\C-y] . [?\C-v])
162 ([?\M-d] . [C-S-right ?\C-x])
163 ([?\M-\d] . [C-S-left ?\C-x])
164 ;; window
165 ([?\s-w] . [?\C-w])
166 ([?\s-q] . [?\C-q])
167 ;; misc
168 ([?\C-s] . [?\C-f])
169 ([?\s-s] . [?\C-s])
170 ([?\C-g] . [escape]))))
171
172(use-package exwm-manage
173 :demand
174 :after exwm
175 :hook
176 (exwm-manage-finish . (lambda ()
177 (when exwm-class-name
178 (cond
179 ((string= exwm-class-name "IceCat")
180 (exwm-input-set-local-simulation-keys
181 `(,@exwm-input-simulation-keys
182 ([?\C-\S-d] . [?\C-d]))))
183 ((string= exwm-class-name "URxvt")
184 (exwm-input-set-local-simulation-keys
185 '(([?\C-c ?\C-c] . [?\C-c])
186 ([?\C-c ?\C-u] . [?\C-u]))))
187 ((string= exwm-class-name "Zathura")
188 (exwm-input-set-local-simulation-keys
189 '(([?\C-p] . [C-up])
190 ([?\C-n] . [C-down])))))))))
191
192(use-package exwm-randr
193 :demand
194 :after exwm
195 :config
196 (exwm-randr-enable)
197 :custom
198 (exwm-randr-workspace-monitor-plist '(1 "VGA-1")))
199
200(use-package exwm-systemtray
201 :demand
202 :after exwm
203 :config
204 (exwm-systemtray-enable))
205
206(use-package exwm-workspace)
207
208(use-package exwm-edit
209 :demand
210 :after exwm)
211
212(provide 'bandali-exwm)