diff options
author | Raul Benencia <id@rbenencia.name> | 2022-06-05 08:26:26 -0700 |
---|---|---|
committer | Raul Benencia <id@rbenencia.name> | 2022-06-05 08:26:26 -0700 |
commit | 8c5138f425572ccd1053e5b8be44c69e32c6e26e (patch) | |
tree | 7b98dd7fb9277b61f3da4663c3b4f07f1947b088 /.emacs.local.d | |
parent | 0ef9506b4d6f44d1cc3bb88a862e8945ccca1ea2 (diff) |
emacs: dark/light mode with dbus support
Diffstat (limited to '.emacs.local.d')
-rw-r--r-- | .emacs.local.d/modes/themes.el | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/.emacs.local.d/modes/themes.el b/.emacs.local.d/modes/themes.el index a8e7787..f9077b7 100644 --- a/.emacs.local.d/modes/themes.el +++ b/.emacs.local.d/modes/themes.el @@ -1 +1,33 @@ -(load-theme 'doom-sourcerer t) +(use-package dbus) +(defun mf/set-theme-from-dbus-value (value) + "Set the appropiate theme according to the color-scheme setting value." + (message "value is %s" value) + (if (equal value '1) + (progn (message "Switch to dark theme") + (modus-themes-load-vivendi)) + (progn (message "Switch to light theme") + (modus-themes-load-operandi)))) + +(defun mf/color-scheme-changed (path var value) + "DBus handler to detect when the color-scheme has changed." + (when (and (string-equal path "org.freedesktop.appearance") + (string-equal var "color-scheme")) + (mf/set-theme-from-dbus-value (car value)) + )) + +;; Register for future changes +(dbus-register-signal + :session "org.freedesktop.portal.Desktop" + "/org/freedesktop/portal/desktop" "org.freedesktop.portal.Settings" + "SettingChanged" + #'mf/color-scheme-changed) + +;; Request the current color-scheme +(dbus-call-method-asynchronously + :session "org.freedesktop.portal.Desktop" + "/org/freedesktop/portal/desktop" "org.freedesktop.portal.Settings" + "Read" + (lambda (value) (mf/set-theme-from-dbus-value (caar value))) + "org.freedesktop.appearance" + "color-scheme" + ) |