add "render" callback on output

phoen
Daniel Barlow 2022-05-05 23:23:49 +01:00
parent f626324825
commit b804bb1c1f
3 changed files with 62 additions and 0 deletions

View File

@ -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;

View File

@ -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);
}

View File

@ -299,6 +299,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,
@ -403,6 +429,37 @@ l_kiwmi_output_on_resize(lua_State *L)
return 0;
}
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)
{
@ -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},
};