From 21d95618eab54a28dc67a699b01d6f998e599b83 Mon Sep 17 00:00:00 2001 From: Ghislain Antony Vaillant Date: Wed, 25 Nov 2020 12:22:19 +0100 Subject: [PATCH] Add further logic for menu bar styling on GTK 3 - Style the menu bar only when a background is set - Style with theme_bg_color if available - Style with sensible defaults otherwise Co-authored-by: asuramaru <69095614+asuramaru@users.noreply.github.com> --- hiro/gtk/window.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/hiro/gtk/window.cpp b/hiro/gtk/window.cpp index fc9b2e16..2d3754de 100755 --- a/hiro/gtk/window.cpp +++ b/hiro/gtk/window.cpp @@ -289,10 +289,27 @@ auto pWindow::setBackgroundColor(Color color) -> void { gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, color ? &gdkColor : nullptr); #if HIRO_GTK==3 - GdkRGBA gtkMenuBackgroundColor; - auto context = gtk_widget_get_style_context(gtkMenu); - gtk_style_context_lookup_color(context, "theme_bg_color", >kMenuBackgroundColor); - gtk_widget_override_background_color(gtkMenu, GTK_STATE_FLAG_NORMAL, >kMenuBackgroundColor); + if(!state().backgroundColor) { + // If no window background color is set, then use the default menu bar color. + gtk_widget_override_color(gtkMenu, GTK_STATE_FLAG_NORMAL, nullptr); + gtk_widget_override_background_color(gtkMenu, GTK_STATE_FLAG_NORMAL, nullptr); + } else { + // Otherwise, fix visual inconsistencies between the menu bar and current theme. + GdkRGBA themeBackgroundColor; + auto context = gtk_widget_get_style_context(gtkMenu); + if(gtk_style_context_lookup_color(context, "theme_bg_color", &themeBackgroundColor)) { + // If the current theme defines theme_bg_color, then use it. + gtk_widget_override_background_color(gtkMenu, GTK_STATE_FLAG_NORMAL, &themeBackgroundColor); + } else { + // Otherwise, set the menu bar to black text on a light gray background. + // FIXME: Maybe compute these colors based on the window background instead? + GdkRGBA textColor, backgroundColor; + gdk_rgba_parse(&textColor, "black"); + gtk_widget_override_color(gtkMenu, GTK_STATE_FLAG_NORMAL, &textColor); + gdk_rgba_parse(&backgroundColor, "gray91"); + gtk_widget_override_background_color(gtkMenu, GTK_STATE_FLAG_NORMAL, &backgroundColor); + } + } #endif }