diff options
author | Denis Gorodnichev <[email protected]> | 2014-07-24 10:37:41 +0400 |
---|---|---|
committer | infirit <[email protected]> | 2014-11-25 18:06:24 +0100 |
commit | b25395fab6fe9ee38bc0cd359941d0a825d88451 (patch) | |
tree | e7b6720a543a00495fae1dd1423d652056bedb03 /src/ui | |
parent | b8d8e52f0effbf76ff909f88932098d4daf4336e (diff) | |
download | marco-b25395fab6fe9ee38bc0cd359941d0a825d88451.tar.bz2 marco-b25395fab6fe9ee38bc0cd359941d0a825d88451.tar.xz |
merge metacity(gtk3) changes
merge metacity(gtk3) changes
fix warnings
clean up unused variables
replace UNUSED_VARIABLE by G_GNUC_UNUSED
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/draw-workspace.c | 60 | ||||
-rw-r--r-- | src/ui/fixedtip.c | 2 | ||||
-rw-r--r-- | src/ui/fixedtip.h | 3 | ||||
-rw-r--r-- | src/ui/frames.c | 49 | ||||
-rw-r--r-- | src/ui/gradient.c | 174 | ||||
-rw-r--r-- | src/ui/gradient.h | 20 | ||||
-rw-r--r-- | src/ui/menu.c | 15 | ||||
-rw-r--r-- | src/ui/preview-widget.c | 120 | ||||
-rw-r--r-- | src/ui/resizepopup.c | 2 | ||||
-rw-r--r-- | src/ui/tabpopup.c | 60 | ||||
-rw-r--r-- | src/ui/testgradient.c | 117 | ||||
-rw-r--r-- | src/ui/theme-parser.c | 12 | ||||
-rw-r--r-- | src/ui/theme.c | 511 | ||||
-rw-r--r-- | src/ui/theme.h | 74 | ||||
-rw-r--r-- | src/ui/tile-preview.c | 74 | ||||
-rw-r--r-- | src/ui/ui.c | 8 |
16 files changed, 985 insertions, 316 deletions
diff --git a/src/ui/draw-workspace.c b/src/ui/draw-workspace.c index 1831b46c..a40579db 100644 --- a/src/ui/draw-workspace.c +++ b/src/ui/draw-workspace.c @@ -27,6 +27,11 @@ #include "draw-workspace.h" +#if GTK_CHECK_VERSION (3, 0, 0) +#define MATE_DESKTOP_USE_UNSTABLE_API +#include <libmate-desktop/mate-desktop-utils.h> +#endif + static void get_window_rect (const WnckWindowDisplayInfo *win, @@ -83,13 +88,18 @@ draw_window (GtkWidget *widget, GdkPixbuf *icon; int icon_x, icon_y, icon_w, icon_h; gboolean is_active; +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color; + GtkStyleContext *style; +#else GdkColor *color; GtkStyle *style; +#endif is_active = win->is_active; #if GTK_CHECK_VERSION(3, 0, 0) - cairo_save(cr); + cairo_save (cr); #else cr = gdk_cairo_create (drawable); #endif @@ -97,6 +107,14 @@ draw_window (GtkWidget *widget, cairo_rectangle (cr, winrect->x, winrect->y, winrect->width, winrect->height); cairo_clip (cr); +#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); + else + gtk_style_context_get_background_color (style, state, &color); + gdk_cairo_set_source_rgba (cr, &color); +#else style = gtk_widget_get_style (widget); if (is_active) color = &style->light[state]; @@ -106,6 +124,7 @@ draw_window (GtkWidget *widget, color->red / 65535., color->green / 65535., color->blue / 65535.); +#endif cairo_rectangle (cr, winrect->x + 1, winrect->y + 1, @@ -156,15 +175,17 @@ draw_window (GtkWidget *widget, cairo_restore (cr); } - if (is_active) - color = &style->fg[state]; - else - color = &style->fg[state]; +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_style_context_get_color (style, state, &color); + gdk_cairo_set_source_rgba (cr, &color); +#else + color = &style->fg[state]; cairo_set_source_rgb (cr, color->red / 65535., color->green / 65535., color->blue / 65535.); +#endif cairo_set_line_width (cr, 1.0); cairo_rectangle (cr, winrect->x + 0.5, winrect->y + 0.5, @@ -198,10 +219,13 @@ wnck_draw_workspace (GtkWidget *widget, { int i; GdkRectangle workspace_rect; +#if GTK_CHECK_VERSION(3, 0, 0) + GtkStateFlags state; + GtkStyleContext *style; +#else GtkStateType state; - #if !GTK_CHECK_VERSION(3, 0, 0) cairo_t *cr; - #endif +#endif workspace_rect.x = x; workspace_rect.y = y; @@ -209,14 +233,27 @@ wnck_draw_workspace (GtkWidget *widget, workspace_rect.height = height; if (is_active) +#if GTK_CHECK_VERSION (3, 0, 0) + state = GTK_STATE_FLAG_SELECTED; +#else state = GTK_STATE_SELECTED; +#endif else if (workspace_background) +#if GTK_CHECK_VERSION (3, 0, 0) + state = GTK_STATE_FLAG_PRELIGHT; +#else state = GTK_STATE_PRELIGHT; +#endif else +#if GTK_CHECK_VERSION (3, 0, 0) + state = GTK_STATE_FLAG_NORMAL; +#else state = GTK_STATE_NORMAL; +#endif #if GTK_CHECK_VERSION(3, 0, 0) - cairo_save(cr); + style = gtk_widget_get_style_context (widget); + cairo_save (cr); #else cr = gdk_cairo_create (drawable); #endif @@ -228,7 +265,14 @@ wnck_draw_workspace (GtkWidget *widget, } else { +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color; + + mate_desktop_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]); +#endif cairo_rectangle (cr, x, y, width, height); cairo_fill (cr); } diff --git a/src/ui/fixedtip.c b/src/ui/fixedtip.c index 6f07c6bb..fc1be2af 100644 --- a/src/ui/fixedtip.c +++ b/src/ui/fixedtip.c @@ -84,7 +84,7 @@ expose_handler (GtkTooltips *tooltips) #endif void -meta_fixed_tip_show (Display *xdisplay, int screen_number, +meta_fixed_tip_show (int screen_number, int root_x, int root_y, const char *markup_text) { diff --git a/src/ui/fixedtip.h b/src/ui/fixedtip.h index e3eac8f5..f20f0d2c 100644 --- a/src/ui/fixedtip.h +++ b/src/ui/fixedtip.h @@ -49,13 +49,12 @@ * displayed, but if it is the window will be reused rather than destroyed * and recreated. * - * \param xdisplay An X display. * \param screen_number The number of the screen. * \param root_x The X coordinate where the tooltip should appear * \param root_y The Y coordinate where the tooltip should appear * \param markup_text Text to display in the tooltip; can contain markup */ -void meta_fixed_tip_show (Display *xdisplay, int screen_number, +void meta_fixed_tip_show (int screen_number, int root_x, int root_y, const char *markup_text); diff --git a/src/ui/frames.c b/src/ui/frames.c index 60e09ea3..099c5052 100644 --- a/src/ui/frames.c +++ b/src/ui/frames.c @@ -1099,16 +1099,14 @@ meta_frames_move_resize_frame (MetaFrames *frames, int height) { MetaUIFrame *frame = meta_frames_lookup_window (frames, xwindow); - int old_x, old_y, old_width, old_height; + int old_width, old_height; - #if GTK_CHECK_VERSION(3, 0, 0) - old_width = gdk_window_get_width(GDK_WINDOW(frame->window)); - old_height = gdk_window_get_height(GDK_WINDOW(frame->window)); - #else - gdk_drawable_get_size(frame->window, &old_width, &old_height); - #endif - - gdk_window_get_position (frame->window, &old_x, &old_y); +#if GTK_CHECK_VERSION(3, 0, 0) + old_width = gdk_window_get_width (frame->window); + old_height = gdk_window_get_height (frame->window); +#else + gdk_drawable_get_size(frame->window, &old_width, &old_height); +#endif gdk_window_move_resize (frame->window, x, y, width, height); @@ -1270,8 +1268,7 @@ show_tip_now (MetaFrames *frames) screen_number = gdk_screen_get_number (gtk_widget_get_screen (GTK_WIDGET (frames))); - meta_fixed_tip_show (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), - screen_number, + meta_fixed_tip_show (screen_number, rect->x + dx, rect->y + rect->height + 2 + dy, tiptext); @@ -2580,7 +2577,6 @@ meta_frames_paint_to_drawable (MetaFrames *frames, int y_offset) #endif { - GtkWidget *widget; MetaFrameFlags flags; MetaFrameType type; GdkPixbuf *mini_icon; @@ -2592,8 +2588,6 @@ meta_frames_paint_to_drawable (MetaFrames *frames, MetaButtonLayout button_layout; MetaGrabOp grab_op; - widget = GTK_WIDGET (frames); - for (i = 0; i < META_BUTTON_TYPE_LAST; i++) button_states[i] = META_BUTTON_STATE_NORMAL; @@ -2694,7 +2688,6 @@ meta_frames_paint_to_drawable (MetaFrames *frames, meta_theme_draw_frame_with_style (meta_theme_get_current (), frame->style, - widget, cr, type, flags, @@ -2767,8 +2760,11 @@ meta_frames_paint_to_drawable (MetaFrames *frames, gdk_window_begin_paint_rect (drawable, &areas[i]); meta_theme_draw_frame_with_style (meta_theme_get_current (), +#if GTK_CHECK_VERSION (3, 0, 0) frame->style, - widget, +#else + GTK_WIDGET(frames), +#endif drawable, NULL, /* &areas[i], */ x_offset, y_offset, @@ -2793,8 +2789,11 @@ meta_frames_paint_to_drawable (MetaFrames *frames, /* Not a window; happens about 1/3 of the time */ meta_theme_draw_frame_with_style (meta_theme_get_current (), +#if GTK_CHECK_VERSION (3, 0, 0) frame->style, - widget, +#else + GTK_WIDGET(frames), +#endif drawable, NULL, x_offset, y_offset, @@ -2835,23 +2834,35 @@ meta_frames_set_window_background (MetaFrames *frames, if (frame_exists && style->window_background_color != NULL) { +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color; +#else GdkColor color; +#endif GdkVisual *visual; meta_color_spec_render (style->window_background_color, - GTK_WIDGET (frames), + frame->style, &color); /* Set A in ARGB to window_background_alpha, if we have ARGB */ visual = gtk_widget_get_visual (GTK_WIDGET (frames)); - if (gdk_visual_get_depth(visual) == 32) /* we have ARGB */ + if (gdk_visual_get_depth (visual) == 32) /* we have ARGB */ + #if GTK_CHECK_VERSION(3, 0, 0) + { + color.alpha = style->window_background_alpha / 255.0; + } + + gdk_window_set_background_rgba (frame->window, &color); + #else { color.pixel = (color.pixel & 0xffffff) & style->window_background_alpha << 24; } gdk_window_set_background (frame->window, &color); + #endif } else { diff --git a/src/ui/gradient.c b/src/ui/gradient.c index 78a5a9eb..dfdb2fa1 100644 --- a/src/ui/gradient.c +++ b/src/ui/gradient.c @@ -26,9 +26,37 @@ #include "util.h" #include <string.h> +#include <gtk/gtk.h> + /* This is all Alfredo's and Dan's usual very nice WindowMaker code, * slightly GTK-ized */ +#if GTK_CHECK_VERSION (3, 0, 0) +static GdkPixbuf* meta_gradient_create_horizontal (int width, + int height, + const GdkRGBA *from, + const GdkRGBA *to); +static GdkPixbuf* meta_gradient_create_vertical (int width, + int height, + const GdkRGBA *from, + const GdkRGBA *to); +static GdkPixbuf* meta_gradient_create_diagonal (int width, + int height, + const GdkRGBA *from, + const GdkRGBA *to); +static GdkPixbuf* meta_gradient_create_multi_horizontal (int width, + int height, + const GdkRGBA *colors, + int count); +static GdkPixbuf* meta_gradient_create_multi_vertical (int width, + int height, + const GdkRGBA *colors, + int count); +static GdkPixbuf* meta_gradient_create_multi_diagonal (int width, + int height, + const GdkRGBA *colors, + int count); +#else static GdkPixbuf* meta_gradient_create_horizontal (int width, int height, const GdkColor *from, @@ -53,6 +81,7 @@ static GdkPixbuf* meta_gradient_create_multi_diagonal (int width, int height, const GdkColor *colors, int count); +#endif /* Used as the destroy notification function for gdk_pixbuf_new() */ @@ -87,12 +116,21 @@ blank_pixbuf (int width, int height, gboolean no_padding) free_buffer, NULL); } +#if GTK_CHECK_VERSION (3, 0, 0) +GdkPixbuf* +meta_gradient_create_simple (int width, + int height, + const GdkRGBA *from, + const GdkRGBA *to, + MetaGradientType style) +#else GdkPixbuf* meta_gradient_create_simple (int width, int height, const GdkColor *from, const GdkColor *to, MetaGradientType style) +#endif { switch (style) { @@ -113,12 +151,21 @@ meta_gradient_create_simple (int width, return NULL; } +#if GTK_CHECK_VERSION (3, 0, 0) +GdkPixbuf* +meta_gradient_create_multi (int width, + int height, + const GdkRGBA *colors, + int n_colors, + MetaGradientType style) +#else GdkPixbuf* meta_gradient_create_multi (int width, int height, const GdkColor *colors, int n_colors, MetaGradientType style) +#endif { if (n_colors > 2) @@ -155,6 +202,15 @@ meta_gradient_create_multi (int width, * are alternated. I'm not sure what it's good for, just copied since * WindowMaker had it. */ +#if GTK_CHECK_VERSION (3, 0, 0) +GdkPixbuf* +meta_gradient_create_interwoven (int width, + int height, + const GdkRGBA colors1[2], + int thickness1, + const GdkRGBA colors2[2], + int thickness2) +#else GdkPixbuf* meta_gradient_create_interwoven (int width, int height, @@ -162,6 +218,7 @@ meta_gradient_create_interwoven (int width, int thickness1, const GdkColor colors2[2], int thickness2) +#endif { int i, j, k, l, ll; @@ -179,6 +236,23 @@ meta_gradient_create_interwoven (int width, pixels = gdk_pixbuf_get_pixels (pixbuf); rowstride = gdk_pixbuf_get_rowstride (pixbuf); +#if GTK_CHECK_VERSION (3, 0, 0) + r1 = (long)(colors1[0].red*0xffffff); + g1 = (long)(colors1[0].green*0xffffff); + b1 = (long)(colors1[0].blue*0xffffff); + + r2 = (long)(colors2[0].red*0xffffff); + g2 = (long)(colors2[0].green*0xffffff); + b2 = (long)(colors2[0].blue*0xffffff); + + dr1 = ((colors1[1].red-colors1[0].red)*0xffffff)/(int)height; + dg1 = ((colors1[1].green-colors1[0].green)*0xffffff)/(int)height; + db1 = ((colors1[1].blue-colors1[0].blue)*0xffffff)/(int)height; + + dr2 = ((colors2[1].red-colors2[0].red)*0xffffff)/(int)height; + dg2 = ((colors2[1].green-colors2[0].green)*0xffffff)/(int)height; + db2 = ((colors2[1].blue-colors2[0].blue)*0xffffff)/(int)height; +#else r1 = colors1[0].red<<8; g1 = colors1[0].green<<8; b1 = colors1[0].blue<<8; @@ -194,6 +268,7 @@ meta_gradient_create_interwoven (int width, dr2 = ((colors2[1].red-colors2[0].red)<<8)/(int)height; dg2 = ((colors2[1].green-colors2[0].green)<<8)/(int)height; db2 = ((colors2[1].blue-colors2[0].blue)<<8)/(int)height; +#endif for (i=0,k=0,l=0,ll=thickness1; i<height; i++) { @@ -255,10 +330,17 @@ meta_gradient_create_interwoven (int width, * None *---------------------------------------------------------------------- */ +#if GTK_CHECK_VERSION (3, 0, 0) +static GdkPixbuf* +meta_gradient_create_horizontal (int width, int height, + const GdkRGBA *from, + const GdkRGBA *to) +#else static GdkPixbuf* meta_gradient_create_horizontal (int width, int height, const GdkColor *from, const GdkColor *to) +#endif { int i; long r, g, b, dr, dg, db; @@ -277,12 +359,21 @@ meta_gradient_create_horizontal (int width, int height, ptr = pixels; rowstride = gdk_pixbuf_get_rowstride (pixbuf); +#if GTK_CHECK_VERSION (3, 0, 0) + r0 = (guchar) (from->red * 0xff); + g0 = (guchar) (from->green * 0xff); + b0 = (guchar) (from->blue * 0xff); + rf = (guchar) (to->red * 0xff); + gf = (guchar) (to->green * 0xff); + bf = (guchar) (to->blue * 0xff); +#else r0 = (guchar) (from->red / 256.0); g0 = (guchar) (from->green / 256.0); b0 = (guchar) (from->blue / 256.0); rf = (guchar) (to->red / 256.0); gf = (guchar) (to->green / 256.0); bf = (guchar) (to->blue / 256.0); +#endif r = r0 << 16; g = g0 << 16; @@ -323,10 +414,17 @@ meta_gradient_create_horizontal (int width, int height, * None *---------------------------------------------------------------------- */ +#if GTK_CHECK_VERSION (3, 0, 0) +static GdkPixbuf* +meta_gradient_create_vertical (int width, int height, + const GdkRGBA *from, + const GdkRGBA *to) +#else static GdkPixbuf* meta_gradient_create_vertical (int width, int height, const GdkColor *from, const GdkColor *to) +#endif { int i, j; long r, g, b, dr, dg, db; @@ -344,12 +442,21 @@ meta_gradient_create_vertical (int width, int height, pixels = gdk_pixbuf_get_pixels (pixbuf); rowstride = gdk_pixbuf_get_rowstride (pixbuf); +#if GTK_CHECK_VERSION (3, 0, 0) + r0 = (guchar) (from->red * 0xff); + g0 = (guchar) (from->green * 0xff); + b0 = (guchar) (from->blue * 0xff); + rf = (guchar) (to->red * 0xff); + gf = (guchar) (to->green * 0xff); + bf = (guchar) (to->blue * 0xff); +#else r0 = (guchar) (from->red / 256.0); g0 = (guchar) (from->green / 256.0); b0 = (guchar) (from->blue / 256.0); rf = (guchar) (to->red / 256.0); gf = (guchar) (to->green / 256.0); bf = (guchar) (to->blue / 256.0); +#endif r = r0<<16; g = g0<<16; @@ -393,11 +500,17 @@ meta_gradient_create_vertical (int width, int height, *---------------------------------------------------------------------- */ - +#if GTK_CHECK_VERSION (3, 0, 0) +static GdkPixbuf* +meta_gradient_create_diagonal (int width, int height, + const GdkRGBA *from, + const GdkRGBA *to) +#else static GdkPixbuf* meta_gradient_create_diagonal (int width, int height, const GdkColor *from, const GdkColor *to) +#endif { GdkPixbuf *pixbuf, *tmp; int j; @@ -441,11 +554,17 @@ meta_gradient_create_diagonal (int width, int height, return pixbuf; } - +#if GTK_CHECK_VERSION (3, 0, 0) +static GdkPixbuf* +meta_gradient_create_multi_horizontal (int width, int height, + const GdkRGBA *colors, + int count) +#else static GdkPixbuf* meta_gradient_create_multi_horizontal (int width, int height, const GdkColor *colors, int count) +#endif { int i, j, k; long r, g, b, dr, dg, db; @@ -475,16 +594,28 @@ meta_gradient_create_multi_horizontal (int width, int height, k = 0; +#if GTK_CHECK_VERSION (3, 0, 0) + r = (long)(colors[0].red * 0xffffff); + g = (long)(colors[0].green * 0xffffff); + b = (long)(colors[0].blue * 0xffffff); +#else r = colors[0].red << 8; g = colors[0].green << 8; b = colors[0].blue << 8; +#endif /* render the first line */ for (i=1; i<count; i++) { +#if GTK_CHECK_VERSION (3, 0, 0) + dr = (int)((colors[i].red - colors[i-1].red) *0xffffff)/(int)width2; + dg = (int)((colors[i].green - colors[i-1].green)*0xffffff)/(int)width2; + db = (int)((colors[i].blue - colors[i-1].blue) *0xffffff)/(int)width2; +#else dr = ((int)(colors[i].red - colors[i-1].red) <<8)/(int)width2; dg = ((int)(colors[i].green - colors[i-1].green)<<8)/(int)width2; db = ((int)(colors[i].blue - colors[i-1].blue) <<8)/(int)width2; +#endif for (j=0; j<width2; j++) { *ptr++ = (unsigned char)(r>>16); @@ -495,9 +626,15 @@ meta_gradient_create_multi_horizontal (int width, int height, b += db; k++; } +#if GTK_CHECK_VERSION (3, 0, 0) + r = (long)(colors[i].red * 0xffffff); + g = (long)(colors[i].green * 0xffffff); + b = (long)(colors[i].blue * 0xffffff); +#else r = colors[i].red << 8; g = colors[i].green << 8; b = colors[i].blue << 8; +#endif } for (j=k; j<width; j++) { @@ -514,10 +651,17 @@ meta_gradient_create_multi_horizontal (int width, int height, return pixbuf; } +#if GTK_CHECK_VERSION (3, 0, 0) +static GdkPixbuf* +meta_gradient_create_multi_vertical (int width, int height, + const GdkRGBA *colors, + int count) +#else static GdkPixbuf* meta_gradient_create_multi_vertical (int width, int height, const GdkColor *colors, int count) +#endif { int i, j, k; long r, g, b, dr, dg, db; @@ -547,15 +691,27 @@ meta_gradient_create_multi_vertical (int width, int height, k = 0; +#if GTK_CHECK_VERSION (3, 0, 0) + r = (long)(colors[0].red * 0xffffff); + g = (long)(colors[0].green * 0xffffff); + b = (long)(colors[0].blue * 0xffffff); +#else r = colors[0].red << 8; g = colors[0].green << 8; b = colors[0].blue << 8; +#endif for (i=1; i<count; i++) { +#if GTK_CHECK_VERSION (3, 0, 0) + dr = (int)((colors[i].red - colors[i-1].red) *0xffffff)/(int)height2; + dg = (int)((colors[i].green - colors[i-1].green)*0xffffff)/(int)height2; + db = (int)((colors[i].blue - colors[i-1].blue) *0xffffff)/(int)height2; +#else dr = ((int)(colors[i].red - colors[i-1].red) <<8)/(int)height2; dg = ((int)(colors[i].green - colors[i-1].green)<<8)/(int)height2; db = ((int)(colors[i].blue - colors[i-1].blue) <<8)/(int)height2; +#endif for (j=0; j<height2; j++) { @@ -574,9 +730,15 @@ meta_gradient_create_multi_vertical (int width, int height, b += db; k++; } +#if GTK_CHECK_VERSION (3, 0, 0) + r = (long)(colors[i].red * 0xffffff); + g = (long)(colors[i].green * 0xffffff); + b = (long)(colors[i].blue * 0xffffff); +#else r = colors[i].red << 8; g = colors[i].green << 8; b = colors[i].blue << 8; +#endif } if (k<height) @@ -603,11 +765,17 @@ meta_gradient_create_multi_vertical (int width, int height, return pixbuf; } - +#if GTK_CHECK_VERSION (3, 0, 0) +static GdkPixbuf* +meta_gradient_create_multi_diagonal (int width, int height, + const GdkRGBA *colors, + int count) +#else static GdkPixbuf* meta_gradient_create_multi_diagonal (int width, int height, const GdkColor *colors, int count) +#endif { GdkPixbuf *pixbuf, *tmp; float a, offset; diff --git a/src/ui/gradient.h b/src/ui/gradient.h index b65b3878..7cbe8977 100644 --- a/src/ui/gradient.h +++ b/src/ui/gradient.h @@ -26,6 +26,7 @@ #include <gdk-pixbuf/gdk-pixbuf.h> #include <gdk/gdk.h> +#include <gtk/gtk.h> typedef enum { @@ -35,6 +36,24 @@ typedef enum META_GRADIENT_LAST } MetaGradientType; +#if GTK_CHECK_VERSION (3, 0 ,0) +GdkPixbuf* meta_gradient_create_simple (int width, + int height, + const GdkRGBA *from, + const GdkRGBA *to, + MetaGradientType style); +GdkPixbuf* meta_gradient_create_multi (int width, + int height, + const GdkRGBA *colors, + int n_colors, + MetaGradientType style); +GdkPixbuf* meta_gradient_create_interwoven (int width, + int height, + const GdkRGBA colors1[2], + int thickness1, + const GdkRGBA colors2[2], + int thickness2); +#else GdkPixbuf* meta_gradient_create_simple (int width, int height, const GdkColor *from, @@ -51,6 +70,7 @@ GdkPixbuf* meta_gradient_create_interwoven (int width, int thickness1, const GdkColor colors2[2], int thickness2); +#endif /* Generate an alpha gradient and multiply it with the existing alpha diff --git a/src/ui/menu.c b/src/ui/menu.c index 41abc441..1dfc7140 100644 --- a/src/ui/menu.c +++ b/src/ui/menu.c @@ -106,7 +106,11 @@ static void popup_position_func(GtkMenu* menu, gint* x, gint* y, gboolean* push_ pos = user_data; +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL); +#else gtk_widget_size_request(GTK_WIDGET(menu), &req); +#endif *x = pos->x; *y = pos->y; @@ -148,7 +152,7 @@ static void activate_cb(GtkWidget* menuitem, gpointer data) md = data; - meta_frames_notify_menu_hide(md->menu->frames); + meta_frames_notify_menu_hide (md->menu->frames); (*md->menu->func)( md->menu, @@ -159,7 +163,7 @@ static void activate_cb(GtkWidget* menuitem, gpointer data) GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), "workspace")), md->menu->data); - /* menu may now be freed */ + /* menu may now be freed */ } /* @@ -389,7 +393,7 @@ meta_window_menu_new (MetaFrames *frames, meta_verbose ("Creating %d-workspace menu current space %lu\n", n_workspaces, active_workspace); - GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(frames)); + GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (frames)); display = GDK_WINDOW_XDISPLAY (window); @@ -497,9 +501,10 @@ meta_window_menu_new (MetaFrames *frames, } } - g_signal_connect (menu->menu, "selection_done", G_CALLBACK(menu_closed), menu); + g_signal_connect (menu->menu, "selection_done", + G_CALLBACK (menu_closed), menu); - return menu; + return menu; } void meta_window_menu_popup(MetaWindowMenu* menu, int root_x, int root_y, int button, guint32 timestamp) diff --git a/src/ui/preview-widget.c b/src/ui/preview-widget.c index 0bc6b42a..58122706 100644 --- a/src/ui/preview-widget.c +++ b/src/ui/preview-widget.c @@ -253,6 +253,66 @@ ensure_info (MetaPreview *preview) } #if GTK_CHECK_VERSION(3, 0, 0) +static gboolean +meta_preview_draw (GtkWidget *widget, + cairo_t *cr) +{ + MetaPreview *preview; + GtkAllocation allocation; + int border_width; + int client_width; + int client_height; + MetaButtonState button_states[META_BUTTON_TYPE_LAST] = + { + META_BUTTON_STATE_NORMAL, + META_BUTTON_STATE_NORMAL, + META_BUTTON_STATE_NORMAL, + META_BUTTON_STATE_NORMAL + }; + + g_return_val_if_fail (META_IS_PREVIEW (widget), FALSE); + + preview = META_PREVIEW (widget); + + ensure_info (preview); + + cairo_save (cr); + + border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); + + gtk_widget_get_allocation (widget, &allocation); + client_width = allocation.width - preview->left_width - preview->right_width - border_width * 2; + client_height = allocation.height - preview->top_height - preview->bottom_height - border_width * 2; + + if (client_width < 0) + client_width = 1; + if (client_height < 0) + client_height = 1; + + if (preview->theme) + { + border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); + + meta_theme_draw_frame (preview->theme, + widget, + cr, + preview->type, + preview->flags, + client_width, client_height, + preview->layout, + preview->text_height, + &preview->button_layout, + button_states, + meta_preview_get_mini_icon (), + meta_preview_get_icon ()); + } + + cairo_restore (cr); + + /* draw child */ + return GTK_WIDGET_CLASS (meta_preview_parent_class)->draw (widget, cr); +} + static void meta_preview_get_preferred_width (GtkWidget *widget, gint *minimum, @@ -325,66 +385,6 @@ meta_preview_get_preferred_height (GtkWidget *widget, *natural += border_width * 2; } -static gboolean -meta_preview_draw(GtkWidget *widget, - cairo_t *cr) -{ - MetaPreview *preview; - GtkAllocation allocation; - int border_width; - int client_width; - int client_height; - MetaButtonState button_states[META_BUTTON_TYPE_LAST] = - { - META_BUTTON_STATE_NORMAL, - META_BUTTON_STATE_NORMAL, - META_BUTTON_STATE_NORMAL, - META_BUTTON_STATE_NORMAL - }; - - g_return_val_if_fail (META_IS_PREVIEW (widget), FALSE); - - preview = META_PREVIEW (widget); - - ensure_info (preview); - - cairo_save (cr); - - border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); - - gtk_widget_get_allocation (widget, &allocation); - client_width = allocation.width - preview->left_width - preview->right_width - border_width * 2; - client_height = allocation.height - preview->top_height - preview->bottom_height - border_width * 2; - - if (client_width < 0) - client_width = 1; - if (client_height < 0) - client_height = 1; - - if (preview->theme) - { - border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); - - meta_theme_draw_frame (preview->theme, - widget, - cr, - preview->type, - preview->flags, - client_width, client_height, - preview->layout, - preview->text_height, - &preview->button_layout, - button_states, - meta_preview_get_mini_icon (), - meta_preview_get_icon ()); - } - - cairo_restore (cr); - - /* draw child */ - return GTK_WIDGET_CLASS (meta_preview_parent_class)->draw (widget, cr); -} - #else static gboolean diff --git a/src/ui/resizepopup.c b/src/ui/resizepopup.c index 7dc6ec5a..977b196b 100644 --- a/src/ui/resizepopup.c +++ b/src/ui/resizepopup.c @@ -126,7 +126,7 @@ update_size_window (MetaResizePopup *popup) if (gtk_widget_get_realized (popup->size_window)) { /* using move_resize to avoid jumpiness */ - gdk_window_move_resize (gtk_widget_get_window(GTK_WIDGET(popup->size_window)), + gdk_window_move_resize (gtk_widget_get_window (popup->size_window), x, y, width, height); } diff --git a/src/ui/tabpopup.c b/src/ui/tabpopup.c index 4c4cf308..dfbdf1a4 100644 --- a/src/ui/tabpopup.c +++ b/src/ui/tabpopup.c @@ -81,15 +81,23 @@ static void select_workspace (GtkWidget *widget); static void unselect_workspace (GtkWidget *widget); static gboolean +#if GTK_CHECK_VERSION (3, 0, 0) +outline_window_draw (GtkWidget *widget, + cairo_t *cr, + gpointer data) +#else outline_window_expose (GtkWidget *widget, GdkEventExpose *event, gpointer data) +#endif { MetaTabPopup *popup; TabEntry *te; +#if !GTK_CHECK_VERSION (3, 0, 0) GtkStyle *style; GdkWindow *window; cairo_t *cr; +#endif popup = data; @@ -97,12 +105,18 @@ outline_window_expose (GtkWidget *widget, return FALSE; te = popup->current_selected_entry; +#if !GTK_CHECK_VERSION (3, 0, 0) window = gtk_widget_get_window (widget); style = gtk_widget_get_style (widget); cr = gdk_cairo_create (window); +#endif cairo_set_line_width (cr, 1.0); +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); +#else gdk_cairo_set_source_color (cr, &style->white); +#endif cairo_rectangle (cr, 0.5, 0.5, @@ -116,7 +130,9 @@ outline_window_expose (GtkWidget *widget, te->inner_rect.height + 1); cairo_stroke (cr); +#if !GTK_CHECK_VERSION (3, 0, 0) cairo_destroy (cr); +#endif return FALSE; } @@ -236,7 +252,11 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries, MetaTabPopup *popup; int i, left, right, top, bottom; int height; +#if GTK_CHECK_VERSION (3, 0, 0) + GtkWidget *grid; +#else GtkWidget *table; +#endif GtkWidget *vbox; GtkWidget *align; GList *tmp; @@ -258,8 +278,13 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries, gtk_widget_set_app_paintable (popup->outline_window, TRUE); gtk_widget_realize (popup->outline_window); +#if GTK_CHECK_VERSION (3, 0, 0) + g_signal_connect (G_OBJECT (popup->outline_window), "draw", + G_CALLBACK (outline_window_draw), popup); +#else g_signal_connect (G_OBJECT (popup->outline_window), "expose_event", G_CALLBACK (outline_window_expose), popup); +#endif popup->window = gtk_window_new (GTK_WINDOW_POPUP); @@ -290,12 +315,21 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries, if (i % width) height += 1; - table = gtk_table_new (height, width, FALSE); vbox = gtk_vbox_new (FALSE, 0); +#if GTK_CHECK_VERSION (3, 0, 0) + grid = gtk_grid_new (); +#else + table = gtk_table_new (height, width, FALSE); +#endif + frame = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT); +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_container_set_border_width (GTK_CONTAINER (grid), 1); +#else gtk_container_set_border_width (GTK_CONTAINER (table), 1); +#endif gtk_container_add (GTK_CONTAINER (popup->window), frame); gtk_container_add (GTK_CONTAINER (frame), @@ -305,8 +339,13 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries, gtk_box_pack_start (GTK_BOX (vbox), align, TRUE, TRUE, 0); +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_container_add (GTK_CONTAINER (align), + grid); +#else gtk_container_add (GTK_CONTAINER (align), table); +#endif popup->label = gtk_label_new (""); @@ -368,16 +407,24 @@ meta_ui_tab_popup_new (const MetaTabEntry *entries, te->widget = image; +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_grid_attach (GTK_GRID (grid), te->widget, left, top, 1, 1); +#else gtk_table_attach (GTK_TABLE (table), te->widget, left, right, top, bottom, 0, 0, 0, 0); +#endif /* Efficiency rules! */ gtk_label_set_markup (GTK_LABEL (popup->label), te->title); +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_widget_get_preferred_size (popup->label, &req, NULL); +#else gtk_widget_size_request (popup->label, &req); +#endif max_label_width = MAX (max_label_width, req.width); tmp = tmp->next; @@ -431,7 +478,8 @@ meta_ui_tab_popup_free (MetaTabPopup *popup) { meta_verbose ("Destroying tab popup window\n"); - gtk_widget_destroy (popup->outline_window); + if (popup->outline_window != NULL) + gtk_widget_destroy (popup->outline_window); gtk_widget_destroy (popup->window); g_list_foreach (popup->entries, free_tab_entry, NULL); @@ -736,7 +784,11 @@ meta_select_image_draw (GtkWidget *widget, misc = GTK_MISC (widget); +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_widget_get_preferred_size (widget, &requisition, NULL); +#else gtk_widget_get_requisition (widget, &requisition); +#endif gtk_misc_get_alignment (misc, &xalign, &yalign); gtk_misc_get_padding (misc, &xpad, &ypad); @@ -895,8 +947,8 @@ unselect_workspace (GtkWidget *widget) static void meta_select_workspace_class_init (MetaSelectWorkspaceClass *klass); #if GTK_CHECK_VERSION(3, 0, 0) -static gboolean meta_select_workspace_draw (GtkWidget *widget, - cairo_t *cr); +static gboolean meta_select_workspace_draw (GtkWidget *widget, + cairo_t *cr); #else static gboolean meta_select_workspace_expose_event (GtkWidget *widget, GdkEventExpose *event); diff --git a/src/ui/testgradient.c b/src/ui/testgradient.c index 8f8cd6a5..8875452d 100644 --- a/src/ui/testgradient.c +++ b/src/ui/testgradient.c @@ -23,12 +23,6 @@ #include "gradient.h" #include <gtk/gtk.h> -#ifdef __GNUC__ -#define UNUSED_VARIABLE __attribute__ ((unused)) -#else -#define UNUSED_VARIABLE -#endif - typedef void (* RenderGradientFunc) ( #if !GTK_CHECK_VERSION (3, 0, 0) GdkDrawable *drawable, @@ -47,14 +41,27 @@ draw_checkerboard (GdkDrawable *drawable, int height) { gint i, j, xcount, ycount; +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color1, color2; +#else GdkColor color1, color2; -#if !GTK_CHECK_VERSION (3, 0, 0) cairo_t *cr; #endif #define CHECK_SIZE 10 #define SPACING 2 +#if GTK_CHECK_VERSION (3, 0, 0) + color1.red = 30000. / 65535.; + color1.green = 30000. / 65535.; + color1.blue = 30000. / 65535.; + color1.alpha = 1.0; + + color2.red = 50000. / 65535.; + color2.green = 50000. / 65535.; + color2.blue = 50000. / 65535.; + color2.alpha = 1.0; +#else color1.red = 30000; color1.green = 30000; color1.blue = 30000; @@ -63,7 +70,6 @@ draw_checkerboard (GdkDrawable *drawable, color2.green = 50000; color2.blue = 50000; -#if !GTK_CHECK_VERSION (3, 0, 0) cr = gdk_cairo_create (drawable); #endif @@ -76,9 +82,17 @@ draw_checkerboard (GdkDrawable *drawable, while (j < height) { if (ycount % 2) +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &color1); +#else gdk_cairo_set_source_color (cr, &color1); +#endif else +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &color2); +#else gdk_cairo_set_source_color (cr, &color2); +#endif /* If we're outside event->area, this will do nothing. * It might be mildly more efficient if we handled @@ -111,10 +125,17 @@ render_simple ( gboolean with_alpha) { GdkPixbuf *pixbuf; +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA from, to; + + gdk_rgba_parse (&from, "blue"); + gdk_rgba_parse (&to, "green"); +#else GdkColor from, to; gdk_color_parse ("blue", &from); gdk_color_parse ("green", &to); +#endif pixbuf = meta_gradient_create_simple (width, height, &from, &to, @@ -138,7 +159,7 @@ render_simple ( META_GRADIENT_HORIZONTAL); #if GTK_CHECK_VERSION (3, 0, 0) - draw_checkerboard (cr , width, height); + draw_checkerboard (cr, width, height); #else draw_checkerboard (drawable, width, height); #endif @@ -222,6 +243,16 @@ render_multi ( { GdkPixbuf *pixbuf; #define N_COLORS 5 + +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA colors[N_COLORS]; + + gdk_rgba_parse (&colors[0], "red"); + gdk_rgba_parse (&colors[1], "blue"); + gdk_rgba_parse (&colors[2], "orange"); + gdk_rgba_parse (&colors[3], "pink"); + gdk_rgba_parse (&colors[4], "green"); +#else GdkColor colors[N_COLORS]; gdk_color_parse ("red", &colors[0]); @@ -229,6 +260,7 @@ render_multi ( gdk_color_parse ("orange", &colors[2]); gdk_color_parse ("pink", &colors[3]); gdk_color_parse ("green", &colors[4]); +#endif pixbuf = meta_gradient_create_multi (width, height, colors, N_COLORS, @@ -297,12 +329,22 @@ render_interwoven_func ( { GdkPixbuf *pixbuf; #define N_COLORS 4 + +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA colors[N_COLORS]; + + gdk_rgba_parse (&colors[0], "red"); + gdk_rgba_parse (&colors[1], "blue"); + gdk_rgba_parse (&colors[2], "pink"); + gdk_rgba_parse (&colors[3], "green"); +#else GdkColor colors[N_COLORS]; gdk_color_parse ("red", &colors[0]); gdk_color_parse ("blue", &colors[1]); gdk_color_parse ("pink", &colors[2]); gdk_color_parse ("green", &colors[3]); +#endif pixbuf = meta_gradient_create_interwoven (width, height, colors, height / 10, @@ -327,21 +369,34 @@ expose_callback (GtkWidget *widget, #endif { RenderGradientFunc func = data; - GdkWindow *window; GtkAllocation allocation; +#if GTK_CHECK_VERSION (3, 0, 0) + GtkStyleContext *style; + GdkRGBA color; + + style = gtk_widget_get_style_context (widget); + + gtk_style_context_save (style); + gtk_style_context_set_state (style, gtk_widget_get_state_flags (widget)); + gtk_style_context_lookup_color (style, "foreground-color", &color); + gtk_style_context_restore (style); +#else + GdkWindow *window; GtkStyle *style; -#if !GTK_CHECK_VERSION (3, 0, 0) cairo_t *cr; -#endif style = gtk_widget_get_style (widget); +#endif + gtk_widget_get_allocation (widget, &allocation); +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_set_source_rgba (cr, color.red, color.green, color.blue, color.alpha); +#else window = gtk_widget_get_window (widget); -#if !GTK_CHECK_VERSION (3, 0, 0) cr = gdk_cairo_create (window); -#endif gdk_cairo_set_source_color (cr, &style->fg[gtk_widget_get_state (widget)]); +#endif (* func) ( #if !GTK_CHECK_VERSION (3, 0, 0) @@ -399,31 +454,29 @@ create_gradient_window (const char *title, static void meta_gradient_test (void) { - GtkWidget UNUSED_VARIABLE *window; - - window = create_gradient_window ("Simple vertical", - render_vertical_func); + create_gradient_window ("Simple vertical", + render_vertical_func); - window = create_gradient_window ("Simple horizontal", - render_horizontal_func); + create_gradient_window ("Simple horizontal", + render_horizontal_func); - window = create_gradient_window ("Simple diagonal", - render_diagonal_func); + create_gradient_window ("Simple diagonal", + render_diagonal_func); - window = create_gradient_window ("Multi vertical", - render_vertical_multi_func); + create_gradient_window ("Multi vertical", + render_vertical_multi_func); - window = create_gradient_window ("Multi horizontal", - render_horizontal_multi_func); + create_gradient_window ("Multi horizontal", + render_horizontal_multi_func); - window = create_gradient_window ("Multi diagonal", - render_diagonal_multi_func); + create_gradient_window ("Multi diagonal", + render_diagonal_multi_func); - window = create_gradient_window ("Interwoven", - render_interwoven_func); + create_gradient_window ("Interwoven", + render_interwoven_func); - window = create_gradient_window ("Simple diagonal with horizontal multi alpha", - render_diagonal_alpha_func); + create_gradient_window ("Simple diagonal with horizontal multi alpha", + render_diagonal_alpha_func); } diff --git a/src/ui/theme-parser.c b/src/ui/theme-parser.c index dccb47ad..f60c7619 100644 --- a/src/ui/theme-parser.c +++ b/src/ui/theme-parser.c @@ -190,12 +190,12 @@ static void parse_shadow_element (GMarkupParseContext *context, ParseInfo *info, GError **error); -static void parse_padding_element (GMarkupParseContext *context, - const gchar *element_name, - const gchar **attribute_names, - const gchar **attribute_values, - ParseInfo *info, - GError **error); +static void parse_padding_element (GMarkupParseContext *context, + const gchar *element_name, + const gchar **attribute_names, + const gchar **attribute_values, + ParseInfo *info, + GError **error); #endif static void parse_menu_icon_element (GMarkupParseContext *context, const gchar *element_name, diff --git a/src/ui/theme.c b/src/ui/theme.c index 2e13fd25..a7dc8d08 100644 --- a/src/ui/theme.c +++ b/src/ui/theme.c @@ -63,6 +63,23 @@ #define __USE_XOPEN #include <math.h> +#if GTK_CHECK_VERSION (3, 0, 0) +#define MATE_DESKTOP_USE_UNSTABLE_API +#include <libmate-desktop/mate-desktop-utils.h> +#endif + +#if GTK_CHECK_VERSION (3, 0, 0) +#define GDK_COLOR_RGBA(color) \ + ((guint32) (0xff | \ + ((int)((color).red * 255) << 24) | \ + ((int)((color).green * 255) << 16) | \ + ((int)((color).blue * 255) << 8))) + +#define GDK_COLOR_RGB(color) \ + ((guint32) (((int)((color).red * 255) << 16) | \ + ((int)((color).green * 255) << 8) | \ + ((int)((color).blue * 255)))) +#else #define GDK_COLOR_RGBA(color) \ ((guint32) (0xff | \ (((color).red / 256) << 24) | \ @@ -73,6 +90,7 @@ ((guint32) ((((color).red / 256) << 16) | \ (((color).green / 256) << 8) | \ (((color).blue / 256)))) +#endif #define ALPHA_TO_UCHAR(d) ((unsigned char) ((d) * 255)) @@ -80,9 +98,15 @@ #define CLAMP_UCHAR(v) ((guchar) (CLAMP (((int)v), (int)0, (int)255))) #define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11) +#if GTK_CHECK_VERSION (3, 0, 0) +static void gtk_style_shade (GdkRGBA *a, + GdkRGBA *b, + gdouble k); +#else static void gtk_style_shade (GdkColor *a, GdkColor *b, gdouble k); +#endif static void rgb_to_hls (gdouble *r, gdouble *g, gdouble *b); @@ -95,9 +119,15 @@ static void hls_to_rgb (gdouble *h, */ static MetaTheme *meta_current_theme = NULL; +#if GTK_CHECK_VERSION (3, 0, 0) +static GdkPixbuf * +colorize_pixbuf (GdkPixbuf *orig, + GdkRGBA *new_color) +#else static GdkPixbuf * colorize_pixbuf (GdkPixbuf *orig, GdkColor *new_color) +#endif { GdkPixbuf *pixbuf; double intensity; @@ -140,16 +170,28 @@ colorize_pixbuf (GdkPixbuf *orig, if (intensity <= 0.5) { /* Go from black at intensity = 0.0 to new_color at intensity = 0.5 */ +#if GTK_CHECK_VERSION (3, 0, 0) + dr = new_color->red * intensity * 2.0; + dg = new_color->green * intensity * 2.0; + db = new_color->blue * intensity * 2.0; +#else dr = (new_color->red * intensity * 2.0) / 65535.0; dg = (new_color->green * intensity * 2.0) / 65535.0; db = (new_color->blue * intensity * 2.0) / 65535.0; +#endif } else { /* Go from new_color at intensity = 0.5 to white at intensity = 1.0 */ +#if GTK_CHECK_VERSION (3, 0, 0) + dr = new_color->red + (1.0 - new_color->red) * (intensity - 0.5) * 2.0; + dg = new_color->green + (1.0 - new_color->green) * (intensity - 0.5) * 2.0; + db = new_color->blue + (1.0 - new_color->blue) * (intensity - 0.5) * 2.0; +#else dr = (new_color->red + (65535 - new_color->red) * (intensity - 0.5) * 2.0) / 65535.0; dg = (new_color->green + (65535 - new_color->green) * (intensity - 0.5) * 2.0) / 65535.0; db = (new_color->blue + (65535 - new_color->blue) * (intensity - 0.5) * 2.0) / 65535.0; +#endif } dest[0] = CLAMP_UCHAR (255 * dr); @@ -173,6 +215,19 @@ colorize_pixbuf (GdkPixbuf *orig, return pixbuf; } +#if GTK_CHECK_VERSION (3, 0, 0) +static void +color_composite (const GdkRGBA *bg, + const GdkRGBA *fg, + double alpha, + GdkRGBA *color) +{ + *color = *bg; + color->red = color->red + (fg->red - color->red) * alpha; + color->green = color->green + (fg->green - color->green) * alpha; + color->blue = color->blue + (fg->blue - color->blue) * alpha; +} +#else static void color_composite (const GdkColor *bg, const GdkColor *fg, @@ -187,6 +242,7 @@ color_composite (const GdkColor *bg, color->green = color->green + (((fg->green - color->green) * alpha + 0x8000) >> 16); color->blue = color->blue + (((fg->blue - color->blue) * alpha + 0x8000) >> 16); } +#endif /** * Sets all the fields of a border to dummy values. @@ -939,7 +995,6 @@ meta_frame_layout_calc_geometry (const MetaFrameLayout *layout, else g_memmove (&(rect->clickable), &(rect->visible), sizeof(rect->clickable)); - x = rect->visible.x + rect->visible.width + layout->button_border.right; if (left_buttons_has_spacer[i]) x += (button_width * 0.75); @@ -1015,14 +1070,26 @@ meta_gradient_spec_free (MetaGradientSpec *spec) g_free (spec); } +#if GTK_CHECK_VERSION (3, 0, 0) +GdkPixbuf* +meta_gradient_spec_render (const MetaGradientSpec *spec, + GtkStyleContext *style, + int width, + int height) +#else GdkPixbuf* meta_gradient_spec_render (const MetaGradientSpec *spec, - GtkWidget *widget, + GtkStyle *style, int width, int height) +#endif { int n_colors; +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA *colors; +#else GdkColor *colors; +#endif GSList *tmp; int i; GdkPixbuf *pixbuf; @@ -1032,13 +1099,17 @@ meta_gradient_spec_render (const MetaGradientSpec *spec, if (n_colors == 0) return NULL; +#if GTK_CHECK_VERSION (3, 0, 0) + colors = g_new (GdkRGBA, n_colors); +#else colors = g_new (GdkColor, n_colors); +#endif i = 0; tmp = spec->color_specs; while (tmp != NULL) { - meta_color_spec_render (tmp->data, widget, &colors[i]); + meta_color_spec_render (tmp->data, style, &colors[i]); tmp = tmp->next; ++i; @@ -1178,7 +1249,11 @@ meta_color_spec_new_from_string (const char *str, const char *bracket; const char *end_bracket; char *tmp; +#if GTK_CHECK_VERSION (3, 0, 0) + GtkStateFlags state; +#else GtkStateType state; +#endif MetaGtkColorComponent component; bracket = str; @@ -1371,7 +1446,11 @@ meta_color_spec_new_from_string (const char *str, { spec = meta_color_spec_new (META_COLOR_SPEC_BASIC); +#if GTK_CHECK_VERSION (3, 0, 0) + if (!gdk_rgba_parse (&spec->data.basic.color, str)) +#else if (!gdk_color_parse (str, &spec->data.basic.color)) +#endif { g_set_error (err, META_THEME_ERROR, META_THEME_ERROR_FAILED, @@ -1387,9 +1466,15 @@ meta_color_spec_new_from_string (const char *str, return spec; } +#if GTK_CHECK_VERSION (3, 0, 0) +MetaColorSpec* +meta_color_spec_new_gtk (MetaGtkColorComponent component, + GtkStateFlags state) +#else MetaColorSpec* meta_color_spec_new_gtk (MetaGtkColorComponent component, GtkStateType state) +#endif { MetaColorSpec *spec; @@ -1401,18 +1486,111 @@ meta_color_spec_new_gtk (MetaGtkColorComponent component, return spec; } +#if GTK_CHECK_VERSION (3, 0, 0) +static void +meta_set_color_from_style (GdkRGBA *color, + GtkStyleContext *context, + GtkStateFlags state, + MetaGtkColorComponent component) +{ + GdkRGBA other; + + switch (component) + { + case META_GTK_COLOR_BG: + case META_GTK_COLOR_BASE: + gtk_style_context_get_background_color (context, state, color); + break; + case META_GTK_COLOR_FG: + case META_GTK_COLOR_TEXT: + gtk_style_context_get_color (context, state, color); + break; + case META_GTK_COLOR_TEXT_AA: + gtk_style_context_get_color (context, state, color); + meta_set_color_from_style (&other, context, state, META_GTK_COLOR_BASE); + + 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_MID: + mate_desktop_gtk_style_get_light_color (context, state, color); + mate_desktop_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); + break; + case META_GTK_COLOR_DARK: + mate_desktop_gtk_style_get_dark_color (context, state, color); + break; + case META_GTK_COLOR_LAST: + g_assert_not_reached (); + break; + } +} +#else +static void +meta_set_color_from_style (GdkColor *color, + GtkStyle *widget_style, + GtkStateType state, + MetaGtkColorComponent component) +{ + switch (component) + { + case META_GTK_COLOR_BG: + *color = widget_style->bg[state]; + break; + case META_GTK_COLOR_FG: + *color = widget_style->fg[state]; + break; + case META_GTK_COLOR_BASE: + *color = widget_style->base[state]; + break; + case META_GTK_COLOR_TEXT: + *color = widget_style->text[state]; + break; + case META_GTK_COLOR_LIGHT: + *color = widget_style->light[state]; + break; + case META_GTK_COLOR_DARK: + *color = widget_style->dark[state]; + break; + case META_GTK_COLOR_MID: + *color = widget_style->mid[state]; + break; + case META_GTK_COLOR_TEXT_AA: + *color = widget_style->text_aa[state]; + break; + case META_GTK_COLOR_LAST: + g_assert_not_reached (); + break; + } +} +#endif + +#if GTK_CHECK_VERSION (3, 0, 0) +void +meta_color_spec_render (MetaColorSpec *spec, + GtkStyleContext *style, + GdkRGBA *color) +#else void meta_color_spec_render (MetaColorSpec *spec, - GtkWidget *widget, + GtkStyle *style, GdkColor *color) +#endif { - GtkStyle *widget_style; - g_return_if_fail (spec != NULL); - g_return_if_fail (GTK_IS_WIDGET (widget)); - widget_style = gtk_widget_get_style (widget); - g_return_if_fail (widget_style != NULL); +#if GTK_CHECK_VERSION (3, 0, 0) + g_return_if_fail (GTK_IS_STYLE_CONTEXT (style)); +#else + g_return_if_fail (style != NULL); +#endif switch (spec->type) { @@ -1421,44 +1599,22 @@ meta_color_spec_render (MetaColorSpec *spec, break; case META_COLOR_SPEC_GTK: - switch (spec->data.gtk.component) - { - case META_GTK_COLOR_BG: - *color = widget_style->bg[spec->data.gtk.state]; - break; - case META_GTK_COLOR_FG: - *color = widget_style->fg[spec->data.gtk.state]; - break; - case META_GTK_COLOR_BASE: - *color = widget_style->base[spec->data.gtk.state]; - break; - case META_GTK_COLOR_TEXT: - *color = widget_style->text[spec->data.gtk.state]; - break; - case META_GTK_COLOR_LIGHT: - *color = widget_style->light[spec->data.gtk.state]; - break; - case META_GTK_COLOR_DARK: - *color = widget_style->dark[spec->data.gtk.state]; - break; - case META_GTK_COLOR_MID: - *color = widget_style->mid[spec->data.gtk.state]; - break; - case META_GTK_COLOR_TEXT_AA: - *color = widget_style->text_aa[spec->data.gtk.state]; - break; - case META_GTK_COLOR_LAST: - g_assert_not_reached (); - break; - } + meta_set_color_from_style (color, + style, + spec->data.gtk.state, + spec->data.gtk.component); break; case META_COLOR_SPEC_BLEND: { +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA bg, fg; +#else GdkColor bg, fg; +#endif - meta_color_spec_render (spec->data.blend.background, widget, &bg); - meta_color_spec_render (spec->data.blend.foreground, widget, &fg); + meta_color_spec_render (spec->data.blend.background, style, &bg); + meta_color_spec_render (spec->data.blend.foreground, style, &fg); color_composite (&bg, &fg, spec->data.blend.alpha, &spec->data.blend.color); @@ -1469,7 +1625,7 @@ meta_color_spec_render (MetaColorSpec *spec, case META_COLOR_SPEC_SHADE: { - meta_color_spec_render (spec->data.shade.base, widget, + meta_color_spec_render (spec->data.shade.base, style, &spec->data.shade.color); gtk_style_shade (&spec->data.shade.color, @@ -3215,7 +3371,11 @@ scale_and_alpha_pixbuf (GdkPixbuf *src, static GdkPixbuf* draw_op_as_pixbuf (const MetaDrawOp *op, - GtkWidget *widget, +#if GTK_CHECK_VERSION (3, 0, 0) + GtkStyleContext *style, +#else + GtkStyle *style, +#endif const MetaDrawInfo *info, int width, int height) @@ -3236,10 +3396,14 @@ draw_op_as_pixbuf (const MetaDrawOp *op, case META_DRAW_RECTANGLE: if (op->data.rectangle.filled) { +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color; +#else GdkColor color; +#endif meta_color_spec_render (op->data.rectangle.color_spec, - widget, + style, &color); pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, @@ -3258,12 +3422,16 @@ draw_op_as_pixbuf (const MetaDrawOp *op, case META_DRAW_TINT: { +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color; +#else GdkColor color; +#endif guint32 rgba; gboolean has_alpha; meta_color_spec_render (op->data.rectangle.color_spec, - widget, + style, &color); has_alpha = @@ -3306,7 +3474,7 @@ draw_op_as_pixbuf (const MetaDrawOp *op, case META_DRAW_GRADIENT: { pixbuf = meta_gradient_spec_render (op->data.gradient.gradient_spec, - widget, width, height); + style, width, height); pixbuf = apply_alpha (pixbuf, op->data.gradient.alpha_spec, @@ -3319,10 +3487,14 @@ draw_op_as_pixbuf (const MetaDrawOp *op, { if (op->data.image.colorize_spec) { +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color; +#else GdkColor color; +#endif meta_color_spec_render (op->data.image.colorize_spec, - widget, &color); + style, &color); if (op->data.image.colorize_cache_pixbuf == NULL || op->data.image.colorize_cache_pixel != GDK_COLOR_RGB (color)) @@ -3430,31 +3602,6 @@ fill_env (MetaPositionExprEnv *env, env->theme = meta_current_theme; } -#if GTK_CHECK_VERSION (3, 0, 0) -static GtkStateFlags -state_flags_from_gtk_state (GtkStateType state) -{ - switch (state) - { - case GTK_STATE_NORMAL: - return 0; - case GTK_STATE_PRELIGHT: - return GTK_STATE_FLAG_PRELIGHT; - case GTK_STATE_ACTIVE: - return GTK_STATE_FLAG_ACTIVE; - case GTK_STATE_SELECTED: - return GTK_STATE_FLAG_SELECTED; - case GTK_STATE_INSENSITIVE: - return GTK_STATE_FLAG_INSENSITIVE; - case GTK_STATE_INCONSISTENT: - return GTK_STATE_FLAG_INCONSISTENT; - case GTK_STATE_FOCUSED: - return GTK_STATE_FLAG_FOCUSED; - } - return 0; -} -#endif - /* This code was originally rendering anti-aliased using X primitives, and * now has been switched to draw anti-aliased using cairo. In general, the * closest correspondence between X rendering and cairo rendering is given @@ -3470,13 +3617,9 @@ static void meta_draw_op_draw_with_env (const MetaDrawOp *op, #if GTK_CHECK_VERSION(3, 0, 0) GtkStyleContext *style_gtk, - #else - GtkStyle *style_gtk, - #endif - GtkWidget *widget, - #if GTK_CHECK_VERSION(3, 0, 0) cairo_t *cr, #else + GtkWidget *widget, GdkDrawable *drawable, const GdkRectangle *clip, #endif @@ -3484,12 +3627,15 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, MetaRectangle rect, MetaPositionExprEnv *env) { - GdkColor color; - #if GTK_CHECK_VERSION(3, 0, 0) - cairo_save(cr); - gtk_style_context_save(style_gtk); + GdkRGBA color; + + cairo_save (cr); + gtk_style_context_save (style_gtk); #else + GdkColor color; + GtkStyle *style_gtk = gtk_widget_get_style (widget); + cairo_t *cr; cr = gdk_cairo_create (drawable); #endif @@ -3510,8 +3656,12 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, { int x1, x2, y1, y2; - meta_color_spec_render (op->data.line.color_spec, widget, &color); + meta_color_spec_render (op->data.line.color_spec, style_gtk, &color); +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &color); +#else gdk_cairo_set_source_color (cr, &color); +#endif if (op->data.line.width > 0) cairo_set_line_width (cr, op->data.line.width); @@ -3598,8 +3748,12 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, { int rx, ry, rwidth, rheight; - meta_color_spec_render (op->data.rectangle.color_spec, widget, &color); + meta_color_spec_render (op->data.rectangle.color_spec, style_gtk, &color); +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &color); +#else gdk_cairo_set_source_color (cr, &color); +#endif rx = parse_x_position_unchecked (op->data.rectangle.x, env); ry = parse_y_position_unchecked (op->data.rectangle.y, env); @@ -3628,8 +3782,12 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, double start_angle, end_angle; double center_x, center_y; - meta_color_spec_render (op->data.arc.color_spec, widget, &color); + meta_color_spec_render (op->data.arc.color_spec, style_gtk, &color); +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &color); +#else gdk_cairo_set_source_color (cr, &color); +#endif rx = parse_x_position_unchecked (op->data.arc.x, env); ry = parse_y_position_unchecked (op->data.arc.y, env); @@ -3683,8 +3841,12 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, if (!needs_alpha) { - meta_color_spec_render (op->data.tint.color_spec, widget, &color); + meta_color_spec_render (op->data.tint.color_spec, style_gtk, &color); +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &color); +#else gdk_cairo_set_source_color (cr, &color); +#endif cairo_rectangle (cr, rx, ry, rwidth, rheight); cairo_fill (cr); @@ -3693,7 +3855,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, { GdkPixbuf *pixbuf; - pixbuf = draw_op_as_pixbuf (op, widget, info, + pixbuf = draw_op_as_pixbuf (op, style_gtk, info, rwidth, rheight); if (pixbuf) @@ -3717,7 +3879,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, rwidth = parse_size_unchecked (op->data.gradient.width, env); rheight = parse_size_unchecked (op->data.gradient.height, env); - pixbuf = draw_op_as_pixbuf (op, widget, info, + pixbuf = draw_op_as_pixbuf (op, style_gtk, info, rwidth, rheight); if (pixbuf) @@ -3744,7 +3906,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, rwidth = parse_size_unchecked (op->data.image.width, env); rheight = parse_size_unchecked (op->data.image.height, env); - pixbuf = draw_op_as_pixbuf (op, widget, info, + pixbuf = draw_op_as_pixbuf (op, style_gtk, info, rwidth, rheight); if (pixbuf) @@ -3791,8 +3953,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, return; } - gtk_style_context_set_state (style_gtk, - state_flags_from_gtk_state (op->data.gtk_arrow.state)); + gtk_style_context_set_state (style_gtk, op->data.gtk_arrow.state); gtk_render_arrow (style_gtk, cr, angle, rx, ry, size); #else @@ -3821,8 +3982,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, rheight = parse_size_unchecked (op->data.gtk_box.height, env); #if GTK_CHECK_VERSION(3, 0, 0) - gtk_style_context_set_state (style_gtk, - state_flags_from_gtk_state (op->data.gtk_box.state)); + gtk_style_context_set_state (style_gtk, op->data.gtk_box.state); gtk_render_background (style_gtk, cr, rx, ry, rwidth, rheight); gtk_render_frame (style_gtk, cr, rx, ry, rwidth, rheight); #else @@ -3847,8 +4007,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, ry2 = parse_y_position_unchecked (op->data.gtk_vline.y2, env); #if GTK_CHECK_VERSION(3, 0, 0) - gtk_style_context_set_state (style_gtk, - state_flags_from_gtk_state (op->data.gtk_vline.state)); + gtk_style_context_set_state (style_gtk, op->data.gtk_vline.state); gtk_render_line (style_gtk, cr, rx, ry1, rx, ry2); #else gtk_paint_vline (style_gtk, @@ -3870,7 +4029,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, rwidth = parse_size_unchecked (op->data.icon.width, env); rheight = parse_size_unchecked (op->data.icon.height, env); - pixbuf = draw_op_as_pixbuf (op, widget, info, + pixbuf = draw_op_as_pixbuf (op, style_gtk, info, rwidth, rheight); if (pixbuf) @@ -3891,8 +4050,12 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, { int rx, ry; - meta_color_spec_render (op->data.title.color_spec, widget, &color); + meta_color_spec_render (op->data.title.color_spec, style_gtk, &color); +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &color); +#else gdk_cairo_set_source_color (cr, &color); +#endif rx = parse_x_position_unchecked (op->data.title.x, env); ry = parse_y_position_unchecked (op->data.title.y, env); @@ -3908,6 +4071,20 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, cairo_pattern_t *linpat; linpat = cairo_pattern_create_linear (rx, ry, text_space, env->title_height); +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_pattern_add_color_stop_rgba (linpat, 0, color.red, + color.green, + color.blue, + color.alpha); + cairo_pattern_add_color_stop_rgba (linpat, startalpha, + color.red, + color.green, + color.blue, + color.alpha); + cairo_pattern_add_color_stop_rgba (linpat, 1, color.red, + color.green, + color.blue, 0); +#else cairo_pattern_add_color_stop_rgb (linpat, 0, color.red/65535.0, color.green/65535.0, color.blue/65535.0); @@ -3918,10 +4095,15 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, cairo_pattern_add_color_stop_rgba (linpat, 1, color.red/65535.0, color.green/65535.0, color.blue/65535.0, 0); +#endif cairo_set_source(cr, linpat); cairo_pattern_destroy(linpat); } else { +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &color); +#else gdk_cairo_set_source_color (cr, &color); +#endif } cairo_move_to (cr, rx, ry); @@ -3939,10 +4121,11 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, d_rect.height = parse_size_unchecked (op->data.op_list.height, env); meta_draw_op_list_draw_with_style (op->data.op_list.op_list, - style_gtk, widget, #if GTK_CHECK_VERSION(3, 0, 0) + style_gtk, cr, #else + widget, drawable, clip, #endif info, d_rect); @@ -3986,7 +4169,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, while (tile.y < (ry + rheight)) { meta_draw_op_list_draw_with_style (op->data.tile.op_list, - style_gtk, widget, cr, info, + style_gtk, cr, info, tile); tile.y += tile.height; @@ -4023,7 +4206,11 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, while (tile.y < (ry + rheight)) { meta_draw_op_list_draw_with_style (op->data.tile.op_list, - style_gtk, widget, drawable, &new_clip, info, +#if GTK_CHECK_VERSION (3, 0, 0) + style_gtk, drawable, &new_clip, info, +#else + widget, drawable, &new_clip, info, +#endif tile); tile.y += tile.height; @@ -4047,11 +4234,11 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op, void meta_draw_op_draw_with_style (const MetaDrawOp *op, - GtkStyle *style_gtk, - GtkWidget *widget, #if GTK_CHECK_VERSION(3, 0, 0) + GtkStyleContext *style_gtk, cairo_t *cr, #else + GtkWidget *widget, GdkDrawable *drawable, const GdkRectangle *clip, #endif @@ -4060,16 +4247,14 @@ meta_draw_op_draw_with_style (const MetaDrawOp *op, { MetaPositionExprEnv env; - #if !GTK_CHECK_VERSION(3, 0, 0) - g_return_if_fail (style_gtk->colormap == gdk_drawable_get_colormap (drawable)); - #endif - fill_env (&env, info, logical_region); - meta_draw_op_draw_with_env (op, style_gtk, widget, + meta_draw_op_draw_with_env (op, #if GTK_CHECK_VERSION(3, 0, 0) + style_gtk, cr, #else + widget, drawable, clip, #endif info, logical_region, @@ -4089,10 +4274,12 @@ meta_draw_op_draw (const MetaDrawOp *op, const MetaDrawInfo *info, MetaRectangle logical_region) { - meta_draw_op_draw_with_style (op, gtk_widget_get_style (widget), widget, + meta_draw_op_draw_with_style (op, #if GTK_CHECK_VERSION(3, 0, 0) + gtk_widget_get_style_context (widget), cr, #else + widget, drawable, clip, #endif info, logical_region); @@ -4147,11 +4334,11 @@ meta_draw_op_list_unref (MetaDrawOpList *op_list) void meta_draw_op_list_draw_with_style (const MetaDrawOpList *op_list, - GtkStyle *style_gtk, - GtkWidget *widget, #if GTK_CHECK_VERSION(3, 0, 0) + GtkStyleContext *style_gtk, cairo_t *cr, #else + GtkWidget *widget, GdkDrawable *drawable, const GdkRectangle *clip, #endif @@ -4167,10 +4354,6 @@ meta_draw_op_list_draw_with_style (const MetaDrawOpList *op_list, #endif MetaPositionExprEnv env; - #if !GTK_CHECK_VERSION(3, 0, 0) - g_return_if_fail (style_gtk->colormap == gdk_drawable_get_colormap (drawable)); - #endif - if (op_list->n_ops == 0) return; @@ -4189,7 +4372,7 @@ meta_draw_op_list_draw_with_style (const MetaDrawOpList *op_list, */ #if GTK_CHECK_VERSION(3, 0, 0) - cairo_save(cr); + cairo_save (cr); #else if (clip) { @@ -4226,10 +4409,7 @@ meta_draw_op_list_draw_with_style (const MetaDrawOpList *op_list, } else if (gdk_cairo_get_clip_rectangle (cr, NULL)) { - meta_draw_op_draw_with_env (op, - style_gtk, widget, cr, info, - rect, - &env); + meta_draw_op_draw_with_env (op, style_gtk, cr, info, rect, &env); } #else @@ -4247,7 +4427,7 @@ meta_draw_op_list_draw_with_style (const MetaDrawOpList *op_list, active_clip.height > 0) { meta_draw_op_draw_with_env (op, - style_gtk, widget, drawable, &active_clip, info, + widget, drawable, &active_clip, info, rect, &env); } @@ -4255,7 +4435,7 @@ meta_draw_op_list_draw_with_style (const MetaDrawOpList *op_list, } #if GTK_CHECK_VERSION(3, 0, 0) - cairo_restore(cr); + cairo_restore (cr); #endif } @@ -4272,10 +4452,12 @@ meta_draw_op_list_draw (const MetaDrawOpList *op_list, MetaRectangle rect) { - meta_draw_op_list_draw_with_style (op_list, gtk_widget_get_style (widget), widget, + meta_draw_op_list_draw_with_style (op_list, #if GTK_CHECK_VERSION(3, 0, 0) + gtk_widget_get_style_context (widget), cr, #else + widget, drawable, clip, #endif info, rect); @@ -4644,13 +4826,9 @@ void meta_frame_style_draw_with_style (MetaFrameStyle *style, #if GTK_CHECK_VERSION(3, 0, 0) GtkStyleContext *style_gtk, - #else - GtkStyle *style_gtk, - #endif - GtkWidget *widget, - #if GTK_CHECK_VERSION(3, 0, 0) cairo_t *cr, #else + GtkWidget *widget, GdkDrawable *drawable, int x_offset, int y_offset, @@ -4676,10 +4854,6 @@ meta_frame_style_draw_with_style (MetaFrameStyle *style, PangoRectangle extents; MetaDrawInfo draw_info; - #if !GTK_CHECK_VERSION(3, 0, 0) - g_return_if_fail (style_gtk->colormap == gdk_drawable_get_colormap (drawable)); - #endif - titlebar_rect.x = 0; titlebar_rect.y = 0; titlebar_rect.width = fgeom->width; @@ -4831,7 +5005,6 @@ meta_frame_style_draw_with_style (MetaFrameStyle *style, m_rect = meta_rect (rect.x, rect.y, rect.width, rect.height); meta_draw_op_list_draw_with_style (op_list, style_gtk, - widget, cr, &draw_info, m_rect); @@ -4870,7 +5043,6 @@ meta_frame_style_draw_with_style (MetaFrameStyle *style, MetaRectangle m_rect; m_rect = meta_rect (rect.x, rect.y, rect.width, rect.height); meta_draw_op_list_draw_with_style (op_list, - style_gtk, widget, drawable, &combined_clip, @@ -4916,7 +5088,6 @@ meta_frame_style_draw_with_style (MetaFrameStyle *style, meta_draw_op_list_draw_with_style (op_list, style_gtk, - widget, cr, &draw_info, m_rect); @@ -4978,7 +5149,6 @@ meta_frame_style_draw_with_style (MetaFrameStyle *style, m_rect = meta_rect (rect.x, rect.y, rect.width, rect.height); meta_draw_op_list_draw_with_style (op_list, - style_gtk, widget, drawable, &combined_clip, @@ -5031,13 +5201,9 @@ meta_frame_style_draw (MetaFrameStyle *style, meta_frame_style_draw_with_style (style, #if GTK_CHECK_VERSION(3, 0, 0) gtk_widget_get_style_context (widget), - #else - gtk_widget_get_style (widget), - #endif - widget, - #if GTK_CHECK_VERSION(3, 0, 0) cr, #else + widget, drawable, x_offset, y_offset, clip, #endif fgeom, client_width, client_height, @@ -5636,13 +5802,9 @@ void meta_theme_draw_frame_with_style (MetaTheme *theme, #if GTK_CHECK_VERSION(3, 0, 0) GtkStyleContext *style_gtk, - #else - GtkStyle *style_gtk, - #endif - GtkWidget *widget, - #if GTK_CHECK_VERSION(3, 0, 0) cairo_t *cr, #else + GtkWidget *widget, GdkDrawable *drawable, const GdkRectangle *clip, int x_offset, @@ -5679,11 +5841,11 @@ meta_theme_draw_frame_with_style (MetaTheme *theme, theme); meta_frame_style_draw_with_style (style, - style_gtk, - widget, #if GTK_CHECK_VERSION(3, 0, 0) + style_gtk, cr, #else + widget, drawable, x_offset, y_offset, clip, #endif &fgeom, @@ -5719,13 +5881,9 @@ meta_theme_draw_frame (MetaTheme *theme, meta_theme_draw_frame_with_style (theme, #if GTK_CHECK_VERSION(3, 0, 0) gtk_widget_get_style_context (widget), - #else - gtk_widget_get_style (widget), - #endif - widget, - #if GTK_CHECK_VERSION(3, 0, 0) cr, #else + widget, drawable, clip, x_offset, y_offset, #endif type, flags, client_width, client_height, @@ -6128,7 +6286,14 @@ meta_gtk_widget_get_font_desc (GtkWidget *widget, g_return_val_if_fail (gtk_widget_get_realized (widget), NULL); +#if GTK_CHECK_VERSION (3, 0, 0) + GtkStyleContext *style = gtk_widget_get_style_context (widget); + GtkStateFlags state = gtk_widget_get_state_flags (widget); + gtk_style_context_get(style, state, GTK_STYLE_PROPERTY_FONT, &font_desc, NULL); + font_desc = pango_font_description_copy (font_desc); +#else font_desc = pango_font_description_copy (gtk_widget_get_style (widget)->font_desc); +#endif if (override) pango_font_description_merge (font_desc, override, TRUE); @@ -6596,6 +6761,30 @@ meta_gradient_type_to_string (MetaGradientType type) return "<unknown>"; } +#if GTK_CHECK_VERSION (3, 0, 0) +GtkStateFlags +meta_gtk_state_from_string (const char *str) +{ + if (g_ascii_strcasecmp ("normal", str) == 0) + return GTK_STATE_FLAG_NORMAL; + else if (g_ascii_strcasecmp ("prelight", str) == 0) + return GTK_STATE_FLAG_PRELIGHT; + else if (g_ascii_strcasecmp ("active", str) == 0) + return GTK_STATE_FLAG_ACTIVE; + else if (g_ascii_strcasecmp ("selected", str) == 0) + return GTK_STATE_FLAG_SELECTED; + else if (g_ascii_strcasecmp ("insensitive", str) == 0) + return GTK_STATE_FLAG_INSENSITIVE; + else if (g_ascii_strcasecmp ("inconsistent", str) == 0) + return GTK_STATE_FLAG_INCONSISTENT; + else if (g_ascii_strcasecmp ("focused", str) == 0) + return GTK_STATE_FLAG_FOCUSED; + else if (g_ascii_strcasecmp ("backdrop", str) == 0) + return GTK_STATE_FLAG_BACKDROP; + else + return -1; /* hack */ +} +#else GtkStateType meta_gtk_state_from_string (const char *str) { @@ -6632,6 +6821,7 @@ meta_gtk_state_to_string (GtkStateType state) return "<unknown>"; } +#endif GtkShadowType meta_gtk_shadow_from_string (const char *str) @@ -6755,18 +6945,31 @@ meta_image_fill_type_to_string (MetaImageFillType fill_type) * \param b [out] the resulting colour * \param k amount to scale lightness and saturation by */ +#if GTK_CHECK_VERSION (3, 0, 0) +static void +gtk_style_shade (GdkRGBA *a, + GdkRGBA *b, + gdouble k) +#else static void gtk_style_shade (GdkColor *a, GdkColor *b, gdouble k) +#endif { gdouble red; gdouble green; gdouble blue; +#if GTK_CHECK_VERSION (3, 0, 0) + red = a->red; + green = a->green; + blue = a->blue; +#else red = (gdouble) a->red / 65535.0; green = (gdouble) a->green / 65535.0; blue = (gdouble) a->blue / 65535.0; +#endif rgb_to_hls (&red, &green, &blue); @@ -6784,9 +6987,15 @@ gtk_style_shade (GdkColor *a, hls_to_rgb (&red, &green, &blue); +#if GTK_CHECK_VERSION (3, 0, 0) + b->red = red; + b->green = green; + b->blue = blue; +#else b->red = red * 65535.0; b->green = green * 65535.0; b->blue = blue * 65535.0; +#endif } /** diff --git a/src/ui/theme.h b/src/ui/theme.h index a4ddb5f6..66996d89 100644 --- a/src/ui/theme.h +++ b/src/ui/theme.h @@ -255,24 +255,40 @@ struct _MetaColorSpec union { struct { +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color; +#else GdkColor color; +#endif } basic; struct { MetaGtkColorComponent component; +#if GTK_CHECK_VERSION (3, 0, 0) + GtkStateFlags state; +#else GtkStateType state; +#endif } gtk; struct { MetaColorSpec *foreground; MetaColorSpec *background; double alpha; +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color; +#else GdkColor color; +#endif } blend; struct { MetaColorSpec *base; double factor; +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color; +#else GdkColor color; +#endif } shade; } data; }; @@ -501,7 +517,11 @@ struct _MetaDrawOp } image; struct { +#if GTK_CHECK_VERSION (3, 0, 0) + GtkStateFlags state; +#else GtkStateType state; +#endif GtkShadowType shadow; GtkArrowType arrow; gboolean filled; @@ -513,7 +533,11 @@ struct _MetaDrawOp } gtk_arrow; struct { +#if GTK_CHECK_VERSION (3, 0, 0) + GtkStateFlags state; +#else GtkStateType state; +#endif GtkShadowType shadow; MetaDrawSpec *x; MetaDrawSpec *y; @@ -522,7 +546,11 @@ struct _MetaDrawOp } gtk_box; struct { +#if GTK_CHECK_VERSION (3, 0, 0) + GtkStateFlags state; +#else GtkStateType state; +#endif MetaDrawSpec *x; MetaDrawSpec *y1; MetaDrawSpec *y2; @@ -898,12 +926,23 @@ void meta_draw_spec_free (MetaDrawSpec *spec); MetaColorSpec* meta_color_spec_new (MetaColorSpecType type); MetaColorSpec* meta_color_spec_new_from_string (const char *str, GError **err); +#if GTK_CHECK_VERSION (3, 0, 0) +MetaColorSpec* meta_color_spec_new_gtk (MetaGtkColorComponent component, + GtkStateFlags state); +#else MetaColorSpec* meta_color_spec_new_gtk (MetaGtkColorComponent component, GtkStateType state); +#endif void meta_color_spec_free (MetaColorSpec *spec); +#if GTK_CHECK_VERSION (3, 0, 0) +void meta_color_spec_render (MetaColorSpec *spec, + GtkStyleContext *style_gtk, + GdkRGBA *color); +#else void meta_color_spec_render (MetaColorSpec *spec, - GtkWidget *widget, + GtkStyle *style_gtk, GdkColor *color); +#endif MetaDrawOp* meta_draw_op_new (MetaDrawType type); @@ -921,11 +960,11 @@ void meta_draw_op_draw (const MetaDrawOp *op, MetaRectangle logical_region); void meta_draw_op_draw_with_style (const MetaDrawOp *op, - GtkStyle *style_gtk, - GtkWidget *widget, #if GTK_CHECK_VERSION(3, 0, 0) + GtkStyleContext *style_gtk, cairo_t *cr, #else + GtkWidget *widget, GdkDrawable *drawable, const GdkRectangle *clip, #endif @@ -947,11 +986,11 @@ void meta_draw_op_list_draw (const MetaDrawOpList *op_list, const MetaDrawInfo *info, MetaRectangle rect); void meta_draw_op_list_draw_with_style (const MetaDrawOpList *op_list, - GtkStyle *style_gtk, - GtkWidget *widget, #if GTK_CHECK_VERSION(3, 0, 0) + GtkStyleContext *style_gtk, cairo_t *cr, #else + GtkWidget *widget, GdkDrawable *drawable, const GdkRectangle *clip, #endif @@ -966,10 +1005,17 @@ gboolean meta_draw_op_list_contains (MetaDrawOpList *op_list, MetaGradientSpec* meta_gradient_spec_new (MetaGradientType type); void meta_gradient_spec_free (MetaGradientSpec *desc); +#if GTK_CHECK_VERSION (3, 0, 0) GdkPixbuf* meta_gradient_spec_render (const MetaGradientSpec *desc, - GtkWidget *widget, + GtkStyleContext *style_gtk, int width, int height); +#else +GdkPixbuf* meta_gradient_spec_render (const MetaGradientSpec *desc, + GtkStyle *style_gtk, + int width, + int height); +#endif gboolean meta_gradient_spec_validate (MetaGradientSpec *spec, GError **error); @@ -1005,13 +1051,9 @@ void meta_frame_style_draw (MetaFrameStyle *style, void meta_frame_style_draw_with_style (MetaFrameStyle *style, #if GTK_CHECK_VERSION(3, 0, 0) GtkStyleContext *style_gtk, - #else - GtkStyle *style_gtk, - #endif - GtkWidget *widget, - #if GTK_CHECK_VERSION(3, 0, 0) cairo_t *cr, #else + GtkWidget *widget, GdkDrawable *drawable, int x_offset, int y_offset, @@ -1104,13 +1146,9 @@ void meta_theme_draw_frame_by_name (MetaTheme *theme, void meta_theme_draw_frame_with_style (MetaTheme *theme, #if GTK_CHECK_VERSION(3, 0, 0) GtkStyleContext *style_gtk, - #else - GtkStyle *style_gtk, - #endif - GtkWidget *widget, - #if GTK_CHECK_VERSION(3, 0, 0) cairo_t *cr, #else + GtkWidget *widget, GdkDrawable *drawable, const GdkRectangle *clip, int x_offset, @@ -1221,8 +1259,12 @@ MetaFrameType meta_frame_type_from_string (const char *s const char* meta_frame_type_to_string (MetaFrameType type); MetaGradientType meta_gradient_type_from_string (const char *str); const char* meta_gradient_type_to_string (MetaGradientType type); +#if GTK_CHECK_VERSION (3, 0, 0) +GtkStateFlags meta_gtk_state_from_string (const char *str); +#else GtkStateType meta_gtk_state_from_string (const char *str); const char* meta_gtk_state_to_string (GtkStateType state); +#endif GtkShadowType meta_gtk_shadow_from_string (const char *str); const char* meta_gtk_shadow_to_string (GtkShadowType shadow); GtkArrowType meta_gtk_arrow_from_string (const char *str); diff --git a/src/ui/tile-preview.c b/src/ui/tile-preview.c index d5a68846..71b2e297 100644 --- a/src/ui/tile-preview.c +++ b/src/ui/tile-preview.c @@ -35,8 +35,12 @@ struct _MetaTilePreview { GtkWidget *preview_window; +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA *preview_color; +#else GdkColor *preview_color; guchar preview_alpha; +#endif MetaRectangle tile_rect; @@ -45,13 +49,14 @@ struct _MetaTilePreview { static gboolean #if GTK_CHECK_VERSION (3, 0, 0) -meta_tile_preview_draw (GtkWidget *widget, - cairo_t *cr, +meta_tile_preview_draw (GtkWidget *widget, + cairo_t *cr, + gpointer user_data) #else meta_tile_preview_expose (GtkWidget *widget, GdkEventExpose *event, -#endif gpointer user_data) +#endif { MetaTilePreview *preview = user_data; #if !GTK_CHECK_VERSION (3, 0, 0) @@ -66,25 +71,42 @@ meta_tile_preview_expose (GtkWidget *widget, if (preview->has_alpha) { +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA preview_color = *preview->preview_color; +#endif /* Fill the preview area with a transparent color */ +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &preview_color); +#else cairo_set_source_rgba (cr, (double)preview->preview_color->red / 0xFFFF, (double)preview->preview_color->green / 0xFFFF, (double)preview->preview_color->blue / 0xFFFF, (double)preview->preview_alpha / 0xFF); +#endif cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); cairo_paint (cr); /* Use the opaque color for the border */ +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &preview_color); +#else gdk_cairo_set_source_color (cr, preview->preview_color); +#endif } else { +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA white = {1.0, 1.0, 1.0, 1.0}; + + gdk_cairo_set_source_rgba (cr, &white); +#else GtkStyle *style = gtk_widget_get_style (preview->preview_window); gdk_cairo_set_source_color (cr, &style->white); +#endif cairo_rectangle (cr, OUTLINE_WIDTH - 0.5, OUTLINE_WIDTH - 0.5, @@ -112,6 +134,22 @@ on_preview_window_style_set (GtkWidget *widget, gpointer user_data) { MetaTilePreview *preview = user_data; +#if GTK_CHECK_VERSION (3, 0, 0) + GtkStyleContext *context = gtk_style_context_new (); + GtkWidgetPath *path = gtk_widget_path_new (); + guchar alpha = 0xFF; + + gtk_widget_path_append_type (path, GTK_TYPE_ICON_VIEW); + gtk_style_context_set_path (context, path); + + gtk_style_context_get (context, GTK_STATE_FLAG_SELECTED, "background-color", &preview->preview_color, NULL); + gtk_style_context_get_style (context, "selection-box-alpha", &alpha, NULL); + + preview->preview_color->alpha = (double)alpha / 0xFF; + + gtk_widget_path_free (path); + g_object_unref (context); +#else GtkStyle *style; style = gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget), @@ -135,6 +173,7 @@ on_preview_window_style_set (GtkWidget *widget, } g_object_unref (style); +#endif } MetaTilePreview * @@ -160,7 +199,9 @@ meta_tile_preview_new (int screen_number, gtk_widget_set_app_paintable (preview->preview_window, TRUE); preview->preview_color = NULL; +#if !GTK_CHECK_VERSION (3, 0, 0) preview->preview_alpha = 0xFF; +#endif preview->tile_rect.x = preview->tile_rect.y = 0; preview->tile_rect.width = preview->tile_rect.height = 0; @@ -207,7 +248,11 @@ meta_tile_preview_free (MetaTilePreview *preview) gtk_widget_destroy (preview->preview_window); if (preview->preview_color) +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_rgba_free (preview->preview_color); +#else gdk_color_free (preview->preview_color); +#endif g_free (preview); } @@ -250,12 +295,20 @@ meta_tile_preview_show (MetaTilePreview *preview, if (!preview->has_alpha) { - GdkRectangle outer_rect, inner_rect; +#if GTK_CHECK_VERSION (3, 0, 0) + cairo_rectangle_int_t outer_rect, inner_rect; cairo_region_t *outer_region, *inner_region; + GdkRGBA black = {.0, .0, .0, 1.0}; + + gdk_window_set_background_rgba (window, &black); +#else + GdkRectangle outer_rect, inner_rect; + GdkRegion *outer_region, *inner_region; GdkColor black; black = gtk_widget_get_style (preview->preview_window)->black; gdk_window_set_background (window, &black); +#endif outer_rect.x = outer_rect.y = 0; outer_rect.width = preview->tile_rect.width; @@ -266,14 +319,25 @@ meta_tile_preview_show (MetaTilePreview *preview, inner_rect.width = outer_rect.width - 2 * OUTLINE_WIDTH; inner_rect.height = outer_rect.height - 2 * OUTLINE_WIDTH; +#if GTK_CHECK_VERSION (3, 0, 0) outer_region = cairo_region_create_rectangle (&outer_rect); inner_region = cairo_region_create_rectangle (&inner_rect); cairo_region_subtract (outer_region, inner_region); cairo_region_destroy (inner_region); - gdk_window_shape_combine_region (window, outer_region, 0, 0); + gtk_widget_shape_combine_region (preview->preview_window, outer_region); cairo_region_destroy (outer_region); +#else + outer_region = gdk_region_rectangle (&outer_rect); + inner_region = gdk_region_rectangle (&inner_rect); + + gdk_region_subtract (outer_region, inner_region); + gdk_region_destroy (inner_region); + + gdk_window_shape_combine_region (window, outer_region, 0, 0); + gdk_region_destroy (outer_region); +#endif } } diff --git a/src/ui/ui.c b/src/ui/ui.c index b187f8cb..226e3c24 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -134,8 +134,8 @@ maybe_redirect_mouse_event (XEvent *xevent) return FALSE; #if GTK_CHECK_VERSION (3, 0, 0) - gmanager = gdk_display_get_device_manager (gdisplay); - gdevice = gdk_device_manager_get_client_pointer (gmanager); + gmanager = gdk_display_get_device_manager (gdisplay); + gdevice = gdk_device_manager_get_client_pointer (gmanager); #endif /* If GDK already thinks it has a grab, we better let it see events; this @@ -256,6 +256,7 @@ maybe_redirect_mouse_event (XEvent *xevent) /* If we've gotten here, we've filled in the gdk_event and should send it on */ #if GTK_CHECK_VERSION (3, 0, 0) gdk_event_set_device (gevent, gdevice); + gtk_main_do_event (gevent); gdk_event_free (gevent); #else gtk_main_do_event (&gevent); @@ -978,7 +979,6 @@ meta_ui_theme_get_frame_borders (MetaUI *ui, #endif PangoContext *context; const PangoFontDescription *font_desc; - GtkStyle *default_style; if (meta_ui_have_a_theme ()) { @@ -1002,6 +1002,8 @@ meta_ui_theme_get_frame_borders (MetaUI *ui, gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, "font", &free_font_desc, NULL); font_desc = (const PangoFontDescription *) free_font_desc; #else + GtkStyle *default_style; + default_style = gtk_widget_get_default_style (); font_desc = default_style->font_desc; #endif |