Add title_change event for views
Works in basically the same way as all the other events (I hope!), allows the config script to update a status bar or whatever.
This commit is contained in:
parent
17814972ab
commit
deff67c224
5 changed files with 75 additions and 0 deletions
|
@ -51,6 +51,7 @@ struct kiwmi_view {
|
|||
struct wl_listener destroy;
|
||||
struct wl_listener request_move;
|
||||
struct wl_listener request_resize;
|
||||
struct wl_listener set_title;
|
||||
|
||||
bool mapped;
|
||||
|
||||
|
@ -60,6 +61,7 @@ struct kiwmi_view {
|
|||
struct wl_signal request_resize;
|
||||
struct wl_signal post_render;
|
||||
struct wl_signal pre_render;
|
||||
struct wl_signal set_title;
|
||||
} events;
|
||||
|
||||
struct kiwmi_xdg_decoration *decoration;
|
||||
|
|
|
@ -247,6 +247,7 @@ view_create(
|
|||
wl_signal_init(&view->events.request_resize);
|
||||
wl_signal_init(&view->events.post_render);
|
||||
wl_signal_init(&view->events.pre_render);
|
||||
wl_signal_init(&view->events.set_title);
|
||||
|
||||
view->desktop_surface.tree = wlr_scene_tree_create(
|
||||
&view->desktop->strata[KIWMI_STRATUM_NORMAL]->node);
|
||||
|
|
|
@ -127,6 +127,13 @@ xdg_toplevel_request_resize_notify(struct wl_listener *listener, void *data)
|
|||
wl_signal_emit(&view->events.request_resize, &new_event);
|
||||
}
|
||||
|
||||
static void
|
||||
xdg_toplevel_set_title_notify(struct wl_listener *listener, void *UNUSED(data))
|
||||
{
|
||||
struct kiwmi_view *view = wl_container_of(listener, view, set_title);
|
||||
wl_signal_emit(&view->events.set_title, view);
|
||||
}
|
||||
|
||||
static void
|
||||
xdg_shell_view_close(struct kiwmi_view *view)
|
||||
{
|
||||
|
@ -258,6 +265,9 @@ xdg_shell_new_surface_notify(struct wl_listener *listener, void *data)
|
|||
|
||||
wlr_xdg_surface_get_geometry(view->xdg_surface, &view->geom);
|
||||
|
||||
view->set_title.notify = xdg_toplevel_set_title_notify;
|
||||
wl_signal_add(&xdg_surface->toplevel->events.set_title, &view->set_title);
|
||||
|
||||
wl_list_insert(&desktop->views, &view->link);
|
||||
}
|
||||
|
||||
|
|
|
@ -561,6 +561,32 @@ kiwmi_view_on_request_resize_notify(struct wl_listener *listener, void *data)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
kiwmi_view_on_set_title_notify(struct wl_listener *listener, void *data)
|
||||
{
|
||||
struct kiwmi_lua_callback *lc = wl_container_of(listener, lc, listener);
|
||||
struct kiwmi_server *server = lc->server;
|
||||
lua_State *L = server->lua->L;
|
||||
struct kiwmi_view *view = data;
|
||||
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, lc->callback_ref);
|
||||
|
||||
lua_pushcfunction(L, luaK_kiwmi_view_new);
|
||||
lua_pushlightuserdata(L, server->lua);
|
||||
lua_pushlightuserdata(L, view);
|
||||
|
||||
if (lua_pcall(L, 2, 1, 0)) {
|
||||
wlr_log(WLR_ERROR, "%s", lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (lua_pcall(L, 1, 0, 0)) {
|
||||
wlr_log(WLR_ERROR, "%s", lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
l_kiwmi_view_on_destroy(lua_State *L)
|
||||
{
|
||||
|
@ -665,12 +691,43 @@ l_kiwmi_view_on_request_resize(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
l_kiwmi_view_on_set_title(lua_State *L)
|
||||
{
|
||||
struct kiwmi_object *obj =
|
||||
*(struct kiwmi_object **)luaL_checkudata(L, 1, "kiwmi_view");
|
||||
luaL_checktype(L, 2, LUA_TFUNCTION);
|
||||
|
||||
if (!obj->valid) {
|
||||
return luaL_error(L, "kiwmi_view no longer valid");
|
||||
}
|
||||
|
||||
struct kiwmi_view *view = obj->object;
|
||||
struct kiwmi_desktop *desktop = view->desktop;
|
||||
struct kiwmi_server *server = wl_container_of(desktop, server, desktop);
|
||||
|
||||
lua_pushcfunction(L, luaK_kiwmi_lua_callback_new);
|
||||
lua_pushlightuserdata(L, server);
|
||||
lua_pushvalue(L, 2);
|
||||
lua_pushlightuserdata(L, kiwmi_view_on_set_title_notify);
|
||||
lua_pushlightuserdata(L, &view->events.set_title);
|
||||
lua_pushlightuserdata(L, obj);
|
||||
|
||||
if (lua_pcall(L, 5, 0, 0)) {
|
||||
wlr_log(WLR_ERROR, "%s", lua_tostring(L, -1));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg kiwmi_view_events[] = {
|
||||
{"destroy", l_kiwmi_view_on_destroy},
|
||||
{"post_render", l_kiwmi_view_on_post_render},
|
||||
{"pre_render", l_kiwmi_view_on_pre_render},
|
||||
{"request_move", l_kiwmi_view_on_request_move},
|
||||
{"request_resize", l_kiwmi_view_on_request_resize},
|
||||
{"set_title", l_kiwmi_view_on_set_title},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
|
|
|
@ -373,3 +373,8 @@ Callback receives the view.
|
|||
|
||||
The view wants to start an interactive resize.
|
||||
Callback receives a table containing the `view`, and `edges`, containing the edges.
|
||||
|
||||
#### set_title
|
||||
|
||||
The view's title has changed.
|
||||
Callback receives the view.
|
||||
|
|
Loading…
Add table
Reference in a new issue