diff options
author | raveit65 <[email protected]> | 2016-06-03 20:18:53 +0200 |
---|---|---|
committer | raveit65 <[email protected]> | 2016-06-07 16:44:56 +0200 |
commit | b8f642a86d8d18747a0b970b4420435603ee5a5f (patch) | |
tree | 51cc7f268a4e60e1a531e662b1dede6d98c868ac | |
parent | 0d633f368b7ddc943ed51ac93d1a389f41a57906 (diff) | |
download | mate-power-manager-b8f642a86d8d18747a0b970b4420435603ee5a5f.tar.bz2 mate-power-manager-b8f642a86d8d18747a0b970b4420435603ee5a5f.tar.xz |
GTK+3 media-keys: sync code with m-s-d and drop include mate-desktop-utils.h
This makes gtk3 migration easier as m-p-m use only
<libmate-desktop/mate-aboutdialog.h yet.
-rw-r--r-- | src/gsd-media-keys-window.c | 74 | ||||
-rw-r--r-- | src/msd-osd-window.c | 150 | ||||
-rw-r--r-- | src/msd-osd-window.h | 2 |
3 files changed, 135 insertions, 91 deletions
diff --git a/src/gsd-media-keys-window.c b/src/gsd-media-keys-window.c index 5bcca8e..cec33f9 100644 --- a/src/gsd-media-keys-window.c +++ b/src/gsd-media-keys-window.c @@ -30,11 +30,6 @@ #include <glib/gi18n.h> #include <gtk/gtk.h> -#if GTK_CHECK_VERSION (3, 0, 0) -#define MATE_DESKTOP_USE_UNSTABLE_API -#include <libmate-desktop/mate-desktop-utils.h> -#endif - #include "gsd-media-keys-window.h" #define MSD_MEDIA_KEYS_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MSD_TYPE_MEDIA_KEYS_WINDOW, MsdMediaKeysWindowPrivate)) @@ -408,32 +403,47 @@ draw_volume_boxes (MsdMediaKeysWindow *window, { gdouble x1; #if GTK_CHECK_VERSION (3, 0, 0) - GdkRGBA color; - GtkStyleContext *style; + GtkStyleContext *context; #else GdkColor color; double r, g, b; GtkStyle *style; #endif +#if !GTK_CHECK_VERSION (3, 0, 0) _x0 += 0.5; _y0 += 0.5; +#endif height = round (height) - 1; width = round (width) - 1; x1 = round ((width - 1) * percentage); - #if GTK_CHECK_VERSION (3, 0, 0) - style = gtk_widget_get_style_context (GTK_WIDGET (window)); + context = gtk_widget_get_style_context (GTK_WIDGET (window)); #else style = gtk_widget_get_style (GTK_WIDGET (window)); #endif /* bar background */ - msd_osd_window_draw_rounded_rectangle (cr, 1.0, _x0, _y0, height / 6, width, height); #if GTK_CHECK_VERSION (3, 0, 0) - mate_desktop_gtk_style_get_dark_color (style, GTK_STATE_FLAG_NORMAL, &color); - cairo_set_operator (cr, CAIRO_OPERATOR_DIFFERENCE); - cairo_set_source_rgba (cr, color.red, color.green, color.blue, MSD_OSD_WINDOW_FG_ALPHA / 2); + gtk_style_context_save (context); + gtk_style_context_add_class (context, GTK_STYLE_CLASS_TROUGH); + + gtk_render_background (context, cr, _x0, _y0, width, height); + gtk_render_frame (context, cr, _x0, _y0, width, height); + + gtk_style_context_restore (context); + + /* bar progress */ + if (percentage < 0.01) + return; + + gtk_style_context_save (context); + gtk_style_context_add_class (context, GTK_STYLE_CLASS_PROGRESSBAR); + + gtk_render_background (context, cr, _x0 + 0.5, _y0 + 0.5, x1, height -1 ); + gtk_render_frame (context, cr, _x0 + 0.5, _y0 + 0.5, x1, height -1 ); + + gtk_style_context_restore (context); #else msd_osd_window_color_reverse (&style->dark[GTK_STATE_NORMAL], &color); r = (float)color.red / 65535.0; @@ -441,41 +451,28 @@ draw_volume_boxes (MsdMediaKeysWindow *window, b = (float)color.blue / 65535.0; msd_osd_window_draw_rounded_rectangle (cr, 1.0, _x0, _y0, height / 6, width, height); cairo_set_source_rgba (cr, r, g, b, MSD_OSD_WINDOW_FG_ALPHA / 2); -#endif cairo_fill_preserve (cr); /* bar border */ -#if GTK_CHECK_VERSION (3, 0, 0) - mate_desktop_gtk_style_get_light_color (style, GTK_STATE_FLAG_NORMAL, &color); - cairo_set_operator (cr, CAIRO_OPERATOR_DIFFERENCE); - cairo_set_source_rgba (cr, color.red, color.green, color.blue, MSD_OSD_WINDOW_FG_ALPHA / 2); -#else msd_osd_window_color_reverse (&style->light[GTK_STATE_NORMAL], &color); r = (float)color.red / 65535.0; g = (float)color.green / 65535.0; b = (float)color.blue / 65535.0; cairo_set_source_rgba (cr, r, g, b, MSD_OSD_WINDOW_FG_ALPHA / 2); -#endif cairo_set_line_width (cr, 1); cairo_stroke (cr); /* bar progress */ if (percentage < 0.01) return; - - msd_osd_window_draw_rounded_rectangle (cr, 1.0, _x0 + 0.5, _y0 + 0.5, height / 6 - 0.5, x1, height - 1); -#if GTK_CHECK_VERSION (3, 0, 0) - gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, GTK_STYLE_PROPERTY_COLOR, &color, NULL); - cairo_set_operator (cr, CAIRO_OPERATOR_DIFFERENCE); - cairo_set_source_rgba (cr, color.red, color.green, color.blue, MSD_OSD_WINDOW_FG_ALPHA); -#else color = style->bg[GTK_STATE_NORMAL]; r = (float)color.red / 65535.0; g = (float)color.green / 65535.0; b = (float)color.blue / 65535.0; + msd_osd_window_draw_rounded_rectangle (cr, 1.0, _x0 + 0.5, _y0 + 0.5, height / 6 - 0.5, x1, height - 1); cairo_set_source_rgba (cr, r, g, b, MSD_OSD_WINDOW_FG_ALPHA); -#endif cairo_fill (cr); +#endif } static void @@ -521,6 +518,14 @@ draw_action_volume (MsdMediaKeysWindow *window, speaker_cx = icon_box_x0 + speaker_width / 2; speaker_cy = icon_box_y0 + speaker_height / 2; +#if 0 + g_message ("speaker box: w=%f h=%f cx=%f cy=%f", + speaker_width, + speaker_height, + speaker_cx, + speaker_cy); +#endif + /* draw speaker symbol */ draw_speaker (cr, speaker_cx, speaker_cy, speaker_width, speaker_height); @@ -622,6 +627,19 @@ draw_action_custom (MsdMediaKeysWindow *window, bright_box_x0 = round (icon_box_x0); bright_box_y0 = round (icon_box_height + icon_box_y0); +#if 0 + g_message ("icon box: w=%f h=%f _x0=%f _y0=%f", + icon_box_width, + icon_box_height, + icon_box_x0, + icon_box_y0); + g_message ("brightness box: w=%f h=%f _x0=%f _y0=%f", + bright_box_width, + bright_box_height, + bright_box_x0, + bright_box_y0); +#endif + res = render_custom (window, cr, icon_box_x0, icon_box_y0, diff --git a/src/msd-osd-window.c b/src/msd-osd-window.c index 6f84b6f..89a9272 100644 --- a/src/msd-osd-window.c +++ b/src/msd-osd-window.c @@ -55,7 +55,11 @@ struct MsdOsdWindowPrivate }; enum { +#if GTK_CHECK_VERSION (3, 0, 0) + DRAW_WHEN_COMPOSITED, +#else EXPOSE_WHEN_COMPOSITED, +#endif LAST_SIGNAL }; @@ -139,6 +143,7 @@ add_hide_timeout (MsdOsdWindow *window) window); } +#if !GTK_CHECK_VERSION (3, 0, 0) void msd_osd_window_draw_rounded_rectangle (cairo_t* cr, gdouble aspect, @@ -191,7 +196,6 @@ msd_osd_window_draw_rounded_rectangle (cairo_t* cr, cairo_close_path (cr); } -#if !GTK_CHECK_VERSION (3, 0, 0) void msd_osd_window_color_reverse (const GdkColor *a, GdkColor *b) @@ -229,7 +233,7 @@ msd_osd_window_color_reverse (const GdkColor *a, */ static void #if GTK_CHECK_VERSION (3, 0, 0) -draw_when_composited (GtkWidget *widget, cairo_t *context) +draw_when_composited (GtkWidget *widget, cairo_t *orig_cr) #else expose_when_composited (GtkWidget *widget, GdkEventExpose *event) #endif @@ -243,7 +247,7 @@ expose_when_composited (GtkWidget *widget, GdkEventExpose *event) int width; int height; #if GTK_CHECK_VERSION (3, 0, 0) - GtkStyleContext *style; + GtkStyleContext *context; #else GtkStyle *style; GdkColor color; @@ -257,14 +261,19 @@ expose_when_composited (GtkWidget *widget, GdkEventExpose *event) #endif #if GTK_CHECK_VERSION (3, 0, 0) - style = gtk_widget_get_style_context (widget); + context = gtk_widget_get_style_context (widget); + cairo_set_operator (orig_cr, CAIRO_OPERATOR_SOURCE); #else style = gtk_widget_get_style (widget); -#endif cairo_set_operator (context, CAIRO_OPERATOR_SOURCE); +#endif gtk_window_get_size (GTK_WINDOW (widget), &width, &height); +#if GTK_CHECK_VERSION (3, 0, 0) + surface = cairo_surface_create_similar (cairo_get_target (orig_cr), +#else surface = cairo_surface_create_similar (cairo_get_target (context), +#endif CAIRO_CONTENT_COLOR_ALPHA, width, height); @@ -284,7 +293,8 @@ expose_when_composited (GtkWidget *widget, GdkEventExpose *event) #endif #if GTK_CHECK_VERSION (3, 0, 0) - gtk_render_background (style, cr, 0, 0, width, height); + gtk_render_background (context, cr, 0, 0, width, height); + gtk_render_frame (context, cr, 0, 0, width, height); #else /* draw a box */ msd_osd_window_draw_rounded_rectangle (cr, 1.0, 0.5, 0.5, height / 10, width-1, height-1); @@ -304,17 +314,30 @@ expose_when_composited (GtkWidget *widget, GdkEventExpose *event) cairo_stroke (cr); #endif +#if GTK_CHECK_VERSION (3, 0, 0) + g_signal_emit (window, signals[DRAW_WHEN_COMPOSITED], 0, cr); +#else g_signal_emit (window, signals[EXPOSE_WHEN_COMPOSITED], 0, cr); +#endif cairo_destroy (cr); /* Make sure we have a transparent background */ +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_rectangle (orig_cr, 0, 0, width, height); + cairo_set_source_rgba (orig_cr, 0.0, 0.0, 0.0, 0.0); + cairo_fill (orig_cr); + + cairo_set_source_surface (orig_cr, surface, 0, 0); + cairo_paint_with_alpha (orig_cr, window->priv->fade_out_alpha); +#else cairo_rectangle (context, 0, 0, width, height); cairo_set_source_rgba (context, 0.0, 0.0, 0.0, 0.0); cairo_fill (context); cairo_set_source_surface (context, surface, 0, 0); cairo_paint_with_alpha (context, window->priv->fade_out_alpha); +#endif done: if (surface != NULL) { @@ -325,44 +348,40 @@ expose_when_composited (GtkWidget *widget, GdkEventExpose *event) #endif } -/* This is our expose-event handler when the window is *not* in a compositing manager. +/* This is our expose/draw-event handler when the window is *not* in a compositing manager. * We just draw a rectangular frame by hand. We do this with hardcoded drawing code, * instead of GtkFrame, to avoid changing the window's internal widget hierarchy: in * either case (composited or non-composited), callers can assume that this works * identically to a GtkWindow without any intermediate widgetry. */ -static void #if GTK_CHECK_VERSION (3, 0, 0) +static void draw_when_not_composited (GtkWidget *widget, cairo_t *cr) +{ + GtkStyleContext *context; + int width; + int height; + + width = gtk_widget_get_allocated_width (widget); + height = gtk_widget_get_allocated_width (widget); + context = gtk_widget_get_style_context (widget); + + gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE); + gtk_render_frame (context, + cr, + 0, + 0, + width, + height); +} #else +static void expose_when_not_composited (GtkWidget *widget, GdkEventExpose *event) -#endif { - MsdOsdWindow *window; -#if GTK_CHECK_VERSION (3, 0, 0) - int width; - int height; -#else GtkAllocation allocation; -#endif - - window = MSD_OSD_WINDOW (widget); -#if GTK_CHECK_VERSION (3, 0, 0) - width = gtk_widget_get_allocated_width (widget); - height = gtk_widget_get_allocated_width (widget); -#else gtk_widget_get_allocation (widget, &allocation); -#endif -#if GTK_CHECK_VERSION (3, 0, 0) - gtk_render_frame (gtk_widget_get_style_context (widget), - cr, - 0, - 0, - width, - height); -#else gtk_paint_shadow (gtk_widget_get_style (widget), gtk_widget_get_window (widget), gtk_widget_get_state (widget), @@ -374,45 +393,52 @@ expose_when_not_composited (GtkWidget *widget, GdkEventExpose *event) 0, allocation.width, allocation.height); -#endif } +#endif -static gboolean #if GTK_CHECK_VERSION (3, 0, 0) +static gboolean msd_osd_window_draw (GtkWidget *widget, - cairo_t *cr) -#else -msd_osd_window_expose_event (GtkWidget *widget, - GdkEventExpose *event) -#endif + cairo_t *cr) { MsdOsdWindow *window; GtkWidget *child; window = MSD_OSD_WINDOW (widget); -#if GTK_CHECK_VERSION (3, 0, 0) if (window->priv->is_composited) draw_when_composited (widget, cr); else draw_when_not_composited (widget, cr); + + child = gtk_bin_get_child (GTK_BIN (window)); + if (child) + gtk_container_propagate_draw (GTK_CONTAINER (window), child, cr); + + return FALSE; +} #else +static gboolean +msd_osd_window_expose_event (GtkWidget *widget, + GdkEventExpose *event) +{ + MsdOsdWindow *window; + GtkWidget *child; + + window = MSD_OSD_WINDOW (widget); + if (window->priv->is_composited) expose_when_composited (widget, event); else expose_when_not_composited (widget, event); -#endif child = gtk_bin_get_child (GTK_BIN (window)); if (child) -#if GTK_CHECK_VERSION (3, 0, 0) - gtk_container_propagate_draw (GTK_CONTAINER (window), child, cr); -#else gtk_container_propagate_expose (GTK_CONTAINER (window), child, event); -#endif - return FALSE; + return FALSE; } +#endif static void msd_osd_window_real_show (GtkWidget *widget) @@ -448,39 +474,40 @@ msd_osd_window_real_realize (GtkWidget *widget) GdkScreen *screen; GdkVisual *visual; cairo_region_t *region; -#else - GdkColormap *colormap; - GtkAllocation allocation; - GdkBitmap *mask; - cairo_t *cr; -#endif -#if GTK_CHECK_VERSION (3, 0, 0) screen = gtk_widget_get_screen (widget); visual = gdk_screen_get_rgba_visual (screen); if (visual == NULL) { visual = gdk_screen_get_system_visual (screen); } + gtk_widget_set_visual (widget, visual); + + if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->realize) { + GTK_WIDGET_CLASS (msd_osd_window_parent_class)->realize (widget); + } + + /* make the whole window ignore events */ + region = cairo_region_create (); + gtk_widget_input_shape_combine_region (widget, region); + cairo_region_destroy (region); #else + GdkColormap *colormap; + GtkAllocation allocation; + GdkBitmap *mask; + cairo_t *cr; + colormap = gdk_screen_get_rgba_colormap (gtk_widget_get_screen (widget)); if (colormap != NULL) { gtk_widget_set_colormap (widget, colormap); } -#endif if (GTK_WIDGET_CLASS (msd_osd_window_parent_class)->realize) { GTK_WIDGET_CLASS (msd_osd_window_parent_class)->realize (widget); } -#if GTK_CHECK_VERSION (3, 0, 0) - /* make the whole window ignore events */ - region = cairo_region_create (); - gtk_widget_input_shape_combine_region (widget, region); - cairo_region_destroy (region); -#else gtk_widget_get_allocation (widget, &allocation); mask = gdk_pixmap_new (gtk_widget_get_window (widget), allocation.width, @@ -498,9 +525,8 @@ msd_osd_window_real_realize (GtkWidget *widget) cairo_destroy (cr); #endif } - -static void #if GTK_CHECK_VERSION (3, 0, 0) +static void msd_osd_window_style_updated (GtkWidget *widget) { GtkStyleContext *context; @@ -518,6 +544,7 @@ msd_osd_window_style_updated (GtkWidget *widget) gtk_container_set_border_width (GTK_CONTAINER (widget), 12 + MAX (padding.left, padding.top)); } #else +static void msd_osd_window_style_set (GtkWidget *widget, GtkStyle *previous_style) { @@ -534,7 +561,6 @@ msd_osd_window_style_set (GtkWidget *widget, gtk_container_set_border_width (GTK_CONTAINER (widget), 12 + MAX (style->xthickness, style->ythickness)); } #endif - #if GTK_CHECK_VERSION (3, 0, 0) static void msd_osd_window_get_preferred_width (GtkWidget *widget, @@ -640,7 +666,7 @@ msd_osd_window_class_init (MsdOsdWindowClass *klass) #endif #if GTK_CHECK_VERSION (3, 0, 0) - signals[EXPOSE_WHEN_COMPOSITED] = g_signal_new ("draw-when-composited", + signals[DRAW_WHEN_COMPOSITED] = g_signal_new ("draw-when-composited", #else signals[EXPOSE_WHEN_COMPOSITED] = g_signal_new ("expose-when-composited", #endif diff --git a/src/msd-osd-window.h b/src/msd-osd-window.h index 52c464f..42229f4 100644 --- a/src/msd-osd-window.h +++ b/src/msd-osd-window.h @@ -84,6 +84,7 @@ gboolean msd_osd_window_is_composited (MsdOsdWindow *windo gboolean msd_osd_window_is_valid (MsdOsdWindow *window); void msd_osd_window_update_and_hide (MsdOsdWindow *window); +#if !GTK_CHECK_VERSION (3, 0, 0) void msd_osd_window_draw_rounded_rectangle (cairo_t *cr, gdouble aspect, gdouble x, @@ -92,7 +93,6 @@ void msd_osd_window_draw_rounded_rectangle (cairo_t *cr, gdouble width, gdouble height); -#if !GTK_CHECK_VERSION (3, 0, 0) void msd_osd_window_color_reverse (const GdkColor *a, GdkColor *b); #endif |