commit b804bb1c1fd79c91d9de86f3bac79b4a8553ee21
parent f626324825626f5da12c6a74e00adf5439e92626
Author: Daniel Barlow <dan@telent.net>
Date: Thu, 5 May 2022 23:23:49 +0100
add "render" callback on output
Diffstat:
3 files changed, 62 insertions(+), 0 deletions(-)
diff --git a/kiwmi/include/desktop/output.h b/kiwmi/include/desktop/output.h
@@ -26,6 +26,7 @@ struct kiwmi_output {
int damaged;
struct {
+ struct wl_signal render;
struct wl_signal destroy;
struct wl_signal resize;
struct wl_signal usable_area_change;
diff --git a/kiwmi/kiwmi/desktop/output.c b/kiwmi/kiwmi/desktop/output.c
@@ -230,6 +230,8 @@ output_frame_notify(struct wl_listener *listener, void *data)
wl_signal_emit(&view->events.post_render, &rdata);
}
+ wl_signal_emit(&output->events.render, output);
+
render_layer(&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &rdata);
render_layer(&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], &rdata);
@@ -372,6 +374,7 @@ new_output_notify(struct wl_listener *listener, void *data)
wl_signal_init(&output->events.destroy);
wl_signal_init(&output->events.resize);
wl_signal_init(&output->events.usable_area_change);
+ wl_signal_init(&output->events.render);
wl_signal_emit(&desktop->events.new_output, output);
}
diff --git a/kiwmi/kiwmi/luak/kiwmi_output.c b/kiwmi/kiwmi/luak/kiwmi_output.c
@@ -300,6 +300,32 @@ kiwmi_output_on_resize_notify(struct wl_listener *listener, void *data)
}
static void
+kiwmi_output_on_render_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_output *output = data;
+
+ lua_rawgeti(L, LUA_REGISTRYINDEX, lc->callback_ref);
+
+ lua_pushcfunction(L, luaK_kiwmi_output_new);
+ lua_pushlightuserdata(L, server->lua);
+ lua_pushlightuserdata(L, output);
+
+ 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 void
kiwmi_output_on_usable_area_change_notify(
struct wl_listener *listener,
void *data)
@@ -404,6 +430,37 @@ l_kiwmi_output_on_resize(lua_State *L)
}
static int
+l_kiwmi_output_on_render(lua_State *L)
+{
+ struct kiwmi_object *obj =
+ *(struct kiwmi_object **)luaL_checkudata(L, 1, "kiwmi_output");
+ luaL_checktype(L, 2, LUA_TFUNCTION);
+
+ if (!obj->valid) {
+ return luaL_error(L, "kiwmi_output no longer valid");
+ }
+
+ struct kiwmi_output *output = obj->object;
+ struct kiwmi_desktop *desktop = output->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_output_on_render_notify);
+ lua_pushlightuserdata(L, &output->events.render);
+ 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 int
l_kiwmi_output_on_usable_area_change(lua_State *L)
{
struct kiwmi_object *obj =
@@ -437,6 +494,7 @@ static const luaL_Reg kiwmi_output_events[] = {
{"destroy", l_kiwmi_output_on_destroy},
{"resize", l_kiwmi_output_on_resize},
{"usable_area_change", l_kiwmi_output_on_usable_area_change},
+ {"render", l_kiwmi_output_on_render},
{NULL, NULL},
};