From 6ca27a4743078f5905f8e1382faae8979261d5ba Mon Sep 17 00:00:00 2001 From: infirit Date: Thu, 20 Aug 2015 13:59:33 +0200 Subject: Gtk3: Fix background color Also drop the mate-desktop dark/light color functions in favour of internal ones. --- src/ui/draw-workspace.c | 11 ++----- src/ui/theme.c | 81 +++++++++++++++++++++++++++++++++++++++++++------ src/ui/theme.h | 8 +++++ 3 files changed, 82 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/ui/draw-workspace.c b/src/ui/draw-workspace.c index a40579db..4feb25c9 100644 --- a/src/ui/draw-workspace.c +++ b/src/ui/draw-workspace.c @@ -26,12 +26,7 @@ */ #include "draw-workspace.h" - -#if GTK_CHECK_VERSION (3, 0, 0) -#define MATE_DESKTOP_USE_UNSTABLE_API -#include -#endif - +#include "theme.h" static void get_window_rect (const WnckWindowDisplayInfo *win, @@ -110,7 +105,7 @@ draw_window (GtkWidget *widget, #if GTK_CHECK_VERSION (3, 0, 0) style = gtk_widget_get_style_context (widget); if (is_active) - mate_desktop_gtk_style_get_light_color (style, state, &color); + meta_gtk_style_get_light_color (style, state, &color); else gtk_style_context_get_background_color (style, state, &color); gdk_cairo_set_source_rgba (cr, &color); @@ -268,7 +263,7 @@ wnck_draw_workspace (GtkWidget *widget, #if GTK_CHECK_VERSION (3, 0, 0) GdkRGBA color; - mate_desktop_gtk_style_get_dark_color (style,state, &color); + meta_gtk_style_get_dark_color (style,state, &color); gdk_cairo_set_source_rgba (cr, &color); #else gdk_cairo_set_source_color (cr, >k_widget_get_style (widget)->dark[state]); diff --git a/src/ui/theme.c b/src/ui/theme.c index 173c58f0..e348f62e 100644 --- a/src/ui/theme.c +++ b/src/ui/theme.c @@ -63,11 +63,6 @@ #define __USE_XOPEN #include -#if GTK_CHECK_VERSION (3, 0, 0) -#define MATE_DESKTOP_USE_UNSTABLE_API -#include -#endif - #if GTK_CHECK_VERSION (3, 0, 0) #define GDK_COLOR_RGBA(color) \ ((guint32) (0xff | \ @@ -1486,6 +1481,72 @@ meta_color_spec_new_gtk (MetaGtkColorComponent component, } #if GTK_CHECK_VERSION (3, 0, 0) +static void +get_background_color_real (GtkStyleContext *context, + GtkStateFlags state, + GdkRGBA *color) +{ + GdkRGBA *c; + + g_return_if_fail (color != NULL); + g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); + + gtk_style_context_get (context, + state, + "background-color", &c, + NULL); + + *color = *c; + gdk_rgba_free (c); +} + +static void +get_background_color (GtkStyleContext *context, + GtkStateFlags state, + GdkRGBA *color) +{ + GdkRGBA empty = { 0.0, 0.0, 0.0, 0.0 }; + GdkRGBA rgba; + + get_background_color_real (context, state, &rgba); + + if (gdk_rgba_equal (&rgba, &empty)) + { + GtkWidget *toplevel; + GtkStyleContext *tmp; + + toplevel = gtk_window_new (GTK_WINDOW_TOPLEVEL); + tmp = gtk_widget_get_style_context (toplevel); + + get_background_color_real (tmp, state, &rgba); + + gtk_widget_destroy (toplevel); + } + + *color = rgba; +} + +/* Based on set_color() in gtkstyle.c */ +#define LIGHTNESS_MULT 1.3 +#define DARKNESS_MULT 0.7 +void +meta_gtk_style_get_light_color (GtkStyleContext *style, + GtkStateFlags state, + GdkRGBA *color) +{ + get_background_color (style, state, color); + gtk_style_shade (color, color, LIGHTNESS_MULT); +} + +void +meta_gtk_style_get_dark_color (GtkStyleContext *style, + GtkStateFlags state, + GdkRGBA *color) +{ + get_background_color (style, state, color); + gtk_style_shade (color, color, DARKNESS_MULT); +} + static void meta_set_color_from_style (GdkRGBA *color, GtkStyleContext *context, @@ -1498,7 +1559,7 @@ meta_set_color_from_style (GdkRGBA *color, { case META_GTK_COLOR_BG: case META_GTK_COLOR_BASE: - gtk_style_context_get_background_color (context, state, color); + get_background_color (context, state, color); break; case META_GTK_COLOR_FG: case META_GTK_COLOR_TEXT: @@ -1513,18 +1574,18 @@ meta_set_color_from_style (GdkRGBA *color, color->blue = (color->blue + other.blue) / 2; break; case META_GTK_COLOR_MID: - mate_desktop_gtk_style_get_light_color (context, state, color); - mate_desktop_gtk_style_get_dark_color (context, state, &other); + meta_gtk_style_get_light_color (context, state, color); + meta_gtk_style_get_dark_color (context, state, &other); color->red = (color->red + other.red) / 2; color->green = (color->green + other.green) / 2; color->blue = (color->blue + other.blue) / 2; break; case META_GTK_COLOR_LIGHT: - mate_desktop_gtk_style_get_light_color (context, state, color); + meta_gtk_style_get_light_color (context, state, color); break; case META_GTK_COLOR_DARK: - mate_desktop_gtk_style_get_dark_color (context, state, color); + meta_gtk_style_get_dark_color (context, state, color); break; case META_GTK_COLOR_LAST: g_assert_not_reached (); diff --git a/src/ui/theme.h b/src/ui/theme.h index 742d01fe..ea3ec196 100644 --- a/src/ui/theme.h +++ b/src/ui/theme.h @@ -1269,6 +1269,14 @@ GtkArrowType meta_gtk_arrow_from_string (const char *s const char* meta_gtk_arrow_to_string (GtkArrowType arrow); MetaImageFillType meta_image_fill_type_from_string (const char *str); const char* meta_image_fill_type_to_string (MetaImageFillType fill_type); +#if GTK_CHECK_VERSION (3, 0, 0) +void meta_gtk_style_get_light_color (GtkStyleContext *style, + GtkStateFlags state, + GdkRGBA *color); +void meta_gtk_style_get_dark_color (GtkStyleContext *style, + GtkStateFlags state, + GdkRGBA *color); +#endif guint meta_theme_earliest_version_with_button (MetaButtonType type); -- cgit v1.2.1