diff --git a/objects/client.c b/objects/client.c index f14331d0..6fab5ca8 100644 --- a/objects/client.c +++ b/objects/client.c @@ -128,6 +128,7 @@ static area_t titlebar_get_area(client_t *c, client_titlebar_t bar); static drawable_t *titlebar_get_drawable(lua_State *L, client_t *c, int cl_idx, client_titlebar_t bar); +static void client_resize_do(client_t *c, area_t geometry, bool force_notice); /** Collect a client. * \param L The Lua VM state. @@ -466,6 +467,24 @@ client_focus_refresh(void) win, globalconf.timestamp); } +static void +border_width_callback(client_t *c, uint16_t old_width, uint16_t new_width) +{ + if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_WIN_GRAVITY) + { + area_t geometry = c->geometry; + int16_t diff = new_width - old_width; + int16_t diff_x = 0, diff_y = 0; + xwindow_translate_for_gravity(c->size_hints.win_gravity, + diff, diff, diff, diff, + &diff_x, &diff_y); + geometry.x += diff_x; + geometry.y += diff_y; + /* force_notice = true -> inform client about changes */ + client_resize_do(c, geometry, true); + } +} + static void client_update_properties(lua_State *L, int cidx, client_t *c) { @@ -537,6 +556,7 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, xcb_get_window_at client_t *c = client_new(L); xcb_screen_t *s = globalconf.screen; + c->border_width_callback = (void (*) (void *, uint16_t, uint16_t)) border_width_callback; /* consider the window banned */ c->isbanned = true; diff --git a/objects/window.c b/objects/window.c index 45077bbf..94254bef 100644 --- a/objects/window.c +++ b/objects/window.c @@ -178,6 +178,7 @@ void window_set_border_width(lua_State *L, int idx, int width) { window_t *window = luaA_checkudata(L, idx, &window_class); + uint16_t old_width = window->border_width; if(width == window->border_width || width < 0) return; @@ -189,6 +190,9 @@ window_set_border_width(lua_State *L, int idx, int width) window->border_width = width; + if(window->border_width_callback) + (*window->border_width_callback)(window, old_width, width); + luaA_object_emit_signal(L, idx, "property::border_width", 0); } diff --git a/objects/window.h b/objects/window.h index 30e492c3..7c20eee7 100644 --- a/objects/window.h +++ b/objects/window.h @@ -67,7 +67,9 @@ typedef enum /** Border width */ \ uint16_t border_width; \ /** The window type */ \ - window_type_t type; + window_type_t type; \ + /** The border width callback */ \ + void (*border_width_callback)(void *, uint16_t old, uint16_t new); /** Window structure */ typedef struct