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; }