Browse Source

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

tags/v0.2.1
pbeliveau 11 months ago
parent
commit
564a0f4e8a
Signed by: Damien Cassou <damien@cassou.me> GPG Key ID: B68746238E59B548
2 changed files with 68 additions and 0 deletions
  1. +1
    -0
      README.org
  2. +67
    -0
      desktop-environment.el

+ 1
- 0
README.org View File

@@ -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


+ 67
- 0
desktop-environment.el View File

@@ -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

Loading…
Cancel
Save