add brightness script

This commit is contained in:
LordMZTE 2023-11-18 23:31:04 +01:00
parent 7879eb2f8d
commit c7a67aeb4c
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
2 changed files with 39 additions and 1 deletions

37
scripts/brightness.rkt Executable file
View file

@ -0,0 +1,37 @@
#!/usr/bin/env racket
#lang racket
(current-print void)
(define sysfs (make-parameter #t))
(define ddc (make-parameter #t))
(define brightness
(command-line #:program "brightness"
#:usage-help "Sets the backlight brightness of connected monitors"
#:once-each
[("-s" "--no-sysfs") "Don't set brightness via sysfs" (sysfs #f)]
[("-d" "--no-ddc") "Don't set brightness via DDC/CI" (ddc #f)]
#:args (brightness-arg)
(let ([brightness-parsed (string->number brightness-arg)])
(unless ((and/c (>=/c 0) (<=/c 100)) brightness-parsed)
(raise-user-error "brightness argument is invalid!"))
brightness-parsed)))
(when (sysfs)
(for ([dir (directory-list "/sys/class/backlight")])
(printf "sysfs: ~a\n" dir)
(let* ([max-brightness (string->number (file->string (build-path dir "max_brightness")))]
[rel-brightness (exact-round (* brightness (/ max-brightness 100)))]
[brightness-path (build-path dir "brightness")])
(display-to-file rel-brightness brightness-path #:exists 'truncate))))
(match* ((ddc) (find-executable-path "ddcutil"))
[(#f _) #f]
[(_ #f) #f]
[(_ ddcutil-exe)
(for ([dpy (regexp-match* #px"Display (\\d+)"
(car (process* ddcutil-exe "detect"))
#:match-select (λ (m) (string->number
(bytes->string/utf-8 (cadr m)))))])
(printf "ddc: #~a\n" dpy)
(system* ddcutil-exe "setvcp" "10" (format "--display=~a" dpy) (number->string brightness)))])

View file

@ -9,6 +9,7 @@
(generate-cgopt-json)
;; Symlink interpreted scripts
(install-link "scripts/brightness.rkt" (bin-path "brightness"))
(install-link "scripts/map-touch-display.rkt" (bin-path "map-touch-display"))
(install-link "scripts/startriver.sh" (bin-path "startriver"))
(install-link "scripts/sysupdate.rkt" (bin-path "sysupdate"))
@ -16,7 +17,7 @@
(install-link "scripts/use-country-mirrors.sh" (bin-path "use-country-mirrors"))
(install-link "scripts/videos-duration.sh" (bin-path "videos-duration"))
;; Compile scripts
;; Compiled scripts
(install-zig "scripts/alecor")
(install-zig "scripts/hyprtool")
(install-rust "scripts/i3status")