x11: Keep a default X Colormap in every visual to construct windows with

This way, we can specify a colormap when constructing windows. And ew
must do that to avoid BadMatch from XCreateWindow when we use a
different visual.
This commit is contained in:
Benjamin Otte 2010-08-29 17:48:58 +02:00
parent 47ee996198
commit 28b4567159
3 changed files with 53 additions and 2 deletions

View File

@ -56,6 +56,8 @@ struct _GdkCursorPrivate
void _gdk_x11_error_handler_push (void); void _gdk_x11_error_handler_push (void);
void _gdk_x11_error_handler_pop (void); void _gdk_x11_error_handler_pop (void);
Colormap _gdk_visual_get_x11_colormap (GdkVisual *visual);
void _gdk_xid_table_insert (GdkDisplay *display, void _gdk_xid_table_insert (GdkDisplay *display,
XID *xid, XID *xid,
gpointer data); gpointer data);

View File

@ -38,6 +38,7 @@ struct _GdkVisualPrivate
{ {
Visual *xvisual; Visual *xvisual;
GdkScreen *screen; GdkScreen *screen;
Colormap colormap;
}; };
struct _GdkVisualClass struct _GdkVisualClass
@ -70,12 +71,26 @@ static const gchar *const visual_names[] =
G_DEFINE_TYPE (GdkVisual, gdk_visual, G_TYPE_OBJECT) G_DEFINE_TYPE (GdkVisual, gdk_visual, G_TYPE_OBJECT)
static void
gdk_visual_finalize (GObject *object)
{
GdkVisualPrivate *priv = (GdkVisualPrivate *) object;
if (priv->colormap != None)
XFreeColormap (GDK_SCREEN_XDISPLAY (priv->screen),
priv->colormap);
G_OBJECT_CLASS (gdk_visual_parent_class)->finalize (object);
}
static void static void
gdk_visual_class_init (GdkVisualClass *visual_class) gdk_visual_class_init (GdkVisualClass *visual_class)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (visual_class); GObjectClass *object_class = G_OBJECT_CLASS (visual_class);
g_type_class_add_private (object_class, sizeof (GdkVisualPrivate)); g_type_class_add_private (object_class, sizeof (GdkVisualPrivate));
object_class->finalize = gdk_visual_finalize;
} }
static void static void
@ -84,6 +99,8 @@ gdk_visual_init (GdkVisual *visual)
visual->priv = G_TYPE_INSTANCE_GET_PRIVATE (visual, visual->priv = G_TYPE_INSTANCE_GET_PRIVATE (visual,
GDK_TYPE_VISUAL, GDK_TYPE_VISUAL,
GdkVisualPrivate); GdkVisualPrivate);
visual->priv->colormap = None;
} }
void void
@ -241,7 +258,11 @@ _gdk_visual_init (GdkScreen *screen)
for (i = 0; i < nvisuals; i++) for (i = 0; i < nvisuals; i++)
{ {
if (default_xvisual->visualid == visuals[i]->priv->xvisual->visualid) if (default_xvisual->visualid == visuals[i]->priv->xvisual->visualid)
screen_x11->system_visual = visuals[i]; {
screen_x11->system_visual = visuals[i];
visuals[i]->priv->colormap = DefaultColormap (screen_x11->xdisplay,
screen_x11->screen_num);
}
/* For now, we only support 8888 ARGB for the "rgba visual". /* For now, we only support 8888 ARGB for the "rgba visual".
* Additional formats (like ABGR) could be added later if they * Additional formats (like ABGR) could be added later if they
@ -632,6 +653,34 @@ gdk_visual_equal (Visual *a,
return (a->visualid == b->visualid); return (a->visualid == b->visualid);
} }
/**
* _gdk_visual_get_x11_colormap:
* @visual: the visual to get the colormap from
*
* Gets the colormap to use
*
* Returns: the X Colormap to use for new windows using @visual
**/
Colormap
_gdk_visual_get_x11_colormap (GdkVisual *visual)
{
GdkVisualPrivate *priv;
g_return_val_if_fail (GDK_IS_VISUAL (visual), None);
priv = visual->priv;
if (priv->colormap == None)
{
priv->colormap = XCreateColormap (GDK_SCREEN_XDISPLAY (priv->screen),
GDK_SCREEN_XROOTWIN (priv->screen),
GDK_VISUAL_XVISUAL (visual),
AllocNone);
}
return priv->colormap;
}
/** /**
* gdk_x11_visual_get_xvisual: * gdk_x11_visual_get_xvisual:
* @visual: a #GdkVisual. * @visual: a #GdkVisual.

View File

@ -784,7 +784,7 @@ _gdk_window_impl_new (GdkWindow *window,
xattributes_mask |= CWBitGravity; xattributes_mask |= CWBitGravity;
xattributes.colormap = GDK_COLORMAP_XCOLORMAP (draw_impl->colormap); xattributes.colormap = _gdk_visual_get_x11_colormap (private->visual);
xattributes_mask |= CWColormap; xattributes_mask |= CWColormap;
if (private->window_type == GDK_WINDOW_TEMP) if (private->window_type == GDK_WINDOW_TEMP)