Make view:tiled user configurable

This commit is contained in:
buffet 2020-01-08 17:24:13 +00:00
parent 783e982206
commit 838aaf2daf
4 changed files with 55 additions and 17 deletions

View file

@ -13,6 +13,7 @@
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/types/wlr_xdg_shell.h> #include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/edges.h>
enum kiwmi_view_type { enum kiwmi_view_type {
KIWMI_VIEW_XDG_SHELL, KIWMI_VIEW_XDG_SHELL,
@ -55,7 +56,7 @@ struct kiwmi_view_impl {
void *user_data); void *user_data);
void (*set_activated)(struct kiwmi_view *view, bool activated); void (*set_activated)(struct kiwmi_view *view, bool activated);
void (*set_size)(struct kiwmi_view *view, uint32_t width, uint32_t height); 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 wlr_surface *(*surface_at)(
struct kiwmi_view *view, struct kiwmi_view *view,
double sx, double sx,
@ -71,7 +72,7 @@ void view_for_each_surface(
void *user_data); void *user_data);
void view_set_activated(struct kiwmi_view *view, bool activated); 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_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 wlr_surface *view_surface_at(
struct kiwmi_view *view, struct kiwmi_view *view,
double sx, double sx,

View file

@ -48,10 +48,10 @@ view_set_size(struct kiwmi_view *view, uint32_t width, uint32_t height)
} }
void 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) { if (view->impl->set_tiled) {
view->impl->set_tiled(view, tiled); view->impl->set_tiled(view, edges);
} }
} }

View file

@ -83,16 +83,8 @@ xdg_shell_view_set_size(struct kiwmi_view *view, uint32_t width, uint32_t height
} }
static void 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); wlr_xdg_toplevel_set_tiled(view->xdg_surface, edges);
} }

View file

@ -7,7 +7,10 @@
#include "luak/kiwmi_view.h" #include "luak/kiwmi_view.h"
#include <string.h>
#include <lauxlib.h> #include <lauxlib.h>
#include <wlr/util/edges.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "desktop/view.h" #include "desktop/view.h"
@ -117,13 +120,55 @@ l_kiwmi_view_tiled(lua_State *L)
{ {
struct kiwmi_view *view = struct kiwmi_view *view =
*(struct kiwmi_view **)luaL_checkudata(L, 1, "kiwmi_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;
}
view_set_tiled(view, edges);
return 0; 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[] = { static const luaL_Reg kiwmi_view_methods[] = {