From 236c76df0e64eaaaac4b108bb21b8140212f0c84 Mon Sep 17 00:00:00 2001 From: Charlotte Meyer Date: Wed, 1 Jan 2020 18:13:24 +0000 Subject: [PATCH] Add view event to kiwmi_server --- include/desktop/desktop.h | 4 ++++ kiwmi/desktop/desktop.c | 2 ++ kiwmi/desktop/xdg_shell.c | 3 ++- kiwmi/luak.c | 50 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/include/desktop/desktop.h b/include/desktop/desktop.h index f798b17..2817c0c 100644 --- a/include/desktop/desktop.h +++ b/include/desktop/desktop.h @@ -22,6 +22,10 @@ struct kiwmi_desktop { struct wl_listener xdg_shell_new_surface; struct wl_listener new_output; + + struct { + struct wl_signal view_map; + } events; }; bool desktop_init(struct kiwmi_desktop *desktop, struct wlr_renderer *renderer); diff --git a/kiwmi/desktop/desktop.c b/kiwmi/desktop/desktop.c index 92fd5dd..23a7a9e 100644 --- a/kiwmi/desktop/desktop.c +++ b/kiwmi/desktop/desktop.c @@ -49,5 +49,7 @@ desktop_init(struct kiwmi_desktop *desktop, struct wlr_renderer *renderer) desktop->new_output.notify = new_output_notify; wl_signal_add(&server->backend->events.new_output, &desktop->new_output); + wl_signal_init(&desktop->events.view_map); + return true; } diff --git a/kiwmi/desktop/xdg_shell.c b/kiwmi/desktop/xdg_shell.c index 2aa028b..f598401 100644 --- a/kiwmi/desktop/xdg_shell.c +++ b/kiwmi/desktop/xdg_shell.c @@ -19,7 +19,8 @@ xdg_surface_map_notify(struct wl_listener *listener, void *UNUSED(data)) { struct kiwmi_view *view = wl_container_of(listener, view, map); view->mapped = true; - view_focus(view); + + wl_signal_emit(&view->desktop->events.view_map, view); } static void diff --git a/kiwmi/luak.c b/kiwmi/luak.c index 7782429..2c5aed5 100644 --- a/kiwmi/luak.c +++ b/kiwmi/luak.c @@ -244,6 +244,27 @@ on_cursor_button_notify(struct wl_listener *listener, void *data) } } +static void +on_view_notify(struct wl_listener *listener, void *data) +{ + struct lua_callback *lc = wl_container_of(listener, lc, listener); + struct kiwmi_server *server = lc->server; + struct lua_State *L = server->lua->L; + struct kiwmi_view *view = data; + + lua_rawgeti(L, LUA_REGISTRYINDEX, lc->callback_ref); + + lua_pushcfunction(L, kiwmi_view_create); + lua_pushlightuserdata(L, view); + if (lua_pcall(L, 1, 1, 0)) { + wlr_log(WLR_ERROR, "%s", lua_tostring(L, -1)); + } + + if (lua_pcall(L, 1, 0, 0)) { + wlr_log(WLR_ERROR, "%s", lua_tostring(L, -1)); + } +} + static int on_cursor_button(lua_State *L) { @@ -273,7 +294,33 @@ on_cursor_button(lua_State *L) } static int -l_quit(lua_State *L) +on_view(lua_State *L) +{ + struct kiwmi_server *server = + *(struct kiwmi_server **)luaL_checkudata(L, 1, "kiwmi_server"); + luaL_checktype(L, 2, LUA_TFUNCTION); // callback + + struct lua_callback *lc = malloc(sizeof(*lc)); + if (!lc) { + return luaL_error(L, "failed to allocate lua_callback"); + } + + wl_list_insert(&server->lua->callbacks, &lc->link); + + lc->server = server; + lc->callback_ref = luaL_ref(L, LUA_REGISTRYINDEX); + + lc->listener.notify = on_view_notify; + wl_signal_add(&server->desktop.events.view_map, &lc->listener); + + lua_pushlightuserdata(L, lc); + lua_callback_create(L); + + return 1; +} + +static int +l_kiwmi_server_quit(lua_State *L) { struct kiwmi_server *server = *(struct kiwmi_server**)luaL_checkudata(L, 1, "kiwmi_server"); @@ -351,6 +398,7 @@ kiwmi_server_register(lua_State *L) static const luaL_Reg kiwmi_events[] = { {"cursor_button", on_cursor_button}, + {"view", on_view}, {NULL, NULL}, };