AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.63k stars 2.22k forks source link

Application.ActualThemeVariant not correct on Linux #13114

Open kuiperzone opened 1 year ago

kuiperzone commented 1 year ago

OS: Debian 12, Gnome 43.6, Wayland

The Application.ActualThemeVariant does not give correct value, at least on the system above. The application itself appears to display the correct theme, but Application.ActualThemeVariant always returns the "light" theme regardless. This means that I cannot adjust my apps styling to suit the system because I can't be certain of what it really is.

Screenshot below. I've even prepared a minimal sample for you guys! Cheers.

image

Avalonia-MinSample.zip

kekekeks commented 1 year ago

Check the theme provided by org.freedesktop.appearance color-scheme property of /org/freedesktop/portal/desktop using some explorer tool like D-Feet.

maxkatz6 commented 8 months ago

Closing as an issue not related to Avalonia, as Avalonia uses OS-provided color-scheme value.

kuiperzone commented 8 months ago

Just so I understand correctly:

Application.ActualThemeVariant

is always initialised to ThemeVariant.Light, regardless of whether the application shows in a dark theme or not?

And that is the planned behaviour because, as you say, this has nothing to do with Avalonia. Presumably then, Avalonia does not know whether it is displaying in a dark or light theme unless the Application.RequestedThemeVariant property is explicitly set by the application.

Therefore, there must be no straight-forward cross-platform way for either Avalonia or the application to ascertain whether the initial theme is actually dark or not?

This, after all, is all I want to discover in the application?

kuiperzone commented 8 months ago

I also note that this was marked as a "os-linux" specific issue. I do not understand why this was done.

I use Avalonia because it is a cross-platform framework. The issue is cross-platform.

kuiperzone commented 8 months ago

And the reason why I would want to ascertain whether the theme is dark or not is so that I can style controls accordingly.

I feel very much that this is a valid use case.

If the answer is going to be ... dig into the fundamentals of the underlying desktop APIs for each platform, then Avalonia is not appropriately abstracting things.

maxkatz6 commented 8 months ago

@kuiperzone please be civil. You haven't answered to this issue for months when kekekeks had a question. And still haven't answered.

maxkatz6 commented 8 months ago

I also note that this was marked as a "os-linux" specific issue. I do not understand why this was done.

Your code with no modification works on Windows.

image image

kuiperzone commented 8 months ago

Hi @maxkatz6

While I have been perfectly civil, I feel this issue has not been understood. I do not see any question @kekekeks in words, hence I have not replied to any.

Moreover, I have not posted here for months because in my own project I side stepped the issue by the forcing the initial theme to light (so I at least know what it is) and then allowing the user to then explicitly set light or dark. In other words, I simply lived with the fact that the app cannot auto-detect light or dark. In future apps, I will still face this so I am still interested.

I've just rebuilt and run the code sample on Linux under 11.0.9. The problem is still there, and indeed it behaves differently on different platforms. Hence, I see why it was regarded as a linux issue. Thank you.

This is a case of things not being both communicated or understood, however. For example, it was not clear to me whether Application.ActualThemeVariant is even intended to convey initial theme variant or not. I can see now that the answer is yes, but does not work under Linux.

I write stuff which take months and months in terms of underlying effort and complexity. I know it is frustrating when a user asks "just make it do this or that", something which on the surface appears simple to them, while effort that would be involved is invisible and horrendous. So, if you guys are saying ... look, this is something we can't reasonably do and have more pressing things, then I completely understand that.

However, it was the case I felt you did not see why I would want to be able to determine between light and dark, and saw this as a non-issue. Thank you for re-opening it.

Besides, I think I have figured out a "kludge fix". Perhaps it might be possible to construct a dummy minimal sized window on app start up, and peek at the window background color. This might be a way of discerning whether it is dark or not?