From deff67c224de54d700749c6ea50004fb3311558a Mon Sep 17 00:00:00 2001 From: Uks2 Date: Mon, 20 Jun 2022 17:23:11 +0100 Subject: [PATCH] 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. --- include/desktop/view.h | 2 ++ kiwmi/desktop/view.c | 1 + kiwmi/desktop/xdg_shell.c | 10 +++++++ kiwmi/luak/kiwmi_view.c | 57 +++++++++++++++++++++++++++++++++++++++ lua_docs.md | 5 ++++ 5 files changed, 75 insertions(+) diff --git a/include/desktop/view.h b/include/desktop/view.h index 5ada1bb..be64ca6 100644 --- a/include/desktop/view.h +++ b/include/desktop/view.h @@ -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; diff --git a/kiwmi/desktop/view.c b/kiwmi/desktop/view.c index efd0d66..bf7c381 100644 --- a/kiwmi/desktop/view.c +++ b/kiwmi/desktop/view.c @@ -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); diff --git a/kiwmi/desktop/xdg_shell.c b/kiwmi/desktop/xdg_shell.c index 733de40..50ba3f8 100644 --- a/kiwmi/desktop/xdg_shell.c +++ b/kiwmi/desktop/xdg_shell.c @@ -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); } diff --git a/kiwmi/luak/kiwmi_view.c b/kiwmi/luak/kiwmi_view.c index 84f9f4c..0a394ee 100644 --- a/kiwmi/luak/kiwmi_view.c +++ b/kiwmi/luak/kiwmi_view.c @@ -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}, }; diff --git a/lua_docs.md b/lua_docs.md index 7f63b60..c4244d6 100644 --- a/lua_docs.md +++ b/lua_docs.md @@ -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.