Skip to content

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

@badcel

Description

@badcel

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions