wish: Automatic GTK dark theme switching (using the Freedesktop standard)

Bug #2002177 reported by Jeff Fortin Tam
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
HomeBank
New
Wishlist
Unassigned

Bug Description

Homebank has a "Dark theme" setting in its preferences dialog, but that's mostly obsolete nowadays, as there is a better way.

Nowadays there is a standardized way for your app to authoritatively know (without just trying to "guess" whether the current GTK theme is dark or not) what the user's intent is in terms of light/dark themes.

* Overview here: https://blogs.gnome.org/alexm/2021/10/04/dark-style-preference/
* Implementation tips here: https://gitlab.gnome.org/GNOME/Initiatives/-/wikis/Dark-Style-Preference

Most applications already support this with GNOME 42+ and Elementary OS 6, even non-purely-GTK applications such as Firefox. I believe lots of applications on KDE support this standard as well.

Knowing "what the user actually _wishes_ for" at any point in time lets your app switch between the two styles in realtime with a clear standardized signal, and also lets it confidently ship its own harmonized colors/stylesheet for both light/dark scenarios if needed. In Homebank's case, this could actually let you simplify your "Amount colors" section by simply switching between your "Tango light" and "Tango dark" color schemes depending on the global light/dark state of the desktop/application.

---

If you want to offer extra configurability to the user (instead of just auto-following the system's state), you could offer the choice between: "Follow system's preference", "Always light", or "Always dark".

On the desktop side, an example of a commonly used UI for this in GTK and GNOME apps is the screenshot you can see here: https://github.com/mjakeman/extension-manager/issues/218

---

That's for the Linux / Freedesktop side. Windows and macOS also have their own light/dark state APIs, but I don't know what they are.

Maxime DOYEN (mdoyen)
Changed in homebank:
importance: Undecided → Wishlist
Maxime DOYEN (mdoyen)
tags: added: user-interface
Revision history for this message
Maxime DOYEN (mdoyen) wrote (last edit ):

that's mostly obsolete nowadays
=> as long as the user can use system default and force dark whenever he wants = nothing is obsolete
But I agree, I have implemented this into my website (not online yet), and as I also switch night/day between light/dark theme, having app following this is a plus, not really better, but I probably miss that 4 mouse click is too much effort for some people at present.

a few comments for me later on:
- freedesktop is a Linux specification
- seems only available for Gnome and Granite
- for example no /appearence set in /org/freedesktop/ in Cinnamon or Mate
- even with GTK4, it requires libadwaita
- on GTK3 for now we can only rely on gtk-application-prefer-dark-theme
- gtk-application-prefer-dark-theme is not initialized on Windows 10, not 11

so it may be possible to implement a more accessible menu entry with force-light/force-dark, but default seems complex to get, on Linux at first, but probably more on Windows, didn't look at Mac.

It would be so much easier if GTK3/4 directly expose a reliable cross platform prefer-dark/light/default as well.
You seem to have connection with the developers: if you can suggest, please do :)

Revision history for this message
Jeff Fortin Tam (kiddo) wrote :

I know that at least KDE also supports it, and Cinnamon now supports it since last month: https://9to5linux.com/cinnamon-5-8-desktop-released-with-gestures-dark-mode-styles-and-more

I don't know what the status is for Mate, but I'm not holding my breath there, they are not exactly known as being the most change/future-oriented DE out there ;)

For Homebank itself, I don't think you actually need to use libadwaita to do this on GTK4, and as far I can tell you don't even need GTK4 to begin with (though it's probably nicer and I suppose you're planning to migrate to it anyway). LibHandy is not needed for GTK3 either. For instance, Firefox, LibreOffice 7.6 and Evolution (which are all GTK3 applications, or hybrids of GTK3 and other stuff) all support this.

I think it is done with the recommendations in the "Other" section here: https://gitlab.gnome.org/GNOME/Initiatives/-/wikis/Dark-Style-Preference#other

I hope this helps!

Revision history for this message
Jeff Fortin Tam (kiddo) wrote :

I asked around, and you can definitely support it "manually" even with a purely GTK3 app (without libhandy) or purely GTK4 app (without libadwaita). It's just more work.

The libadwaita pref works "out of the box" (basically zero lines of code needed specifically for this), and also works on macOS and Windows; the libhandy approach requires a single line of code, but doesn't work on macOS and Windows.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.