1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
;;; window-manager.el -*- lexical-binding: t; -*-
;;;
;;; Author: Jakob L. Kreuze <zerodaysfordays@sdf.org>
;;; URL: https://git.sr.ht/~jakob/.emacs.d/
;;;
;;; My configuration for the EXWM package [1]. Yes, I use Emacs as my window
;;; manager. You should, too!
;;;
;;; [1]: https://github.com/ch11ng/exwm
;;;
(use-package exwm
:config
(exwm-enable)
;; I find that four workspaces is enough to start out with, and I like being
;; able to use my X windows across workspaces.
:init
(setq exwm-workspace-number 4
exwm-workspace-show-all-buffers t
exwm-layout-show-all-buffers t)
;; "Global key bindings" in EXWM work essentially anywhere, including buffers
;; that are currently in char mode. I've taken this as an opportunity to
;; incorporate windmove to my workflow, now that I have the super key at my
;; disposal.
:init
(require 'windmove)
;; Define some interactive functions for dealing with a multi-head setup.
(when (string= (system-name) "Epsilon")
(defun my-windmove-right ()
(interactive)
(if (windmove-find-other-window 'right)
(windmove-right)
(if (= exwm-workspace-current-index 1)
(exwm-workspace-switch 0)
(exwm-workspace-switch 1))))
(defun my-windmove-left ()
(interactive)
(if (windmove-find-other-window 'left)
(windmove-left)
(if (= exwm-workspace-current-index 1)
(exwm-workspace-switch 0)
(exwm-workspace-switch 1)))))
;; And if we haven't defined those functions because we aren't on a multi-head
;; setup, define aliases to the underlying windmove functions.
(when (and (not (fboundp #'my-windmove-left))
(not (fboundp #'my-windmove-right)))
(defalias #'my-windmove-left #'windmove-left)
(defalias #'my-windmove-right #'windmove-right))
(setq exwm-input-global-keys
`(([?\s-r] . exwm-reset)
([?\s-a] . my-windmove-left)
([?\s-d] . my-windmove-right)
([?\s-w] . windmove-up)
([?\s-s] . windmove-down)
([?\s-p] . (lambda (command)
(interactive (list (read-shell-command "$ ")))
(start-process-shell-command command nil command)))
([?\s-X] . (lambda ()
(interactive)
(start-process "" nil "slock")))
([?\s-f] . (lambda ()
(interactive)
(start-process "" nil "firefox")))
(,(kbd "s-<return>") . (lambda ()
(interactive)
(start-process "" nil "alacritty")))
;; Keys are offset such that <s-1> corresponds to the 0th workspace.
,@(mapcar (lambda (i)
`(,(kbd (format "s-%d" i)) .
(lambda ()
(interactive)
(exwm-workspace-switch-create ,(- i 1)))))
(number-sequence 1 9))))
;; Ah, yes. Simulation keys, the reason I decided to look at EXWM in the first
;; place.
:init
(setq exwm-input-simulation-keys
'(([?\C-b] . [left])
([?\M-b] . [C-left])
([?\C-f] . [right])
([?\M-f] . [C-right])
([?\C-p] . [up])
([?\C-n] . [down])
([?\C-a] . [home])
([?\C-e] . [end])
([?\M-v] . [prior])
([?\C-v] . [next])
([?\C-d] . [delete])
([?\C-k] . [S-end delete])
([?\C-w] . [?\C-x])
([?\M-w] . [?\C-c])
([?\C-y] . [?\C-v])
([?\C-s] . [?\C-f])))
;; The tab management functionality of Firefox's Saka Key extension is
;; limited, so I'm using simulation keys instead. I've also disabled
;; simulation keys for alacritty because it doesn't play nicely with readline.
:hook
(exwm-manage-finish . (lambda ()
(when (and exwm-class-name
(string= exwm-class-name "Firefox"))
(exwm-input-set-local-simulation-keys
(concatenate 'list
exwm-input-simulation-keys
'(([?\C-q] . [?\C-w])))))
(when (and exwm-class-name
(string= exwm-class-name "Alacritty"))
(exwm-input-set-local-simulation-keys nil))))
;; EXWM's buffers are named '*EXWM*' upon creation, which makes switching
;; between windows a pain. This snippet renames buffers when their class or
;; title changes.
:hook
(exwm-update-class . (lambda ()
(exwm-workspace-rename-buffer exwm-class-name)))
(exwm-update-title . (lambda ()
(when (not exwm-instance-name)
(exwm-workspace-rename-buffer exwm-title))))
;; Start the Emacs daemon so that 'emacsclient' can be used from the command
;; line to pop a new buffer for editing.
:config
(server-start)
;; Configure the resolution of my monitors and let EXWM know about them.
:config
(require 'exwm-randr)
(defun hdmi-out ()
(and (string= (system-name) "Upsilon")
(save-window-excursion
(with-temp-buffer
(shell-command "xrandr" (current-buffer))
(cl-search "HDMI-1 connected" (buffer-string))))))
(setq exwm-randr-workspace-monitor-plist
(if (string= (system-name) "Epsilon")
'(0 "DVI-D-0" 1 "HDMI-A-0")
'(0 (if (hdmi-out) "HDMI-1" "eDP-1"))))
(add-hook 'exwm-randr-screen-change-hook
(lambda ()
(start-process-shell-command
"xrandr" nil
(if (string= (system-name) "Epsilon")
"xrandr --output DVI-D-0 --primary --left-of HDMI-A-0"
(if (hdmi-out)
"xrandr --output HDMI-1 --mode 1920x1080 --output eDP-1 --off"
"xrandr --output eDP-1 --mode 1920x1080")))))
(exwm-randr-enable))
;; Some keybindings for buffer-move that are analagous to my keybindings for
;; windmove above.
(use-package buffer-move
:bind
("M-s-w" . buf-move-up)
("M-s-a" . buf-move-left)
("M-s-s" . buf-move-down)
("M-s-d" . buf-move-right))
;; EXWM has issues popping any sort of pinentry window, so I just let Emacs do
;; pinentry's job.
(use-package epa
:straight nil
:config
(setq epa-pinentry-mode 'loopback))
;; And on that note, allow 'gpg-agent' to query Emacs for my passphrase.
(use-package pinentry
:demand t
:config
(setenv "INSIDE_EMACS" (format "%s,comint" emacs-version))
(pinentry-start))
|