From 3f5ce6d74fbfd1a4cc00797989c3807e531a0410 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 9 Feb 2018 19:04:59 -0600 Subject: [PATCH] fix gtk3 deprecation warnings setting menubar colors --- atom/browser/ui/views/menu_bar.cc | 68 +++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/atom/browser/ui/views/menu_bar.cc b/atom/browser/ui/views/menu_bar.cc index 329dec295627..3e71cfad9d1f 100644 --- a/atom/browser/ui/views/menu_bar.cc +++ b/atom/browser/ui/views/menu_bar.cc @@ -24,27 +24,63 @@ namespace atom { namespace { +#if defined(USE_X11) +#if GTK_CHECK_VERSION(3,0,0) + +SkColor GdkRgbaToSkColor(const GdkRGBA& rgba) { + return SkColorSetARGB(rgba.alpha*255, rgba.red*255, + rgba.green*255, rgba.blue*255); +} + +SkColor GetStyleContextFgColor(GtkStyleContext* style_context, + GtkStateFlags state) { + GdkRGBA rgba; + gtk_style_context_get_color(style_context, state, &rgba); + return GdkRgbaToSkColor(rgba); +} + +SkColor GetStyleContextBgColor(GtkStyleContext* style_context, + GtkStateFlags state) { + GdkRGBA rgba; + gtk_style_context_get_background_color(style_context, state, &rgba); + return GdkRgbaToSkColor(rgba); +} + +// GTK+ 3 impl +void GetMenuBarColor(SkColor* enabled, SkColor* disabled, SkColor* highlight, + SkColor* hover, SkColor* background) { + GtkWidget* menu_bar = gtk_menu_bar_new(); + GtkStyleContext* style_context = gtk_widget_get_style_context(menu_bar); + *enabled = GetStyleContextFgColor(style_context, GTK_STATE_FLAG_NORMAL); + *disabled = GetStyleContextFgColor(style_context, GTK_STATE_FLAG_INSENSITIVE); + *highlight = GetStyleContextFgColor(style_context, GTK_STATE_FLAG_SELECTED); + *hover = GetStyleContextFgColor(style_context, GTK_STATE_FLAG_PRELIGHT); + *background = GetStyleContextBgColor(style_context, GTK_STATE_FLAG_NORMAL); + g_object_unref(G_OBJECT(menu_bar)); +} + +#else // GTK_CHECK_VERSION(3,0,0) + +// GTK+ 2 impl +void GetMenuBarColor(SkColor* enabled, SkColor* disabled, SkColor* highlight, + SkColor* hover, SkColor* background) { + GtkWidget* menu_bar = gtk_menu_bar_new(); + GtkStyle* style = gtk_rc_get_style(menu_bar); + *enabled = libgtkui::GdkColorToSkColor(style->fg[GTK_STATE_NORMAL]); + *disabled = libgtkui::GdkColorToSkColor(style->fg[GTK_STATE_INSENSITIVE]); + *highlight = libgtkui::GdkColorToSkColor(style->fg[GTK_STATE_SELECTED]); + *hover = libgtkui::GdkColorToSkColor(style->fg[GTK_STATE_PRELIGHT]); + *background = libgtkui::GdkColorToSkColor(style->bg[GTK_STATE_NORMAL]); + g_object_unref(G_OBJECT(menu_bar)); +} +#endif // GTK_CHECK_VERSION(3,0,0) +#endif // USE_X11 + const char kViewClassName[] = "ElectronMenuBar"; // Default color of the menu bar. const SkColor kDefaultColor = SkColorSetARGB(255, 233, 233, 233); -#if defined(USE_X11) -void GetMenuBarColor(SkColor* enabled, SkColor* disabled, SkColor* highlight, - SkColor* hover, SkColor* background) { - GtkWidget* menu_bar = gtk_menu_bar_new(); - - GtkStyle* style = gtk_rc_get_style(menu_bar); - *enabled = libgtkui::GdkColorToSkColor(style->fg[GTK_STATE_NORMAL]); - *disabled = libgtkui::GdkColorToSkColor(style->fg[GTK_STATE_INSENSITIVE]); - *highlight = libgtkui::GdkColorToSkColor(style->fg[GTK_STATE_SELECTED]); - *hover = libgtkui::GdkColorToSkColor(style->fg[GTK_STATE_PRELIGHT]); - *background = libgtkui::GdkColorToSkColor(style->bg[GTK_STATE_NORMAL]); - - gtk_widget_destroy(menu_bar); -} -#endif - } // namespace MenuBar::MenuBar(NativeWindow* window)