diff options
Diffstat (limited to 'home-configuration.scm')
-rw-r--r-- | home-configuration.scm | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/home-configuration.scm b/home-configuration.scm index 521b5794..0bae52aa 100644 --- a/home-configuration.scm +++ b/home-configuration.scm @@ -294,28 +294,25 @@ replacement spec (to which `regexp-substitute/global' is applied)." (ice-9 regex) (ice-9 textual-ports)) - (define (read-from-process . command) - (let* ((port (apply open-pipe* OPEN_READ command)) + (define (read-from-pactl . args) + (let* ((port (apply open-pipe* OPEN_READ + #$(package-binary "pulseaudio" "pactl") args)) (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")) + (read-from-pactl "get-default-sink")) (define* (sink-muted? #:optional (sink %default-sink)) - (match (read-from-process #$(package-binary "pulseaudio" "pactl") - "get-sink-mute" sink) + (match (read-from-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-match "[0-9]+%" (read-from-pactl "get-sink-volume" sink)))) (string->number (substring match start (1- end))))) ; trim trailing "%" (define* (set-sink-mute! #:optional (state "toggle") (sink %default-sink)) @@ -339,20 +336,17 @@ replacement spec (to which `regexp-substitute/global' is applied)." "-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))))))) + (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))))))) (simple-service 'gui-files home-files-service-type |