Verified Commit 564a0f4e authored by pbeliveau's avatar pbeliveau Committed by Damien Cassou

Change keyboard backlight. Uses the Emacs API for D-Bus.

parent a97e8b4b
Pipeline #1696 passed with stage
in 30 seconds
......@@ -75,6 +75,7 @@ be available on your system:
- Brightness: [[https://github.com/Hummer12007/brightnessctl][brightnessctl]]
- Screenshot: [[https://tracker.debian.org/pkg/scrot][scrot]]
- Screenlock: [[https://tools.suckless.org/slock/][slock]]
- Keyboard backlight: [[https://upower.freedesktop.org/][upower]]
** License
......
......@@ -36,11 +36,23 @@
;;; Code:
(require 'dbus)
(defgroup desktop-environment nil
"Configure desktop-environment."
:group 'environment)
;;; Customization - keyboard backlight
(defcustom desktop-environment-keyboard-backlight-normal-increment 1
"Normal keyboard increment value."
:type 'integer)
(defcustom desktop-environment-keyboard-backlight-normal-decrement -1
"Normal keyboard decrement value."
:type 'integer)
;;; Customization - brightness
(defcustom desktop-environment-brightness-normal-increment "10%+"
......@@ -182,6 +194,44 @@ portion of the screen."
(message "New volume value: %s" (desktop-environment-volume-get)))
;;; Helper functions - keyboard backlight
(defun desktop-environment-keyboard-backlight-percent ()
"Return the new keyboard backlight value as a % of maximum backlight."
(let ((backlight-level (desktop-environment-keyboard-backlight-get)))
(if (eq backlight-level 0)
"0.0"
(*
(/ (* backlight-level 1.0)
(* (desktop-environment-keyboard-backlight-get-max) 1.0))
100))))
(defun desktop-environment-keyboard-backlight-get ()
"Return a number representing keyboard backlight current level."
(dbus-call-method :system
"org.freedesktop.UPower"
"/org/freedesktop/UPower/KbdBacklight"
"org.freedesktop.UPower.KbdBacklight"
"GetBrightness"))
(defun desktop-environment-keyboard-backlight-get-max ()
"Return a number representing keyboard backlight maximum level."
(dbus-call-method :system
"org.freedesktop.UPower"
"/org/freedesktop/UPower/KbdBacklight"
"org.freedesktop.UPower.KbdBacklight"
"GetMaxBrightness"))
(defun desktop-environment-keyboard-backlight-set (value)
"Set keyboard backlight to VALUE."
(dbus-call-method :system
"org.freedesktop.UPower"
"/org/freedesktop/UPower/KbdBacklight"
"org.freedesktop.UPower.KbdBacklight"
"SetBrightness"
:int32 value)
(message "New keyboard value: %s%%" (desktop-environment-keyboard-backlight-percent)))
;;; Commands - brightness
;;;###autoload
......@@ -250,6 +300,23 @@ portion of the screen."
(shell-command-to-string desktop-environment-volume-toggle-microphone-command)))
;;; Commands - keyboard backlight
;;;###autoload
(defun desktop-environment-keyboard-backlight-increment ()
"Increment keyboard backlight by `desktop-environment-keyboard-backlight-normal-increment'."
(interactive)
(desktop-environment-keyboard-backlight-set
(+ desktop-environment-keyboard-backlight-normal-increment
(desktop-environment-keyboard-backlight-get))))
(defun desktop-environment-keyboard-backlight-decrement ()
"Decrement keyboard backlight by `desktop-environment-keyboard-backlight-normal-decrement'."
(interactive)
(desktop-environment-keyboard-backlight-set
(+ desktop-environment-keyboard-backlight-normal-decrement
(desktop-environment-keyboard-backlight-get))))
;;; Commands - screenshots
;;;###autoload
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment