Add view:pos and view:resize

This commit is contained in:
buffet 2020-01-04 23:54:55 +00:00
parent 758e793281
commit a0bae4f8b5
4 changed files with 47 additions and 0 deletions

View file

@ -53,6 +53,7 @@ struct kiwmi_view_impl {
struct kiwmi_view *view,
wlr_surface_iterator_func_t iterator,
void *user_data);
void (*resize)(struct kiwmi_view *view, uint32_t width, uint32_t height);
void (*set_activated)(struct kiwmi_view *view, bool activated);
struct wlr_surface *(*surface_at)(
struct kiwmi_view *view,
@ -67,6 +68,7 @@ void view_for_each_surface(
struct kiwmi_view *view,
wlr_surface_iterator_func_t iterator,
void *user_data);
void view_resize(struct kiwmi_view *view, uint32_t width, uint32_t height);
void view_set_activated(struct kiwmi_view *view, bool activated);
struct wlr_surface *view_surface_at(
struct kiwmi_view *view,

View file

@ -31,6 +31,14 @@ view_for_each_surface(
}
}
void
view_resize(struct kiwmi_view *view, uint32_t width, uint32_t height)
{
if (view->impl->resize) {
view->impl->resize(view, width, height);
}
}
void
view_set_activated(struct kiwmi_view *view, bool activated)
{

View file

@ -69,6 +69,12 @@ xdg_shell_view_for_each_surface(
wlr_xdg_surface_for_each_surface(view->xdg_surface, iterator, user_data);
}
static void
xdg_shell_view_resize(struct kiwmi_view *view, uint32_t width, uint32_t height)
{
wlr_xdg_toplevel_set_size(view->xdg_surface, width, height);
}
static void
xdg_shell_view_set_activated(struct kiwmi_view *view, bool activated)
{
@ -89,6 +95,7 @@ xdg_shell_view_surface_at(
static const struct kiwmi_view_impl xdg_shell_view_impl = {
.close = xdg_shell_view_close,
.for_each_surface = xdg_shell_view_for_each_surface,
.resize = xdg_shell_view_resize,
.set_activated = xdg_shell_view_set_activated,
.surface_at = xdg_shell_view_surface_at,
};

View file

@ -73,6 +73,34 @@ l_kiwmi_view_move(lua_State *L)
return 0;
}
static int
l_kiwmi_view_pos(lua_State *L)
{
struct kiwmi_view *view =
*(struct kiwmi_view **)luaL_checkudata(L, 1, "kiwmi_view");
lua_pushnumber(L, view->x);
lua_pushnumber(L, view->y);
return 2;
}
static int
l_kiwmi_view_resize(lua_State *L)
{
struct kiwmi_view *view =
*(struct kiwmi_view **)luaL_checkudata(L, 1, "kiwmi_view");
luaL_checktype(L, 2, LUA_TNUMBER); // w
luaL_checktype(L, 3, LUA_TNUMBER); // h
double w = lua_tonumber(L, 2);
double h = lua_tonumber(L, 3);
view_resize(view, w, h);
return 0;
}
static int
l_kiwmi_view_show(lua_State *L)
{
@ -91,6 +119,8 @@ static const luaL_Reg kiwmi_view_methods[] = {
{"hide", l_kiwmi_view_hide},
{"move", l_kiwmi_view_move},
{"on", luaK_callback_register_dispatch},
{"pos", l_kiwmi_view_pos},
{"resize", l_kiwmi_view_resize},
{"show", l_kiwmi_view_show},
{NULL, NULL},
};