From e342e7ae390c4496cea301bf1942a03916d4de44 Mon Sep 17 00:00:00 2001 From: Denis Gorodnichev Date: Tue, 10 May 2016 23:38:44 +0300 Subject: gtk3: css themes for MsdOsdWindow --- src/gsd-media-keys-window.c | 37 +++++++++++++++++++++++++++++++++++- src/msd-osd-window.c | 46 +++++++++++++++++++++++++++++++++++++-------- src/msd-osd-window.h | 2 ++ 3 files changed, 76 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/gsd-media-keys-window.c b/src/gsd-media-keys-window.c index 63f93a5..5bcca8e 100644 --- a/src/gsd-media-keys-window.c +++ b/src/gsd-media-keys-window.c @@ -30,6 +30,11 @@ #include #include +#if GTK_CHECK_VERSION (3, 0, 0) +#define MATE_DESKTOP_USE_UNSTABLE_API +#include +#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)) @@ -402,44 +407,74 @@ draw_volume_boxes (MsdMediaKeysWindow *window, double height) { gdouble x1; +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color; + GtkStyleContext *style; +#else GdkColor color; double r, g, b; GtkStyle *style; +#endif _x0 += 0.5; _y0 += 0.5; 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)); +#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); +#else msd_osd_window_color_reverse (&style->dark[GTK_STATE_NORMAL], &color); 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, _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); } diff --git a/src/msd-osd-window.c b/src/msd-osd-window.c index 46dfebd..e15927f 100644 --- a/src/msd-osd-window.c +++ b/src/msd-osd-window.c @@ -191,6 +191,7 @@ 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) @@ -220,6 +221,7 @@ msd_osd_window_color_reverse (const GdkColor *a, b->green = green * 65535.0; b->blue = blue * 65535.0; } +#endif /* This is our expose-event handler when the window is in a compositing manager. * We draw everything by hand, using Cairo, so that we can have a nice @@ -240,9 +242,13 @@ expose_when_composited (GtkWidget *widget, GdkEventExpose *event) cairo_surface_t *surface; int width; int height; +#if GTK_CHECK_VERSION (3, 0, 0) + GtkStyleContext *style; +#else GtkStyle *style; GdkColor color; double r, g, b; +#endif window = MSD_OSD_WINDOW (widget); @@ -250,7 +256,11 @@ expose_when_composited (GtkWidget *widget, GdkEventExpose *event) context = gdk_cairo_create (gtk_widget_get_window (widget)); #endif +#if GTK_CHECK_VERSION (3, 0, 0) + style = gtk_widget_get_style_context (widget); +#else style = gtk_widget_get_style (widget); +#endif cairo_set_operator (context, CAIRO_OPERATOR_SOURCE); gtk_window_get_size (GTK_WINDOW (widget), &width, &height); @@ -267,10 +277,15 @@ expose_when_composited (GtkWidget *widget, GdkEventExpose *event) if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) { goto done; } +#if !GTK_CHECK_VERSION (3, 0, 0) cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); cairo_paint (cr); +#endif +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_render_background (style, 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); msd_osd_window_color_reverse (&style->bg[GTK_STATE_NORMAL], &color); @@ -287,6 +302,7 @@ expose_when_composited (GtkWidget *widget, GdkEventExpose *event) cairo_set_source_rgba (cr, r, g, b, BG_ALPHA / 2); cairo_set_line_width (cr, 1); cairo_stroke (cr); +#endif g_signal_emit (window, signals[EXPOSE_WHEN_COMPOSITED], 0, cr); @@ -339,25 +355,23 @@ expose_when_not_composited (GtkWidget *widget, GdkEventExpose *event) gtk_widget_get_allocation (widget, &allocation); #endif - gtk_paint_shadow (gtk_widget_get_style (widget), #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), -#endif gtk_widget_get_state (widget), GTK_SHADOW_OUT, -#if !GTK_CHECK_VERSION (3, 0, 0) &event->area, -#endif widget, NULL, /* NULL detail -> themes should use the MsdOsdWindow widget name, probably */ 0, 0, -#if GTK_CHECK_VERSION (3, 0, 0) - width, - height); -#else allocation.width, allocation.height); #endif @@ -571,6 +585,12 @@ msd_osd_window_constructor (GType type, "focus-on-map", FALSE, NULL); +#if GTK_CHECK_VERSION (3, 0, 0) + GtkWidget *widget = GTK_WIDGET (object); + GtkStyleContext *style_context = gtk_widget_get_style_context (widget); + gtk_style_context_add_class (style_context, "osd"); +#endif + return object; } @@ -612,6 +632,11 @@ msd_osd_window_class_init (MsdOsdWindowClass *klass) G_TYPE_NONE, 1, G_TYPE_POINTER); +#if GTK_CHECK_VERSION (3, 20, 0) + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); + gtk_widget_class_set_css_name (widget_class, "MsdOsdWindow"); +#endif + g_type_class_add_private (klass, sizeof (MsdOsdWindowPrivate)); } @@ -659,6 +684,11 @@ msd_osd_window_init (MsdOsdWindow *window) gtk_window_set_decorated (GTK_WINDOW (window), FALSE); gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE); +#if GTK_CHECK_VERSION (3, 0, 0) + GtkStyleContext *style = gtk_widget_get_style_context (GTK_WIDGET (window)); + gtk_style_context_add_class (style, "window-frame"); +#endif + /* assume 130x130 on a 640x480 display and scale from there */ scalew = gdk_screen_get_width (screen) / 640.0; scaleh = gdk_screen_get_height (screen) / 480.0; diff --git a/src/msd-osd-window.h b/src/msd-osd-window.h index fd33d36..52c464f 100644 --- a/src/msd-osd-window.h +++ b/src/msd-osd-window.h @@ -92,8 +92,10 @@ 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 #ifdef __cplusplus } -- cgit v1.2.1