From fb3305fb9bf7801f0b8608cd92f90d8b548688a8 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Tue, 17 Mar 2020 18:32:34 +0000 Subject: [PATCH] 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 --- src/win.c | 12 +++++++----- src/win.h | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/win.c b/src/win.c index d011514..ff85e51 100644 --- a/src/win.c +++ b/src/win.c @@ -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(®_win, 0, 0, w->g.width, w->g.height); + pixman_region32_init_rects(®_win, (rect_t[]){0, 0, outer_width, outer_height}, 1); pixman_region32_intersect(res, ®_win, res); pixman_region32_fini(®_win); } diff --git a/src/win.h b/src/win.h index 3b374e5..385275f 100644 --- a/src/win.h +++ b/src/win.h @@ -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;