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

Linux: Use desktop portals to get dark theme information #1381

Closed
badcel opened this issue Aug 16, 2024 · 2 comments · Fixed by #1382
Closed

Linux: Use desktop portals to get dark theme information #1381

badcel opened this issue Aug 16, 2024 · 2 comments · Fixed by #1382

Comments

@badcel
Copy link
Contributor

badcel commented Aug 16, 2024

If I might chime in on this issue:
I noticed you changed the code to check the GTK theme name in order to check for dark mode.
This is not an ideal way to check it. In fact, on a modern Gnome Desktop, it doesn't detect dark mode at all:

Bildschirmfoto vom 2024-08-16 09-11-12

To give a few details:
While setting dark mode with the GTK theme name was a popular workaround when there was no proper standard, it still has it flaws. For example, GTK_THEME is regarded for use in debugging, not to set a dark theme. And some frameworks, like libadwaita, even ignore it entirely. Which is also why Gnome is not setting the GTK theme name when setting dark mode.

Instead, the proper way would be to check the Settings Portal, part of the XDG Desktop Portals. The dark mode preference of Gnome sets the value read by the portal. And the libadwaita code you've used read the dark mode preference from this portal.

Since GTK does not include support for a dark mode preference, you would need to read the portal directly. You could do this by directly accessing the DBus interface with a library like Tmds.Dbus. There's also a C library called libportal, but I'm not sure what the easier way would be.

TLDR: Using the GTK theme name to check for dark mode is not ideal (maybe for a fallback), ideally the Settings portal should be used.

Originally posted by @CodedOre in #1378 (comment)

@badcel
Copy link
Contributor Author

badcel commented Aug 16, 2024

You don't need an additional DBus library as there is already a DBus implementation inside Gio which is part of Gir.Core.

You can probably just use it already as it is a dependency of Gdk, which itself is a dependency of Gtk.

I wrote a small sample to detect the color-scheme which works for me on fedora 40. Any feedback that it works on other current distributions is very welcome.

If it works, something similar should probably the base for DevToys color-scheme detection. I worked this out via the linked documentation and a tool called D-Spy.

D-Spy

@veler
Copy link
Collaborator

veler commented Aug 17, 2024

Hi @badcel ,

Thank you soooo much for taking the time to explain all this and to provide a sample. You made my life sooo much easier !

I made a pull request that followed your advices: #1382

Have a wonderful day !

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 a pull request may close this issue.

2 participants