Remove API that relies on our rendering

This is a preparation for switching to the wlroots scene-graph. There is
no replacement planned for output:redraw() because it will no longer be
necessary (as far as i can tell), while scene-compatible replacements
for the view pre_render/post_render events are planned.
This commit is contained in:
tiosgz 2021-12-22 18:15:09 +00:00
parent 83dc21feb1
commit afb2c78a6e
7 changed files with 6 additions and 271 deletions

View file

@ -1,16 +0,0 @@
/* Copyright (c), Charlotte Meyer <dev@buffet.sh>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#ifndef KIWMI_LUAK_KIWMI_RENDERER_H
#define KIWMI_LUAK_KIWMI_RENDERER_H
#include <lua.h>
int luaK_kiwmi_renderer_new(lua_State *L);
int luaK_kiwmi_renderer_register(lua_State *L);
#endif /* KIWMI_LUAK_KIWMI_RENDERER_H */

View file

@ -98,23 +98,6 @@ l_kiwmi_output_pos(lua_State *L)
return 2; return 2;
} }
static int
l_kiwmi_output_redraw(lua_State *L)
{
struct kiwmi_object *obj =
*(struct kiwmi_object **)luaL_checkudata(L, 1, "kiwmi_output");
if (!obj->valid) {
return luaL_error(L, "kiwmi_output no longer valid");
}
struct kiwmi_output *output = obj->object;
output_damage(output);
return 0;
}
static int static int
l_kiwmi_output_size(lua_State *L) l_kiwmi_output_size(lua_State *L)
{ {
@ -168,7 +151,6 @@ static const luaL_Reg kiwmi_output_methods[] = {
{"name", l_kiwmi_output_name}, {"name", l_kiwmi_output_name},
{"on", luaK_callback_register_dispatch}, {"on", luaK_callback_register_dispatch},
{"pos", l_kiwmi_output_pos}, {"pos", l_kiwmi_output_pos},
{"redraw", l_kiwmi_output_redraw},
{"size", l_kiwmi_output_size}, {"size", l_kiwmi_output_size},
{"usable_area", l_kiwmi_output_usable_area}, {"usable_area", l_kiwmi_output_usable_area},
{NULL, NULL}, {NULL, NULL},

View file

@ -1,100 +0,0 @@
/* Copyright (c), Charlotte Meyer <dev@buffet.sh>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "luak/kiwmi_renderer.h"
#include <stdlib.h>
#include <string.h>
#include <lauxlib.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_output.h>
#include <wlr/util/log.h>
#include "color.h"
#include "desktop/output.h"
#include "luak/lua_compat.h"
#include "luak/luak.h"
struct kiwmi_renderer {
struct wlr_renderer *wlr_renderer;
struct kiwmi_output *output;
};
static int
l_kiwmi_renderer_draw_rect(lua_State *L)
{
struct kiwmi_renderer *renderer =
(struct kiwmi_renderer *)luaL_checkudata(L, 1, "kiwmi_renderer");
luaL_checktype(L, 2, LUA_TSTRING); // color
luaL_checktype(L, 3, LUA_TNUMBER); // x
luaL_checktype(L, 4, LUA_TNUMBER); // y
luaL_checktype(L, 5, LUA_TNUMBER); // width
luaL_checktype(L, 6, LUA_TNUMBER); // height
struct wlr_renderer *wlr_renderer = renderer->wlr_renderer;
struct kiwmi_output *output = renderer->output;
struct wlr_output *wlr_output = output->wlr_output;
float color[4];
if (!color_parse(lua_tostring(L, 2), color)) {
return luaL_argerror(L, 2, "not a valid color");
}
struct wlr_box box = {
.x = lua_tonumber(L, 3),
.y = lua_tonumber(L, 4),
.width = lua_tonumber(L, 5),
.height = lua_tonumber(L, 6),
};
wlr_render_rect(wlr_renderer, &box, color, wlr_output->transform_matrix);
return 0;
}
static const luaL_Reg kiwmi_renderer_methods[] = {
{"draw_rect", l_kiwmi_renderer_draw_rect},
{NULL, NULL},
};
int
luaK_kiwmi_renderer_new(lua_State *L)
{
luaL_checktype(L, 1, LUA_TLIGHTUSERDATA); // kiwmi_lua
luaL_checktype(L, 2, LUA_TLIGHTUSERDATA); // wlr_renderer
luaL_checktype(L, 3, LUA_TLIGHTUSERDATA); // wlr_output
struct kiwmi_lua *UNUSED(lua) = lua_touserdata(L, 1);
struct wlr_renderer *wlr_renderer = lua_touserdata(L, 2);
struct kiwmi_output *output = lua_touserdata(L, 3);
struct kiwmi_renderer *renderer_ud =
lua_newuserdata(L, sizeof(*renderer_ud));
luaL_getmetatable(L, "kiwmi_renderer");
lua_setmetatable(L, -2);
renderer_ud->wlr_renderer = wlr_renderer;
renderer_ud->output = output;
return 1;
}
int
luaK_kiwmi_renderer_register(lua_State *L)
{
luaL_newmetatable(L, "kiwmi_renderer");
lua_pushvalue(L, -1);
lua_setfield(L, -2, "__index");
luaC_setfuncs(L, kiwmi_renderer_methods, 0);
lua_pushcfunction(L, luaK_usertype_ref_equal);
lua_setfield(L, -2, "__eq");
return 0;
}

View file

@ -21,7 +21,6 @@
#include "input/seat.h" #include "input/seat.h"
#include "luak/kiwmi_lua_callback.h" #include "luak/kiwmi_lua_callback.h"
#include "luak/kiwmi_output.h" #include "luak/kiwmi_output.h"
#include "luak/kiwmi_renderer.h"
#include "luak/lua_compat.h" #include "luak/lua_compat.h"
#include "server.h" #include "server.h"
@ -471,65 +470,6 @@ kiwmi_view_on_destroy_notify(struct wl_listener *listener, void *data)
} }
} }
static void
kiwmi_view_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_render_data *rdata = data;
struct kiwmi_view *view = rdata->data;
struct wlr_renderer *renderer = rdata->renderer;
struct kiwmi_output *output = rdata->output->data;
lua_rawgeti(L, LUA_REGISTRYINDEX, lc->callback_ref);
lua_newtable(L);
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;
}
lua_setfield(L, -2, "view");
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;
}
lua_setfield(L, -2, "output");
lua_pushcfunction(L, luaK_kiwmi_renderer_new);
lua_pushlightuserdata(L, server->lua);
lua_pushlightuserdata(L, 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));
lua_pop(L, 1);
}
}
static void static void
kiwmi_view_on_request_move_notify(struct wl_listener *listener, void *data) kiwmi_view_on_request_move_notify(struct wl_listener *listener, void *data)
{ {
@ -644,62 +584,16 @@ l_kiwmi_view_on_destroy(lua_State *L)
} }
static int static int
l_kiwmi_view_on_post_render(lua_State *L) l_kiwmi_view_on_post_render(lua_State *UNUSED(L))
{ {
struct kiwmi_object *obj = // noop
*(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_render_notify);
lua_pushlightuserdata(L, &view->events.post_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; return 0;
} }
static int static int
l_kiwmi_view_on_pre_render(lua_State *L) l_kiwmi_view_on_pre_render(lua_State *UNUSED(L))
{ {
struct kiwmi_object *obj = // noop
*(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_render_notify);
lua_pushlightuserdata(L, &view->events.pre_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; return 0;
} }

View file

@ -18,7 +18,6 @@
#include "luak/kiwmi_keyboard.h" #include "luak/kiwmi_keyboard.h"
#include "luak/kiwmi_lua_callback.h" #include "luak/kiwmi_lua_callback.h"
#include "luak/kiwmi_output.h" #include "luak/kiwmi_output.h"
#include "luak/kiwmi_renderer.h"
#include "luak/kiwmi_server.h" #include "luak/kiwmi_server.h"
#include "luak/kiwmi_view.h" #include "luak/kiwmi_view.h"
@ -220,8 +219,6 @@ luaK_create(struct kiwmi_server *server)
error |= lua_pcall(L, 0, 0, 0); error |= lua_pcall(L, 0, 0, 0);
lua_pushcfunction(L, luaK_kiwmi_output_register); lua_pushcfunction(L, luaK_kiwmi_output_register);
error |= lua_pcall(L, 0, 0, 0); error |= lua_pcall(L, 0, 0, 0);
lua_pushcfunction(L, luaK_kiwmi_renderer_register);
error |= lua_pcall(L, 0, 0, 0);
lua_pushcfunction(L, luaK_kiwmi_server_register); lua_pushcfunction(L, luaK_kiwmi_server_register);
error |= lua_pcall(L, 0, 0, 0); error |= lua_pcall(L, 0, 0, 0);
lua_pushcfunction(L, luaK_kiwmi_view_register); lua_pushcfunction(L, luaK_kiwmi_view_register);

View file

@ -17,7 +17,6 @@ kiwmi_sources = files(
'luak/kiwmi_keyboard.c', 'luak/kiwmi_keyboard.c',
'luak/kiwmi_lua_callback.c', 'luak/kiwmi_lua_callback.c',
'luak/kiwmi_output.c', 'luak/kiwmi_output.c',
'luak/kiwmi_renderer.c',
'luak/kiwmi_server.c', 'luak/kiwmi_server.c',
'luak/kiwmi_view.c', 'luak/kiwmi_view.c',
'luak/lua_compat.c', 'luak/lua_compat.c',

View file

@ -240,10 +240,6 @@ Used to register event listeners.
Get the position of the output. Get the position of the output.
Returns two parameters: `x` and `y`. Returns two parameters: `x` and `y`.
#### output:redraw()
Force the output to redraw. Useful e.g. when you know the view `pre_render`/`post_render` callbacks are going to change.
#### output:size() #### output:size()
Get the size of the output. Get the size of the output.
@ -270,17 +266,6 @@ Callback receives a table containing the `output`, the new `width`, and the new
The usable area of this output has changed, e.g. because the output was resized or the bars around it changed. The usable area of this output has changed, e.g. because the output was resized or the bars around it changed.
Callback receives a table containing the `output` and the new `x`, `y`, `width` and `height`. Callback receives a table containing the `output` and the new `x`, `y`, `width` and `height`.
## kiwmi_renderer
Represents a rendering context, to draw on the output.
### Methods
#### renderer:draw_rect(color, x, y, w, h)
Draws a rect at the given position.
Color is a string in the form #rrggbb or #rrggbbaa.
## kiwmi_view ## kiwmi_view
Represents a view (a window in kiwmi terms). Represents a view (a window in kiwmi terms).
@ -373,17 +358,11 @@ Callback receives the view.
#### post_render #### post_render
The view finished being rendered. This is a no-op event. Temporarily preserved only to make config migration easier.
Callback receives a table with the `view`, the `renderer` and the `output`.
This event occurs once per output the view might be drawn on.
#### pre_render #### pre_render
The view is about to be rendered. This is a no-op event. Temporarily preserved only to make config migration easier.
Callback receives a table with the `view`, the `renderer` and the `output`.
This event occurs once per output the view might be drawn on.
#### request_move #### request_move