Add view:title, view:app_id, view:pid
This commit is contained in:
parent
557a7ff753
commit
22f12dc506
4 changed files with 109 additions and 0 deletions
|
@ -11,10 +11,17 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/types/wlr_xdg_shell.h>
|
||||
#include <wlr/util/edges.h>
|
||||
|
||||
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);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
#include "desktop/xdg_shell.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include <wlr/types/wlr_xdg_shell.h>
|
||||
#include <wlr/util/edges.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
@ -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,
|
||||
|
|
|
@ -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},
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue