From d5b681502a376afad5983eba4174b93a67132295 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Tue, 24 Jan 2017 05:41:22 -0500 Subject: [PATCH] maximize: Stop mixing horizontal, vertical and both. Before this commit, do this: c.maximize_hoizontal = true c.maximize = true c.maximize = false assert(c.maximize_hoizontal) Would not work because the states were not preserved individually. This commit fixes that. Awesome wont be confused about it's own state anymore. This may seem pointless, but when it come to undoing these maximizations, it was ambiguous. --- ewmh.c | 5 +++-- lib/awful/client.lua | 2 ++ lib/awful/ewmh.lua | 4 ++-- objects/client.c | 43 +++++++++++++++++-------------------------- objects/client.h | 4 ++++ 5 files changed, 28 insertions(+), 30 deletions(-) diff --git a/ewmh.c b/ewmh.c index ca862a1ef..608276478 100644 --- a/ewmh.c +++ b/ewmh.c @@ -49,9 +49,9 @@ ewmh_client_update_hints(lua_State *L) state[i++] = _NET_WM_STATE_MODAL; if(c->fullscreen) state[i++] = _NET_WM_STATE_FULLSCREEN; - if(c->maximized_vertical) + if(c->maximized_vertical || c->maximized) state[i++] = _NET_WM_STATE_MAXIMIZED_VERT; - if(c->maximized_horizontal) + if(c->maximized_horizontal || c->maximized) state[i++] = _NET_WM_STATE_MAXIMIZED_HORZ; if(c->sticky) state[i++] = _NET_WM_STATE_STICKY; @@ -220,6 +220,7 @@ ewmh_init_lua(void) luaA_class_connect_signal(L, &client_class, "property::fullscreen" , ewmh_client_update_hints); luaA_class_connect_signal(L, &client_class, "property::maximized_horizontal" , ewmh_client_update_hints); luaA_class_connect_signal(L, &client_class, "property::maximized_vertical" , ewmh_client_update_hints); + luaA_class_connect_signal(L, &client_class, "property::maximized" , ewmh_client_update_hints); luaA_class_connect_signal(L, &client_class, "property::sticky" , ewmh_client_update_hints); luaA_class_connect_signal(L, &client_class, "property::skip_taskbar" , ewmh_client_update_hints); luaA_class_connect_signal(L, &client_class, "property::above" , ewmh_client_update_hints); diff --git a/lib/awful/client.lua b/lib/awful/client.lua index 73caf2cff..f8318bcce 100644 --- a/lib/awful/client.lua +++ b/lib/awful/client.lua @@ -138,6 +138,7 @@ function client.tiled(s, stacked) for _, c in pairs(clients) do if not client.object.get_floating(c) and not c.fullscreen + and not c.maximized and not c.maximized_vertical and not c.maximized_horizontal then table.insert(tclients, c) @@ -668,6 +669,7 @@ function client.object.get_floating(c) or c.fullscreen or c.maximized_vertical or c.maximized_horizontal + or c.maximized or client.object.is_fixed(c) then return true end diff --git a/lib/awful/ewmh.lua b/lib/awful/ewmh.lua index ae34b6ba0..76ae57929 100644 --- a/lib/awful/ewmh.lua +++ b/lib/awful/ewmh.lua @@ -45,10 +45,10 @@ local function geometry_change(window) -- Fix up the geometry in case this window needs to cover the whole screen. local bw = window.border_width or 0 local g = window.screen.workarea - if window.maximized_vertical then + if window.maximized_vertical or window.maximized then window:geometry { height = g.height - 2*bw, y = g.y } end - if window.maximized_horizontal then + if window.maximized_horizontal or window.maximized then window:geometry { width = g.width - 2*bw, x = g.x } end if window.fullscreen then diff --git a/objects/client.c b/objects/client.c index f38b25739..7683aa4c4 100644 --- a/objects/client.c +++ b/objects/client.c @@ -809,6 +809,7 @@ typedef enum { CLIENT_MAXIMIZED_NONE = 0 << 0, CLIENT_MAXIMIZED_V = 1 << 0, CLIENT_MAXIMIZED_H = 1 << 1, + CLIENT_MAXIMIZED_BOTH = 1 << 2, /* V|H == BOTH, but ~(V|H) != ~(BOTH)... */ } client_maximized_t; static area_t titlebar_get_area(client_t *c, client_titlebar_t bar); @@ -1940,16 +1941,6 @@ client_set_fullscreen(lua_State *L, int cidx, bool s) } } -/** Get a clients maximized state (horizontally and vertically). - * \param c The client. - * \return The maximized state. - */ -static int -client_get_maximized(client_t *c) -{ - return c->maximized_horizontal && c->maximized_vertical; -} - /** Set a client horizontally|vertically maximized. * \param L The Lua VM state. * \param cidx The client index. @@ -1962,21 +1953,28 @@ client_set_maximized_common(lua_State *L, int cidx, bool s, const char* type, co /* Store the current and next state on 2 bit */ const client_maximized_t current = ( - (c->maximized_vertical ? CLIENT_MAXIMIZED_V : CLIENT_MAXIMIZED_NONE)| - (c->maximized_horizontal ? CLIENT_MAXIMIZED_H : CLIENT_MAXIMIZED_NONE) + (c->maximized_vertical ? CLIENT_MAXIMIZED_V : CLIENT_MAXIMIZED_NONE)| + (c->maximized_horizontal ? CLIENT_MAXIMIZED_H : CLIENT_MAXIMIZED_NONE)| + (c->maximized ? CLIENT_MAXIMIZED_BOTH : CLIENT_MAXIMIZED_NONE) ); - const client_maximized_t next = s ? val : CLIENT_MAXIMIZED_NONE; + client_maximized_t next = s ? (val | current) : (current & (~val)); + + /* When both are already set during startup, assume `maximized` is true*/ + if (next == (CLIENT_MAXIMIZED_H|CLIENT_MAXIMIZED_V) && !globalconf.loop) + next = CLIENT_MAXIMIZED_BOTH; if(current != next) { int abs_cidx = luaA_absindex(L, cidx); - int max_before = client_get_maximized(c); + int max_before = c->maximized; int h_before = c->maximized_horizontal; int v_before = c->maximized_vertical; /*Update the client properties */ - c->maximized_horizontal = !!(next & CLIENT_MAXIMIZED_H); - c->maximized_vertical = !!(next & CLIENT_MAXIMIZED_V); + c->maximized_horizontal = !!(next & CLIENT_MAXIMIZED_H ); + c->maximized_vertical = !!(next & CLIENT_MAXIMIZED_V ); + c->maximized = !!(next & CLIENT_MAXIMIZED_BOTH); + /* Request the changes to be applied */ lua_pushstring(L, type); @@ -1987,7 +1985,7 @@ client_set_maximized_common(lua_State *L, int cidx, bool s, const char* type, co luaA_object_emit_signal(L, abs_cidx, "property::maximized_horizontal", 0); if (v_before != c->maximized_vertical) luaA_object_emit_signal(L, abs_cidx, "property::maximized_vertical", 0); - if(max_before != client_get_maximized(c)) + if(max_before != c->maximized) luaA_object_emit_signal(L, abs_cidx, "property::maximized", 0); stack_windows(); @@ -1998,8 +1996,7 @@ void client_set_maximized(lua_State *L, int cidx, bool s) { return client_set_maximized_common( - L, cidx, s, "maximized", - CLIENT_MAXIMIZED_H | CLIENT_MAXIMIZED_V + L, cidx, s, "maximized", CLIENT_MAXIMIZED_BOTH ); } @@ -3057,15 +3054,9 @@ LUA_OBJECT_EXPORT_PROPERTY(client, client_t, sticky, lua_pushboolean) LUA_OBJECT_EXPORT_PROPERTY(client, client_t, size_hints_honor, lua_pushboolean) LUA_OBJECT_EXPORT_PROPERTY(client, client_t, maximized_horizontal, lua_pushboolean) LUA_OBJECT_EXPORT_PROPERTY(client, client_t, maximized_vertical, lua_pushboolean) +LUA_OBJECT_EXPORT_PROPERTY(client, client_t, maximized, lua_pushboolean) LUA_OBJECT_EXPORT_PROPERTY(client, client_t, startup_id, lua_pushstring) -static int -luaA_client_get_maximized(lua_State *L, client_t *c) -{ - lua_pushboolean(L, client_get_maximized(c)); - return 1; -} - static int luaA_client_get_content(lua_State *L, client_t *c) { diff --git a/objects/client.h b/objects/client.h index 760fb13cf..ad94e1333 100644 --- a/objects/client.h +++ b/objects/client.h @@ -82,6 +82,10 @@ struct client_t bool maximized_horizontal; /** True if the client is maximized vertically */ bool maximized_vertical; + /** True if the client is maximized both horizontally and vertically by the + * the user + */ + bool maximized; /** True if the client is above others */ bool above; /** True if the client is below others */