win: fix calculation of window frame region

The geometry returned by xcb_get_geometry doesn't include the window
border, so we have to include that when calculating the frame.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2020-03-17 18:32:34 +00:00
parent cf3e95f0a4
commit fb3305fb9b
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
2 changed files with 9 additions and 5 deletions

View File

@ -211,24 +211,26 @@ void win_get_region_noframe_local(const struct managed_win *w, region_t *res) {
void win_get_region_frame_local(const struct managed_win *w, region_t *res) {
const margin_t extents = win_calc_frame_extents(w);
auto outer_width = extents.left + extents.right + w->g.width;
auto outer_height = extents.top + extents.bottom + w->g.height;
pixman_region32_fini(res);
pixman_region32_init_rects(
res,
(rect_t[]){
// top
{.x1 = 0, .y1 = 0, .x2 = w->g.width, .y2 = extents.top},
{.x1 = 0, .y1 = 0, .x2 = outer_width, .y2 = extents.top},
// bottom
{.x1 = 0, .y1 = w->g.height - extents.bottom, .x2 = w->g.width, .y2 = w->g.height},
{.x1 = 0, .y1 = outer_height - extents.bottom, .x2 = outer_width, .y2 = outer_height},
// left
{.x1 = 0, .y1 = 0, .x2 = extents.left, .y2 = w->g.height},
{.x1 = 0, .y1 = 0, .x2 = extents.left, .y2 = outer_height},
// right
{.x1 = w->g.width - extents.right, .y1 = 0, .x2 = w->g.width, .y2 = w->g.height},
{.x1 = outer_width - extents.right, .y1 = 0, .x2 = outer_width, .y2 = outer_height},
},
4);
// limit the frame region to inside the window
region_t reg_win;
pixman_region32_init_rect(&reg_win, 0, 0, w->g.width, w->g.height);
pixman_region32_init_rects(&reg_win, (rect_t[]){0, 0, outer_width, outer_height}, 1);
pixman_region32_intersect(res, &reg_win, res);
pixman_region32_fini(&reg_win);
}

View File

@ -107,6 +107,8 @@ struct managed_win {
winstate_t state;
/// Window attributes.
xcb_get_window_attributes_reply_t a;
/// Reply of xcb_get_geometry, which returns the geometry of the window body,
/// excluding the window border.
xcb_get_geometry_reply_t g;
/// Xinerama screen this window is on.
int xinerama_scr;