ui: Port to GtkStyleContext

GtkStyle has been deprecated in favor of GtkStyleContext. A full
port would involve replacing GdkColor with GdkRGBA - leave this
out for the time being.

Bump the required version of GTK+.

https://bugzilla.gnome.org/show_bug.cgi?id=637761
This commit is contained in:
Florian Müllner 2010-12-09 14:52:16 +01:00
parent 42fdd4f4d8
commit 565f002bc4
11 changed files with 230 additions and 182 deletions

View File

@ -55,13 +55,11 @@ draw_handler (GtkWidget *tooltips,
cairo_t *cr,
gpointer user_data)
{
gtk_paint_flat_box (gtk_widget_get_style (tip),
cr,
GTK_STATE_NORMAL, GTK_SHADOW_OUT,
tip, "tooltip",
0, 0,
gtk_widget_get_allocated_width (tip),
gtk_widget_get_allocated_height (tip));
gtk_render_background (gtk_widget_get_style_context (tooltips),
cr,
0, 0,
gtk_widget_get_allocated_width (tooltips),
gtk_widget_get_allocated_height (tooltips));
return FALSE;
}

View File

@ -43,12 +43,11 @@
#define DEFAULT_INNER_BUTTON_BORDER 3
static void meta_frames_destroy (GtkWidget *object);
static void meta_frames_finalize (GObject *object);
static void meta_frames_style_set (GtkWidget *widget,
GtkStyle *prev_style);
static void meta_frames_map (GtkWidget *widget);
static void meta_frames_unmap (GtkWidget *widget);
static void meta_frames_destroy (GtkWidget *object);
static void meta_frames_finalize (GObject *object);
static void meta_frames_style_updated (GtkWidget *widget);
static void meta_frames_map (GtkWidget *widget);
static void meta_frames_unmap (GtkWidget *widget);
static void meta_frames_update_prelit_control (MetaFrames *frames,
MetaUIFrame *frame,
@ -137,7 +136,7 @@ meta_frames_class_init (MetaFramesClass *class)
widget_class->destroy = meta_frames_destroy;
widget_class->style_set = meta_frames_style_set;
widget_class->style_updated = meta_frames_style_updated;
widget_class->map = meta_frames_map;
widget_class->unmap = meta_frames_unmap;
@ -422,8 +421,7 @@ reattach_style_func (gpointer key, gpointer value, gpointer data)
}
static void
meta_frames_style_set (GtkWidget *widget,
GtkStyle *prev_style)
meta_frames_style_updated (GtkWidget *widget)
{
MetaFrames *frames;
@ -434,7 +432,7 @@ meta_frames_style_set (GtkWidget *widget,
g_hash_table_foreach (frames->frames,
reattach_style_func, frames);
GTK_WIDGET_CLASS (meta_frames_parent_class)->style_set (widget, prev_style);
GTK_WIDGET_CLASS (meta_frames_parent_class)->style_updated (widget);
}
static void
@ -577,12 +575,9 @@ meta_frames_attach_style (MetaFrames *frames,
MetaUIFrame *frame)
{
if (frame->style != NULL)
gtk_style_detach (frame->style);
g_object_unref (frame->style);
/* Weirdly, gtk_style_attach() steals a reference count from the style passed in */
g_object_ref (gtk_widget_get_style (GTK_WIDGET (frames)));
frame->style = gtk_style_attach (gtk_widget_get_style (GTK_WIDGET (frames)),
frame->window);
frame->style = g_object_ref (gtk_widget_get_style_context (GTK_WIDGET (frames)));
}
void
@ -653,7 +648,7 @@ meta_frames_unmanage_window (MetaFrames *frames,
g_hash_table_remove (frames->frames, &frame->xwindow);
gtk_style_detach (frame->style);
g_object_unref (frame->style);
gdk_window_destroy (frame->window);
@ -2469,8 +2464,7 @@ meta_frames_set_window_background (MetaFrames *frames,
}
else
{
gtk_style_set_background (frame->style,
frame->window, GTK_STATE_NORMAL);
gtk_style_context_set_background (frame->style, frame->window);
}
}

View File

@ -75,7 +75,7 @@ struct _MetaUIFrame
{
Window xwindow;
GdkWindow *window;
GtkStyle *style;
GtkStyleContext *style;
MetaFrameStyle *cache_style;
PangoLayout *layout;
int text_height;

View File

@ -255,6 +255,7 @@ meta_accel_label_draw (GtkWidget *widget,
if (allocation.width >= requisition.width + ac_width)
{
GtkStyleContext *style;
PangoLayout *label_layout;
PangoLayout *accel_layout;
GtkLabel *label = GTK_LABEL (widget);
@ -302,14 +303,15 @@ meta_accel_label_draw (GtkWidget *widget,
y = (allocation.height - (requisition.height - ypad * 2)) * yalign + 1.5;
gtk_paint_layout (gtk_widget_get_style (widget),
cr,
gtk_widget_get_state (widget),
FALSE,
widget,
"accellabel",
x, y,
accel_layout);
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_render_layout (gtk_widget_get_style_context (widget),
cr,
x, y,
accel_layout);
gtk_style_context_restore (style);
g_object_unref (accel_layout);
}

View File

@ -78,7 +78,6 @@ outline_window_draw (GtkWidget *widget,
{
MetaTabPopup *popup;
TabEntry *te;
GtkStyle *style;
popup = data;
@ -86,10 +85,9 @@ outline_window_draw (GtkWidget *widget,
return FALSE;
te = popup->current_selected_entry;
style = gtk_widget_get_style (widget);
cairo_set_line_width (cr, 1.0);
gdk_cairo_set_source_color (cr, &style->white);
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
cairo_rectangle (cr,
0.5, 0.5,
@ -479,6 +477,7 @@ display_entry (MetaTabPopup *popup,
{
cairo_region_t *region;
cairo_region_t *inner_region;
GdkRGBA black = { 0.0, 0.0, 0.0, 1.0 };
window = gtk_widget_get_window (popup->outline_window);
@ -495,9 +494,7 @@ display_entry (MetaTabPopup *popup,
te->rect.x, te->rect.y,
te->rect.width, te->rect.height);
gdk_window_set_background (window,
&gtk_widget_get_style (popup->outline_window)->black);
gdk_window_set_background_rgba (window, &black);
region = cairo_region_create_rectangle (&rect);
@ -709,9 +706,9 @@ meta_select_image_draw (GtkWidget *widget,
{
GtkMisc *misc;
GtkRequisition requisition;
GtkStyle *style;
GtkStateType state;
GtkStyleContext *context;
GdkWindow *window;
GdkRGBA color;
int x, y, w, h;
gint xpad, ypad;
gfloat xalign, yalign;
@ -732,11 +729,15 @@ meta_select_image_draw (GtkWidget *widget,
h = requisition.height - OUTSIDE_SELECT_RECT * 2 - 1;
window = gtk_widget_get_window (widget);
style = gtk_widget_get_style (widget);
state = gtk_widget_get_state (widget);
context = gtk_widget_get_style_context (widget);
gtk_style_context_set_state (context,
gtk_widget_get_state_flags (widget));
gtk_style_context_lookup_color (context, "color", &color);
cairo_set_line_width (cr, 2.0);
gdk_cairo_set_source_color (cr, &style->fg[state]);
cairo_set_source_rgb (cr, color.red, color.green, color.blue);
cairo_rectangle (cr, x, y, w + 1, h + 1);
cairo_stroke (cr);
@ -891,7 +892,6 @@ meta_select_workspace_draw (GtkWidget *widget,
MetaWorkspace *workspace;
WnckWindowDisplayInfo *windows;
GtkAllocation allocation;
GtkStyle *style;
int i, n_windows;
GList *tmp, *list;
@ -949,11 +949,18 @@ meta_select_workspace_draw (GtkWidget *widget,
if (META_SELECT_WORKSPACE (widget)->selected)
{
style = gtk_widget_get_style (widget);
GtkStyleContext *context;
GdkRGBA color;
context = gtk_widget_get_style_context (widget);
gtk_style_context_set_state (context,
gtk_widget_get_state_flags (widget));
gtk_style_context_lookup_color (context, "color", &color);
gdk_cairo_set_source_color (cr,
&style->fg[gtk_widget_get_state (widget)]);
cairo_set_line_width (cr, SELECT_OUTLINE_WIDTH);
cairo_set_source_rgb (cr, color.red, color.green, color.blue);
cairo_rectangle (cr,
SELECT_OUTLINE_WIDTH / 2.0, SELECT_OUTLINE_WIDTH / 2.0,

View File

@ -224,11 +224,17 @@ draw_callback (GtkWidget *widget,
gpointer data)
{
RenderGradientFunc func = data;
GtkStyle *style;
GtkStyleContext *style;
GdkRGBA color;
style = gtk_widget_get_style (widget);
style = gtk_widget_get_style_context (widget);
gdk_cairo_set_source_color (cr, &style->fg[gtk_widget_get_state (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);
cairo_set_source_rgba (cr, color.red, color.green, color.blue, color.alpha);
(* func) (cr,
gtk_widget_get_allocated_width (widget),

View File

@ -975,7 +975,7 @@ void meta_draw_op_draw (const MetaDrawOp *op,
MetaRectangle logical_region);
void meta_draw_op_draw_with_style (const MetaDrawOp *op,
GtkStyle *style_gtk,
GtkStyleContext *style_gtk,
GtkWidget *widget,
cairo_t *cr,
const MetaDrawInfo *info,
@ -991,7 +991,7 @@ 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,
GtkStyleContext *style_gtk,
GtkWidget *widget,
cairo_t *cr,
const MetaDrawInfo *info,
@ -1035,7 +1035,7 @@ void meta_frame_style_draw (MetaFrameStyle *style,
void meta_frame_style_draw_with_style (MetaFrameStyle *style,
GtkStyle *style_gtk,
GtkStyleContext *style_gtk,
GtkWidget *widget,
cairo_t *cr,
const MetaFrameGeometry *fgeom,
@ -1101,7 +1101,7 @@ void meta_theme_draw_frame_by_name (MetaTheme *theme,
GdkPixbuf *icon);
void meta_theme_draw_frame_with_style (MetaTheme *theme,
GtkStyle *style_gtk,
GtkStyleContext *style_gtk,
GtkWidget *widget,
cairo_t *cr,
MetaFrameType type,

View File

@ -472,7 +472,7 @@ get_window_flags (MetaFrameType type)
static GtkWidget*
preview_collection (int font_size,
PangoFontDescription *base_desc)
const PangoFontDescription *base_desc)
{
GtkWidget *box;
GtkWidget *sw;
@ -780,7 +780,8 @@ benchmark_summary (void)
int
main (int argc, char **argv)
{
GtkStyle *style;
GtkStyleContext *style;
const PangoFontDescription *font_desc;
GtkWidget *window;
GtkWidget *collection;
GError *err;
@ -857,28 +858,29 @@ main (int argc, char **argv)
G_CALLBACK (gtk_main_quit), NULL);
gtk_widget_realize (window);
style = gtk_widget_get_style (window);
style = gtk_widget_get_style_context (window);
font_desc = gtk_style_context_get_font (style, 0);
g_assert (style);
g_assert (style->font_desc);
g_assert (font_desc);
notebook = gtk_notebook_new ();
gtk_container_add (GTK_CONTAINER (window), notebook);
collection = preview_collection (FONT_SIZE_NORMAL,
style->font_desc);
font_desc);
gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
collection,
gtk_label_new (_("Normal Title Font")));
collection = preview_collection (FONT_SIZE_SMALL,
style->font_desc);
font_desc);
gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
collection,
gtk_label_new (_("Small Title Font")));
collection = preview_collection (FONT_SIZE_LARGE,
style->font_desc);
font_desc);
gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
collection,
gtk_label_new (_("Large Title Font")));
@ -929,7 +931,12 @@ get_flags (GtkWidget *widget)
static int
get_text_height (GtkWidget *widget)
{
return meta_pango_font_desc_get_text_height (gtk_widget_get_style (widget)->font_desc,
GtkStyleContext *style;
const PangoFontDescription *font_desc;
style = gtk_widget_get_style_context (widget);
font_desc = gtk_style_context_get_font (style, 0);
return meta_pango_font_desc_get_text_height (font_desc,
gtk_widget_get_pango_context (widget));
}

View File

@ -3472,6 +3472,30 @@ fill_env (MetaPositionExprEnv *env,
env->theme = meta_current_theme;
}
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;
}
/* 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
@ -3485,7 +3509,7 @@ fill_env (MetaPositionExprEnv *env,
*/
static void
meta_draw_op_draw_with_env (const MetaDrawOp *op,
GtkStyle *style_gtk,
GtkStyleContext *style_gtk,
GtkWidget *widget,
cairo_t *cr,
const MetaDrawInfo *info,
@ -3495,6 +3519,7 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
GdkColor color;
cairo_save (cr);
gtk_style_context_save (style_gtk);
cairo_set_line_width (cr, 1.0);
@ -3744,21 +3769,36 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
case META_DRAW_GTK_ARROW:
{
int rx, ry, rwidth, rheight;
double angle = 0, size;
rx = parse_x_position_unchecked (op->data.gtk_arrow.x, env);
ry = parse_y_position_unchecked (op->data.gtk_arrow.y, env);
rwidth = parse_size_unchecked (op->data.gtk_arrow.width, env);
rheight = parse_size_unchecked (op->data.gtk_arrow.height, env);
gtk_paint_arrow (style_gtk,
cr,
op->data.gtk_arrow.state,
op->data.gtk_arrow.shadow,
widget,
"metacity",
op->data.gtk_arrow.arrow,
op->data.gtk_arrow.filled,
rx, ry, rwidth, rheight);
size = MAX(rwidth, rheight);
switch (op->data.gtk_arrow.arrow)
{
case GTK_ARROW_UP:
angle = 0;
break;
case GTK_ARROW_RIGHT:
angle = M_PI / 2;
break;
case GTK_ARROW_DOWN:
angle = M_PI;
break;
case GTK_ARROW_LEFT:
angle = 3 * M_PI / 2;
break;
case GTK_ARROW_NONE:
return;
}
gtk_style_context_set_state (style_gtk,
state_flags_from_gtk_state (op->data.gtk_arrow.state));
gtk_render_arrow (style_gtk, cr, angle, rx, ry, size);
}
break;
@ -3771,13 +3811,10 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
rwidth = parse_size_unchecked (op->data.gtk_box.width, env);
rheight = parse_size_unchecked (op->data.gtk_box.height, env);
gtk_paint_box (style_gtk,
cr,
op->data.gtk_box.state,
op->data.gtk_box.shadow,
widget,
"metacity",
rx, ry, rwidth, rheight);
gtk_style_context_set_state (style_gtk,
state_flags_from_gtk_state (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);
}
break;
@ -3789,12 +3826,9 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
ry1 = parse_y_position_unchecked (op->data.gtk_vline.y1, env);
ry2 = parse_y_position_unchecked (op->data.gtk_vline.y2, env);
gtk_paint_vline (style_gtk,
cr,
op->data.gtk_vline.state,
widget,
"metacity",
ry1, ry2, rx);
gtk_style_context_set_state (style_gtk,
state_flags_from_gtk_state (op->data.gtk_vline.state));
gtk_render_line (style_gtk, cr, rx, ry1, rx, ry2);
}
break;
@ -3939,15 +3973,16 @@ meta_draw_op_draw_with_env (const MetaDrawOp *op,
}
cairo_restore (cr);
gtk_style_context_restore (style_gtk);
}
void
meta_draw_op_draw_with_style (const MetaDrawOp *op,
GtkStyle *style_gtk,
GtkWidget *widget,
cairo_t *cr,
const MetaDrawInfo *info,
MetaRectangle logical_region)
GtkStyleContext *style_gtk,
GtkWidget *widget,
cairo_t *cr,
const MetaDrawInfo *info,
MetaRectangle logical_region)
{
MetaPositionExprEnv env;
@ -3966,8 +4001,8 @@ 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,
cr, info, logical_region);
meta_draw_op_draw_with_style (op, gtk_widget_get_style_context (widget),
widget, cr, info, logical_region);
}
/**
@ -4023,11 +4058,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,
cairo_t *cr,
const MetaDrawInfo *info,
MetaRectangle rect)
GtkStyleContext *style_gtk,
GtkWidget *widget,
cairo_t *cr,
const MetaDrawInfo *info,
MetaRectangle rect)
{
int i;
MetaPositionExprEnv env;
@ -4088,7 +4123,7 @@ 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, gtk_widget_get_style_context (widget), widget,
cr, info, rect);
}
@ -4472,17 +4507,17 @@ button_rect (MetaButtonType type,
void
meta_frame_style_draw_with_style (MetaFrameStyle *style,
GtkStyle *style_gtk,
GtkWidget *widget,
cairo_t *cr,
const MetaFrameGeometry *fgeom,
int client_width,
int client_height,
PangoLayout *title_layout,
int text_height,
MetaButtonState button_states[META_BUTTON_TYPE_LAST],
GdkPixbuf *mini_icon,
GdkPixbuf *icon)
GtkStyleContext *style_gtk,
GtkWidget *widget,
cairo_t *cr,
const MetaFrameGeometry *fgeom,
int client_width,
int client_height,
PangoLayout *title_layout,
int text_height,
MetaButtonState button_states[META_BUTTON_TYPE_LAST],
GdkPixbuf *mini_icon,
GdkPixbuf *icon)
{
int i, j;
GdkRectangle titlebar_rect;
@ -4640,10 +4675,10 @@ 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);
widget,
cr,
&draw_info,
m_rect);
}
}
@ -4723,7 +4758,7 @@ meta_frame_style_draw (MetaFrameStyle *style,
GdkPixbuf *mini_icon,
GdkPixbuf *icon)
{
meta_frame_style_draw_with_style (style, gtk_widget_get_style (widget), widget,
meta_frame_style_draw_with_style (style, gtk_widget_get_style_context (widget), widget,
cr, fgeom, client_width, client_height,
title_layout, text_height,
button_states, mini_icon, icon);
@ -5336,19 +5371,19 @@ meta_theme_get_title_scale (MetaTheme *theme,
void
meta_theme_draw_frame_with_style (MetaTheme *theme,
GtkStyle *style_gtk,
GtkWidget *widget,
cairo_t *cr,
MetaFrameType type,
MetaFrameFlags flags,
int client_width,
int client_height,
PangoLayout *title_layout,
int text_height,
const MetaButtonLayout *button_layout,
MetaButtonState button_states[META_BUTTON_TYPE_LAST],
GdkPixbuf *mini_icon,
GdkPixbuf *icon)
GtkStyleContext *style_gtk,
GtkWidget *widget,
cairo_t *cr,
MetaFrameType type,
MetaFrameFlags flags,
int client_width,
int client_height,
PangoLayout *title_layout,
int text_height,
const MetaButtonLayout *button_layout,
MetaButtonState button_states[META_BUTTON_TYPE_LAST],
GdkPixbuf *mini_icon,
GdkPixbuf *icon)
{
MetaFrameGeometry fgeom;
MetaFrameStyle *style;
@ -5396,7 +5431,7 @@ meta_theme_draw_frame (MetaTheme *theme,
GdkPixbuf *mini_icon,
GdkPixbuf *icon)
{
meta_theme_draw_frame_with_style (theme, gtk_widget_get_style (widget), widget,
meta_theme_draw_frame_with_style (theme, gtk_widget_get_style_context (widget), widget,
cr, type,flags,
client_width, client_height,
title_layout, text_height,
@ -5783,11 +5818,13 @@ meta_gtk_widget_get_font_desc (GtkWidget *widget,
double scale,
const PangoFontDescription *override)
{
GtkStyleContext *style;
PangoFontDescription *font_desc;
g_return_val_if_fail (gtk_widget_get_realized (widget), NULL);
font_desc = pango_font_description_copy (gtk_widget_get_style (widget)->font_desc);
style = gtk_widget_get_style_context (widget);
font_desc = pango_font_description_copy (gtk_style_context_get_font (style, 0));
if (override)
pango_font_description_merge (font_desc, override, TRUE);

View File

@ -36,8 +36,7 @@ struct _MetaTilePreview {
GtkWidget *preview_window;
gulong create_serial;
GdkColor *preview_color;
guchar preview_alpha;
GdkRGBA *preview_color;
MetaRectangle tile_rect;
@ -57,22 +56,23 @@ meta_tile_preview_draw (GtkWidget *widget,
{
/* Fill the preview area with a transparent color */
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);
preview->preview_color->red,
preview->preview_color->green,
preview->preview_color->blue,
preview->preview_color->alpha);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_paint (cr);
/* Use the opaque color for the border */
gdk_cairo_set_source_color (cr, preview->preview_color);
cairo_set_source_rgb (cr,
preview->preview_color->red,
preview->preview_color->green,
preview->preview_color->blue);
}
else
{
GtkStyle *style = gtk_widget_get_style (preview->preview_window);
gdk_cairo_set_source_color (cr, &style->white);
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
cairo_rectangle (cr,
OUTLINE_WIDTH - 0.5, OUTLINE_WIDTH - 0.5,
@ -90,37 +90,6 @@ meta_tile_preview_draw (GtkWidget *widget,
return FALSE;
}
static void
on_preview_window_style_set (GtkWidget *widget,
GtkStyle *previous,
gpointer user_data)
{
MetaTilePreview *preview = user_data;
GtkStyle *style;
style = gtk_rc_get_style_by_paths (gtk_widget_get_settings (widget),
"GtkWindow.GtkIconView",
"GtkWindow.GtkIconView",
GTK_TYPE_ICON_VIEW);
if (style != NULL)
g_object_ref (style);
else
style = gtk_style_new ();
gtk_style_get (style, GTK_TYPE_ICON_VIEW,
"selection-box-color", &preview->preview_color,
"selection-box-alpha", &preview->preview_alpha,
NULL);
if (!preview->preview_color)
{
GdkColor selection = style->base[GTK_STATE_SELECTED];
preview->preview_color = gdk_color_copy (&selection);
}
g_object_unref (style);
}
MetaTilePreview *
meta_tile_preview_new (int screen_number,
gboolean composited)
@ -138,7 +107,6 @@ meta_tile_preview_new (int screen_number,
gtk_widget_set_app_paintable (preview->preview_window, TRUE);
preview->preview_color = NULL;
preview->preview_alpha = 0xFF;
preview->tile_rect.x = preview->tile_rect.y = 0;
preview->tile_rect.width = preview->tile_rect.height = 0;
@ -148,11 +116,38 @@ meta_tile_preview_new (int screen_number,
if (preview->has_alpha)
{
GtkStyleContext *context;
GtkWidgetPath *path;
guchar selection_alpha = 0xFF;
gtk_widget_set_visual (preview->preview_window,
gdk_screen_get_rgba_visual (screen));
g_signal_connect (preview->preview_window, "style-set",
G_CALLBACK (on_preview_window_style_set), preview);
path = gtk_widget_path_new ();
gtk_widget_path_append_type (path, GTK_TYPE_ICON_VIEW);
context = gtk_style_context_new ();
gtk_style_context_set_path (context, path);
gtk_style_context_add_class (context,
GTK_STYLE_CLASS_RUBBERBAND);
gtk_widget_path_free (path);
gtk_style_context_get (context, GTK_STATE_FLAG_SELECTED,
"background-color", &preview->preview_color,
NULL);
/* The background-color for the .rubberband class should probably
* contain the correct alpha value - unfortunately, at least for now
* it doesn't. Hopefully the following workaround can be removed
* when GtkIconView gets ported to GtkStyleContext.
*/
gtk_style_context_get_style (context,
"selection-box-alpha", &selection_alpha,
NULL);
preview->preview_color->alpha = (double)selection_alpha / 0xFF;
g_object_unref (context);
}
/* We make an assumption that XCreateWindow will be the first operation
@ -173,7 +168,7 @@ meta_tile_preview_free (MetaTilePreview *preview)
gtk_widget_destroy (preview->preview_window);
if (preview->preview_color)
gdk_color_free (preview->preview_color);
gdk_rgba_free (preview->preview_color);
g_free (preview);
}
@ -214,10 +209,9 @@ meta_tile_preview_show (MetaTilePreview *preview,
{
cairo_region_t *outer_region, *inner_region;
GdkRectangle outer_rect, inner_rect;
GdkColor black;
GdkRGBA black = { 0.0, 0.0, 0.0, 1.0 };
black = gtk_widget_get_style (preview->preview_window)->black;
gdk_window_set_background (window, &black);
gdk_window_set_background_rgba (window, &black);
outer_rect.x = outer_rect.y = 0;
outer_rect.width = preview->tile_rect.width;

View File

@ -713,9 +713,9 @@ meta_ui_theme_get_frame_borders (MetaUI *ui,
int *right_width)
{
int text_height;
GtkStyleContext *style = NULL;
PangoContext *context;
const PangoFontDescription *font_desc;
GtkStyle *default_style;
if (meta_ui_have_a_theme ())
{
@ -724,8 +724,8 @@ meta_ui_theme_get_frame_borders (MetaUI *ui,
if (!font_desc)
{
default_style = gtk_widget_get_default_style ();
font_desc = default_style->font_desc;
style = gtk_style_context_new ();
font_desc = gtk_style_context_get_font (style, 0);
}
text_height = meta_pango_font_desc_get_text_height (font_desc, context);
@ -739,6 +739,9 @@ meta_ui_theme_get_frame_borders (MetaUI *ui,
{
*top_height = *bottom_height = *left_width = *right_width = 0;
}
if (style != NULL)
g_object_unref (style);
}
void