system.el (6009B)
1 ;; -*- lexical-binding: t; -*- 2 ;;; Configuration for system related functionality. 3 4 (use-package exwm 5 :init 6 (setq exwm-workspace-number 2) 7 (setq exwm-input-global-keys `(([?\s-r] . exwm-reset))) 8 (setq exwm-input-simulation-keys 9 '(([?\C-a] . [home]) 10 ([?\C-e] . [end]) 11 ([?\C-s] . ?\C-f) 12 ([?\M-w] . ?\C-c) 13 ([?\C-y] . ?\C-v) 14 ([?\C-x?\C-s] . ?\C-s) 15 ([?\M-v] . [prior]) 16 ([?\C-v] . [next]) 17 ([?\C-d] . [delete]) 18 ([?\C-k] . [S-end delete]))) 19 20 (setq exwm-layout-show-all-buffers t) 21 (setq exwm-workspace-show-all-buffers t) 22 23 (defun b3n-exwm-set-buffer-name () 24 (if (and (stringp exwm-title) (= (length (s-split " — " exwm-title)) 3)) 25 (cl-destructuring-bind (title url _) (s-split " — " exwm-title) 26 (setq-local buffer-file-name url) 27 (setq-local exwm-title (concat exwm-class-name "<" title ">"))) 28 (setq-local exwm-title 29 (concat 30 exwm-class-name 31 "<" 32 (if (<= (length exwm-title) 50) 33 exwm-title 34 (concat (substring exwm-title 0 50) "…")) 35 ">"))) 36 37 (exwm-workspace-rename-buffer exwm-title)) 38 39 (require 'exwm-randr) 40 (setq exwm-randr-workspace-monitor-plist '(0 "eDP" 1 "DisplayPort-1")) 41 (exwm-randr-mode) 42 43 (defun find-and-switch-to-app (app-name) 44 "Looks for a buffer that probably corresponds to the window of an app." 45 (let* ((predicate 46 (lambda (b) 47 (and (string-match-p (regexp-quote (format "%s |" app-name)) (buffer-name b)) 48 (eq (buffer-local-value 'major-mode b) 'exwm-mode)))) 49 (cands (seq-filter predicate (buffer-list)))) 50 (if (car cands) 51 (or (switch-to-buffer (car cands)) t)))) 52 53 (defun open-discord () 54 "Switches to any open EXWM buffer of Discord or opens it." 55 (interactive) 56 (if (not (find-and-switch-to-app "discord")) 57 (call-process-shell-command 58 "env MOZ_USE_XINPUT2=1 firefox --new-window discord.com/app" nil 0))) 59 60 (defun bind-exwm-key (keystr func) 61 (define-key override-global-map (kbd keystr) func) 62 (define-key exwm-mode-map (kbd keystr) func)) 63 64 (defmacro bind-named-cmd (keystr name cmd) 65 "Helper macro to define a wrapper around a shell command and bind 66 it to a key in both the global map and the EXWM map. 67 68 This is useful because it means that describe-key can meaningfully 69 describe what is bound to the key (instead of just pointing to an 70 anonymous function)." 71 `(progn 72 (defun ,name () 73 (interactive) 74 (call-process-shell-command ,cmd nil 0)) 75 (bind-exwm-key ,keystr ',name))) 76 77 ;; TODO consider warning in the event these aren't found? 78 (when (executable-find "brightnessctl") 79 (bind-named-cmd "<XF86MonBrightnessUp>" brightness-up-10 "brightnessctl set 10%+") 80 (bind-named-cmd "<XF86MonBrightnessDown>" brightness-down-10 "brightnessctl set 10%-")) 81 82 (when (executable-find "amixer") 83 (bind-named-cmd "<XF86AudioRaiseVolume>" volume-up-5 "amixer set Master 5%+") 84 (bind-named-cmd "<XF86AudioLowerVolume>" volume-down-5 "amixer set Master 5%-") 85 (bind-named-cmd "<XF86AudioMute>" volume-toggle "amixer set Master toggle")) 86 87 (when (executable-find "firefox") 88 (bind-named-cmd "M-f" firefox-new-tab "env MOZ_USE_XINPUT2=1 firefox --new-window") 89 (bind-exwm-key "M-d" 'open-discord)) 90 91 (when (executable-find "slock") 92 (bind-named-cmd "M-l" lock-screen "slock")) 93 94 (when (executable-find "flameshot") 95 (bind-named-cmd "M-s M-s" flameshot 96 "flameshot gui -r | xclip -selection clipboard -t image/png")) 97 98 (bind-exwm-key "M-k" 'other-window) 99 (bind-exwm-key "M-j" (lambda () (interactive) (other-window -1))) 100 (bind-exwm-key "C-M-j" 'other-frame) 101 (bind-exwm-key "C-M-k" (lambda () (interactive) (other-frame -1))) 102 103 (exwm-enable) 104 105 :hook 106 ((exwm-update-class . b3n-exwm-set-buffer-name) 107 (exwm-update-title . b3n-exwm-set-buffer-name))) 108 109 (use-package dmenu 110 :init (bind-exwm-key "M-p" 'dmenu)) 111 112 (use-package prodigy :demand t 113 :config 114 (setq prodigy-kill-process-buffer-on-stop t) 115 116 (defun my/prodigy-define-services () 117 (prodigy-define-service 118 :name "earlyOOM" :command "earlyoom" :args '("-r" "0") 119 :tags '(stability) :auto-start t) 120 (prodigy-define-service 121 :name "Unclutter" :command "unclutter" 122 :tags '(x11) :auto-start t) 123 (prodigy-define-service 124 :name "Picom" :command "picom" 125 :tags '(x11) :auto-start t) 126 127 (dolist (x (seq-filter #'stringp exwm-randr-workspace-monitor-plist)) 128 (prodigy-define-service 129 :name (format "Polybar (%s)" x) :command "polybar" 130 :args (list "-q" "main" "-c" (concat (getenv "HOME") "/.config/polybar/shades/config.ini")) 131 :env (list (list "MONITOR" x)) 132 :tags '(theme) :auto-start t))) 133 134 (defun prodigy-autostart () 135 "Start all unstarted services with `:auto-start' set to non-nil." 136 (interactive) 137 (prodigy-with-refresh 138 (--each prodigy-services 139 (when (and (plist-get it :auto-start) 140 (not (prodigy-service-started-p it))) 141 (prodigy-start-service it))))) 142 143 (defun prodigy-killall () 144 (interactive) 145 (prodigy-with-refresh 146 (--each prodigy-services (prodigy-stop-service it)))) 147 148 :hook ((exwm-init . (lambda () (my/prodigy-define-services) (prodigy-autostart))) 149 (kill-emacs . prodigy-killall))) 150 151 (use-package exwm-outer-gaps 152 :ensure (:host github :repo "walseb/exwm-outer-gaps") 153 :config 154 (defun exwm-outer-gaps-redraw () 155 "exwm-outer gaps sometimes has artifacts in the gap area. 156 Quickly toggling the mode on and off works forces a redraw of 157 the gaps and gets rid of them." 158 (interactive) 159 (exwm-outer-gaps-mode)) 160 (setq exwm-outer-gaps-width [25 25 25 0]) 161 :hook (exwm-init . exwm-outer-gaps-mode)) 162 163 (use-package exwm-mff 164 :hook (exwm-init . exwm-mff-mode))