stumpwmrc 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. #-quicklisp
  2. (let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp"
  3. (user-homedir-pathname))))
  4. (when (probe-file quicklisp-init)
  5. (load quicklisp-init)))
  6. (in-package :stumpwm)
  7. (setf *default-package* :stumpwm)
  8. (when *initializing*
  9. (defvar *env*
  10. (let* ((os-string (string-trim
  11. '(#\newline)
  12. (run-shell-command "uname" t)))
  13. (os (intern os-string :keyword)))
  14. (case os
  15. (:|Linux| :linux)
  16. (:|NetBSD| :netbsd)
  17. (t :other)))))
  18. (set-module-dir "/home/kev/personal/src/stumpwm-contrib/")
  19. (setf *startup-message* nil)
  20. (defvar *start-up-cmds*
  21. (case *env*
  22. (:linux '("exec pipewire"
  23. "exec setxkbmap -option \"ctrl:nocaps\""
  24. "exec xrdb -merge ~/.Xresources"
  25. "exec xsetroot -cursor_name left_ptr"
  26. "exec sh ~/.screenlayout/three-monitor-setup.sh"))
  27. (:netbsd '("exec setxkbmap -option \"ctrl:nocaps\""
  28. "exec xrdb -merge ~/.Xresources"))
  29. (t '())))
  30. (when *initializing*
  31. (dolist (cmd *start-up-cmds*)
  32. (run-shell-command cmd)))
  33. (ql:quickload :clx-truetype)
  34. (when (eq *env* :linux)
  35. (progn
  36. (load-module "ttf-fonts")
  37. ;; FantasqueSansMono Nerd Font Mono
  38. (set-font `(,(make-instance
  39. 'xft:font
  40. :family "LiterationMono Nerd Font Mono"
  41. :subfamily "Regular"
  42. :size 20
  43. :antialias t)))))
  44. (setf *mode-line-timeout* 2)
  45. (setf *time-modeline-string* "%F %I:%M%p")
  46. (setf *group-format* "%t")
  47. (setf *window-format* "%n: %30t")
  48. (defvar kev-green "#39623d")
  49. (defvar kev-cream "#f1e9d2")
  50. (defvar kev-gray "#4c566a")
  51. (defvar kev-red "#cd4f34")
  52. (when (eq *env* :linux)
  53. (load-module "battery-portable")
  54. ;; requires `wireless_tools` to be installed
  55. (load-module "wifi"))
  56. (setf *mode-line-background-color* kev-green
  57. *mode-line-foreground-color* kev-cream)
  58. (setf *mode-line-border-color* kev-cream
  59. *mode-line-border-width* 0)
  60. (set-border-color kev-cream)
  61. (set-focus-color kev-red)
  62. (set-unfocus-color kev-gray)
  63. (set-float-focus-color kev-cream)
  64. (set-float-unfocus-color kev-gray)
  65. ;;(set-fg-color kev-gray)
  66. ;;(set-bg-color kev-cream)
  67. (setf *normal-border-width* 5
  68. *float-window-border* 10
  69. *float-window-title-height* 15
  70. ;; *window-border-style* :none
  71. *window-format* "%n:(%t)")
  72. (setf *input-window-gravity* :top
  73. *message-window-padding* 10
  74. *message-window-y-padding* 10
  75. *message-window-gravity* :top)
  76. (setf *mode-line-highlight-template* "(~A)")
  77. ;; TODO: add a module for NetBSD WIFI and battery :)
  78. (defvar *mode-line-format*
  79. (case *env*
  80. (:linux (format nil "^(:bg \"~A\")^(:fg \"~A\")%g^(:fg \"~A\")^(:bg \"~A\")^(:bg \"~A\")^(:fg \"~A\") %W^>^(:fg \"~A\")^(:fg \"~A\")^(:bg \"~A\")%I ^(:bg \"~A\")^(:bg \"~A\")^(:fg \"~A\")%B ^(:fg \"~A\")^(:bg \"~A\")^(:fg \"~A\")%d"
  81. kev-cream kev-green kev-cream kev-green kev-green kev-cream kev-cream kev-green kev-cream kev-cream kev-green kev-cream kev-cream kev-cream kev-green))
  82. (t (format nil "^(:bg \"~A\")^(:fg \"~A\")%g^(:fg \"~A\")^(:bg \"~A\")^(:bg \"~A\")^(:fg \"~A\") %W^>^(:fg \"~A\")^(:bg \"~A\")^(:fg \"~A\")%d^(:bg \"~A\")"
  83. kev-cream kev-green kev-cream kev-green kev-green kev-cream kev-cream)))
  84. "List of formatters for the modeline.")
  85. (defcommand reload-modeline () ()
  86. "Reload modeline."
  87. (sb-thread:make-thread
  88. (lambda ()
  89. (setf *screen-mode-line-format* *mode-line-format*))))
  90. (reload-modeline)
  91. (when *initializing*
  92. (mode-line))
  93. (setf *mouse-focus-policy* :click
  94. *float-window-modifier* :SUPER)
  95. (load-module "beckon")
  96. (load-module "end-session")
  97. (load-module "globalwindows")
  98. (load-module "stump-backlight")
  99. (load-module "urgentwindows")
  100. (load-module "pass")
  101. (ql:quickload "zpng")
  102. (load-module "screenshot")
  103. (load-module "swm-gaps")
  104. (setf swm-gaps:*head-gaps-size* 0
  105. swm-gaps:*inner-gaps-size* 5
  106. swm-gaps:*outer-gaps-size* 0)
  107. (when *initializing*
  108. (swm-gaps:toggle-gaps))
  109. (defparameter *output-dir* "~/Pictures")
  110. (set-prefix-key (kbd "C-h"))
  111. ;;; Keybindings
  112. (define-key *root-map* (kbd "B") "beckon")
  113. (define-key *root-map* (kbd "C-b") "banish")
  114. (define-key *root-map* (kbd "c") "exec kitty")
  115. (define-key *root-map* (kbd "d") "exec dmenu_run")
  116. (define-key *root-map* (kbd "C-c") "exec chromium")
  117. (define-key *root-map* (kbd "C-C") "exec dbeaver")
  118. (define-key *root-map* (kbd "l") "move-focus right")
  119. (define-key *root-map* (kbd "H") *help-map*)
  120. (define-key *root-map* (kbd "k") "move-focus up")
  121. (define-key *root-map* (kbd "j") "move-focus down")
  122. (define-key *root-map* (kbd "L") "exec xlock -mode star -trek 1000")
  123. (define-key *root-map* (kbd "F") "fullscreen")
  124. (define-key *root-map* (kbd "h") "move-focus left")
  125. ;; audio
  126. (define-key *top-map* (kbd "XF86AudioRaiseVolume") "exec wpctl set-volume @DEFAULT_SINK@ 5%+")
  127. (define-key *top-map* (kbd "XF86AudioLowerVolume") "exec wpctl set-volume @DEFAULT_SINK@ 5%-")
  128. (define-key *top-map* (kbd "XF86AudioMute") "exec wpctl set-mute @DEFAULT_SINK@ toggle")
  129. ;; brightness
  130. (define-key *top-map* (kbd "XF86MonBrightnessDown") "exec brillo -U 5")
  131. (define-key *top-map* (kbd "XF86MonBrightnessUp") "exec brillo -A 5")
  132. ;;; --- bluetooth ---------------------------------------------------
  133. (defvar *bluetooth-command* "bluetoothctl"
  134. "Base command for interacting with bluetooth.")
  135. (defun bluetooth-message (&rest message)
  136. (message (format nil
  137. "^2Bluetooth:^7 ~{~A~^ ~}"
  138. message)))
  139. (defun bluetooth-make-command (&rest args)
  140. (format nil
  141. "~a ~{~A~^ ~}"
  142. *bluetooth-command*
  143. args))
  144. (defmacro bluetooth-command (&rest args)E `(run-shell-command (bluetooth-make-command ,@args) t))
  145. (defmacro bluetooth-message-command (&rest args)
  146. `(bluetooth-message (bluetooth-command ,@args)))
  147. (defcommand bluetooth-turn-on () ()
  148. "Turn on bluetooth."
  149. (bluetooth-message-command "power" "on"))
  150. (defcommand bluetooth-turn-off () ()
  151. "Turn off bluetooth."
  152. (bluetooth-message-command "power" "off"))
  153. (defstruct (bluetooth-device
  154. (:constructor
  155. make-bluetooth-device (&key (address "")
  156. (name nil)))
  157. (:constructor
  158. make-bluetooth-device-from-command
  159. (&key (raw-name "")
  160. &aux (address (cadr (cl-ppcre:split " " raw-name)))
  161. (full-name (format nil "~{~A~^ ~}" (cddr (cl-ppcre:split " " raw-name)))))))
  162. address
  163. (full-name (progn
  164. (format nil "~{~A~^ ~}" name))))
  165. (defun bluetooth-get-devices ()
  166. (let ((literal-devices (bluetooth-command "devices")))
  167. (mapcar (lambda (device)
  168. (make-bluetooth-device-from-command :raw-name device))
  169. (cl-ppcre:split "\\n" literal-devices))))
  170. (defun bluetooth-connect-device (device)
  171. (progn
  172. (bluetooth-turn-on)
  173. (cond ((bluetooth-device-p device) ;; it is a bluetooth-device structure
  174. (bluetooth-message-command "connect"
  175. (bluetooth-device-address device)))
  176. ((stringp device) ;; assume it is a MAC address
  177. (bluetooth-message-command "connect" device))
  178. ((null device)
  179. (message "Abort."))
  180. (t (message (format nil "Cannot work with device ~a" device))))))
  181. (defun bluetooth-disconnect-device (device)
  182. (progn
  183. (cond ((bluetooth-device-p device) ;; it is a bluetooth-device structure
  184. (bluetooth-message-command "disconnect"
  185. (bluetooth-device-address device)))
  186. ((stringp device) ;; assume it is a MAC address
  187. (bluetooth-message-command "disconnect" device))
  188. ((null device)
  189. (message "Abort."))
  190. (t (message (format nil "Cannot work with device ~a" device))))))
  191. (defcommand bluetooth-info () ()
  192. (bluetooth-message-command "info"))
  193. (defcommand bluetooth-connect () ()
  194. (sb-thread:make-thread
  195. (lambda ()
  196. (let* ((devices (bluetooth-get-devices))
  197. (choice (cadr (select-from-menu
  198. (current-screen)
  199. (mapcar (lambda (device)
  200. `(,(bluetooth-device-full-name device) ,device))
  201. devices)))))
  202. (bluetooth-connect-device choice)))))
  203. (defcommand bluetooth-disconnect () ()
  204. (sb-thread:make-thread
  205. (lambda ()
  206. (let* ((devices (bluetooth-get-devices))
  207. (choice (cadr (select-from-menu
  208. (current-screen)
  209. (mapcar (lambda (device)
  210. `(,(bluetooth-device-full-name device) ,device))
  211. devices)))))
  212. (bluetooth-disconnect-device choice)))))
  213. (defcommand flatpak-run () ()
  214. (let* ((pak-list (run-shell-command "flatpak list | awk -F'\\t' 'NR > 0 { print $2 }'" t))
  215. (paks (cl-ppcre:split "\\n" pak-list))
  216. (pak (select-from-menu
  217. (current-screen)
  218. paks)))
  219. (run-shell-command (format nil "dbus-run-session flatpak run ~a" (car pak)))))
  220. ;; TODO:
  221. ;;; Audio Issues:
  222. ;;; If no mic:
  223. ;;; $ pacmd list-cards
  224. ;;; then find the card name (the stuff between the <>)
  225. ;;; $ pacmd set-card-profile <name> handsfree_head_unit