diff --git a/include/luak/lua_compat.h b/include/luak/lua_compat.h index ff1d567..d18b410 100644 --- a/include/luak/lua_compat.h +++ b/include/luak/lua_compat.h @@ -11,11 +11,10 @@ #include #include -#define luaC_newlibtable(L, l) \ - lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1) +#define luaC_newlibtable(L, l) \ + lua_createtable(L, 0, sizeof(l) / sizeof((l)[0]) - 1) -#define luaC_newlib(L, l) \ - (luaC_newlibtable(L, l), luaC_setfuncs(L, l, 0)) +#define luaC_newlib(L, l) (luaC_newlibtable(L, l), luaC_setfuncs(L, l, 0)) void luaC_setfuncs(lua_State *L, const luaL_Reg *l, int nup); diff --git a/kiwmi/luak/kiwmi_cursor.c b/kiwmi/luak/kiwmi_cursor.c index a70bb06..eb6d2b0 100644 --- a/kiwmi/luak/kiwmi_cursor.c +++ b/kiwmi/luak/kiwmi_cursor.c @@ -17,10 +17,38 @@ #include "desktop/view.h" #include "input/cursor.h" #include "luak/kiwmi_lua_callback.h" +#include "luak/kiwmi_output.h" #include "luak/kiwmi_view.h" #include "luak/lua_compat.h" #include "luak/luak.h" +static int +l_kiwmi_cursor_output_at_pos(lua_State *L) +{ + struct kiwmi_object *obj = + *(struct kiwmi_object **)luaL_checkudata(L, 1, "kiwmi_server"); + + struct kiwmi_cursor *cursor = obj->object; + struct kiwmi_server *server = cursor->server; + + struct wlr_output *wlr_output = wlr_output_layout_output_at( + server->desktop.output_layout, cursor->cursor->x, cursor->cursor->y); + + if (wlr_output) { + lua_pushcfunction(L, luaK_kiwmi_output_new); + lua_pushlightuserdata(L, obj->lua); + lua_pushlightuserdata(L, wlr_output->data); + if (lua_pcall(L, 2, 1, 0)) { + wlr_log(WLR_ERROR, "%s", lua_tostring(L, -1)); + return 0; + } + } else { + lua_pushnil(L); + } + + return 1; +} + static int l_kiwmi_cursor_pos(lua_State *L) { @@ -74,6 +102,7 @@ l_kiwmi_cursor_view_at_pos(lua_State *L) static const luaL_Reg kiwmi_cursor_methods[] = { {"on", luaK_callback_register_dispatch}, + {"output_at_pos", l_kiwmi_cursor_output_at_pos}, {"pos", l_kiwmi_cursor_pos}, {"view_at_pos", l_kiwmi_cursor_view_at_pos}, {NULL, NULL}, diff --git a/kiwmi/luak/kiwmi_server.c b/kiwmi/luak/kiwmi_server.c index 2d1dc43..ff6251e 100644 --- a/kiwmi/luak/kiwmi_server.c +++ b/kiwmi/luak/kiwmi_server.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "desktop/view.h" @@ -70,6 +71,37 @@ l_kiwmi_server_focused_view(lua_State *L) return 1; } +static int +l_kiwmi_server_output_at(lua_State *L) +{ + struct kiwmi_object *obj = + *(struct kiwmi_object **)luaL_checkudata(L, 1, "kiwmi_server"); + luaL_checktype(L, 2, LUA_TNUMBER); // lx + luaL_checktype(L, 3, LUA_TNUMBER); // ly + + struct kiwmi_server *server = obj->object; + + double lx = lua_tonumber(L, 2); + double ly = lua_tonumber(L, 3); + + struct wlr_output *wlr_output = + wlr_output_layout_output_at(server->desktop.output_layout, lx, ly); + + if (wlr_output) { + lua_pushcfunction(L, luaK_kiwmi_output_new); + lua_pushlightuserdata(L, obj->lua); + lua_pushlightuserdata(L, wlr_output->data); + if (lua_pcall(L, 2, 1, 0)) { + wlr_log(WLR_ERROR, "%s", lua_tostring(L, -1)); + return 0; + } + } else { + lua_pushnil(L); + } + + return 1; +} + static int l_kiwmi_server_quit(lua_State *L) { @@ -180,20 +212,20 @@ l_kiwmi_server_view_at(lua_State *L) { struct kiwmi_object *obj = *(struct kiwmi_object **)luaL_checkudata(L, 1, "kiwmi_server"); - luaL_checktype(L, 2, LUA_TNUMBER); // x - luaL_checktype(L, 3, LUA_TNUMBER); // y + luaL_checktype(L, 2, LUA_TNUMBER); // lx + luaL_checktype(L, 3, LUA_TNUMBER); // ly struct kiwmi_server *server = obj->object; - double x = lua_tonumber(L, 2); - double y = lua_tonumber(L, 3); + double lx = lua_tonumber(L, 2); + double ly = lua_tonumber(L, 3); struct wlr_surface *surface; double sx; double sy; struct kiwmi_view *view = - view_at(&server->desktop, x, y, &surface, &sx, &sy); + view_at(&server->desktop, lx, ly, &surface, &sx, &sy); if (view) { lua_pushcfunction(L, luaK_kiwmi_view_new); @@ -214,6 +246,7 @@ static const luaL_Reg kiwmi_server_methods[] = { {"cursor", l_kiwmi_server_cursor}, {"focused_view", l_kiwmi_server_focused_view}, {"on", luaK_callback_register_dispatch}, + {"output_at", l_kiwmi_server_output_at}, {"quit", l_kiwmi_server_quit}, {"schedule", l_kiwmi_server_schedule}, {"spawn", l_kiwmi_server_spawn}, diff --git a/lua_docs.md b/lua_docs.md index 5727823..8434097 100644 --- a/lua_docs.md +++ b/lua_docs.md @@ -21,6 +21,10 @@ Returns a reference to the cursor object. Returns the currently focused view. +#### kiwmi:output_at(lx, ly) + +Returns the output at a specified position + #### kiwmi:on(event, callback) Used to register event listeners. @@ -43,7 +47,7 @@ Spawn a new process. Stops an interactive move or resize. -#### kiwmi:view_at(x, y) +#### kiwmi:view_at(lx, ly) Get the view at a specified position. @@ -70,6 +74,10 @@ A reference to the cursor object. ### Methods +#### cursor:output_at_pos() + + Returns the output at the cursor position or `nil` if there is none. + #### cursor:on(event, callback) Used to register event listeners. @@ -171,7 +179,7 @@ Represents an output (most often a display). Tells the compositor to start automatically positioning the output (this is on per default). -#### output:move(x, y) +#### output:move(lx, ly) Moves the output to a specified position. This is referring to the top-left corner. @@ -257,7 +265,7 @@ Starts an interactive move. Starts an interactive resize. Takes a table containing the edges, that the resize is happening on. -#### view:move(x, y) +#### view:move(lx, ly) Moves the view to the specified position.