1
0
Fork 0

theme: Get GTK+ colors from style context

Rather than using a single widget's style for GTK+ colors in themes,
use the style context parameter of the drawing functions for those
colors. Right now, a single style context is shared between frames,
but this will change to support different style variants.

https://bugzilla.gnome.org/show_bug.cgi?id=645355
This commit is contained in:
Florian Müllner 2011-03-18 16:42:41 +01:00
parent 37aeb5baf1
commit da4486b833
3 changed files with 35 additions and 29 deletions

View file

@ -2526,7 +2526,7 @@ meta_frames_set_window_background (MetaFrames *frames,
GdkVisual *visual; GdkVisual *visual;
meta_color_spec_render (style->window_background_color, meta_color_spec_render (style->window_background_color,
GTK_WIDGET (frames), frame->style,
&color); &color);
/* Set A in ARGB to window_background_alpha, if we have ARGB */ /* Set A in ARGB to window_background_alpha, if we have ARGB */

View file

@ -961,7 +961,7 @@ MetaColorSpec* meta_color_spec_new_gtk (MetaGtkColorComponent component,
GtkStateType state); GtkStateType state);
void meta_color_spec_free (MetaColorSpec *spec); void meta_color_spec_free (MetaColorSpec *spec);
void meta_color_spec_render (MetaColorSpec *spec, void meta_color_spec_render (MetaColorSpec *spec,
GtkWidget *widget, GtkStyleContext *style_gtk,
GdkColor *color); GdkColor *color);
@ -1006,7 +1006,7 @@ gboolean meta_draw_op_list_contains (MetaDrawOpList *op_list,
MetaGradientSpec* meta_gradient_spec_new (MetaGradientType type); MetaGradientSpec* meta_gradient_spec_new (MetaGradientType type);
void meta_gradient_spec_free (MetaGradientSpec *desc); void meta_gradient_spec_free (MetaGradientSpec *desc);
GdkPixbuf* meta_gradient_spec_render (const MetaGradientSpec *desc, GdkPixbuf* meta_gradient_spec_render (const MetaGradientSpec *desc,
GtkWidget *widget, GtkStyleContext *gtk_style,
int width, int width,
int height); int height);
gboolean meta_gradient_spec_validate (MetaGradientSpec *spec, gboolean meta_gradient_spec_validate (MetaGradientSpec *spec,

View file

@ -1015,7 +1015,7 @@ meta_gradient_spec_free (MetaGradientSpec *spec)
GdkPixbuf* GdkPixbuf*
meta_gradient_spec_render (const MetaGradientSpec *spec, meta_gradient_spec_render (const MetaGradientSpec *spec,
GtkWidget *widget, GtkStyleContext *style,
int width, int width,
int height) int height)
{ {
@ -1036,7 +1036,7 @@ meta_gradient_spec_render (const MetaGradientSpec *spec,
tmp = spec->color_specs; tmp = spec->color_specs;
while (tmp != NULL) while (tmp != NULL)
{ {
meta_color_spec_render (tmp->data, widget, &colors[i]); meta_color_spec_render (tmp->data, style, &colors[i]);
tmp = tmp->next; tmp = tmp->next;
++i; ++i;
@ -1416,17 +1416,18 @@ meta_color_spec_new_gtk (MetaGtkColorComponent component,
} }
void void
meta_color_spec_render (MetaColorSpec *spec, meta_color_spec_render (MetaColorSpec *spec,
GtkWidget *widget, GtkStyleContext *context,
GdkColor *color) GdkColor *color)
{ {
GtkStyle *style; GtkStyle *style;
style = gtk_widget_get_style (widget);
g_return_if_fail (spec != NULL); g_return_if_fail (spec != NULL);
g_return_if_fail (GTK_IS_WIDGET (widget)); g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
g_return_if_fail (style != NULL);
style = g_object_new (GTK_TYPE_STYLE,
"context", context,
NULL);
switch (spec->type) switch (spec->type)
{ {
@ -1471,8 +1472,8 @@ meta_color_spec_render (MetaColorSpec *spec,
{ {
GdkColor bg, fg; GdkColor bg, fg;
meta_color_spec_render (spec->data.blend.background, widget, &bg); meta_color_spec_render (spec->data.blend.background, context, &bg);
meta_color_spec_render (spec->data.blend.foreground, widget, &fg); meta_color_spec_render (spec->data.blend.foreground, context, &fg);
color_composite (&bg, &fg, spec->data.blend.alpha, color_composite (&bg, &fg, spec->data.blend.alpha,
&spec->data.blend.color); &spec->data.blend.color);
@ -1483,7 +1484,7 @@ meta_color_spec_render (MetaColorSpec *spec,
case META_COLOR_SPEC_SHADE: case META_COLOR_SPEC_SHADE:
{ {
meta_color_spec_render (spec->data.shade.base, widget, meta_color_spec_render (spec->data.shade.base, context,
&spec->data.shade.color); &spec->data.shade.color);
gtk_style_shade (&spec->data.shade.color, gtk_style_shade (&spec->data.shade.color,
@ -1493,6 +1494,8 @@ meta_color_spec_render (MetaColorSpec *spec,
} }
break; break;
} }
g_object_unref (style);
} }
/** /**
@ -3255,7 +3258,7 @@ scale_and_alpha_pixbuf (GdkPixbuf *src,
static GdkPixbuf* static GdkPixbuf*
draw_op_as_pixbuf (const MetaDrawOp *op, draw_op_as_pixbuf (const MetaDrawOp *op,
GtkWidget *widget, GtkStyleContext *context,
const MetaDrawInfo *info, const MetaDrawInfo *info,
int width, int width,
int height) int height)
@ -3279,7 +3282,7 @@ draw_op_as_pixbuf (const MetaDrawOp *op,
GdkColor color; GdkColor color;
meta_color_spec_render (op->data.rectangle.color_spec, meta_color_spec_render (op->data.rectangle.color_spec,
widget, context,
&color); &color);
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
@ -3303,7 +3306,7 @@ draw_op_as_pixbuf (const MetaDrawOp *op,
gboolean has_alpha; gboolean has_alpha;
meta_color_spec_render (op->data.rectangle.color_spec, meta_color_spec_render (op->data.rectangle.color_spec,
widget, context,
&color); &color);
has_alpha = has_alpha =
@ -3346,7 +3349,7 @@ draw_op_as_pixbuf (const MetaDrawOp *op,
case META_DRAW_GRADIENT: case META_DRAW_GRADIENT:
{ {
pixbuf = meta_gradient_spec_render (op->data.gradient.gradient_spec, pixbuf = meta_gradient_spec_render (op->data.gradient.gradient_spec,
widget, width, height); context, width, height);
pixbuf = apply_alpha (pixbuf, pixbuf = apply_alpha (pixbuf,
op->data.gradient.alpha_spec, op->data.gradient.alpha_spec,
@ -3362,7 +3365,7 @@ draw_op_as_pixbuf (const MetaDrawOp *op,
GdkColor color; GdkColor color;
meta_color_spec_render (op->data.image.colorize_spec, meta_color_spec_render (op->data.image.colorize_spec,
widget, &color); context, &color);
if (op->data.image.colorize_cache_pixbuf == NULL || if (op->data.image.colorize_cache_pixbuf == NULL ||
op->data.image.colorize_cache_pixel != GDK_COLOR_RGB (color)) op->data.image.colorize_cache_pixel != GDK_COLOR_RGB (color))
@ -3531,7 +3534,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
{ {
int x1, x2, y1, y2; 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);
gdk_cairo_set_source_color (cr, &color); gdk_cairo_set_source_color (cr, &color);
if (op->data.line.width > 0) if (op->data.line.width > 0)
@ -3606,7 +3609,8 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
{ {
int rx, ry, rwidth, rheight; 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);
gdk_cairo_set_source_color (cr, &color); gdk_cairo_set_source_color (cr, &color);
rx = parse_x_position_unchecked (op->data.rectangle.x, env); rx = parse_x_position_unchecked (op->data.rectangle.x, env);
@ -3636,7 +3640,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
double start_angle, end_angle; double start_angle, end_angle;
double center_x, center_y; 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);
gdk_cairo_set_source_color (cr, &color); gdk_cairo_set_source_color (cr, &color);
rx = parse_x_position_unchecked (op->data.arc.x, env); rx = parse_x_position_unchecked (op->data.arc.x, env);
@ -3691,7 +3695,8 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
if (!needs_alpha) 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);
gdk_cairo_set_source_color (cr, &color); gdk_cairo_set_source_color (cr, &color);
cairo_rectangle (cr, rx, ry, rwidth, rheight); cairo_rectangle (cr, rx, ry, rwidth, rheight);
@ -3701,7 +3706,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
{ {
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
pixbuf = draw_op_as_pixbuf (op, widget, info, pixbuf = draw_op_as_pixbuf (op, style_gtk, info,
rwidth, rheight); rwidth, rheight);
if (pixbuf) if (pixbuf)
@ -3725,7 +3730,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
rwidth = parse_size_unchecked (op->data.gradient.width, env); rwidth = parse_size_unchecked (op->data.gradient.width, env);
rheight = parse_size_unchecked (op->data.gradient.height, 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); rwidth, rheight);
if (pixbuf) if (pixbuf)
@ -3752,7 +3757,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
rwidth = parse_size_unchecked (op->data.image.width, env); rwidth = parse_size_unchecked (op->data.image.width, env);
rheight = parse_size_unchecked (op->data.image.height, 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); rwidth, rheight);
if (pixbuf) if (pixbuf)
@ -3842,7 +3847,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
rwidth = parse_size_unchecked (op->data.icon.width, env); rwidth = parse_size_unchecked (op->data.icon.width, env);
rheight = parse_size_unchecked (op->data.icon.height, 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); rwidth, rheight);
if (pixbuf) if (pixbuf)
@ -3864,7 +3869,8 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
int rx, ry; int rx, ry;
PangoRectangle ink_rect, logical_rect; PangoRectangle ink_rect, logical_rect;
meta_color_spec_render (op->data.title.color_spec, widget, &color); meta_color_spec_render (op->data.title.color_spec,
style_gtk, &color);
gdk_cairo_set_source_color (cr, &color); gdk_cairo_set_source_color (cr, &color);
rx = parse_x_position_unchecked (op->data.title.x, env); rx = parse_x_position_unchecked (op->data.title.x, env);