wxWidgets / wxWidgets

Cross-Platform C++ GUI Library
https://www.wxwidgets.org/
5.77k stars 1.7k forks source link

Change theme when changing appearance in wxGTK if necessary #24476

Closed vadz closed 3 weeks ago

vadz commented 1 month ago

At least under Ubuntu 22.04 (GNOME 42) resetting the dark preference is not enough to switch to light appearance when the theme is set to the default value of "Yaru-dark" in system-wide dark mode, so change the theme to remove the explicit dark theme selector to make this work.

Note that it does not seem to be necessary to add "-dark" back when switching from light mode to dark, i.e. using "prefer-dark-theme" to choose the dark mode of the default theme seems to have exactly the same effect as choosing the dark theme variant.


This couldn't be as simple as I thought, of course... More testing showed that changing appearance doesn't work with GNOME 42 under Ubuntu 22.04 (even though it did for me with GNOME 43 under Debian Bookworm) and I don't see any other way to make it work than by changing the theme too. Please let me know if you have any comments/better suggestions!

paulcor commented 4 weeks ago

Changing the theme name this way (or at all really) does not seem like a good idea. First of all, there are few if any theme names ending -light. And the "dark" part may not be a suffix, for example on my system there is Mint-Y-Dark-Aqua amongst others. I'm not aware of any easy way to know whether a theme name is valid. And if you set an invalid name, you're going to get Adwaita, which might not be anything like what the DE is using.

I'm becoming more and more uncomfortable with the whole idea of trying to force the dark setting. The rationale for doing so is dubious at best.

vadz commented 4 weeks ago

Changing the theme name this way (or at all really) does not seem like a good idea. First of all, there are few if any theme names ending -light.

I guess we could just remove the "-dark" suffix too.

And the "dark" part may not be a suffix, for example on my system there is Mint-Y-Dark-Aqua amongst others.

We could also search for any "-dark" substring. But note that the assumption that "-dark" could only be a suffix was there from the beginning, i.e. this is not really specific to this PR.

I'm not aware of any easy way to know whether a theme name is valid.

Unfortunately me neither.

And if you set an invalid name, you're going to get Adwaita, which might not be anything like what the DE is using.

I'd be fine with documenting that calling this function under GTK could change the current theme. Arguably, showing an application that really wants to use dark mode using dark Adwaita is still better than showing it in the default light theme.

I'm becoming more and more uncomfortable with the whole idea of trying to force the dark setting. The rationale for doing so is dubious at best.

It's been asked for several times, including for the application I'm working on right now, so there is clearly some request for it. I really don't see any harm in doing this on the best effort basis knowing that people who object to it can just not call this function in the first place.

paulcor commented 4 weeks ago

But note that the assumption that "-dark" could only be a suffix was there from the beginning, i.e. this is not really specific to this PR.

The current code does search for a substring, and so does not assume "-dark" can only be a suffix. That assumption is very much specific to the changes in this PR.

Arguably, showing an application that really wants to use dark mode using dark Adwaita is still better than showing it in the default light theme.

But it won't be dark Adwaita, the fallback is just regular Adwaita, not dark.

vadz commented 4 weeks ago

But note that the assumption that "-dark" could only be a suffix was there from the beginning, i.e. this is not really specific to this PR.

The current code does search for a substring, and so does not assume "-dark" can only be a suffix. That assumption is very much specific to the changes in this PR.

I'm really sorry, this was a brain fart. I've removed this part now, what do you think of the latest version?

Note that, as mentioned in the commit message, it does not seem necessary to set theme to xxx-dark when switching to the dark mode, it's just the switch in the other direction which is problematic. At least things work fine for me under Ubuntu 22.04 with this change.

Arguably, showing an application that really wants to use dark mode using dark Adwaita is still better than showing it in the default light theme.

But it won't be dark Adwaita, the fallback is just regular Adwaita, not dark.

AFAICS there is no dark Adwaita variant (any more), just a dark variant of the same theme. See e.g. GTK Inspector Adwaita page.

paulcor commented 4 weeks ago

what do you think of the latest version?

I think it will work.

AFAICS there is no dark Adwaita variant (any more), just a dark variant of the same theme. See e.g. GTK Inspector Adwaita page.

Note that that documentation is for GTK4. I'm not sure what you think the difference is between "dark Adwaita variant" and "dark variant of... Adwaita", but there is definitely a (built in) Adwaita-dark theme in GTK3 (and a place holder for it in /usr/share/themes). A dark "variant" is always a separate theme in GTK3.

vadz commented 4 weeks ago

what do you think of the latest version?

I think it will work.

Thanks! FWIW I do agree that all this is pretty ugly but I don't believe it's a good reason to tell people who want to use some program in mode different from the default one that they can't do it. And we're not the only ones doing this, if it can help.

AFAICS there is no dark Adwaita variant (any more), just a dark variant of the same theme. See e.g. GTK Inspector Adwaita page.

Note that that documentation is for GTK4. I'm not sure what you think the difference is between "dark Adwaita variant" and "dark variant of... Adwaita",

OK, sorry, this was pretty badly formulated even by my own standards, but I meant the difference between "Adwaita-dark" and "Adwaita with app-prefers-dark option turned on".

but there is definitely a (built in) Adwaita-dark theme in GTK3 (and a place holder for it in /usr/share/themes). A dark "variant" is always a separate theme in GTK3.

Then GTK3 must be selecting "Adwaita-dark" automatically because running the code from this PR with WXTRACE=darkmode shows that the theme is always just "Adwaita", yet the appearance changes to dark. In the same way, testing under Ubuntu 22.04 shows that the appearance is the same (or I don't see the difference, which is also possible) with "Yaru-dark" and just "Yaru" and app-prefers-dark set to TRUE. I guess that in principle it's perfectly possible for "SomeTheme-dark" to appear completely differently from "SomeTheme when app-prefers-dark is on", but I can only hope this doesn't happen in practice...

paulcor commented 3 weeks ago

Then GTK3 must be selecting "Adwaita-dark" automatically

Looking into it more carefully, this isn't technically what happens, but it doesn't matter, as you are correct that Adwaita-dark is the same thing as Adwaita with gtk-application-prefer-dark-theme==true. And it seems reasonable to assume the same for other themes.