commit 7c061624c741fae52871cf48ec7a7333d3365d67
parent b804bb1c1fd79c91d9de86f3bac79b4a8553ee21
Author: Daniel Barlow <dan@telent.net>
Date: Thu, 5 May 2022 23:38:39 +0100
output render callback accepts { : output : renderer }
Diffstat:
3 files changed, 50 insertions(+), 3 deletions(-)
diff --git a/kiwmi/kiwmi/desktop/output.c b/kiwmi/kiwmi/desktop/output.c
@@ -230,7 +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);
+ rdata.data = NULL;
+ wl_signal_emit(&output->events.render, &rdata);
render_layer(&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &rdata);
render_layer(&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], &rdata);
diff --git a/kiwmi/kiwmi/luak/kiwmi_output.c b/kiwmi/kiwmi/luak/kiwmi_output.c
@@ -305,10 +305,13 @@ 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;
+ struct kiwmi_render_data *rdata = data;
+ struct kiwmi_output *output = rdata->output->data;
lua_rawgeti(L, LUA_REGISTRYINDEX, lc->callback_ref);
+ lua_newtable(L);
+
lua_pushcfunction(L, luaK_kiwmi_output_new);
lua_pushlightuserdata(L, server->lua);
lua_pushlightuserdata(L, output);
@@ -318,6 +321,20 @@ kiwmi_output_on_render_notify(struct wl_listener *listener, void *data)
lua_pop(L, 1);
return;
}
+ lua_setfield(L, -2, "output");
+
+ lua_pushcfunction(L, luaK_kiwmi_renderer_new);
+ lua_pushlightuserdata(L, server->lua);
+ lua_pushlightuserdata(L, rdata->renderer);
+ lua_pushlightuserdata(L, output);
+
+ if (lua_pcall(L, 3, 1, 0)) {
+ wlr_log(WLR_ERROR, "%s", lua_tostring(L, -1));
+ lua_pop(L, 1);
+ return;
+ }
+
+ lua_setfield(L, -2, "renderer");
if (lua_pcall(L, 1, 0, 0)) {
wlr_log(WLR_ERROR, "%s", lua_tostring(L, -1));
diff --git a/rc.fnl b/rc.fnl
@@ -1,4 +1,33 @@
-(kiwmi:on "output" #(doto $1 (: :set_mode 360 720 0)))
+(local { : GdkPixbuf } (require :lgi))
+(local { : view } (require :fennel))
+
+(var texture nil)
+
+(local pixels
+ (let [(buf err) (GdkPixbuf.Pixbuf.new_from_file "globe.png")]
+ (if (not buf) (print :err err))
+ buf))
+
+(kiwmi:on
+ "output"
+ (fn [output]
+ (output:set_mode 360 720 0)
+ (let [r (output:renderer)]
+ (set texture (r:texture_from_pixels
+ pixels.rowstride
+ pixels.width
+ pixels.height
+ (pixels:get_pixels)))
+ (output:on "render"
+ (fn [{: output : renderer}]
+ (renderer:draw_texture
+ texture
+ [1 0 0
+ 0 1 0
+ 0 0 1]
+ 150 150 0.7)))
+ (print :texture texture))))
+
(kiwmi:on "view"
(fn [view]
(let [(w h) (: (kiwmi:active_output) :size)]