albertosottile / darkdetect

Detect OS Dark Mode from Python
Other
178 stars 18 forks source link

Add full support for freedesktop Dark Mode specification #36

Open raghavdhingra24 opened 1 year ago

raghavdhingra24 commented 1 year ago

Hi there, I have added full support for the freedesktop specifications as suggested by JackobDev in this post https://github.com/albertosottile/darkdetect/pull/34#issuecomment-1359455980 except it uses the dbus-send command. I have also removed the older version of the code for detecting dark mode using freedesktop specifications as it was interfering with theme detection on some DEs. This code has been tested on the following distros and DEs:

Gnome 43 (Ubuntu 22.10) ======= Working
Gnome 3.38 (Ubuntu 20.04) ===== Working (Fallback to older methods)
KDE 5.26 (Kubuntu 22.10) ====== Working
XFCE 4.16 (Fedora 37) ========= Working (Fallback to older methods)
Cinnamon 5.6.5(Linux Mint) ==== Works but buggy (default themes not having -dark in names)
axoroll7 commented 1 year ago

It is great. Do you plan to add the listener too ? I would love to see this module working with KDE.

raghavdhingra24 commented 1 year ago

Yes, I plan to implement listener as well. Would do this whenever I get some time to work on it.

raghavdhingra24 commented 1 year ago

Listener support:

Gnome 44 (Ubuntu 23.04) ============ Works
Gnome 42 (Ubuntu 22.04) ============ Works
Gnome 3.36 (Ubuntu 20.04) ========== Works
Linux Mint 21.0 ==================== Does not work with both - old and new listeners
Plasma 5.27 (Kubuntu 23.04) ======== Works
XFCE 4.18 (Fedora 38) ============== Works
maharvey commented 11 months ago

dbus is not working on XFCE 4.18.1 on Manjaro. I am getting:

$ dbus-send --session --print-reply=literal --dest=org.freedesktop.portal.Desktop /org/freedesktop/portal/desktop org.freedesktop.portal.Settings.Read string:org.freedesktop.appearance string:color-scheme

Error org.freedesktop.DBus.Error.UnknownMethod: No such interface “org.freedesktop.portal.Settings” on object at path /org/freedesktop/portal/desktop

theme() is swallowing the dbus error and falling back to gsettings (which works for gnome but not XFCE).

raghavdhingra24 commented 11 months ago

dbus is not working on XFCE 4.18.1 on Manjaro. I am getting:

$ dbus-send --session --print-reply=literal --dest=org.freedesktop.portal.Desktop /org/freedesktop/portal/desktop org.freedesktop.portal.Settings.Read string:org.freedesktop.appearance string:color-scheme

Error org.freedesktop.DBus.Error.UnknownMethod: No such interface “org.freedesktop.portal.Settings” on object at path /org/freedesktop/portal/desktop

theme() is swallowing the dbus error and falling back to gsettings (which works for gnome but not XFCE).

I have added fallback to gsettings in listener if dbus key is not available and would try to check why it is not working in Manjaro XFCE.

maharvey commented 11 months ago

The thing with XFCE is that it uses xfconf-query, but xfce4-settings-manager does not set gsettings. The two configuration are entirely separate, and most XFCE users probably won't realize this; I've been using it 5 years and it wasn't until darkdetect didn't work for me and I dug into the source code that I figured this out.

I made myself a script to keep the XFCE and GTK settings in sync, and that allows darkdetect to work (and also triggers various GTK applications properly). Interestingly they use the same desktop and icon themes. Here is an excerpt from my script showing how they correspond:

# set dark theme
xfconf-query -c xsettings -p /Net/ThemeName -s $dark_desk_theme
xfconf-query -c xsettings -p /Net/IconThemeName -s $dark_icon_theme
xfconf-query -c xfce4-panel -p /panels/dark-mode -s true
gsettings set org.gnome.desktop.interface gtk-theme $dark_desk_theme
gsettings set org.gnome.desktop.interface icon-theme $dark_icon_theme
gsettings set org.gnome.desktop.interface color-scheme prefer-dark

I created a PR to support xfconf-query, before I saw this PR. If you want to roll the xfconf-query functionality into your PR I'd be happy to cancel mine. (I know I should have checked, but this is my first time trying to contribute to an open source github project and still finding my way around.)

It would probably be good to fix xfce-settings-manager too, but I haven't looked into that yet, I was just trying to support dark mode on a python project.

raghavdhingra24 commented 11 months ago

My concern here was that this code was properly working in Fedora 38 (XFCE 4.18) but not in Manjaro XFCE as in your case (Probably Fedora applied some patches). Since this PR is about adding Freedesktop standard support, adding XFCE support using xfconf-query would be out of scope of this PR. Your PR looks great for xfce support, no need to cancel it.