mirror of
https://github.com/stumpwm/stumpwm-contrib.git
synced 2026-09-10 07:26:25 -04:00
Fixed some minor bugs in backlight and added ability to use CLI utils
This commit is contained in:
parent
f5af33375a
commit
36daccd715
|
|
@ -1,31 +1,50 @@
|
|||
(in-package #:stump-backlight)
|
||||
|
||||
|
||||
(defvar *scale* 10
|
||||
"The backlight scale. Increase if you want more granularity.")
|
||||
|
||||
(defvar *default-percent* 50
|
||||
"Default value for an output's percentage.")
|
||||
|
||||
(defvar *use-clx-randr* t
|
||||
"Use CLX's randr extension. If not, call shell command set by `*cli-format-str*'")
|
||||
|
||||
(defvar *cli-format-str* "brightnessctl s ~a%"
|
||||
"Format string that when passed an output percentage, sets the brightness.")
|
||||
|
||||
(defvar *current-percent* (make-hash-table)
|
||||
"CLX does not let us query the existing backlight, so we need to keep track of
|
||||
it manually.")
|
||||
|
||||
;; This just returns a random slot to hold in the hash table... It
|
||||
;; doesn't return the actual output percentage.
|
||||
(defun current-output ()
|
||||
(xlib:rr-get-output-primary (stumpwm:window-xwin (stumpwm:current-window))))
|
||||
(xlib:rr-get-output-primary (stumpwm:screen-root (stumpwm:current-screen))))
|
||||
|
||||
|
||||
(defun cli-update (output)
|
||||
(stumpwm:dformat 5 (format nil *cli-format-str* output))
|
||||
(stumpwm:run-shell-command (format nil *cli-format-str* output)))
|
||||
|
||||
(stumpwm:defcommand backlight-increase () ()
|
||||
(let* ((output (current-output))
|
||||
(current-percent (or (gethash output *current-percent*) *default-percent*)))
|
||||
(when (< current-percent 100)
|
||||
(setf (gethash output *current-percent*) (* (1+ (/ current-percent *scale*)) *scale*))
|
||||
(update output))))
|
||||
(if *use-clx-randr*
|
||||
(update output)
|
||||
(cli-update (gethash output *current-percent*))))))
|
||||
|
||||
(stumpwm:defcommand backlight-decrease () ()
|
||||
(let* ((output (current-output))
|
||||
(current-percent (or (gethash output *current-percent*) *default-percent*)))
|
||||
(when (> current-percent 0)
|
||||
(setf (gethash output *current-percent*) (* (1- (/ current-percent *scale*)) *scale*))
|
||||
(update output))))
|
||||
(if *use-clx-randr*
|
||||
(update output)
|
||||
(cli-update (gethash output *current-percent*))))))
|
||||
|
||||
|
||||
(defun update (output)
|
||||
(let ((backlight-limits
|
||||
|
|
|
|||
Loading…
Reference in a new issue