From e8167f33d7f11a483743c31081499d1b49f000fa Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 10 Jan 2025 17:30:43 -0800 Subject: [PATCH] Grab GTK default colors for infobar This implements the wxWidgets fix for KiCad. We can't wait for distros to update their wx libs so until then, we'll roll our own. Nicely, this also implements the MacOS setting that was an ifdef previously Fixes https://gitlab.com/kicad/code/kicad/-/issues/19506 --- common/widgets/wx_infobar.cpp | 9 +++--- libs/kiplatform/include/kiplatform/ui.h | 5 ++++ libs/kiplatform/port/wxgtk/ui.cpp | 39 +++++++++++++++++++++++++ libs/kiplatform/port/wxmsw/ui.cpp | 7 +++++ libs/kiplatform/port/wxosx/ui.mm | 12 ++++++++ 5 files changed, 67 insertions(+), 5 deletions(-) diff --git a/common/widgets/wx_infobar.cpp b/common/widgets/wx_infobar.cpp index 3f5c877762..5012b5b56f 100644 --- a/common/widgets/wx_infobar.cpp +++ b/common/widgets/wx_infobar.cpp @@ -58,12 +58,11 @@ WX_INFOBAR::WX_INFOBAR( wxWindow* aParent, wxAuiManager* aMgr, wxWindowID aWinid { m_showTimer = new wxTimer( this, ID_CLOSE_INFOBAR ); + wxColour fg, bg; + KIPLATFORM::UI::GetInfoBarColours( bg, fg ); + SetBackgroundColour( bg ); + SetForegroundColour( fg ); #ifdef __WXMAC__ - // wxWidgets hard-codes wxSYS_COLOUR_INFOBK to { 0xFF, 0xFF, 0xD3 } on Mac. - if( KIPLATFORM::UI::IsDarkTheme() ) - SetBackgroundColour( wxColour( 28, 27, 20 ) ); - else - SetBackgroundColour( wxColour( 255, 249, 189 ) ); // Infobar is broken on Mac without the effects SetShowHideEffects( wxSHOW_EFFECT_ROLL_TO_BOTTOM, wxSHOW_EFFECT_ROLL_TO_TOP ); diff --git a/libs/kiplatform/include/kiplatform/ui.h b/libs/kiplatform/include/kiplatform/ui.h index 5694d9f9c9..81aeaa7cf5 100644 --- a/libs/kiplatform/include/kiplatform/ui.h +++ b/libs/kiplatform/include/kiplatform/ui.h @@ -119,6 +119,11 @@ namespace KIPLATFORM */ double GetContentScaleFactor( const wxWindow* aWindow ); + /** + * Return the background and foreground colors for info bars in the current scheme + */ + void GetInfoBarColours( wxColour& aFGColour, wxColour& aBGColour ); + /** * Tries to determine the size of the viewport of a scrollable widget (wxDataViewCtrl, wxGrid) * that won't be obscured by scrollbars. diff --git a/libs/kiplatform/port/wxgtk/ui.cpp b/libs/kiplatform/port/wxgtk/ui.cpp index 68695a65b4..d896e35edc 100644 --- a/libs/kiplatform/port/wxgtk/ui.cpp +++ b/libs/kiplatform/port/wxgtk/ui.cpp @@ -64,6 +64,45 @@ wxColour KIPLATFORM::UI::GetDialogBGColour() } +void KIPLATFORM::UI::GetInfoBarColours( wxColour& aBgColour, wxColour& aFgColour ) +{ + // The GTK3.24 way of getting the colours is to use the style context + // Earlier GTKs should be able to use the system settings +#if( GTK_CHECK_VERSION( 3, 24, 0 ) ) + GdkRGBA* rgba; + GtkWidgetPath* path = gtk_widget_path_new(); + GtkStyleContext* sc = gtk_style_context_new(); + gtk_widget_path_append_type( path, GTK_TYPE_WINDOW ); + gtk_widget_path_iter_set_object_name( path, -1, "infobar" ); + gtk_widget_path_iter_add_class( path, -1, "background" ); + gtk_widget_path_iter_add_class( path, -1, "info" ); + gtk_widget_path_append_type( path, G_TYPE_NONE ); + gtk_widget_path_iter_set_object_name( path, -1, "revealer" ); + gtk_widget_path_append_type( path, G_TYPE_NONE ); + gtk_widget_path_iter_set_object_name( path, -1, "box" ); + + gtk_style_context_set_path( sc, path ); + gtk_style_context_set_state( sc, GTK_STATE_FLAG_NORMAL ); + + gtk_style_context_get( sc, GTK_STATE_FLAG_NORMAL, "background-color", &rgba, NULL ); + aBgColour = wxColour(*rgba); + gdk_rgba_free(rgba); + + gtk_style_context_get( sc, GTK_STATE_FLAG_NORMAL, "color", &rgba, NULL ); + aFgColour = wxColour(*rgba); + gdk_rgba_free(rgba); + + gtk_widget_path_free( path ); + g_object_unref( sc ); + +#else + aBgColour = wxSystemSettings::GetColour( wxSYS_COLOUR_INFOBK ); + aFgColour = wxSystemSettings::GetColour( wxSYS_COLOUR_INFOTEXT ); +#endif + +} + + void KIPLATFORM::UI::ForceFocus( wxWindow* aWindow ) { aWindow->SetFocus(); diff --git a/libs/kiplatform/port/wxmsw/ui.cpp b/libs/kiplatform/port/wxmsw/ui.cpp index f79299be57..dba8b287c3 100644 --- a/libs/kiplatform/port/wxmsw/ui.cpp +++ b/libs/kiplatform/port/wxmsw/ui.cpp @@ -73,6 +73,13 @@ wxColour KIPLATFORM::UI::GetDialogBGColour() } +wxColour KIPLATFORM::UI::GetInfoBarColours( wxColour& aFGColour, wxColour& aBGColour ) +{ + aBGColour = wxSystemSettings::GetColour( wxSYS_COLOUR_INFOBK ); + aFGColour = wxSystemSettings::GetColour( wxSYS_COLOUR_INFOTEXT ); +} + + void KIPLATFORM::UI::ForceFocus( wxWindow* aWindow ) { aWindow->SetFocus(); diff --git a/libs/kiplatform/port/wxosx/ui.mm b/libs/kiplatform/port/wxosx/ui.mm index 1090781a99..48c4187540 100644 --- a/libs/kiplatform/port/wxosx/ui.mm +++ b/libs/kiplatform/port/wxosx/ui.mm @@ -62,6 +62,18 @@ wxColour KIPLATFORM::UI::GetDialogBGColour() } +void KIPLATFORM::UI::GetInfoBarColours( wxColour& aFGColour, wxColour& aBGColour ) +{ + aFGColour = wxSystemSettings::GetColour( wxSYS_COLOUR_INFOTEXT ); + + // wxWidgets hard-codes wxSYS_COLOUR_INFOBK to { 0xFF, 0xFF, 0xD3 } on Mac. + if( KIPLATFORM::UI::IsDarkTheme() ) + aBGColour = wxColour( 28, 27, 20 ); + else + aBGColour = wxColour( 255, 249, 189 ); +} + + void KIPLATFORM::UI::ForceFocus( wxWindow* aWindow ) { // On OSX we need to forcefully give the focus to the window