GtkStyle is specific to a particular colormap. Metacity uses different

2009-01-27  Owen Taylor  <otaylor@redhat.com>

       GtkStyle is specific to a particular colormap. Metacity
       uses different colormaps for windows with different
       visuals, so it must specialize the GtkStyle.

       Closes #568365 and #513944.

       * src/ui/frames.[ch]: Keep a GtkStyle for each MetaUIFrame, which is
         obtained by calling gtk_style_attach() on the style for the
         MetaFrames. When the style of the MetaFrames changes, reattach
         everything. When we call gtk_style_set_background() pass in the
         right style.

       * src/ui/themes.[ch]: Create a _with_style() variant of functions that
         previously took the style from widget->style passed in, so we
         can draw with the right style for the colormap.


svn path=/trunk/; revision=4092
This commit is contained in:
Owen Taylor
2009-01-28 01:47:18 +00:00
committed by Thomas James Alexander Thurman
parent 0a172cc053
commit a6c951352f
5 changed files with 293 additions and 92 deletions

View File

@ -68,6 +68,9 @@ static gboolean meta_frames_enter_notify_event (GtkWidget *widget,
static gboolean meta_frames_leave_notify_event (GtkWidget *widget,
GdkEventCrossing *event);
static void meta_frames_attach_style (MetaFrames *frames,
MetaUIFrame *frame);
static void meta_frames_paint_to_drawable (MetaFrames *frames,
MetaUIFrame *frame,
GdkDrawable *drawable,
@ -420,6 +423,18 @@ meta_frames_button_layout_changed (MetaFrames *frames)
queue_draw_func, frames);
}
static void
reattach_style_func (gpointer key, gpointer value, gpointer data)
{
MetaUIFrame *frame;
MetaFrames *frames;
frames = META_FRAMES (data);
frame = value;
meta_frames_attach_style (frames, frame);
}
static void
meta_frames_style_set (GtkWidget *widget,
GtkStyle *prev_style)
@ -430,6 +445,9 @@ meta_frames_style_set (GtkWidget *widget,
meta_frames_font_changed (frames);
g_hash_table_foreach (frames->frames,
reattach_style_func, frames);
GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
}
@ -561,6 +579,24 @@ meta_frames_new (int screen_number)
NULL);
}
/* In order to use a style with a window it has to be attached to that
* window. Actually, the colormaps just have to match, but since GTK+
* already takes care of making sure that its cheap to attach a style
* to multiple windows with the same colormap, we can just go ahead
* and attach separately for each window.
*/
static void
meta_frames_attach_style (MetaFrames *frames,
MetaUIFrame *frame)
{
if (frame->style != NULL)
gtk_style_detach (frame->style);
/* Weirdly, gtk_style_attach() steals a reference count from the style passed in */
gtk_style_ref (GTK_WIDGET (frames)->style);
frame->style = gtk_style_attach (GTK_WIDGET (frames)->style, frame->window);
}
void
meta_frames_manage_window (MetaFrames *frames,
Window xwindow,
@ -576,6 +612,9 @@ meta_frames_manage_window (MetaFrames *frames,
gdk_window_set_user_data (frame->window, frames);
frame->style = NULL;
meta_frames_attach_style (frames, frame);
/* Don't set event mask here, it's in frame.c */
frame->xwindow = xwindow;
@ -626,6 +665,8 @@ meta_frames_unmanage_window (MetaFrames *frames,
g_hash_table_remove (frames->frames, &frame->xwindow);
gtk_style_detach (frame->style);
gdk_window_destroy (frame->window);
if (frame->layout)
@ -2435,7 +2476,8 @@ meta_frames_paint_to_drawable (MetaFrames *frames,
gdk_window_begin_paint_rect (drawable, &areas[i]);
meta_theme_draw_frame (meta_theme_get_current (),
meta_theme_draw_frame_with_style (meta_theme_get_current (),
frame->style,
widget,
drawable,
NULL, /* &areas[i], */
@ -2460,19 +2502,20 @@ meta_frames_paint_to_drawable (MetaFrames *frames,
{
/* Not a window; happens about 1/3 of the time */
meta_theme_draw_frame (meta_theme_get_current (),
widget,
drawable,
NULL,
x_offset, y_offset,
type,
flags,
w, h,
frame->layout,
frame->text_height,
&button_layout,
button_states,
mini_icon, icon);
meta_theme_draw_frame_with_style (meta_theme_get_current (),
frame->style,
widget,
drawable,
NULL,
x_offset, y_offset,
type,
flags,
w, h,
frame->layout,
frame->text_height,
&button_layout,
button_states,
mini_icon, icon);
}
}
@ -2525,7 +2568,7 @@ meta_frames_set_window_background (MetaFrames *frames,
}
else
{
gtk_style_set_background (GTK_WIDGET (frames)->style,
gtk_style_set_background (frame->style,
frame->window, GTK_STATE_NORMAL);
}
}