From 520aeacd8c6d14931fb7eac619d248f76567fa3b Mon Sep 17 00:00:00 2001 From: Alx Sa Date: Tue, 22 Jul 2025 15:04:55 +0000 Subject: [PATCH] widgets: Follow theme mode on Critical Dialog (Win) Following the improvement in fe4cbb65, the Critical Dialogue uses the native titlebar in Windows. This means it no longer adapts to dark and light mode automatically. Since we don't want GimpCriticalDialog to be dependent on internal GIMP code, this patch copies over the fallback code in gimp_window_set_title_bar_theme () (which sets the title bar based on the background color) when the dialogue is realized. --- app/widgets/gimpcriticaldialog.c | 56 ++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/app/widgets/gimpcriticaldialog.c b/app/widgets/gimpcriticaldialog.c index f01d7f30f9..08bc54afc9 100644 --- a/app/widgets/gimpcriticaldialog.c +++ b/app/widgets/gimpcriticaldialog.c @@ -38,7 +38,13 @@ #ifdef G_OS_WIN32 #undef DATADIR +#include +#include #include + +#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE +#define DWMWA_USE_IMMERSIVE_DARK_MODE 20 +#endif #endif #include "gimpcriticaldialog.h" @@ -75,6 +81,10 @@ static void gimp_critical_dialog_copy_info (GimpCriticalDialog *dialog); static gboolean browser_open_url (GtkWindow *window, const gchar *url, GError **error); +#ifdef G_OS_WIN32 +static void gimp_critical_dialog_realize (GtkWidget *widget, + GimpCriticalDialog *dialog); +#endif G_DEFINE_TYPE (GimpCriticalDialog, gimp_critical_dialog, GTK_TYPE_DIALOG) @@ -277,6 +287,46 @@ gimp_critical_dialog_constructed (GObject *object) gtk_container_add (GTK_CONTAINER (scrolled), dialog->details); } +/* Copied from app/widgets/gimpwidgets-utils.c, to reduce dependency + * on internal GIMP procedures */ +#ifdef G_OS_WIN32 +static void +gimp_critical_dialog_realize (GtkWidget *widget, + GimpCriticalDialog *dialog) +{ + HWND hwnd; + GdkWindow *window = NULL; + GtkStyleContext *style; + GdkRGBA *color = NULL; + gboolean use_dark_mode = FALSE; + + window = gtk_widget_get_window (GTK_WIDGET (widget)); + if (window) + { + /* Workaround if we don't have access to GimpGuiConfig. + * If the background color is below the threshold, then we're + * likely in dark mode. + */ + style = gtk_widget_get_style_context (widget); + gtk_style_context_get (style, gtk_style_context_get_state (style), + GTK_STYLE_PROPERTY_BACKGROUND_COLOR, &color, + NULL); + if (color) + { + if (color->red < 0.5 && color->green < 0.5 && color->blue < 0.5) + use_dark_mode = TRUE; + + gdk_rgba_free (color); + } + + hwnd = (HWND) gdk_win32_window_get_handle (window); + DwmSetWindowAttribute (hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, + &use_dark_mode, sizeof (use_dark_mode)); + } +} +#endif + + static void gimp_critical_dialog_finalize (GObject *object) { @@ -531,6 +581,12 @@ gimp_critical_dialog_new (const gchar *title, NULL); g_free (date); +#ifdef G_OS_WIN32 + g_signal_connect_object (dialog, "realize", + G_CALLBACK (gimp_critical_dialog_realize), + NULL, 0); +#endif + return dialog; }