1

Is there a way on linux (Ubuntu 20, Gnome) to detect changes in system's dark mode vs light mode and change emacs themes to a dark theme or light theme that I specify?

I see this question Change theme when OS dark mode changes? and several other resources on the internet which seem to work for MacOS only (there seems to be no ns-system-appearance-change-functions in my system when trying auto-complete with M-: as mentioned in the top answer)

1 Answer 1

1

As I don't use GNOME, I cannot say specifically with regards to that, but under KDE, it's pretty straight forward and presumably this can be adapted to GNOME with very few changes:

(when (and IS-LINUX ;; this is doom specific
           (featurep! :ui dbus)) ;; so is this
  ;; I should use a better name than `a`
  (defun theme--handle-dbus-event (a setting values)
    "Handler for FreeDesktop theme changes."
    (when (string= setting "ColorScheme")
      (let ((scheme (car values)))
        (cond
         ((string-match-p "Dark" scheme)
          (+theme-dark)) ;; my custom function that sets a dark theme
         ((string-match-p "Light" scheme)
          (+theme-light)) ;; 1000 internet points to whoever guesses what this does
         (t (message "I don't know how to handle scheme: %s" scheme))))))

  (require 'dbus)

  ;; since this is all FreeDesktop stuff, this *might* work on GNOME without changes
  (dbus-register-signal :session
                        "org.freedesktop.portal"
                        "/org/freedesktop/portal/desktop"
                        "org.freedesktop.impl.portal.Settings"
                        "SettingChanged"
                        #'theme--handle-dbus-event))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.