https://github.com/wxWidgets/wxWidgets/pull/23764
(3 files)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@ColinKinloch commented on this pull request.
> @@ -840,6 +849,31 @@ wxFont wxSystemSettingsNative::GetFont( wxSystemFont index )
return font;
}
+ bool wxSystemAppearance::IsDark() const
+ {
+ GVariant* out = NULL;
⬇️ Suggested change
- GVariant* out = NULL; + GVariant* out = nullptr;
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@ColinKinloch pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
> + nullptr,
+ "org.freedesktop.portal.Desktop",
+ "/org/freedesktop/portal/desktop",
+ "org.freedesktop.portal.Settings",
+ nullptr,
+ nullptr);
+ g_autoptr (GVariant) ret =
+ g_dbus_proxy_call_sync(proxy, "Read",
+ g_variant_new ("(ss)", "org.freedesktop.appearance", "color-scheme"),
+ G_DBUS_CALL_FLAGS_NONE, G_MAXINT, nullptr, nullptr);
+
+ g_autoptr (GVariant) child = nullptr;
+ g_variant_get(ret, "(v)", &child);
+ g_variant_get(child, "v", &out);
+
+ printf("heloo %s\n", g_variant_print(out, true));
⬇️ Suggested change
- printf("heloo %s\n", g_variant_print(out, true));
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@ColinKinloch pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@ColinKinloch pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@ColinKinloch pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@ColinKinloch pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@ColinKinloch pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@ColinKinloch pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@ColinKinloch pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@ColinKinloch pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Thanks for working on this! Listening to the colours change event would be definitely nice, but if it's not easy to implement, perhaps we should merge the changes here already and leave it for a separate PR?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@ColinKinloch pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Yeah, I think it would be pretty trivial to implement.
However probably an easy job for someone more familiar with on the codebase than I am.
Here's the relevant file in libadwaita: https://gitlab.gnome.org/GNOME/libadwaita/-/blob/d7307a4b0da7a47de2cc1e84f23e45d604aa00c7/src/adw-settings-impl-portal.c
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@vadz commented on this pull request.
I think we should merge this already (after fixing the trivial issues below), please let me know if anybody -- notably @paulcor -- has any objections.
> @@ -840,6 +853,53 @@ wxFont wxSystemSettingsNative::GetFont( wxSystemFont index )
return font;
}
+#if defined(__WXGTK3__) || defined(__WXGTK__)
+bool wxSystemAppearance::IsSystemDark() const
+{
+ GVariant *out = nullptr;
+ GVariant *child = nullptr;
+ GVariant *ret = nullptr;
+ GError *error = nullptr;
We could/should use wxGtkError instead of dealing with raw Glib types.
> @@ -26,6 +26,19 @@ #include "wx/gtk/private/stylecontext.h" #include "wx/gtk/private/value.h" +#define PORTAL_BUS_NAME "org.freedesktop.portal.Desktop" +#define PORTAL_OBJECT_PATH "/org/freedesktop/portal/desktop" +#define PORTAL_SETTINGS_INTERFACE "org.freedesktop.portal.Settings" + +enum ColorScheme
Interesting, the only documentation for this I could find was https://docs.flatpak.org/fr/latest/portal-api-reference.html
but this doesn't seem to be flatpak-specific. Do you know of some better/more authoritative documentation for this? I'd like to add a link to it to a comment here somewhere.
> + PORTAL_BUS_NAME,
+ PORTAL_OBJECT_PATH,
+ PORTAL_SETTINGS_INTERFACE,
+ nullptr,
+ &error);
+
+ if (proxy) {
+ ret = g_dbus_proxy_call_sync(proxy, "Read",
+ g_variant_new ("(ss)", "org.freedesktop.appearance", "color-scheme"),
+ G_DBUS_CALL_FLAGS_NONE, G_MAXINT, nullptr, nullptr);
+
+ if (ret) {
+ g_variant_get(ret, "(v)", &child);
+ g_variant_get(child, "v", &out);
+
+ isDark = g_variant_get_uint32(out) == FDO_PREFER_DARK;
I'm not 100% sure if we should set it to false for FDO_DEFAULT, it could be better to fallback to IsDark() in this case.
> + GVariant *child = nullptr;
+ GVariant *ret = nullptr;
+ GError *error = nullptr;
+
+ bool isDark = IsDark();
+
+ GDBusProxy *proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ nullptr,
+ PORTAL_BUS_NAME,
+ PORTAL_OBJECT_PATH,
+ PORTAL_SETTINGS_INTERFACE,
+ nullptr,
+ &error);
+
+ if (proxy) {
⬇️ Suggested change
- if (proxy) {
+ if (proxy)
+ {
> +
+ GDBusProxy *proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ nullptr,
+ PORTAL_BUS_NAME,
+ PORTAL_OBJECT_PATH,
+ PORTAL_SETTINGS_INTERFACE,
+ nullptr,
+ &error);
+
+ if (proxy) {
+ ret = g_dbus_proxy_call_sync(proxy, "Read",
+ g_variant_new ("(ss)", "org.freedesktop.appearance", "color-scheme"),
+ G_DBUS_CALL_FLAGS_NONE, G_MAXINT, nullptr, nullptr);
+
+ if (ret) {
⬇️ Suggested change
- if (ret) {
+ if (ret)
+ {
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@ColinKinloch commented on this pull request.
> @@ -26,6 +26,19 @@ #include "wx/gtk/private/stylecontext.h" #include "wx/gtk/private/value.h" +#define PORTAL_BUS_NAME "org.freedesktop.portal.Desktop" +#define PORTAL_OBJECT_PATH "/org/freedesktop/portal/desktop" +#define PORTAL_SETTINGS_INTERFACE "org.freedesktop.portal.Settings" + +enum ColorScheme
The xdg-desktop-portal code is hosted on github which links to: https://flatpak.github.io/xdg-desktop-portal/
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@ColinKinloch pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
So, the whole point of this is really just to have wxSystemAppearance::IsSystemDark() return the correct value, right? I think that could be done much more simply by examining the theme name; if it ends with "-dark", or the GTK_THEME environment variable ends with ":dark", it's dark.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
GTK_THEME isn't in my environment and isn't set by gnome settings.
If GTK_THEME were set gtk would ignore gtk-application-prefer-dark-mode and select whichever theme/variant it was set to.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Looking at libadwaita there is also the GSettings interface with the field color-scheme on the org.gnome.desktop.interface schema.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
There's also gsettings get org.gnome.desktop.interface gtk-theme which yields 'Adwaita' on my dark mode system.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
FWIW gsettings get org.gnome.desktop.interface color-scheme returns prefer-dark for me in dark mode and default otherwise with GNOME 43.6 (Debian Bookworm). Should we just use this?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
So support GSettings when the portal fails or just not support flatpak?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
So try GSettings when the portal fails or just not support flatpak?
Sorry but I don't know much about flatpak -- is GSettings unavailable when using it?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
flatpak run --command=gsettings org.freedesktop.Platform get org.gnome.desktop.interface color-scheme
Yields 'default'.
I had a look just now, I couldn't figure out the specific incantation of permissions to give it access to the hosts GSettings.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
The theme name is available from GtkSettings as the gtk-theme-name property.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
The theme name is available from
GtkSettingsas thegtk-theme-nameproperty.
But this one is always "Adwaita" for me, both in light (default) and dark modes.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
How are you enabling dark mode?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
How are you enabling dark mode?
Going to GNOME Settings and choosing "Dark" style in the "Appearance" page.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Is any of this compatible with non-Gnome desktop environments? Mate doesn't have dedicated settings to select dark mode, so to do dark mode you actually switch the theme to something else. For instance, I have a theme for dark and a theme for light, and it would appear to be defined inside a different gsettings key: org.mate.interface gtk-theme, which when I query it returns the theme:
$ gsettings get org.mate.interface gtk-theme
'Mint-Y-Dark-Blue'
(or at least the controls theme, since I actually have a custom theme that uses that for the controls portion). Querying the gnome one would just give the result for the Gnome DE that I don't use (but still have installed):
$ gsettings get org.gnome.desktop.interface color-scheme
'default'
So reading the gnome key would be bad for my system, because then it would try to use the appearance of a desktop environment that isn't actually the one being used.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@imciner2 Does using portal work under Mate? If so, then we should probably just do it as it's supposed to be the WM/desktop-agnostic way to check this, IIUC.
For the reference, I'm using
dbus-send --session --print-reply=literal --dest=org.freedesktop.portal.Desktop /org/freedesktop/portal/desktop org.freedesktop.portal.Settings.Read string:org.freedesktop.appearance string:color-scheme
to check this.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
The desktop portal for mate is here: https://github.com/linuxmint/xdg-desktop-portal-xapp
There's a commit from March that says Mate doesn't support dark mode then: linuxmint/xdg-desktop-portal-xapp@b342a7f
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Does using portal work under Mate? If so, then we should probably just do it as it's supposed to be the WM/desktop-agnostic way to check this, IIUC.
Using the command you posted, this is the output I get on my Fedora 38 install:
$ dbus-send --session --print-reply=literal --dest=org.freedesktop.portal.Desktop /org/freedesktop/portal/desktop org.freedesktop.portal.Settings.Read string:org.freedesktop.appearance string:color-scheme
variant variant uint32 0
I'm running a dark color scheme based on the Mint-Y-Dark-Blue control theme to give a dark mode. According to the spec (https://github.com/flatpak/xdg-desktop-portal/blob/d7a304a00697d7d608821253cd013f3b97ac0fb6/data/org.freedesktop.impl.portal.Settings.xml#L33-L45), 0 means "No preference," so it doesn't indicate one way or the other on my system, but I would want the app to use a dark mode.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
If I'm understanding correctly the portal implementation for Mate returns "No preference" because Mate is yet to implement dark mode.
It looks like Mate gives you a theme setting which this MR wont override.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
The theme name is available from
GtkSettingsas thegtk-theme-nameproperty.But this one is always "Adwaita" for me, both in light (default) and dark modes.
Based on the GTK source code, I'm having difficulty understanding how this is possible. So I have to ask, are you sure? Could you check with this?
diff --git a/src/gtk/toplevel.cpp b/src/gtk/toplevel.cpp index 13b1857c6b..4fc1bdd66f 100644 --- a/src/gtk/toplevel.cpp +++ b/src/gtk/toplevel.cpp @@ -507,6 +507,15 @@ gtk_frame_window_state_callback( GtkWidget* WXUNUSED(widget), } } +static void f() +{ + char* theme_name; + gboolean prefer_dark; + g_object_get(gtk_settings_get_default(), "gtk-theme-name", theme_name, + "gtk-application-prefer-dark-theme", &prefer_dark, nullptr); + fprintf(stderr, "%s %d\n", theme_name, prefer_dark); + g_free(theme_name); +} //----------------------------------------------------------------------------- // "notify::gtk-theme-name" from GtkSettings //----------------------------------------------------------------------------- @@ -514,6 +523,7 @@ gtk_frame_window_state_callback( GtkWidget* WXUNUSED(widget), extern "C" { static void notify_gtk_theme_name(GObject*, GParamSpec*, wxTopLevelWindowGTK* win) { + f(); wxSysColourChangedEvent event; event.SetEventObject(win); win->HandleWindowEvent(event); @@ -896,6 +906,7 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent, g_signal_connect_after(gtk_settings_get_default(), "notify::gtk-theme-name", G_CALLBACK(notify_gtk_theme_name), this); + f(); return true; }
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
The theme name is available from
GtkSettingsas thegtk-theme-nameproperty.But this one is always "Adwaita" for me, both in light (default) and dark modes.
Based on the GTK source code, I'm having difficulty understanding how this is possible.
Doesn't GNOME use GTK 4 nowadays?
So I have to ask, are you sure? Could you check with this?
I've checked (after replacing theme_name with &theme_name to avoid crashing) and it always outputs Adwaita 0 for me (whether I start it in light or dark mode) and doesn't react to the theme change.
It looks like there is a new mechanism for dark mode support: previously it was indeed just another theme but now they use "color scheme" parameter (and also accent colours) without changing the theme at all -- presumably to be more like macOS, as usual...
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
GTK doesn't integrate with system dark mode. Its development seems to be under the umbrella of libadwaita which is more of a opinionated human interface design library.
Since wx had a dark mode API I think this MR provides a good first step for a wxGTK implementation.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
it always outputs Adwaita 0 for me (whether I start it in light or dark mode) and doesn't react to the theme change.
OK, I didn't realize the app is not reacting to this Gnome "dark style". It turns out GTK3 doesn't work with whatever Gnome is using now. How very typical. GTK4 does work though, and it doesn't appear to be using the portal color-scheme thing, nor does it use libadwaita. I'd like to understand how GTK4 is getting this dark mode indication before proceeding, and leave the Flatpak issue aside for the moment.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
What are you using to test GTK4? I was using gtk4-demo
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
I also used gtk4-demo. Although I'm not sure what I did, as I just re-checked and it appears GTK4 doesn't work either...
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
It occurred to me that wxTopLevelWindowGTK::Create probably isn't the correct place to handle dark mode, since gtk-application-prefer-dark-theme is a property of GtkSettings.
Is there a more appropriate place in wxGTK to handle global settings/events? Somewhere a GDBusProxy for the lifetime of an application?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Sorry, I'm rather lost here by now. Paul, are you going to take some decision about this or should I?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
I'm working on it.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
The default wxSystemAppearance::IsDark() seems to work fine for wxGTK, so I don't see a strong need to implement that. But using the "color-scheme" setting to get an actual dark theme seems more important, so I've done that now in 9b9ec14.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
Closed #23764.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()