summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--home-configuration.scm90
-rw-r--r--i3.conf5
2 files changed, 90 insertions, 5 deletions
diff --git a/home-configuration.scm b/home-configuration.scm
index 3d54e558..124dbf0f 100644
--- a/home-configuration.scm
+++ b/home-configuration.scm
@@ -263,14 +263,94 @@ replacement spec (to which `regexp-substitute/global' is applied)."
,(local-file #.(string-append "catppuccin/zathura/src/catppuccin-"
catppuccin-theme-variant)))))
- (service
- home-files-service-type
- `((".icons/default/index.theme" ,(local-file "cursors.ini"))
- ;; https://sw.kovidgoyal.net/kitty/kittens/diff/
+ (simple-service
+ 'scripts home-files-service-type
+ `(;; https://sw.kovidgoyal.net/kitty/kittens/diff/
(".local/bin/kdiff"
,(program-file "kdiff" #~(apply execl #$(package-binary "kitty") "kitty"
"+kitten" "diff" (cdr (command-line)))))
- ;; GnuPG config files must be in ~/.local/share/gnupg, not ~/.config,
+ (".local/bin/volume"
+ ,(program-file
+ "volume"
+ (with-imported-modules '((ice-9 format)
+ (ice-9 match)
+ (ice-9 popen)
+ (ice-9 regex)
+ (ice-9 textual-ports))
+ #~(begin
+ (use-modules (ice-9 format)
+ (ice-9 match)
+ (ice-9 popen)
+ (ice-9 regex)
+ (ice-9 textual-ports))
+
+ (define (read-from-process . command)
+ (let* ((port (apply open-pipe* OPEN_READ command))
+ (output (get-string-all port)))
+ (close-pipe port)
+ (string-trim-right output #\newline)))
+
+ (define %default-sink
+ (read-from-process #$(package-binary "pulseaudio" "pactl")
+ "get-default-sink"))
+
+ (define* (sink-muted? #:optional (sink %default-sink))
+ (match (read-from-process #$(package-binary "pulseaudio" "pactl")
+ "get-sink-mute" sink)
+ ("Mute: yes" #t)
+ ("Mute: no" #f)
+ (output (error "Unknown `pactl get-sink-mute' output" output))))
+
+ (define* (sink-volume #:optional (sink %default-sink))
+ (match-let ((`#(,match (,start . ,end))
+ (string-match "[0-9]+%" (read-from-process
+ #$(package-binary "pulseaudio" "pactl")
+ "get-sink-volume" sink))))
+ (string->number (substring match start (1- end))))) ; trim trailing "%"
+
+ (define* (set-sink-mute! #:optional (state "toggle") (sink %default-sink))
+ (status:exit-val
+ (system* #$(package-binary "pulseaudio" "pactl") "set-sink-mute" sink state)))
+
+ (define* (increment-sink-volume! increment-percent #:optional (sink %default-sink))
+ (status:exit-val
+ (system* #$(package-binary "pulseaudio" "pactl")
+ "set-sink-volume" sink
+ ;; A percentage with a sign is an increment.
+ (format #f "~@d%" increment-percent))))
+
+ (define* (notify #:optional (muted? (sink-muted?)) (volume (sink-volume)))
+ (status:exit-val
+ (system* "dunstify" "-a" "volume" "-u" "low"
+ "-i" (cond (muted? "audio-volume-muted")
+ ((< volume 50) "audio-volume-low")
+ (#t "audio-volume-high"))
+ "-h" "string:x-canonical-private-synchronous:volume"
+ "-h" (format #f "int:value:~d" (if muted? 0 volume))
+ (if muted? "Volume muted" "Volume"))))
+
+ (define (main)
+ (match (cdr (program-arguments))
+ (() 0) ; notify only
+ (("mute") (set-sink-mute! "true"))
+ (("unmute") (set-sink-mute! "false"))
+ (("toggle-mute") (set-sink-mute! "toggle"))
+ (((? string->number increment-percent))
+ (and (set-sink-mute! "false")
+ (increment-sink-volume!
+ (string->number increment-percent))))
+ (args (error "Could not parse command-line arguments:" args)))
+ (notify))
+
+ (main)))))))
+
+ (simple-service
+ 'gui-files home-files-service-type
+ `((".icons/default/index.theme" ,(local-file "cursors.ini"))))
+
+ (simple-service
+ 'terminal-files home-files-service-type
+ `(;; GnuPG config files must be in ~/.local/share/gnupg, not ~/.config,
;; so we can't use `home-xdg-configuration-files-service-type'.
(".local/share/gnupg/gpg.conf" ,(local-file "gpg.conf"))
(".local/share/gnupg/gpg-agent.conf"
diff --git a/i3.conf b/i3.conf
index fecbaa45..d78a51d2 100644
--- a/i3.conf
+++ b/i3.conf
@@ -54,6 +54,11 @@ bindsym $mod+slash exec kitty -o term=xterm-kitty -T ranger env "EDITOR=$ASYNC_E
bindsym $mod+semicolon exec --no-startup-id nheko
bindsym $mod+y exec kitty -T pulsemixer pulsemixer
+# volume
+bindsym XF86AudioRaiseVolume exec --no-startup-id volume +5
+bindsym XF86AudioLowerVolume exec --no-startup-id volume -5
+bindsym XF86AudioMute exec --no-startup-id volume toggle-mute
+
# notifications
bindsym $mod+n exec dunstctl close
bindsym $mod+shift+n exec dunstctl history-pop