From 2ebd1202239a90586e907323ec5ff6b264419c49 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Mon, 20 Aug 2018 10:28:21 +0200 Subject: [PATCH 1/3] Refactor event_handle_configurerequest Before this commit, the code in here first handled clients changing its x/y position and afterwards it handled resizes. This meant that the special case of "client resizes without moving itself so we need to apply gravity" had to have special checks on whether the client moved itself or not. Change the code so that resizes are handled first and moves later. This naturally handles the problem: If the client resizes and moves itself, the move done for the resize is later overwritten when the move is handled. No functional changes are intended. Signed-off-by: Uli Schlachter --- event.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/event.c b/event.c index 9ab67653..29bcbe8d 100644 --- a/event.c +++ b/event.c @@ -343,16 +343,6 @@ event_handle_configurerequest(xcb_configure_request_event_t *ev) lua_State *L = globalconf_get_lua_State(); - if(ev->value_mask & XCB_CONFIG_WINDOW_X) - { - geometry.x = ev->x; - xwindow_translate_for_gravity(c->size_hints.win_gravity, deco_left, 0, deco_right, 0, &geometry.x, NULL); - } - if(ev->value_mask & XCB_CONFIG_WINDOW_Y) - { - geometry.y = ev->y; - xwindow_translate_for_gravity(c->size_hints.win_gravity, 0, deco_top, 0, deco_bottom, NULL, &geometry.y); - } if(ev->value_mask & XCB_CONFIG_WINDOW_WIDTH) { uint16_t old_w = geometry.width; @@ -383,12 +373,17 @@ event_handle_configurerequest(xcb_configure_request_event_t *ev) /* If the client resizes without moving itself, apply window gravity */ if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_WIN_GRAVITY) { - int16_t diff_x = 0, diff_y = 0; - xwindow_translate_for_gravity(c->size_hints.win_gravity, diff_border, diff_border, diff_w, diff_h, &diff_x, &diff_y); - if(!(ev->value_mask & XCB_CONFIG_WINDOW_X)) - geometry.x += diff_x; - if(!(ev->value_mask & XCB_CONFIG_WINDOW_Y)) - geometry.y += diff_y; + xwindow_translate_for_gravity(c->size_hints.win_gravity, diff_border, diff_border, diff_w, diff_h, &geometry.x, &geometry.y); + } + if(ev->value_mask & XCB_CONFIG_WINDOW_X) + { + geometry.x = ev->x; + xwindow_translate_for_gravity(c->size_hints.win_gravity, deco_left, 0, deco_right, 0, &geometry.x, NULL); + } + if(ev->value_mask & XCB_CONFIG_WINDOW_Y) + { + geometry.y = ev->y; + xwindow_translate_for_gravity(c->size_hints.win_gravity, 0, deco_top, 0, deco_bottom, NULL, &geometry.y); } c->got_configure_request = true; From 62d27950faaef7b3328e3d53f1d75c082d131fd5 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Mon, 20 Aug 2018 10:33:06 +0200 Subject: [PATCH 2/3] Handle border width changes in ConfigureRequests early The function window_set_border_width() causes its own gravity handling. Thus, to make sure that this gravity handling does not interfere with what the code in here does later, we just apply changes to the border width first, and then do everything else. Signed-off-by: Uli Schlachter --- event.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/event.c b/event.c index 29bcbe8d..b6a1977b 100644 --- a/event.c +++ b/event.c @@ -329,6 +329,14 @@ event_handle_configurerequest(xcb_configure_request_event_t *ev) if((c = client_getbywin(ev->window))) { + lua_State *L = globalconf_get_lua_State(); + if(ev->value_mask & XCB_CONFIG_WINDOW_BORDER_WIDTH) + { + luaA_object_push(L, c); + window_set_border_width(L, -1, ev->border_width); + lua_pop(L, 1); + } + area_t geometry = c->geometry; uint16_t bw = c->border_width; uint16_t tb_left = c->titlebar[CLIENT_TITLEBAR_LEFT].size; @@ -339,9 +347,7 @@ event_handle_configurerequest(xcb_configure_request_event_t *ev) uint16_t deco_right = bw + tb_right; uint16_t deco_top = bw + tb_top; uint16_t deco_bottom = bw + tb_bottom; - int16_t diff_w = 0, diff_h = 0, diff_border = 0; - - lua_State *L = globalconf_get_lua_State(); + int16_t diff_w = 0, diff_h = 0; if(ev->value_mask & XCB_CONFIG_WINDOW_WIDTH) { @@ -359,21 +365,11 @@ event_handle_configurerequest(xcb_configure_request_event_t *ev) geometry.height += tb_top + tb_bottom; diff_h = geometry.height - old_h; } - if(ev->value_mask & XCB_CONFIG_WINDOW_BORDER_WIDTH) - { - diff_border = ev->border_width - bw; - diff_h += diff_border; - diff_w += diff_border; - - luaA_object_push(L, c); - window_set_border_width(L, -1, ev->border_width); - lua_pop(L, 1); - } /* If the client resizes without moving itself, apply window gravity */ if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_WIN_GRAVITY) { - xwindow_translate_for_gravity(c->size_hints.win_gravity, diff_border, diff_border, diff_w, diff_h, &geometry.x, &geometry.y); + xwindow_translate_for_gravity(c->size_hints.win_gravity, 0, 0, diff_w, diff_h, &geometry.x, &geometry.y); } if(ev->value_mask & XCB_CONFIG_WINDOW_X) { From a54fea40ef83cac377ef8d38a067a4b0f6922b73 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Mon, 20 Aug 2018 10:40:58 +0200 Subject: [PATCH 3/3] event_handle_configurerequest: Add missing test c->size_hints.win_gravity only contains something valid if the XCB_ICCCM_SIZE_HINT_P_WIN_GRAVITY bit is set in the flags. Most likely this wasn't noticed before, because most code just happens to zero-initialize this field and gravity 0 is NorthWest, which does not do anything. Signed-off-by: Uli Schlachter --- event.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/event.c b/event.c index b6a1977b..e264d886 100644 --- a/event.c +++ b/event.c @@ -374,12 +374,14 @@ event_handle_configurerequest(xcb_configure_request_event_t *ev) if(ev->value_mask & XCB_CONFIG_WINDOW_X) { geometry.x = ev->x; - xwindow_translate_for_gravity(c->size_hints.win_gravity, deco_left, 0, deco_right, 0, &geometry.x, NULL); + if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_WIN_GRAVITY) + xwindow_translate_for_gravity(c->size_hints.win_gravity, deco_left, 0, deco_right, 0, &geometry.x, NULL); } if(ev->value_mask & XCB_CONFIG_WINDOW_Y) { geometry.y = ev->y; - xwindow_translate_for_gravity(c->size_hints.win_gravity, 0, deco_top, 0, deco_bottom, NULL, &geometry.y); + if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_WIN_GRAVITY) + xwindow_translate_for_gravity(c->size_hints.win_gravity, 0, deco_top, 0, deco_bottom, NULL, &geometry.y); } c->got_configure_request = true;