Skip to content

Instantly share code, notes, and snippets.

@dieggsy
Created September 8, 2017 12:35
Show Gist options
  • Save dieggsy/a150c60c56f471464703e4a8a925bc0c to your computer and use it in GitHub Desktop.
Save dieggsy/a150c60c56f471464703e4a8a925bc0c to your computer and use it in GitHub Desktop.
#!/usr/local/bin/csi -s
(use dbus)
(: main (-> string))
(define (main)
(let* ((kb-light (make-context
#:bus system-bus
#:service 'org.freedesktop.UPower
#:interface 'org.freedesktop.UPower.KbdBacklight
#:path '/org/freedesktop/UPower/KbdBacklight))
(argv (command-line-arguments))
(up-down (when (not (null? argv)) (car argv)))
(delta (cond ((equal? up-down "+") 17)
((equal? up-down "-") -17)
(else 0)))
(current (car (call kb-light "GetBrightness")))
(maximum (car (call kb-light "GetMaxBrightness")))
(new (max 0 (+ current delta))))
(when (<= 0 new maximum)
(call kb-light "SetBrightness" new))
(format #t "~s~%" (inexact->exact
(round (* 100 (/ new maximum)))))))
(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment