Skip to content

Commit

Permalink
render: fix binding the root background pixmap in case of depth mismatch
Browse files Browse the repository at this point in the history
fix the same issue in the legacy backends, see the previous commit for
details. this commit also removes the x_validate_pixmap function because
it was used only in the get_root_tile function and the fix pretty much
implies and embeds it.
  • Loading branch information
absolutelynothelix committed Feb 1, 2024
1 parent 3c92b40 commit 18cb511
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 30 deletions.
20 changes: 13 additions & 7 deletions src/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,28 +604,35 @@ static bool get_root_tile(session_t *ps) {
bool fill = false;
xcb_pixmap_t pixmap = x_get_root_back_pixmap(&ps->c, 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.c, xcb_get_geometry(ps->c.c, pixmap), NULL);

Check warning on line 609 in src/render.c

View check run for this annotation

Codecov / codecov/patch

src/render.c#L608-L609

Added lines #L608 - L609 were not covered by tests
}

// Create a pixmap if there isn't any
if (!pixmap) {
xcb_visualid_t visual;
if (!pixmap || !r) {

Check warning on line 614 in src/render.c

View check run for this annotation

Codecov / codecov/patch

src/render.c#L614

Added line #L614 was not covered by tests
pixmap =
x_create_pixmap(&ps->c, (uint8_t)ps->c.screen_info->root_depth, 1, 1);
if (pixmap == XCB_NONE) {
log_error("Failed to create pixmaps for root tile.");
return false;
}
visual = ps->c.screen_info->root_visual;

Check warning on line 621 in src/render.c

View check run for this annotation

Codecov / codecov/patch

src/render.c#L621

Added line #L621 was not covered by tests
fill = true;
} else {
visual = r->depth == ps->c.screen_info->root_depth
? ps->c.screen_info->root_visual
: x_get_visual_for_depth(&ps->c, r->depth);
free(r);

Check warning on line 627 in src/render.c

View check run for this annotation

Codecov / codecov/patch

src/render.c#L624-L627

Added lines #L624 - L627 were not covered by tests
}

// 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->c.screen_info->root_visual, pixmap, XCB_RENDER_CP_REPEAT, &pa);
&ps->c, visual, pixmap, XCB_RENDER_CP_REPEAT, &pa);

// Fill pixmap if needed
if (fill) {
Expand All @@ -646,8 +653,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->c.screen_info->root_visual, false);
return paint_bind_tex(ps, &ps->root_tile_paint, 0, 0, true, 0, visual, false);

Check warning on line 656 in src/render.c

View check run for this annotation

Codecov / codecov/patch

src/render.c#L656

Added line #L656 was not covered by tests
}
#endif

Expand Down
21 changes: 0 additions & 21 deletions src/x.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,27 +704,6 @@ xcb_pixmap_t x_create_pixmap(struct x_connection *c, uint8_t depth, int width, i
return XCB_NONE;
}

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

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

bool ret = r->width && r->height;
free(r);
return ret;
}

/// We don't use the _XSETROOT_ID root window property as a source of the background
/// pixmap because it most likely points to a dummy pixmap used to keep the colormap
/// associated with the background pixmap alive but we listen for it's changes and update
Expand Down
2 changes: 0 additions & 2 deletions src/x.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,6 @@ const char *x_strerror(xcb_generic_error_t *e);

xcb_pixmap_t x_create_pixmap(struct x_connection *, uint8_t depth, int width, int height);

bool x_validate_pixmap(struct x_connection *, xcb_pixmap_t pxmap);

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

0 comments on commit 18cb511

Please sign in to comment.