From 5d9ebb43d0ca103b49eaacaf31e52c9b25af9742 Mon Sep 17 00:00:00 2001 From: buffet Date: Wed, 8 Jan 2020 22:26:17 +0000 Subject: [PATCH] Add view:size --- include/desktop/view.h | 2 ++ kiwmi/desktop/view.c | 8 ++++++++ kiwmi/desktop/xdg_shell.c | 10 ++++++++++ kiwmi/luak/kiwmi_view.c | 17 +++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/include/desktop/view.h b/include/desktop/view.h index dda325f..1eef928 100644 --- a/include/desktop/view.h +++ b/include/desktop/view.h @@ -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); diff --git a/kiwmi/desktop/view.c b/kiwmi/desktop/view.c index e2635de..7e6bdf2 100644 --- a/kiwmi/desktop/view.c +++ b/kiwmi/desktop/view.c @@ -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) { diff --git a/kiwmi/desktop/xdg_shell.c b/kiwmi/desktop/xdg_shell.c index 0651169..6b758fd 100644 --- a/kiwmi/desktop/xdg_shell.c +++ b/kiwmi/desktop/xdg_shell.c @@ -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, diff --git a/kiwmi/luak/kiwmi_view.c b/kiwmi/luak/kiwmi_view.c index 6e11562..ad9ac3d 100644 --- a/kiwmi/luak/kiwmi_view.c +++ b/kiwmi/luak/kiwmi_view.c @@ -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}, };