Add view:size

This commit is contained in:
buffet 2020-01-08 22:26:17 +00:00
parent 866a8a2cad
commit 6fb13b2871
4 changed files with 37 additions and 0 deletions

View file

@ -54,6 +54,7 @@ struct kiwmi_view_impl {
struct kiwmi_view *view,
wlr_surface_iterator_func_t iterator,
void *user_data);
void (*get_size)(struct kiwmi_view *view, uint32_t *width, uint32_t *height);
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, enum wlr_edges edges);
@ -70,6 +71,7 @@ void view_for_each_surface(
struct kiwmi_view *view,
wlr_surface_iterator_func_t iterator,
void *user_data);
void view_get_size(struct kiwmi_view *view, uint32_t *width, uint32_t *height);
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, enum wlr_edges edges);

View file

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

View file

@ -70,6 +70,15 @@ xdg_shell_view_for_each_surface(
wlr_xdg_surface_for_each_surface(view->xdg_surface, iterator, user_data);
}
static void
xdg_shell_view_get_size(struct kiwmi_view *view, uint32_t *width, uint32_t *height)
{
struct wlr_box *geom = &view->xdg_surface->geometry;
*width = geom->width;
*height = geom->height;
}
static void
xdg_shell_view_set_activated(struct kiwmi_view *view, bool activated)
{
@ -105,6 +114,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,
.get_size = xdg_shell_view_get_size,
.set_activated = xdg_shell_view_set_activated,
.set_size = xdg_shell_view_set_size,
.set_tiled = xdg_shell_view_set_tiled,

View file

@ -115,6 +115,22 @@ l_kiwmi_view_show(lua_State *L)
return 0;
}
static int
l_kiwmi_view_size(lua_State *L)
{
struct kiwmi_view *view =
*(struct kiwmi_view **)luaL_checkudata(L, 1, "kiwmi_view");
uint32_t width;
uint32_t height;
view_get_size(view, &width, &height);
lua_pushinteger(L, width);
lua_pushinteger(L, height);
return 2;
}
static int
l_kiwmi_view_tiled(lua_State *L)
{
@ -182,6 +198,7 @@ static const luaL_Reg kiwmi_view_methods[] = {
{"pos", l_kiwmi_view_pos},
{"resize", l_kiwmi_view_resize},
{"show", l_kiwmi_view_show},
{"size", l_kiwmi_view_size},
{"tiled", l_kiwmi_view_tiled},
{NULL, NULL},
};