Skip to content

Commit

Permalink
render: fix root back pixmap binding in case of depth mismatch
Browse files Browse the repository at this point in the history
backport of the previous commit to legacy backends. it also eliminates
the x_validate_pixmap function since it was only used in the
get_root_tile function and the fix implies and embeds it.
  • Loading branch information
absolutelynothelix committed Jan 14, 2023
1 parent 7c9d59a commit 1f12f87
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 deletions.
18 changes: 12 additions & 6 deletions src/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,26 +597,32 @@ static bool get_root_tile(session_t *ps) {
bool fill = false;
xcb_pixmap_t pixmap = x_get_root_back_pixmap(ps->c, ps->root, ps->atoms);

// Make sure the pixmap we got is valid
if (pixmap && !x_validate_pixmap(ps->c, pixmap))
pixmap = XCB_NONE;
xcb_get_geometry_reply_t *r;
if (pixmap) {
r = xcb_get_geometry_reply(ps->c, xcb_get_geometry(ps->c, pixmap), NULL);
}

// Create a pixmap if there isn't any
if (!pixmap) {
xcb_visualid_t vis;
if (!pixmap || !r) {
pixmap = x_create_pixmap(ps->c, (uint8_t)ps->depth, ps->root, 1, 1);
if (pixmap == XCB_NONE) {
log_error("Failed to create pixmaps for root tile.");
return false;
}
vis = ps->vis;
fill = true;
} else {
vis = x_get_visual_for_depth(ps->c, r->depth);
free(r);
}

// Create Picture
xcb_render_create_picture_value_list_t pa = {
.repeat = true,
};
ps->root_tile_paint.pict = x_create_picture_with_visual_and_pixmap(
ps->c, ps->vis, pixmap, XCB_RENDER_CP_REPEAT, &pa);
ps->c, vis, pixmap, XCB_RENDER_CP_REPEAT, &pa);

// Fill pixmap if needed
if (fill) {
Expand All @@ -637,7 +643,7 @@ static bool get_root_tile(session_t *ps) {
ps->root_tile_paint.pixmap = pixmap;
#ifdef CONFIG_OPENGL
if (BKEND_GLX == ps->o.backend)
return paint_bind_tex(ps, &ps->root_tile_paint, 0, 0, true, 0, ps->vis, false);
return paint_bind_tex(ps, &ps->root_tile_paint, 0, 0, true, 0, vis, false);
#endif

return true;
Expand Down
20 changes: 0 additions & 20 deletions src/x.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,26 +622,6 @@ xcb_pixmap_t x_create_pixmap(xcb_connection_t *c, uint8_t depth, xcb_drawable_t
return XCB_NONE;
}

/**
* Validate a pixmap.
*
* Detect whether the pixmap is valid with XGetGeometry. Well, maybe there
* are better ways.
*/
bool x_validate_pixmap(xcb_connection_t *c, xcb_pixmap_t pixmap) {
if (pixmap == XCB_NONE) {
return false;
}

auto r = xcb_get_geometry_reply(c, xcb_get_geometry(c, pixmap), NULL);
if (!r) {
return false;
}

bool ret = r->width && r->height;
free(r);
return ret;
}
/// Names of root window properties that could point to a pixmap of
/// background.
static const char *background_props_str[] = {
Expand Down
2 changes: 0 additions & 2 deletions src/x.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,6 @@ const char *x_strerror(xcb_generic_error_t *e);
xcb_pixmap_t x_create_pixmap(xcb_connection_t *, uint8_t depth, xcb_drawable_t drawable,
int width, int height);

bool x_validate_pixmap(xcb_connection_t *, xcb_pixmap_t pxmap);

/**
* Free a <code>winprop_t</code>.
*
Expand Down

0 comments on commit 1f12f87

Please sign in to comment.