From 22f12dc5067ab0b621857f8514b684ff99be1e93 Mon Sep 17 00:00:00 2001 From: Charlotte Meyer Date: Sun, 19 Jan 2020 23:36:12 +0000 Subject: [PATCH] Add view:title, view:app_id, view:pid --- include/desktop/view.h | 13 +++++++++++++ kiwmi/desktop/view.c | 30 ++++++++++++++++++++++++++++++ kiwmi/desktop/xdg_shell.c | 30 ++++++++++++++++++++++++++++++ kiwmi/luak/kiwmi_view.c | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+) diff --git a/include/desktop/view.h b/include/desktop/view.h index 0c6975e..e95fbf7 100644 --- a/include/desktop/view.h +++ b/include/desktop/view.h @@ -11,10 +11,17 @@ #include #include +#include + #include #include #include +enum kiwmi_view_prop { + KIWMI_VIEW_PROP_APP_ID, + KIWMI_VIEW_PROP_TITLE, +}; + enum kiwmi_view_type { KIWMI_VIEW_XDG_SHELL, }; @@ -59,10 +66,13 @@ struct kiwmi_view_impl { struct kiwmi_view *view, wlr_surface_iterator_func_t iterator, void *user_data); + pid_t (*get_pid)(struct kiwmi_view *view); 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); + const char *( + *get_string_prop)(struct kiwmi_view *view, enum kiwmi_view_prop prop); void (*set_tiled)(struct kiwmi_view *view, enum wlr_edges edges); struct wlr_surface *(*surface_at)( struct kiwmi_view *view, @@ -77,7 +87,10 @@ void view_for_each_surface( struct kiwmi_view *view, wlr_surface_iterator_func_t iterator, void *user_data); +pid_t view_get_pid(struct kiwmi_view *view); void view_get_size(struct kiwmi_view *view, uint32_t *width, uint32_t *height); +const char *view_get_app_id(struct kiwmi_view *view); +const char *view_get_title(struct kiwmi_view *view); 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 7a35479..eba8dc3 100644 --- a/kiwmi/desktop/view.c +++ b/kiwmi/desktop/view.c @@ -34,6 +34,16 @@ view_for_each_surface( } } +pid_t +view_get_pid(struct kiwmi_view *view) +{ + if (view->impl->get_pid) { + return view->impl->get_pid(view); + } + + return -1; +} + void view_get_size(struct kiwmi_view *view, uint32_t *width, uint32_t *height) { @@ -42,6 +52,26 @@ view_get_size(struct kiwmi_view *view, uint32_t *width, uint32_t *height) } } +const char * +view_get_app_id(struct kiwmi_view *view) +{ + if (view->impl->get_string_prop) { + return view->impl->get_string_prop(view, KIWMI_VIEW_PROP_APP_ID); + } + + return NULL; +} + +const char * +view_get_title(struct kiwmi_view *view) +{ + if (view->impl->get_string_prop) { + return view->impl->get_string_prop(view, KIWMI_VIEW_PROP_TITLE); + } + + return NULL; +} + 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 e2dccc7..d095c94 100644 --- a/kiwmi/desktop/xdg_shell.c +++ b/kiwmi/desktop/xdg_shell.c @@ -7,6 +7,8 @@ #include "desktop/xdg_shell.h" +#include + #include #include #include @@ -104,6 +106,17 @@ xdg_shell_view_for_each_surface( wlr_xdg_surface_for_each_surface(view->xdg_surface, iterator, user_data); } +static pid_t +xdg_shell_view_get_pid(struct kiwmi_view *view) +{ + struct wl_client *client = view->xdg_surface->client->client; + + pid_t pid; + wl_client_get_credentials(client, &pid, NULL, NULL); + + return pid; +} + static void xdg_shell_view_get_size( struct kiwmi_view *view, @@ -116,6 +129,21 @@ xdg_shell_view_get_size( *height = geom->height; } +static const char * +xdg_shell_view_get_string_prop( + struct kiwmi_view *view, + enum kiwmi_view_prop prop) +{ + switch (prop) { + case KIWMI_VIEW_PROP_APP_ID: + return view->xdg_surface->toplevel->title; + case KIWMI_VIEW_PROP_TITLE: + return view->xdg_surface->toplevel->title; + default: + return NULL; + } +} + static void xdg_shell_view_set_activated(struct kiwmi_view *view, bool activated) { @@ -151,7 +179,9 @@ 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_pid = xdg_shell_view_get_pid, .get_size = xdg_shell_view_get_size, + .get_string_prop = xdg_shell_view_get_string_prop, .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 3d28137..00f330c 100644 --- a/kiwmi/luak/kiwmi_view.c +++ b/kiwmi/luak/kiwmi_view.c @@ -19,6 +19,17 @@ #include "luak/kiwmi_lua_callback.h" #include "server.h" +static int +l_kiwmi_view_app_id(lua_State *L) +{ + struct kiwmi_view *view = + *(struct kiwmi_view **)luaL_checkudata(L, 1, "kiwmi_view"); + + lua_pushstring(L, view_get_app_id(view)); + + return 1; +} + static int l_kiwmi_view_close(lua_State *L) { @@ -82,6 +93,17 @@ l_kiwmi_view_move(lua_State *L) return 0; } +static int +l_kiwmi_view_pid(lua_State *L) +{ + struct kiwmi_view *view = + *(struct kiwmi_view **)luaL_checkudata(L, 1, "kiwmi_view"); + + lua_pushinteger(L, view_get_pid(view)); + + return 1; +} + static int l_kiwmi_view_pos(lua_State *L) { @@ -194,18 +216,32 @@ l_kiwmi_view_tiled(lua_State *L) return luaL_argerror(L, 2, "expected bool or table"); } +static int +l_kiwmi_view_title(lua_State *L) +{ + struct kiwmi_view *view = + *(struct kiwmi_view **)luaL_checkudata(L, 1, "kiwmi_view"); + + lua_pushstring(L, view_get_app_id(view)); + + return 1; +} + static const luaL_Reg kiwmi_view_methods[] = { + {"app_id", l_kiwmi_view_app_id}, {"close", l_kiwmi_view_close}, {"focus", l_kiwmi_view_focus}, {"hidden", l_kiwmi_view_hidden}, {"hide", l_kiwmi_view_hide}, {"move", l_kiwmi_view_move}, {"on", luaK_callback_register_dispatch}, + {"pid", l_kiwmi_view_pid}, {"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}, + {"title", l_kiwmi_view_title}, {NULL, NULL}, };