From e75b462fc18d1d1622c72566e11427b3b99dbf96 Mon Sep 17 00:00:00 2001 From: buffet Date: Wed, 8 Jan 2020 17:24:13 +0000 Subject: [PATCH] Make view:tiled user configurable --- include/desktop/view.h | 5 ++-- kiwmi/desktop/view.c | 4 +-- kiwmi/desktop/xdg_shell.c | 10 +------- kiwmi/luak/kiwmi_view.c | 53 ++++++++++++++++++++++++++++++++++++--- 4 files changed, 55 insertions(+), 17 deletions(-) diff --git a/include/desktop/view.h b/include/desktop/view.h index 927c639..dda325f 100644 --- a/include/desktop/view.h +++ b/include/desktop/view.h @@ -13,6 +13,7 @@ #include #include +#include enum kiwmi_view_type { KIWMI_VIEW_XDG_SHELL, @@ -55,7 +56,7 @@ struct kiwmi_view_impl { void *user_data); void (*set_activated)(struct kiwmi_view *view, bool activated); void (*set_size)(struct kiwmi_view *view, uint32_t width, uint32_t height); - void (*set_tiled)(struct kiwmi_view *view, bool tiled); + void (*set_tiled)(struct kiwmi_view *view, enum wlr_edges edges); struct wlr_surface *(*surface_at)( struct kiwmi_view *view, double sx, @@ -71,7 +72,7 @@ void view_for_each_surface( void *user_data); void view_set_activated(struct kiwmi_view *view, bool activated); void view_set_size(struct kiwmi_view *view, uint32_t width, uint32_t height); -void view_set_tiled(struct kiwmi_view *view, bool tiled); +void view_set_tiled(struct kiwmi_view *view, enum wlr_edges edges); struct wlr_surface *view_surface_at( struct kiwmi_view *view, double sx, diff --git a/kiwmi/desktop/view.c b/kiwmi/desktop/view.c index cf4a21c..e2635de 100644 --- a/kiwmi/desktop/view.c +++ b/kiwmi/desktop/view.c @@ -48,10 +48,10 @@ view_set_size(struct kiwmi_view *view, uint32_t width, uint32_t height) } void -view_set_tiled(struct kiwmi_view *view, bool tiled) +view_set_tiled(struct kiwmi_view *view, enum wlr_edges edges) { if (view->impl->set_tiled) { - view->impl->set_tiled(view, tiled); + view->impl->set_tiled(view, edges); } } diff --git a/kiwmi/desktop/xdg_shell.c b/kiwmi/desktop/xdg_shell.c index 44d3f9e..89f6c21 100644 --- a/kiwmi/desktop/xdg_shell.c +++ b/kiwmi/desktop/xdg_shell.c @@ -83,16 +83,8 @@ xdg_shell_view_set_size(struct kiwmi_view *view, uint32_t width, uint32_t height } static void -xdg_shell_view_set_tiled(struct kiwmi_view *view, bool tiled) +xdg_shell_view_set_tiled(struct kiwmi_view *view, enum wlr_edges edges) { - enum wlr_edges edges; - - if (tiled) { - edges = WLR_EDGE_TOP | WLR_EDGE_BOTTOM | WLR_EDGE_LEFT | WLR_EDGE_RIGHT; - } else { - edges = WLR_EDGE_NONE; - } - wlr_xdg_toplevel_set_tiled(view->xdg_surface, edges); } diff --git a/kiwmi/luak/kiwmi_view.c b/kiwmi/luak/kiwmi_view.c index 3babb85..28f177d 100644 --- a/kiwmi/luak/kiwmi_view.c +++ b/kiwmi/luak/kiwmi_view.c @@ -7,7 +7,10 @@ #include "luak/kiwmi_view.h" +#include + #include +#include #include #include "desktop/view.h" @@ -117,13 +120,55 @@ l_kiwmi_view_tiled(lua_State *L) { struct kiwmi_view *view = *(struct kiwmi_view **)luaL_checkudata(L, 1, "kiwmi_view"); - luaL_checktype(L, 2, LUA_TBOOLEAN); - bool tiled = lua_toboolean(L, 2); + if (lua_isboolean(L, 2)) { + enum wlr_edges edges = WLR_EDGE_NONE; - view_set_tiled(view, tiled); + if (lua_toboolean(L, 2)) { + edges = WLR_EDGE_TOP | WLR_EDGE_BOTTOM | WLR_EDGE_LEFT | WLR_EDGE_RIGHT; + } - return 0; + view_set_tiled(view, edges); + + return 0; + } + + if (lua_istable(L, 2)) { + enum wlr_edges edges = WLR_EDGE_NONE; + + lua_pushnil(L); + while (lua_next(L, 2)) { + if (!lua_isstring(L, -1)) { + lua_pop(L, 1); + continue; + } + + const char *edge = lua_tostring(L, -1); + + switch (edge[0]) { + case 't': + edges |= WLR_EDGE_TOP; + break; + case 'b': + edges |= WLR_EDGE_BOTTOM; + break; + case 'l': + edges |= WLR_EDGE_LEFT; + break; + case 'r': + edges |= WLR_EDGE_RIGHT; + break; + } + + lua_pop(L, 1); + } + + view_set_tiled(view, edges); + + return 0; + } + + return luaL_argerror(L, 2, "expected bool or table"); } static const luaL_Reg kiwmi_view_methods[] = {