diff options
author | jdlugosz963 <jdlugosz963@gmail.com> | 2023-10-19 20:46:52 +0200 |
---|---|---|
committer | jdlugosz963 <jdlugosz963@gmail.com> | 2023-10-19 20:46:52 +0200 |
commit | d2506288ca7a8beb1767cd0abc787ad35d8bc2af (patch) | |
tree | 41fd62282e38c38ce479e86d11ee13b869ef744a /.stumpwm.d/init.lisp | |
parent | c6c985d1188830ac90a546cfa27a77c220c9d096 (diff) | |
download | dotfiles-d2506288ca7a8beb1767cd0abc787ad35d8bc2af.tar.gz dotfiles-d2506288ca7a8beb1767cd0abc787ad35d8bc2af.zip |
Add stumpwm init.lisp.
Diffstat (limited to '.stumpwm.d/init.lisp')
-rwxr-xr-x | .stumpwm.d/init.lisp | 243 |
1 files changed, 243 insertions, 0 deletions
diff --git a/.stumpwm.d/init.lisp b/.stumpwm.d/init.lisp new file mode 100755 index 0000000..bde84fd --- /dev/null +++ b/.stumpwm.d/init.lisp | |||
@@ -0,0 +1,243 @@ | |||
1 | (in-package :stumpwm) | ||
2 | |||
3 | |||
4 | (setq *message-window-gravity* :center) | ||
5 | (setq *message-window-input-gravity* :center) | ||
6 | (setq *input-window-gravity* :center) | ||
7 | (setq *window-border-style* :none) | ||
8 | |||
9 | (set-bg-color :gray10) | ||
10 | (setq *mode-line-background-color* "Gray10") | ||
11 | |||
12 | (set-prefix-key (kbd "C-z")) | ||
13 | (setq *float-window-modifier* :super) | ||
14 | |||
15 | (define-key *top-map* (kbd "s-w") "gselect") | ||
16 | |||
17 | (defcommand lock () () | ||
18 | (run-shell-command "slock")) | ||
19 | |||
20 | (define-key *top-map* (kbd "s-l") "lock") | ||
21 | |||
22 | (defcommand server-start () () | ||
23 | (slynk:create-server :port 4005) | ||
24 | (message "server started at port: \"4005\"!")) | ||
25 | |||
26 | |||
27 | (define-key *root-map* (kbd "C-q") "send-raw-key") | ||
28 | |||
29 | (define-key *root-map* (kbd "M") "mode-line") | ||
30 | |||
31 | ;; (run-commands "gnew Code" | ||
32 | ;; "gnew Web" | ||
33 | ;; "gnew Music" | ||
34 | ;; "gnew Game" | ||
35 | ;; "gnew School") | ||
36 | |||
37 | (define-remapped-keys | ||
38 | '(("(Firefox|Chrome|qutebrowser)" | ||
39 | ("C-n" . "Down") | ||
40 | ("C-p" . "Up") | ||
41 | ("C-f" . "Right") | ||
42 | ("C-b" . "Left") | ||
43 | ("C-v" . "Next") | ||
44 | ("M-v" . "Prior") | ||
45 | ("M-w" . "C-c") | ||
46 | ("C-w" . "C-x") | ||
47 | ("C-y" . "C-v") | ||
48 | ("M-<" . "Home") | ||
49 | ("M->" . "End") | ||
50 | ("C-a" . "Home") | ||
51 | ("C-e" . "End") | ||
52 | ("C-M-b" . "M-Left") | ||
53 | ("C-M-f" . "M-Right") | ||
54 | ("C-g" . "ESC") | ||
55 | ("C-k" . ("C-S-End" "C-x"))))) | ||
56 | |||
57 | (defcommand emacsclient () () | ||
58 | "Start emacs unless it is already running, in which case focus it." | ||
59 | (run-or-raise "emacsclient -c" '(:class "Emacs"))) | ||
60 | |||
61 | |||
62 | (run-shell-command "~/.fehbg") | ||
63 | |||
64 | (require :pamixer) | ||
65 | (require :pass) | ||
66 | |||
67 | (require :screenshot) | ||
68 | (pamixer:volume-down 10) | ||
69 | |||
70 | (defun get-brightness () | ||
71 | (let ((c (parse-integer (string-trim | ||
72 | (string #\newline) | ||
73 | (run-shell-command "brightnessctl g" t)))) | ||
74 | (m (parse-integer (string-trim | ||
75 | (string #\newline) | ||
76 | (run-shell-command "brightnessctl m" t))))) | ||
77 | (format nil "~3,1f%" (* (/ c m) 100)))) | ||
78 | |||
79 | (defun set-brightness (x) | ||
80 | (run-shell-command (concat "brightnessctl s " x)) | ||
81 | (message (concat "Brightness: " (get-brightness)))) | ||
82 | |||
83 | (defcommand my-volume-down () () | ||
84 | (pamixer:volume-down 5) | ||
85 | (message (format nil "Volume: ~s%" (pamixer:get-volume)))) | ||
86 | |||
87 | (defcommand my-volume-up () () | ||
88 | (pamixer:volume-up 5) | ||
89 | (message (format nil "Volume: ~s%" (pamixer:get-volume)))) | ||
90 | |||
91 | (defcommand my-toggle-mute () () | ||
92 | (pamixer:toggle-mute) | ||
93 | (if (pamixer:get-mute) | ||
94 | (message "Mute: ^2ON") | ||
95 | (message "Mute: ^1OFF"))) | ||
96 | |||
97 | (defcommand my-brightness-up () () | ||
98 | (set-brightness "+5%")) | ||
99 | |||
100 | (defcommand my-brightness-down () () | ||
101 | (set-brightness "5%-")) | ||
102 | |||
103 | (defcommand my-brightness-one () () | ||
104 | (set-brightness "1")) | ||
105 | |||
106 | |||
107 | (define-key *top-map* (kbd "XF86AudioMute") "my-toggle-mute") | ||
108 | (define-key *top-map* (kbd "XF86AudioRaiseVolume") "my-volume-up") | ||
109 | (define-key *top-map* (kbd "XF86AudioLowerVolume") "my-volume-down") | ||
110 | |||
111 | (define-key *top-map* (kbd "XF86MonBrightnessUp") "my-brightness-up") | ||
112 | (define-key *top-map* (kbd "XF86MonBrightnessDown") "my-brightness-down") | ||
113 | |||
114 | (defun my-screenshoot-command-wrapper (screenshot-command ss-name) | ||
115 | (apply screenshot-command (list (concat | ||
116 | "~/Pictures/Screenshots/" | ||
117 | (string-trim | ||
118 | (string #\newline) | ||
119 | (run-shell-command "date +%Y-%M-%d-%T" t)) | ||
120 | "-" (or ss-name "untitled") | ||
121 | ".png")))) | ||
122 | |||
123 | |||
124 | (defcommand my-screenshot-area (ss-name) | ||
125 | ((:string "Screenshot name: ")) | ||
126 | (my-screenshoot-command-wrapper #'screenshot:screenshot-area ss-name)) | ||
127 | |||
128 | (defcommand my-screenshot-window (ss-name) | ||
129 | ((:string "Screenshot name: ")) | ||
130 | (my-screenshoot-command-wrapper #'screenshot:screenshot-window ss-name)) | ||
131 | |||
132 | (defcommand my-screenshot (ss-name) | ||
133 | ((:string "Screenshot name: ")) | ||
134 | (my-screenshoot-command-wrapper #'screenshot:screenshot ss-name)) | ||
135 | |||
136 | (defvar *misc-keymap* | ||
137 | (let ((m (make-sparse-keymap))) | ||
138 | (define-key m (kbd "0") "my-toggle-mute") | ||
139 | (define-key m (kbd "+") "my-volume-up") | ||
140 | (define-key m (kbd "=") "my-volume-up") | ||
141 | (define-key m (kbd "-") "my-volume-down") | ||
142 | |||
143 | (define-key m (kbd "p") "pass-copy-menu") | ||
144 | (define-key m (kbd "C-p") "pass-copy-menu") | ||
145 | (define-key m (kbd "g") "pass-generate") | ||
146 | (define-key m (kbd "C-g") "pass-generate") | ||
147 | |||
148 | (define-key m (kbd "C-a") "my-screenshot-area") | ||
149 | (define-key m (kbd "a") "my-screenshot-area") | ||
150 | (define-key m (kbd "C-w") "my-screenshot-window") | ||
151 | (define-key m (kbd "w") "my-screenshot-window") | ||
152 | (define-key m (kbd "C-s") "my-screenshot") | ||
153 | (define-key m (kbd "s") "my-screenshot") | ||
154 | |||
155 | m)) | ||
156 | |||
157 | |||
158 | |||
159 | |||
160 | (define-key *root-map* (kbd "C-m") '*misc-keymap*) | ||
161 | |||
162 | ;; | ||
163 | ;; ;;; MODE-LINE | ||
164 | (require :cpu) | ||
165 | (require :mem) | ||
166 | (require :net) | ||
167 | |||
168 | (require :stumptray) | ||
169 | (stumptray:add-mode-line-hooks) | ||
170 | |||
171 | (defun update-stumptray-position (&rest args) | ||
172 | (setf (symbol-value (find-symbol "*TRAY-HEAD-SELECTION-FN*" :stumptray)) | ||
173 | (if (>= (list-length (stumpwm:screen-heads (stumpwm:current-screen))) 2) | ||
174 | #'second | ||
175 | #'first))) | ||
176 | |||
177 | (stumpwm:add-hook stumpwm:*new-head-hook* 'update-stumptray-position) | ||
178 | (update-stumptray-position) | ||
179 | |||
180 | (defun get-battery-status () | ||
181 | (let* ((state (string-trim | ||
182 | (string #\newline) | ||
183 | (run-shell-command | ||
184 | (concat "upower -i /org/freedesktop/UPower/devices/battery_BAT0 " | ||
185 | "| grep state: " | ||
186 | "| awk '{print $2}'") | ||
187 | t))) | ||
188 | (perc (string-trim | ||
189 | (string #\newline) | ||
190 | (run-shell-command (concat | ||
191 | "upower -i /org/freedesktop/UPower/devices/battery_BAT0 " | ||
192 | "| grep perc " | ||
193 | "| awk '{print $2}'") | ||
194 | t))) | ||
195 | (perc-num (parse-integer (aref (nth-value 1 (cl-ppcre:scan-to-strings "^(.*)\%$" perc)) 0)))) | ||
196 | (format | ||
197 | nil | ||
198 | (concat | ||
199 | "BAT: " | ||
200 | (cond | ||
201 | ((and (equal state "discharging") | ||
202 | (<= perc-num 20)) | ||
203 | "^1[-~a]^]") | ||
204 | ((equal state "discharging") "[-~a]") | ||
205 | ((equal state "charging") "[+~a]") | ||
206 | ((equal state "fully-charged") "[~a]") | ||
207 | (t (concat state " [~a]")))) | ||
208 | perc))) | ||
209 | |||
210 | |||
211 | |||
212 | (setq *screen-mode-line-format* (list "[^B%n^b] %W ^> %C | %M | %l | " | ||
213 | '(:eval (get-battery-status)) | ||
214 | " " ;; empty space for stumptray icons | ||
215 | )) | ||
216 | |||
217 | (require :yason) ;; json parser | ||
218 | (require :drakma) ;; http client | ||
219 | |||
220 | |||
221 | (defcommand kto-hakuje-p () () | ||
222 | (let* ((response (yason:parse | ||
223 | (flexi-streams:octets-to-string | ||
224 | (drakma:http-request "https://whois.at.hsp.sh/api/now")))) | ||
225 | (users (gethash "users" response)) | ||
226 | (unknown-devices (gethash "unknown_devices" response))) | ||
227 | (message (cond | ||
228 | ((and (= (list-length users) 0) | ||
229 | (= unknown-devices 0)) | ||
230 | "Spejs jest pusty!") | ||
231 | ((and (= (list-length users) 0) | ||
232 | (> unknown-devices 0)) | ||
233 | (format nil "W spejsie jest nieznanych ~a urzadzen." unknown-devices)) | ||
234 | ((and (> (list-length users) 0) | ||
235 | (= unknown-devices 0)) | ||
236 | (format nil "W spejsie jest ~a." users)) | ||
237 | ((and (> (list-length users) 0) | ||
238 | (> unknown-devices 0)) | ||
239 | (format nil "W spejsie jest ~a oraz ~a nieznane urzadzenia." users unknown-devices)))))) | ||
240 | |||
241 | |||
242 | (define-key *misc-keymap* (kbd "h") "kto-hakuje-p") | ||
243 | (define-key *misc-keymap* (kbd "C-h") "kto-hakuje-p") | ||