diff options
| author | Thomas Voss <mail@thomasvoss.com> | 2026-04-03 03:55:27 +0200 |
|---|---|---|
| committer | Thomas Voss <mail@thomasvoss.com> | 2026-04-03 03:55:27 +0200 |
| commit | dc6440c9c3775894303a75f64730345181bd1815 (patch) | |
| tree | a0322736bdd8c0c8af9f2065a22565d77aee2367 | |
| parent | 5641da7d5172c945402d019e4d3bbe815e4ed105 (diff) | |
emacs: Auto theme switching
| -rw-r--r-- | .config/emacs/early-init.el | 41 | ||||
| -rw-r--r-- | .config/emacs/init.el | 4 | ||||
| -rw-r--r-- | .config/emacs/modules/mm-theme.el | 31 |
3 files changed, 51 insertions, 25 deletions
diff --git a/.config/emacs/early-init.el b/.config/emacs/early-init.el index baac7ba..0fbff0f 100644 --- a/.config/emacs/early-init.el +++ b/.config/emacs/early-init.el @@ -90,19 +90,28 @@ file-name-handler-alist saved-file-name-handler-alist)))) -;;; Avoid Flashbang - -;; (setq-default mode-line-format nil) ; This will be set in init.el - -;; Colors taken from ‘mango-theme’ -(let ((background "#2B303B") - (foreground "#C5C8C6")) - (set-face-attribute - 'default nil - :background background - :foreground foreground) - (set-face-attribute - 'mode-line nil - :background background - :foreground foreground - :box 'unspecified)) +;;; Set Load Paths + +(dolist (directory '("." "modules" "site-lisp")) + (add-to-list 'load-path (expand-file-name directory mm-config-directory))) +(setopt custom-theme-directory (expand-file-name "themes" mm-config-directory)) + + +;;; Set Theme + +(defun mm-dark-p () + (cond + ((eq system-type 'gnu/linux) + (string-match-p + "prefer-dark" + (shell-command-to-string + "gsettings get org.gnome.desktop.interface color-scheme 2>/dev/null"))) + ((eq system-type 'darwin) + (if (boundp 'ns-system-appearance) + (eq ns-system-appearance 'dark) + (string-match-p + "Dark" + (shell-command-to-string + "defaults read -g AppleInterfaceStyle 2>/dev/null")))))) + +(load-theme (if (mm-dark-p) 'mango-dark 'mango-light) :no-confirm) diff --git a/.config/emacs/init.el b/.config/emacs/init.el index 6e85356..9a21ff1 100644 --- a/.config/emacs/init.el +++ b/.config/emacs/init.el @@ -10,10 +10,6 @@ (eval '(setq inhibit-startup-echo-area-message "thomasvoss")) (eval '(setq inhibit-startup-echo-area-message "thomas"))) -;; Add custom lisp code into the load path -(dolist (directory '("." "modules" "site-lisp")) - (add-to-list 'load-path (expand-file-name directory mm-config-directory))) - ;; Require helpers used by the rest of the config (require 'mm-lib) diff --git a/.config/emacs/modules/mm-theme.el b/.config/emacs/modules/mm-theme.el index 572064b..dc56012 100644 --- a/.config/emacs/modules/mm-theme.el +++ b/.config/emacs/modules/mm-theme.el @@ -1,10 +1,31 @@ ;;; mm-theme.el --- Emacs theme settings -*- lexical-binding: t; -*- - -;;; Themes - -(setopt custom-theme-directory (expand-file-name "themes" mm-config-directory)) -(load-theme 'mango-dark :no-confirm) +;;; Auto Theme Switching + +(defun mm-theme-switch-theme (darkp) + "Switch to a light or dark theme." + (mapc #'disable-theme custom-enabled-themes) + (load-theme (if darkp 'mango-dark 'mango-light) :no-confirm)) + +(defun mm-theme-dbus-theme-handler (namespace key value) + "Listen for Freedesktop color-scheme changes and switch themes." + (when (and (string= namespace "org.freedesktop.appearance") + (string= key "color-scheme")) + (let* ((value (car value)) + (darkp (eq value 1))) + (mm-theme-switch-theme darkp)))) + +(use-package dbus + :demand t + :config + (when (dbus-ping :session "org.freedesktop.portal.Desktop" 100) + (dbus-register-signal + :session + "org.freedesktop.portal.Desktop" + "/org/freedesktop/portal/desktop" + "org.freedesktop.portal.Settings" + "SettingChanged" + #'mm-theme-dbus-theme-handler))) ;;; Disable Cursor Blink |