diff options
-rw-r--r-- | libmate-panel-applet/mate-panel-applet.c | 115 | ||||
-rw-r--r-- | libmate-panel-applet/mate-panel-applet.h | 2 | ||||
-rw-r--r-- | mate-panel/panel-background.c | 105 | ||||
-rw-r--r-- | mate-panel/panel-background.h | 8 | ||||
-rw-r--r-- | mate-panel/panel-profile.c | 54 | ||||
-rw-r--r-- | mate-panel/panel-profile.h | 17 | ||||
-rw-r--r-- | mate-panel/panel-properties-dialog.c | 35 | ||||
-rw-r--r-- | mate-panel/panel-types.h | 2 | ||||
-rw-r--r-- | mate-panel/panel-widget.c | 104 | ||||
-rw-r--r-- | mate-panel/panel.c | 11 |
10 files changed, 366 insertions, 87 deletions
diff --git a/libmate-panel-applet/mate-panel-applet.c b/libmate-panel-applet/mate-panel-applet.c index 3c03bfd1..4f3fecdf 100644 --- a/libmate-panel-applet/mate-panel-applet.c +++ b/libmate-panel-applet/mate-panel-applet.c @@ -1279,12 +1279,21 @@ mate_panel_applet_focus (GtkWidget *widget, static gboolean mate_panel_applet_parse_color (const gchar *color_str, - GdkColor *color) +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA *color) +#else + GdkColor *color) +#endif { +#if !GTK_CHECK_VERSION (3, 0, 0) int r, g, b; +#endif g_assert (color_str && color); +#if GTK_CHECK_VERSION (3, 0, 0) + return gdk_rgba_parse (color, color_str); +#else if (sscanf (color_str, "%4x%4x%4x", &r, &g, &b) != 3) return FALSE; @@ -1293,6 +1302,7 @@ mate_panel_applet_parse_color (const gchar *color_str, color->blue = b; return TRUE; +#endif } static gboolean @@ -1335,11 +1345,11 @@ mate_panel_applet_parse_pixmap_str (const char *str, if (tmp == elements [2]) goto ERROR_AND_FREE; - g_strfreev (elements); + g_strfreev (elements); return TRUE; - ERROR_AND_FREE: - g_strfreev (elements); +ERROR_AND_FREE: + g_strfreev (elements); return FALSE; } @@ -1379,7 +1389,7 @@ mate_panel_applet_get_pixmap (MatePanelApplet *applet, #if GTK_CHECK_VERSION (3, 0, 0) cairo_surface_t *background; cairo_surface_t *surface; - cairo_matrix_t matrix; + cairo_matrix_t matrix; #else gboolean display_grabbed; GdkPixmap *pixmap; @@ -1440,6 +1450,7 @@ mate_panel_applet_get_pixmap (MatePanelApplet *applet, #if GTK_CHECK_VERSION(3, 0, 0) width = gdk_window_get_width(window); height = gdk_window_get_height(window); + surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, width, height); #else gdk_drawable_get_size(GDK_DRAWABLE(window), &width, &height); #endif @@ -1471,7 +1482,7 @@ mate_panel_applet_get_pixmap (MatePanelApplet *applet, cairo_matrix_scale (&matrix, width, height); cairo_pattern_set_matrix (pattern, &matrix); cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD); - } + } cairo_destroy (cr); cairo_surface_destroy (surface); @@ -1499,15 +1510,16 @@ mate_panel_applet_get_pixmap (MatePanelApplet *applet, static MatePanelAppletBackgroundType mate_panel_applet_handle_background_string (MatePanelApplet *applet, - GdkColor *color, #if GTK_CHECK_VERSION (3, 0, 0) - cairo_pattern_t **pattern) + GdkRGBA *color, + cairo_pattern_t **pattern) #else - GdkPixmap **pixmap) + GdkColor *color, + GdkPixmap **pixmap) #endif { MatePanelAppletBackgroundType retval; - char **elements; + char **elements; retval = PANEL_NO_BACKGROUND; @@ -1579,12 +1591,13 @@ mate_panel_applet_handle_background_string (MatePanelApplet *applet, } MatePanelAppletBackgroundType -mate_panel_applet_get_background (MatePanelApplet *applet, - GdkColor *color, +mate_panel_applet_get_background (MatePanelApplet *applet, #if GTK_CHECK_VERSION (3, 0, 0) - cairo_pattern_t **pattern) + GdkRGBA *color, + cairo_pattern_t **pattern) #else - GdkPixmap **pixmap) + GdkColor *color, + GdkPixmap **pixmap) #endif { g_return_val_if_fail (PANEL_IS_APPLET (applet), PANEL_NO_BACKGROUND); @@ -1598,7 +1611,11 @@ mate_panel_applet_get_background (MatePanelApplet *applet, *pixmap = NULL; #endif if (color != NULL) +#if GTK_CHECK_VERSION (3, 0, 0) + memset (color, 0, sizeof (GdkRGBA)); +#else memset (color, 0, sizeof (GdkColor)); +#endif #if GTK_CHECK_VERSION (3, 0, 0) return mate_panel_applet_handle_background_string (applet, color, pattern); @@ -1625,44 +1642,96 @@ mate_panel_applet_set_background_string (MatePanelApplet *applet, g_object_notify (G_OBJECT (applet), "background"); } +#if GTK_CHECK_VERSION (3, 0, 0) +static GtkStyleProperties * +_mate_panel_applet_get_widget_style_properties (GtkWidget *widget, gboolean create_if_needed) +{ + GtkStyleProperties *properties; + + properties = g_object_get_data (G_OBJECT (widget), "panel-applet-style-props"); + if (!properties && create_if_needed) { + properties = gtk_style_properties_new (); + g_object_set_data_full (G_OBJECT (widget), "panel-applet-style-props", + properties, (GDestroyNotify) g_object_unref); + } + return properties; +} + +static void +_mate_panel_applet_reset_widget_style_properties (GtkWidget *widget) +{ + GtkStyleProperties *properties; + + properties = _mate_panel_applet_get_widget_style_properties (widget, FALSE); + + if (properties) + gtk_style_context_remove_provider (gtk_widget_get_style_context (widget), + GTK_STYLE_PROVIDER (properties)); + + g_object_set_data (G_OBJECT (widget), "panel-applet-style-props", NULL); +} +#endif + static void mate_panel_applet_update_background_for_widget (GtkWidget *widget, MatePanelAppletBackgroundType type, - GdkColor *color, #if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA *color, cairo_pattern_t *pattern) #else + GdkColor *color, GdkPixmap *pixmap) #endif { +#if GTK_CHECK_VERSION (3, 0, 0) + GtkStyleProperties *properties; +#else GtkRcStyle *rc_style; GtkStyle *style; +#endif +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_widget_reset_style (widget); + if (!pattern) { + _mate_panel_applet_reset_widget_style_properties (widget); + return; + } +#else /* reset style */ gtk_widget_set_style (widget, NULL); rc_style = gtk_rc_style_new (); gtk_widget_modify_style (widget, rc_style); g_object_unref (rc_style); +#endif switch (type) { case PANEL_NO_BACKGROUND: break; case PANEL_COLOR_BACKGROUND: +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_style_properties_set (properties, GTK_STATE_FLAG_NORMAL, + "background-color", &color, + "background-image", NULL, + NULL); +#else gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, color); +#endif break; case PANEL_PIXMAP_BACKGROUND: - style = gtk_style_copy (gtk_widget_get_style (widget)); #if GTK_CHECK_VERSION (3, 0, 0) - if (style->background[GTK_STATE_NORMAL]) - cairo_pattern_destroy (style->background[GTK_STATE_NORMAL]); - style->background[GTK_STATE_NORMAL] = cairo_pattern_reference (pattern); + gtk_style_properties_set (properties, GTK_STATE_FLAG_NORMAL, + /* background-color can't be NULL, + * but is ignored anyway */ + "background-image", pattern, + NULL); #else + style = gtk_style_copy (gtk_widget_get_style (widget)); if (style->bg_pixmap[GTK_STATE_NORMAL]) g_object_unref (style->bg_pixmap[GTK_STATE_NORMAL]); style->bg_pixmap[GTK_STATE_NORMAL] = g_object_ref (pixmap); -#endif gtk_widget_set_style (widget, style); g_object_unref (style); +#endif break; default: g_assert_not_reached (); @@ -1674,8 +1743,8 @@ static void mate_panel_applet_handle_background (MatePanelApplet *applet) { MatePanelAppletBackgroundType type; - GdkColor color; #if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color; cairo_pattern_t *pattern; type = mate_panel_applet_get_background (applet, &color, &pattern); @@ -1684,6 +1753,7 @@ mate_panel_applet_handle_background (MatePanelApplet *applet) mate_panel_applet_update_background_for_widget (applet->priv->background_widget, type, &color, pattern); #else + GdkColor color; GdkPixmap *pixmap; type = mate_panel_applet_get_background (applet, &color, &pixmap); @@ -2427,8 +2497,8 @@ mate_panel_applet_set_background_widget (MatePanelApplet *applet, if (widget) { MatePanelAppletBackgroundType type; - GdkColor color; #if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color; cairo_pattern_t *pattern; type = mate_panel_applet_get_background (applet, &color, &pattern); mate_panel_applet_update_background_for_widget (widget, type, @@ -2436,6 +2506,7 @@ mate_panel_applet_set_background_widget (MatePanelApplet *applet, if (type == PANEL_PIXMAP_BACKGROUND) cairo_pattern_destroy (pattern); #else + GdkColor color; GdkPixmap *pixmap; type = mate_panel_applet_get_background (applet, &color, &pixmap); mate_panel_applet_update_background_for_widget (widget, type, diff --git a/libmate-panel-applet/mate-panel-applet.h b/libmate-panel-applet/mate-panel-applet.h index ed089c22..35157e68 100644 --- a/libmate-panel-applet/mate-panel-applet.h +++ b/libmate-panel-applet/mate-panel-applet.h @@ -95,7 +95,7 @@ GtkWidget* mate_panel_applet_new(void); MatePanelAppletOrient mate_panel_applet_get_orient(MatePanelApplet* applet); guint mate_panel_applet_get_size(MatePanelApplet* applet); #if GTK_CHECK_VERSION (3, 0, 0) -MatePanelAppletBackgroundType mate_panel_applet_get_background (MatePanelApplet *applet, /* return values */ GdkColor* color, cairo_pattern_t** pattern); +MatePanelAppletBackgroundType mate_panel_applet_get_background (MatePanelApplet *applet, /* return values */ GdkRGBA* color, cairo_pattern_t** pattern); #else MatePanelAppletBackgroundType mate_panel_applet_get_background(MatePanelApplet* applet, /* return values */ GdkColor* color, GdkPixmap** pixmap); #endif diff --git a/mate-panel/panel-background.c b/mate-panel/panel-background.c index eb2308e5..f85fb939 100644 --- a/mate-panel/panel-background.c +++ b/mate-panel/panel-background.c @@ -29,7 +29,11 @@ #include <string.h> #include <gdk/gdkx.h> #include <gdk/gdk.h> +#include <gtk/gtk.h> #include <cairo.h> +#if GTK_CHECK_VERSION (3, 0, 0) +#include <cairo-xlib.h> +#endif #include "panel-background-monitor.h" #include "panel-util.h" @@ -43,15 +47,11 @@ static void free_prepared_resources (PanelBackground *background) { background->prepared = FALSE; - +#if !GTK_CHECK_VERSION (3, 0, 0) switch (background->type) { case PANEL_BACK_NONE: break; case PANEL_BACK_COLOR: -#if GTK_CHECK_VERSION (3, 0, 0) - if (!background->has_alpha) - background->color.red = background->color.green = background->color.blue = 0.; -#else if (background->has_alpha) { if (background->pixmap) g_object_unref (background->pixmap); @@ -63,19 +63,17 @@ free_prepared_resources (PanelBackground *background) &background->color.gdk, 1); background->color.gdk.pixel = 0; } -#endif break; case PANEL_BACK_IMAGE: -#if !GTK_CHECK_VERSION (3, 0, 0) if (background->pixmap) g_object_unref (background->pixmap); background->pixmap = NULL; -#endif break; default: g_assert_not_reached (); break; } +#endif } static void @@ -146,8 +144,13 @@ panel_background_prepare (PanelBackground *background) TRUE); #endif } else +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_window_set_background_rgba ( + background->window, &background->default_color); +#else gdk_window_set_background ( background->window, &background->default_color); +#endif break; case PANEL_BACK_COLOR: if (background->has_alpha && @@ -278,9 +281,7 @@ static GdkPixbuf * #endif composite_image_onto_desktop (PanelBackground *background) { -#if GTK_CHECK_VERSION (3, 0, 0) - static const cairo_user_data_key_t key; -#else +#if !GTK_CHECK_VERSION (3, 0, 0) GdkPixbuf *retval; unsigned char *data; #endif @@ -708,7 +709,11 @@ panel_background_update_has_alpha (PanelBackground *background) gboolean has_alpha = FALSE; if (background->type == PANEL_BACK_COLOR) +#if GTK_CHECK_VERSION (3, 0, 0) + has_alpha = (background->color.alpha < 1.); +#else has_alpha = (background->color.alpha != 0xffff); +#endif else if (background->type == PANEL_BACK_IMAGE && background->loaded_image) @@ -786,12 +791,17 @@ panel_background_set_gdk_color (PanelBackground *background, panel_background_set_gdk_color_no_update (background, gdk_color); panel_background_transform (background); } +#endif static void panel_background_set_opacity_no_update (PanelBackground *background, guint16 opacity) { +#if GTK_CHECK_VERSION (3, 0, 0) + background->color.alpha = opacity / 65535.0; +#else background->color.alpha = opacity; +#endif panel_background_update_has_alpha (background); } @@ -799,14 +809,17 @@ void panel_background_set_opacity (PanelBackground *background, guint16 opacity) { +#if GTK_CHECK_VERSION (3, 0, 0) + if (background->color.alpha == (opacity / 65535.0)) +#else if (background->color.alpha == opacity) +#endif return; free_transformed_resources (background); panel_background_set_opacity_no_update (background, opacity); panel_background_transform (background); } -#endif static void panel_background_set_color_no_update (PanelBackground *background, @@ -974,10 +987,11 @@ panel_background_set (PanelBackground *background, void panel_background_set_default_style (PanelBackground *background, - GdkColor *color, #if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA *color, cairo_pattern_t *pattern) #else + GdkColor *color, GdkPixmap *pixmap) #endif { @@ -1180,10 +1194,18 @@ panel_background_init (PanelBackground *background, #else background->default_pixmap = NULL; #endif + +#if GTK_CHECK_VERSION (3, 0, 0) + background->default_color.red = 0.; + background->default_color.green = 0.; + background->default_color.blue = 0.; + background->default_color.alpha = 1.; +#else background->default_color.red = 0; background->default_color.green = 0; background->default_color.blue = 0; background->default_color.pixel = 0; +#endif background->fit_image = FALSE; background->stretch_image = FALSE; @@ -1246,7 +1268,7 @@ panel_background_make_string (PanelBackground *background, { PanelBackgroundType effective_type; char *retval; - + retval = NULL; effective_type = panel_background_effective_type (background); @@ -1254,7 +1276,10 @@ panel_background_make_string (PanelBackground *background, if (effective_type == PANEL_BACK_IMAGE || (effective_type == PANEL_BACK_COLOR && background->has_alpha)) { #if GTK_CHECK_VERSION (3, 0, 0) - Window pixmap_xid; + cairo_surface_t *surface; + + if (!background->composited_pattern) + return NULL; #else GdkNativeWindow pixmap_xid; @@ -1263,31 +1288,37 @@ panel_background_make_string (PanelBackground *background, #endif #if GTK_CHECK_VERSION (3, 0, 0) - pixmap_xid = gdk_x11_window_get_xid (background->window); + if (cairo_pattern_get_surface (background->composited_pattern, &surface)) + return NULL; + + if (cairo_surface_get_type (surface) != CAIRO_SURFACE_TYPE_XLIB) + return NULL; + + retval = g_strdup_printf ("pixmap:%d,%d,%d", (guint32)cairo_xlib_surface_get_drawable (surface), x, y); #else pixmap_xid = gdk_x11_drawable_get_xid ( GDK_DRAWABLE (background->pixmap)); -#endif retval = g_strdup_printf ("pixmap:%d,%d,%d", pixmap_xid, x, y); - - } else if (effective_type == PANEL_BACK_COLOR) - retval = g_strdup_printf ( - "color:%.4x%.4x%.4x", +#endif + } else if (effective_type == PANEL_BACK_COLOR) { #if GTK_CHECK_VERSION (3, 0, 0) - background->color.red, - background->color.green, - background->color.blue); + gchar *rgba = gdk_rgba_to_string (&background->color); + retval = g_strdup_printf ( + "color:%s", + rgba); + g_free (rgba); #else + retval = g_strdup_printf ( + "color:%.4x%.4x%.4x", background->color.gdk.red, background->color.gdk.green, background->color.gdk.blue); #endif - else + } else retval = g_strdup ("none:"); - return retval; - + return retval; } PanelBackgroundType @@ -1335,6 +1366,7 @@ panel_background_effective_type (PanelBackground *background) return retval; } +#if !GTK_CHECK_VERSION (3, 0, 0) static void panel_background_set_no_background_on_widget (PanelBackground *background, GtkWidget *widget) @@ -1346,6 +1378,7 @@ panel_background_set_no_background_on_widget (PanelBackground *background, gtk_widget_modify_style (widget, rc_style); g_object_unref (rc_style); } +#endif #if GTK_CHECK_VERSION (3, 0, 0) static cairo_pattern_t * @@ -1432,37 +1465,23 @@ panel_background_set_image_background_on_widget (PanelBackground *background, #endif } +#if !GTK_CHECK_VERSION (3, 0, 0) static void panel_background_set_color_background_on_widget (PanelBackground *background, GtkWidget *widget) { -#if GTK_CHECK_VERSION (3, 0, 0) - const GdkRGBA *color; - GdkColor gdkcolor; -#else const PanelColor *color; -#endif color = panel_background_get_color (background); -#if GTK_CHECK_VERSION (3, 0, 0) - if (color->alpha < 1.) { -#else if (color->alpha != 0xffff) { -#endif panel_background_set_image_background_on_widget (background, widget); return; } -#if GTK_CHECK_VERSION (3, 0, 0) - gdkcolor.red = color->red * 65535.; - gdkcolor.green = color->green * 65535.; - gdkcolor.blue = color->blue * 65535.; - gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, &gdkcolor); -#else gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, &color->gdk); -#endif } +#endif #if GTK_CHECK_VERSION (3, 0, 0) static GtkStyleProperties * diff --git a/mate-panel/panel-background.h b/mate-panel/panel-background.h index b5aeb6eb..fead8648 100644 --- a/mate-panel/panel-background.h +++ b/mate-panel/panel-background.h @@ -69,13 +69,14 @@ struct _PanelBackground { GdkWindow *window; #if GTK_CHECK_VERSION (3, 0, 0) cairo_pattern_t *default_pattern; + GdkRGBA default_color; #else GdkPixmap *pixmap; GdkColormap *colormap; GdkGC *gc; GdkPixmap *default_pixmap; -#endif GdkColor default_color; +#endif guint fit_image : 1; guint stretch_image : 1; @@ -109,9 +110,9 @@ void panel_background_set_type (PanelBackground *background, #if !GTK_CHECK_VERSION (3, 0, 0) void panel_background_set_gdk_color (PanelBackground *background, GdkColor *gdk_color); +#endif void panel_background_set_opacity (PanelBackground *background, guint16 opacity); -#endif void panel_background_set_color (PanelBackground *background, #if GTK_CHECK_VERSION (3, 0, 0) const GdkRGBA *color); @@ -127,10 +128,11 @@ void panel_background_set_stretch (PanelBackground *background, void panel_background_set_rotate (PanelBackground *background, gboolean rotate_image); void panel_background_set_default_style (PanelBackground *background, - GdkColor *color, #if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA *color, cairo_pattern_t *pattern); #else + GdkColor *color, GdkPixmap *pixmap); #endif void panel_background_realized (PanelBackground *background, diff --git a/mate-panel/panel-profile.c b/mate-panel/panel-profile.c index 2c5b328c..3dad813b 100644 --- a/mate-panel/panel-profile.c +++ b/mate-panel/panel-profile.c @@ -232,20 +232,67 @@ panel_profile_get_background_type (PanelToplevel *toplevel) void panel_profile_set_background_color (PanelToplevel *toplevel, +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA *color) +#else PanelColor *color) +#endif { +#if GTK_CHECK_VERSION (3, 0, 0) + panel_profile_set_background_gdk_rgba_color (toplevel, color); +#else panel_profile_set_background_gdk_color (toplevel, &color->gdk); +#endif panel_profile_set_background_opacity (toplevel, color->alpha); } void panel_profile_get_background_color (PanelToplevel *toplevel, +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA *color) +#else PanelColor *color) +#endif { +#if GTK_CHECK_VERSION (3, 0, 0) + panel_profile_get_background_gdk_rgba_color (toplevel, color); + color->alpha = panel_profile_get_background_opacity (toplevel) / 65535.0; +#else panel_profile_get_background_gdk_color (toplevel, &(color->gdk)); color->alpha = panel_profile_get_background_opacity (toplevel); +#endif } +#if GTK_CHECK_VERSION (3, 0, 0) +void +panel_profile_set_background_gdk_rgba_color (PanelToplevel *toplevel, + GdkRGBA *color) +{ + char *color_str; + + color_str = gdk_rgba_to_string (color); + + g_settings_set_string(toplevel->background_settings, "color", color_str); + + g_free (color_str); +} + +void +panel_profile_get_background_gdk_rgba_color (PanelToplevel *toplevel, + GdkRGBA *color) +{ + char *color_str; + + color_str = g_settings_get_string (toplevel->background_settings, "color"); + if (!color_str || !gdk_rgba_parse (color, color_str)) { + color->red = 0.; + color->green = 0.; + color->blue = 0.; + } + + g_free (color_str); +} +#else void panel_profile_set_background_gdk_color (PanelToplevel *toplevel, GdkColor *gdk_color) @@ -277,6 +324,7 @@ panel_profile_get_background_gdk_color (PanelToplevel *toplevel, g_free (color_str); } +#endif void panel_profile_set_background_opacity (PanelToplevel *toplevel, @@ -518,7 +566,11 @@ get_background_color (PanelToplevel *toplevel, #endif g_free (color_str); +#if GTK_CHECK_VERSION (3, 0, 0) + color->alpha = g_settings_get_int (toplevel->background_settings, "opacity") / 65535.0; +#else color->alpha = g_settings_get_int (toplevel->background_settings, "opacity"); +#endif } static char * @@ -855,10 +907,8 @@ panel_profile_background_change_notify (GSettings *settings, g_free (str); #endif } else if (!strcmp (key, "opacity")) { -#if !GTK_CHECK_VERSION (3, 0, 0) panel_background_set_opacity (background, g_settings_get_int (settings, key)); -#endif } else if (!strcmp (key, "image")) { panel_background_set_image (background, g_settings_get_string (settings, key)); diff --git a/mate-panel/panel-profile.h b/mate-panel/panel-profile.h index 665e237b..ffa43af3 100644 --- a/mate-panel/panel-profile.h +++ b/mate-panel/panel-profile.h @@ -110,14 +110,29 @@ PanelBackgroundType panel_profile_get_background_type (PanelToplevel *toplevel); void panel_profile_set_background_color (PanelToplevel *toplevel, +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA *color); +#else PanelColor *color); +#endif void panel_profile_get_background_color (PanelToplevel *toplevel, +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA *color); +#else PanelColor *color); - +#endif + +#if GTK_CHECK_VERSION (3, 0, 0) +void panel_profile_set_background_gdk_rgba_color (PanelToplevel *toplevel, + GdkRGBA *color); +void panel_profile_get_background_gdk_rgba_color (PanelToplevel *toplevel, + GdkRGBA *color); +#else void panel_profile_set_background_gdk_color (PanelToplevel *toplevel, GdkColor *gdk_color); void panel_profile_get_background_gdk_color (PanelToplevel *toplevel, GdkColor *gdk_color); +#endif void panel_profile_set_background_opacity (PanelToplevel *toplevel, guint16 opacity); diff --git a/mate-panel/panel-properties-dialog.c b/mate-panel/panel-properties-dialog.c index 5818522f..c14dae99 100644 --- a/mate-panel/panel-properties-dialog.c +++ b/mate-panel/panel-properties-dialog.c @@ -327,19 +327,32 @@ static void panel_properties_dialog_color_changed (PanelPropertiesDialog *dialog, GtkColorButton *color_button) { +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color; +#else GdkColor color; +#endif g_assert (dialog->color_button == GTK_WIDGET (color_button)); +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_color_button_get_rgba (color_button, &color); + panel_profile_set_background_gdk_rgba_color (dialog->toplevel, &color); +#else gtk_color_button_get_color (color_button, &color); panel_profile_set_background_gdk_color (dialog->toplevel, &color); +#endif } static void panel_properties_dialog_setup_color_button (PanelPropertiesDialog *dialog, GtkBuilder *gui) { +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color; +#else PanelColor color; +#endif dialog->color_button = PANEL_GTK_BUILDER_GET (gui, "color_button"); g_return_if_fail (dialog->color_button != NULL); @@ -348,8 +361,13 @@ panel_properties_dialog_setup_color_button (PanelPropertiesDialog *dialog, panel_profile_get_background_color (dialog->toplevel, &color); +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_color_button_set_rgba (GTK_COLOR_BUTTON (dialog->color_button), + &color); +#else gtk_color_button_set_color (GTK_COLOR_BUTTON (dialog->color_button), &(color.gdk)); +#endif g_signal_connect_swapped (dialog->color_button, "color_set", G_CALLBACK (panel_properties_dialog_color_changed), @@ -693,19 +711,36 @@ static void panel_properties_dialog_update_background_color (PanelPropertiesDialog *dialog, gchar *str_color) { +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA new_color; + GdkRGBA old_color; +#else GdkColor new_color = { 0, }; GdkColor old_color; +#endif +#if GTK_CHECK_VERSION (3, 0, 0) + if (!gdk_rgba_parse (&new_color, str_color)) +#else if (!gdk_color_parse (str_color, &new_color)) +#endif return; +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_color_button_get_rgba (GTK_COLOR_BUTTON (dialog->color_button), +#else gtk_color_button_get_color (GTK_COLOR_BUTTON (dialog->color_button), +#endif &old_color); if (old_color.red != new_color.red || old_color.green != new_color.green || old_color.blue != new_color.blue) +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_color_button_set_rgba (GTK_COLOR_BUTTON (dialog->color_button), +#else gtk_color_button_set_color (GTK_COLOR_BUTTON (dialog->color_button), +#endif &new_color); } diff --git a/mate-panel/panel-types.h b/mate-panel/panel-types.h index e71549ae..2d16942f 100644 --- a/mate-panel/panel-types.h +++ b/mate-panel/panel-types.h @@ -11,9 +11,11 @@ typedef enum { PANEL_SPEED_FAST } PanelSpeed; +#if !GTK_CHECK_VERSION (3, 0, 0) typedef struct { GdkColor gdk; guint16 alpha; } PanelColor; +#endif #endif diff --git a/mate-panel/panel-widget.c b/mate-panel/panel-widget.c index 969096b2..734eb459 100644 --- a/mate-panel/panel-widget.c +++ b/mate-panel/panel-widget.c @@ -87,10 +87,16 @@ static void panel_widget_destroy (GtkObject *obj); static void panel_widget_finalize (GObject *obj); static void panel_widget_realize (GtkWidget *widget); static void panel_widget_unrealize (GtkWidget *panel); +#if GTK_CHECK_VERSION (3, 0, 0) +static void panel_widget_state_flags_changed (GtkWidget *widget, + GtkStateFlags previous_state); +static void panel_widget_style_updated (GtkWidget *widget); +#else static void panel_widget_state_changed (GtkWidget *widget, GtkStateType previous_state); static void panel_widget_style_set (GtkWidget *widget, GtkStyle *previous_style); +#endif static void panel_widget_background_changed (PanelBackground *background, PanelWidget *panel); @@ -127,6 +133,11 @@ static void emit_applet_moved (PanelWidget *panel_widget, AppletData *applet) { +#if GTK_CHECK_VERSION (3, 0, 0) + /* we always want to queue a draw after moving, so do it here instead + * of after the signal emission in all callers */ + gtk_widget_queue_draw (applet->applet); +#endif g_signal_emit (panel_widget, panel_widget_signals [APPLET_MOVE_SIGNAL], 0, applet->applet); @@ -445,8 +456,13 @@ panel_widget_class_init (PanelWidgetClass *class) widget_class->realize = panel_widget_realize; widget_class->unrealize = panel_widget_unrealize; widget_class->focus = panel_widget_real_focus; +#if GTK_CHECK_VERSION (3, 0, 0) + widget_class->state_flags_changed = panel_widget_state_flags_changed; + widget_class->style_updated = panel_widget_style_updated; +#else widget_class->state_changed = panel_widget_state_changed; widget_class->style_set = panel_widget_style_set; +#endif container_class->add = panel_widget_cadd; container_class->remove = panel_widget_cremove; @@ -1244,7 +1260,11 @@ panel_widget_size_request(GtkWidget *widget, GtkRequisition *requisition) for(list = panel->applet_list; list!=NULL; list = g_list_next(list)) { AppletData *ad = list->data; GtkRequisition chreq; - gtk_widget_size_request(ad->applet,&chreq); +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_widget_get_preferred_size (ad->applet, &chreq, NULL); +#else + gtk_widget_size_request(ad->applet, &chreq); +#endif if (panel->orient == GTK_ORIENTATION_HORIZONTAL) { if (requisition->height < chreq.height && !ad->size_constrained) @@ -1424,7 +1444,11 @@ panel_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation) AppletData *ad = list->data; GtkAllocation challoc; GtkRequisition chreq; - gtk_widget_get_child_requisition(ad->applet,&chreq); +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_widget_get_preferred_size (ad->applet, &chreq, NULL); +#else + gtk_widget_get_child_requisition(ad->applet, &chreq); +#endif ad->constrained = i; @@ -1475,7 +1499,11 @@ panel_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation) AppletData *ad = list->data; GtkRequisition chreq; - gtk_widget_get_child_requisition(ad->applet,&chreq); +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_widget_get_preferred_size (ad->applet, &chreq, NULL); +#else + gtk_widget_get_child_requisition(ad->applet, &chreq); +#endif if (!ad->expand_major || !ad->size_hints) { if(panel->orient == GTK_ORIENTATION_HORIZONTAL) @@ -1545,7 +1573,11 @@ panel_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation) AppletData *ad = list->data; GtkAllocation challoc; GtkRequisition chreq; - gtk_widget_get_child_requisition(ad->applet,&chreq); +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_widget_get_preferred_size (ad->applet, &chreq, NULL); +#else + gtk_widget_get_child_requisition (ad->applet, &chreq); +#endif challoc.width = chreq.width; challoc.height = chreq.height; if(panel->orient == GTK_ORIENTATION_HORIZONTAL) { @@ -1564,6 +1596,9 @@ panel_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation) challoc.y = ad->constrained; } + challoc.width = MAX(challoc.width, 1); + challoc.height = MAX(challoc.height, 1); + gtk_widget_size_allocate(ad->applet,&challoc); } } @@ -1607,31 +1642,61 @@ panel_widget_is_cursor(PanelWidget *panel, int overlap) } static void -panel_widget_style_set (GtkWidget *widget, - GtkStyle *previous_style) +#if GTK_CHECK_VERSION (3, 0, 0) +panel_widget_set_background_default_style (GtkWidget *widget) +#else +panel_widget_style_set (GtkWidget *widget, GtkStyle *previous_style) +#endif { +#if GTK_CHECK_VERSION (3, 0, 0) + GtkStyleContext *context; + GtkStateFlags state; + GdkRGBA bg_color; + cairo_pattern_t *bg_image; +#else GtkStyle *style; GtkStateType state; +#endif if (gtk_widget_get_realized (widget)) { +#if GTK_CHECK_VERSION (3, 0, 0) + context = gtk_widget_get_style_context (widget); + state = gtk_widget_get_state_flags (widget); + + gtk_style_context_get_background_color (context, state, &bg_color); + gtk_style_context_get (context, state, "background-image", &bg_image, NULL); +#else style = gtk_widget_get_style (widget); state = gtk_widget_get_state (widget); +#endif panel_background_set_default_style ( &PANEL_WIDGET (widget)->background, - &style->bg [state], #if GTK_CHECK_VERSION (3, 0, 0) - style->background [state]); + &bg_color, + bg_image); + + if (bg_image) + cairo_pattern_destroy (bg_image); #else + &style->bg [state], style->bg_pixmap [state]); #endif } } static void +#if GTK_CHECK_VERSION (3, 0, 0) +panel_widget_style_updated (GtkWidget *widget) +#else panel_widget_state_changed (GtkWidget *widget, GtkStateType previous_state) +#endif { +#if GTK_CHECK_VERSION (3, 0, 0) + panel_widget_set_background_default_style (widget); + GTK_WIDGET_CLASS (panel_widget_parent_class)->style_updated (widget); +#else GtkStyle *style; GtkStateType state; @@ -1642,14 +1707,19 @@ panel_widget_state_changed (GtkWidget *widget, panel_background_set_default_style ( &PANEL_WIDGET (widget)->background, &style->bg [state], -#if GTK_CHECK_VERSION (3, 0, 0) - style->background [state]); -#else style->bg_pixmap [state]); -#endif } +#endif } +#if GTK_CHECK_VERSION (3, 0, 0) +static void +panel_widget_state_flags_changed (GtkWidget *widget, GtkStateFlags previous_state) +{ + panel_widget_set_background_default_style (widget); +} +#endif + static gboolean toplevel_configure_event (GtkWidget *widget, GdkEventConfigure *event, @@ -1665,8 +1735,10 @@ panel_widget_realize (GtkWidget *widget) { PanelWidget *panel = (PanelWidget *) widget; GdkWindow *window; +#if !GTK_CHECK_VERSION (3, 0, 0) GtkStyle *style; GtkStateType state; +#endif g_signal_connect (panel->toplevel, "configure-event", G_CALLBACK (toplevel_configure_event), panel); @@ -1674,19 +1746,21 @@ panel_widget_realize (GtkWidget *widget) GTK_WIDGET_CLASS (panel_widget_parent_class)->realize (widget); window = gtk_widget_get_window (widget); +#if !GTK_CHECK_VERSION (3, 0, 0) style = gtk_widget_get_style (widget); state = gtk_widget_get_state (widget); +#endif /* For auto-hidden panels with a colored background, we need native * windows to avoid some uglyness on unhide */ gdk_window_ensure_native (window); +#if GTK_CHECK_VERSION (3, 0, 0) + panel_widget_set_background_default_style (widget); +#else panel_background_set_default_style ( &panel->background, &style->bg [state], -#if GTK_CHECK_VERSION (3, 0, 0) - style->background [state]); -#else style->bg_pixmap [state]); #endif diff --git a/mate-panel/panel.c b/mate-panel/panel.c index 8ac44a88..666a62b7 100644 --- a/mate-panel/panel.c +++ b/mate-panel/panel.c @@ -433,7 +433,11 @@ static gboolean set_background_color (PanelToplevel *toplevel, guint16 *dropped) { +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color; +#else PanelColor color; +#endif if (!dropped) return FALSE; @@ -442,10 +446,17 @@ set_background_color (PanelToplevel *toplevel, ! panel_profile_background_key_is_writable (toplevel, "type")) return FALSE; +#if GTK_CHECK_VERSION (3, 0, 0) + color.red = dropped [0]; + color.green = dropped [1]; + color.blue = dropped [2]; + color.alpha = 1.; +#else color.gdk.red = dropped [0]; color.gdk.green = dropped [1]; color.gdk.blue = dropped [2]; color.alpha = 65535; +#endif panel_profile_set_background_color (toplevel, &color); panel_profile_set_background_type (toplevel, PANEL_BACK_COLOR); |