about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--exwm147
1 files changed, 147 insertions, 0 deletions
diff --git a/exwm b/exwm new file mode 100644 index 0000000..0b52846 --- /dev/null +++ b/exwm
@@ -0,0 +1,147 @@
1;;; ~/.exwm -*- mode: emacs-lisp; lexical-binding: t; -*-
2
3(require 'exwm-systemtray)
4
5;;; Functions
6
7(defun exwm-spawn (command)
8 (interactive (list (read-shell-command "$ ")))
9 (start-process-shell-command command nil command))
10
11(defun ^exwm-spawn (command)
12 (lambda () (interactive) (exwm-spawn command)))
13
14(defun exwm-autostart (command)
15 (start-process-shell-command
16 (format "<autostart> %s" command) " *autostart*" command))
17
18;; Wifi info
19(defun dBm->perc (dBm)
20 (truncate (+ (- (/ (* dBm dBm) 105.0))
21 (/ dBm 21.0)
22 100)))
23
24(defun %wifi-info ()
25 (let (ssid dBm signal)
26 (with-temp-buffer
27 (call-process "iw" nil t nil "dev" "wlan0" "link")
28 (goto-char (point-min))
29 (setq ssid (progn (search-forward "SSID: " nil t)
30 (buffer-substring (point)
31 (pos-eol))))
32 (setq dBm (progn (search-forward "signal: " nil t)
33 (string-to-number
34 (buffer-substring (point)
35 (progn (forward-word)
36 (point))))))
37 (setq signal (dBm->perc dBm))
38 (list ssid signal dBm))))
39
40(defun wifi-info ()
41 (interactive)
42 (apply #'message "Connected to `%s' at %s%% (%s dBm)"
43 (%wifi-info)))
44
45(defvar display-wifi-info-timer nil)
46(defvar display-wifi-info-string "")
47
48(defun display-wifi-info-update ()
49 (setq display-wifi-info-string
50 (let ((info (%wifi-info)))
51 (format " [🛜%s%%]" (cadr info))))
52 (force-mode-line-update 'all))
53
54(define-minor-mode display-wifi-info-mode
55 "Toggle display of wifi connection status in mode line."
56 :global t
57 (cond
58 (display-wifi-info-mode
59 (or (memq 'display-wifi-info-string global-mode-string)
60 (setq global-mode-string
61 (append global-mode-string '(display-wifi-info-string))))
62 (setq display-wifi-info-timer
63 (run-with-timer 0 30 #'display-wifi-info-update)))
64 (t (and (timerp display-wifi-info-timer)
65 (cancel-timer display-wifi-info-timer))
66 (setq display-wifi-info-timer nil)
67 (setq display-wifi-info-string nil))))
68
69;;; Options
70
71(setopt exwm-workspace-number 4)
72
73;; Tab bar
74(tab-bar-mode)
75(setopt tab-bar-show t)
76(setopt tab-bar-format
77 '(tab-bar-format-tabs
78 tab-bar-format-align-right
79 tab-bar-format-global))
80(setopt tab-bar-close-button-show nil)
81
82;; System information
83(setopt display-time-default-load-average nil)
84(setopt display-time-format "%e %a %R")
85(setopt battery-mode-line-format "[🔋%b%p%]")
86
87(setopt global-mode-string
88 '("" jabber-activity-mode-string
89 display-wifi-info-string
90 " " battery-mode-line-string
91 " " (:propertize ("" display-time-string)
92 face tab-bar-tab)))
93
94(display-wifi-info-mode)
95(display-battery-mode)
96(display-time-mode)
97
98;;; Window management
99
100(after exwm-update-class-hook
101 (exwm-workspace-rename-buffer exwm-class-name))
102
103;;; Keys
104
105(setopt exwm-input-global-keys
106 `(;; Command shortcuts
107 ([?\s-p] . ,(^exwm-spawn "keepassxc"))
108 ([?\s-b] . ,(^exwm-spawn "firefox --new-tab"))
109 ;; 's-r': Reset (to line-mode).
110 ([?\s-r] . exwm-reset)
111 ;; 's-w': Switch workspace.
112 ([?\s-w] . exwm-workspace-switch)
113 ;; 's-&': Launch application.
114 ([?\s-&] . exwm-spawn)
115 ;; 's-N': Switch to certain workspace.
116 ,@(mapcar (lambda (i)
117 `(,(kbd (format "s-%d" i)) .
118 (lambda ()
119 (interactive)
120 (exwm-workspace-switch-create ,i))))
121 (number-sequence 1 9))))
122
123(setopt exwm-input-simulation-keys
124 '(([?\C-b] . [left])
125 ([?\C-f] . [right])
126 ([?\C-p] . [up])
127 ([?\C-n] . [down])
128 ([?\C-a] . [home])
129 ([?\C-e] . [end])
130 ([?\M-v] . [prior])
131 ([?\C-v] . [next])
132 ([?\C-d] . [delete])
133 ([?\C-k] . [S-end delete])))
134
135;;; Startup
136
137;; Start exwm
138(exwm-enable)
139(exwm-systemtray-enable)
140
141;; Start other stuff
142(after init
143 (exwm-autostart "nextcloud")
144 (exwm-autostart "dunst"))
145
146;; Turn off debug mode
147(setopt toggle-debug-on-error nil)