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
This commit is contained in:
Seth Hillbrand 2025-01-10 17:30:43 -08:00
parent 8d25a4c09d
commit e8167f33d7
5 changed files with 67 additions and 5 deletions

View File

@ -58,12 +58,11 @@ WX_INFOBAR::WX_INFOBAR( wxWindow* aParent, wxAuiManager* aMgr, wxWindowID aWinid
{ {
m_showTimer = new wxTimer( this, ID_CLOSE_INFOBAR ); m_showTimer = new wxTimer( this, ID_CLOSE_INFOBAR );
wxColour fg, bg;
KIPLATFORM::UI::GetInfoBarColours( bg, fg );
SetBackgroundColour( bg );
SetForegroundColour( fg );
#ifdef __WXMAC__ #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 // Infobar is broken on Mac without the effects
SetShowHideEffects( wxSHOW_EFFECT_ROLL_TO_BOTTOM, wxSHOW_EFFECT_ROLL_TO_TOP ); SetShowHideEffects( wxSHOW_EFFECT_ROLL_TO_BOTTOM, wxSHOW_EFFECT_ROLL_TO_TOP );

View File

@ -119,6 +119,11 @@ namespace KIPLATFORM
*/ */
double GetContentScaleFactor( const wxWindow* aWindow ); 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) * Tries to determine the size of the viewport of a scrollable widget (wxDataViewCtrl, wxGrid)
* that won't be obscured by scrollbars. * that won't be obscured by scrollbars.

View File

@ -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 ) void KIPLATFORM::UI::ForceFocus( wxWindow* aWindow )
{ {
aWindow->SetFocus(); aWindow->SetFocus();

View File

@ -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 ) void KIPLATFORM::UI::ForceFocus( wxWindow* aWindow )
{ {
aWindow->SetFocus(); aWindow->SetFocus();

View File

@ -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 ) void KIPLATFORM::UI::ForceFocus( wxWindow* aWindow )
{ {
// On OSX we need to forcefully give the focus to the window // On OSX we need to forcefully give the focus to the window