Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add full support for freedesktop Dark Mode specification #36

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

raghavdhingra24
Copy link
Contributor

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)

Copy link

@axoroll7 axoroll7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the print line ? It should be removed ?

Sorry, I didn't see the others commits.

@axoroll7
Copy link

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

@raghavdhingra24
Copy link
Contributor Author

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

Removed some pass statements and added listener support while removing old one as it supports the old method also.
@raghavdhingra24
Copy link
Contributor Author

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
Copy link

maharvey commented Nov 3, 2023

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
Copy link
Contributor Author

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
Copy link

maharvey commented Nov 7, 2023

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
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants