Apply window gravity for border width changes

Together with the previous changes, this also fixes the initial positions for
metacity's test-gravity.c.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2015-10-10 17:45:24 +02:00
parent 3b97d1c1a7
commit b2aaefd095
3 changed files with 27 additions and 1 deletions

View File

@ -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;

View File

@ -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);
}

View File

@ -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