LionyxML / auto-dark-emacs

Auto-Dark-Emacs is an auto changer between 2 themes, dark/light, following MacOS, Linux or Windows Dark Mode settings
GNU General Public License v2.0
140 stars 34 forks source link

Linux dark mode requires specific theme #19

Closed ProjectMoon closed 1 year ago

ProjectMoon commented 1 year ago

This is a copy and paste of my Reddit comment.

Unless I'm missing something, this only works if you have the Yaru-dark theme installed and in use. This isn't a standard GNOME theme (usually it is Adwaita).

It would make more sense to provide configurable variables for the light/dark GTK theme names. Or better yet, make use of the /org/gnome/desktop/interface/color-scheme dconf setting. This is the new Gnome standard way of doing dark mode. When it's light, it's default, and when it's dark, it's prefer-dark. I think it's available from Gnome 42 onwards.

Edit: The \n should be removed from the check as well, because string-trim gets rid of it, and thus the equality check fails when \n is there.

ProjectMoon commented 1 year ago

Based on another comment in the same Reddit thread, it is probably best to utilize dbus to expose a similar hook system like on Mac OS: https://git.sr.ht/%7Edsemy/emacs-config/tree/master/item/init.d/init-interfaces.el#L44

manueldeljesus commented 1 year ago

I can confirm that auto-dark-mode does not work on Fedora with customized themes. Most probably for the reasons explained above. I look forward to test new versions of the package with updated functionality.

real-or-random commented 1 year ago

Based on another comment in the same Reddit thread, it is probably best to utilize dbus to expose a similar hook system like on Mac OS: git.sr.ht/%7Edsemy/emacs-config/tree/master/item/init.d/init-interfaces.el#L44

I can confirm that the dbus code works well (GNOME 43.1 with custom theme), and this seems much better than a polling solution.

Full snippet for spacemacs users ```elisp (defvar init-interfaces-dbus-color-scheme-change-functions nil "Special hook run when a color scheme change is detected through D-Bus. Each function in this hook is called with a single argument, `light' or `dark', according to the current color scheme.") (add-hook 'init-interfaces-dbus-color-scheme-change-functions (lambda (mode) (if (eq mode 'dark) (spacemacs/load-theme 'solarized-dark nil t) (spacemacs/load-theme 'solarized-light nil t)))) (when-let (((require 'dbus nil t)) (service (car (member "org.freedesktop.portal.Desktop" (dbus-list-activatable-names :session))))) (dbus-register-signal :session service "/org/freedesktop/portal/desktop" "org.freedesktop.portal.Settings" "SettingChanged" (lambda (path var val) (and (string= path "org.freedesktop.appearance") (string= var "color-scheme") (run-hook-with-args 'init-interfaces-dbus-color-scheme-change-functions (pcase (car val) (0 'light) (1 'dark)))))) (run-hook-with-args 'init-interfaces-dbus-color-scheme-change-functions (pcase (caar (dbus-call-method :session service "/org/freedesktop/portal/desktop" "org.freedesktop.portal.Settings" "Read" "org.freedesktop.appearance" "color-scheme")) (0 'light) (1 'dark)))) ```
LionyxML commented 1 year ago

Hello there! Sorry I've been out for a while. Personal stuff :(

I agree with you guys that a solution base on d-bus integration might be a better approach for Linux users.

Anyone willing to tweak the code and open a PR? I might do it myself in the future, but currently I don't even have Linux installed here around.

ProjectMoon commented 1 year ago

After having used the dbus snippet in my own emacs config for a while, the main thing it needs is to test light/dark mode on Emacs startup. Otherwise, it's only responding to events and you may end up with the wrong theme when starting a new instance of Emacs.

real-or-random commented 1 year ago

The above snippet for spacemacs handles the setting at startup via run-hook-with-args. (By the way, I think the only spacemacs-specific thing here is spacemacs/load-theme.)

ProjectMoon commented 1 year ago

Hmm, you are right. Somehow I had the hook defined after the rest of the code, and it didn't run on startup. But after putting the hook definition above, it works.

LionyxML commented 1 year ago

Hello there good people! :)

@J3RN's PR #20 has been merged and is already available on MELPA.

auto-dark now uses D-Bus as default theme checker for GNU/Linux.

manueldeljesus commented 1 year ago

It does not seem to set the correct theme on startup. Is there need still to configure a hook to make the initial check?

real-or-random commented 1 year ago

It does not seem to set the correct theme on startup. Is there need still to configure a hook to make the initial check?

Are you on spacemacs by any chance? I'm on spacemacs and I just figured out that I need to replace the load-theme with spacemacs/load-theme in auto-dark--set-theme to make this work on startup...

I'm not sure how to approach this issue properly, to be honest. Maybe there should be a possibility to tell spacemacs to just get out of the way with their theme logic. Setting dotspacemacs-themes to nil doesn't achieve this.

manueldeljesus commented 1 year ago

I am on Doom Emacs, but I imagine that something similar to what you mention may be happening. I will investigate the issue a bit, and will revise also how circadian solves it, since circadian is working flawlessly -although I must set a fixed time for the change-.

Thanks your help. Wish me luck! 🤓

manueldeljesus commented 1 year ago

Auto-dark works if, after opening Emacs, I disable it manually and re-enable it manually. At that point it loads the correct theme. May anyone please share how are you configuring it on your config file? I may be doing something wrong there and thus the problem on opening.

LionyxML commented 1 year ago

Hello there!

I really think these feedbacks are great! But doing so from this "closed" issue may not get to all people involved.

I just opened the issue #25

May we migrate this to there?