From de748ed33175f7bbf2a084e73b1cfa593d88668e Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 26 Jun 2024 12:38:31 -0500 Subject: EXWM --- exwm | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 exwm (limited to 'exwm') diff --git a/exwm b/exwm new file mode 100644 index 0000000..0b52846 --- /dev/null +++ b/exwm @@ -0,0 +1,147 @@ +;;; ~/.exwm -*- mode: emacs-lisp; lexical-binding: t; -*- + +(require 'exwm-systemtray) + +;;; Functions + +(defun exwm-spawn (command) + (interactive (list (read-shell-command "$ "))) + (start-process-shell-command command nil command)) + +(defun ^exwm-spawn (command) + (lambda () (interactive) (exwm-spawn command))) + +(defun exwm-autostart (command) + (start-process-shell-command + (format " %s" command) " *autostart*" command)) + +;; Wifi info +(defun dBm->perc (dBm) + (truncate (+ (- (/ (* dBm dBm) 105.0)) + (/ dBm 21.0) + 100))) + +(defun %wifi-info () + (let (ssid dBm signal) + (with-temp-buffer + (call-process "iw" nil t nil "dev" "wlan0" "link") + (goto-char (point-min)) + (setq ssid (progn (search-forward "SSID: " nil t) + (buffer-substring (point) + (pos-eol)))) + (setq dBm (progn (search-forward "signal: " nil t) + (string-to-number + (buffer-substring (point) + (progn (forward-word) + (point)))))) + (setq signal (dBm->perc dBm)) + (list ssid signal dBm)))) + +(defun wifi-info () + (interactive) + (apply #'message "Connected to `%s' at %s%% (%s dBm)" + (%wifi-info))) + +(defvar display-wifi-info-timer nil) +(defvar display-wifi-info-string "") + +(defun display-wifi-info-update () + (setq display-wifi-info-string + (let ((info (%wifi-info))) + (format " [🛜%s%%]" (cadr info)))) + (force-mode-line-update 'all)) + +(define-minor-mode display-wifi-info-mode + "Toggle display of wifi connection status in mode line." + :global t + (cond + (display-wifi-info-mode + (or (memq 'display-wifi-info-string global-mode-string) + (setq global-mode-string + (append global-mode-string '(display-wifi-info-string)))) + (setq display-wifi-info-timer + (run-with-timer 0 30 #'display-wifi-info-update))) + (t (and (timerp display-wifi-info-timer) + (cancel-timer display-wifi-info-timer)) + (setq display-wifi-info-timer nil) + (setq display-wifi-info-string nil)))) + +;;; Options + +(setopt exwm-workspace-number 4) + +;; Tab bar +(tab-bar-mode) +(setopt tab-bar-show t) +(setopt tab-bar-format + '(tab-bar-format-tabs + tab-bar-format-align-right + tab-bar-format-global)) +(setopt tab-bar-close-button-show nil) + +;; System information +(setopt display-time-default-load-average nil) +(setopt display-time-format "%e %a %R") +(setopt battery-mode-line-format "[🔋%b%p%]") + +(setopt global-mode-string + '("" jabber-activity-mode-string + display-wifi-info-string + " " battery-mode-line-string + " " (:propertize ("" display-time-string) + face tab-bar-tab))) + +(display-wifi-info-mode) +(display-battery-mode) +(display-time-mode) + +;;; Window management + +(after exwm-update-class-hook + (exwm-workspace-rename-buffer exwm-class-name)) + +;;; Keys + +(setopt exwm-input-global-keys + `(;; Command shortcuts + ([?\s-p] . ,(^exwm-spawn "keepassxc")) + ([?\s-b] . ,(^exwm-spawn "firefox --new-tab")) + ;; 's-r': Reset (to line-mode). + ([?\s-r] . exwm-reset) + ;; 's-w': Switch workspace. + ([?\s-w] . exwm-workspace-switch) + ;; 's-&': Launch application. + ([?\s-&] . exwm-spawn) + ;; 's-N': Switch to certain workspace. + ,@(mapcar (lambda (i) + `(,(kbd (format "s-%d" i)) . + (lambda () + (interactive) + (exwm-workspace-switch-create ,i)))) + (number-sequence 1 9)))) + +(setopt exwm-input-simulation-keys + '(([?\C-b] . [left]) + ([?\C-f] . [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]))) + +;;; Startup + +;; Start exwm +(exwm-enable) +(exwm-systemtray-enable) + +;; Start other stuff +(after init + (exwm-autostart "nextcloud") + (exwm-autostart "dunst")) + +;; Turn off debug mode +(setopt toggle-debug-on-error nil) -- cgit 1.4.1-21-gabe81