Add kiwmi:output_at, cursor:output_at_pos, use lx, ly more consistenty

This commit is contained in:
buffet 2021-07-30 20:36:26 +00:00
parent 3b22a7ab88
commit 540f931d2d
4 changed files with 81 additions and 12 deletions

View file

@ -11,11 +11,10 @@
#include <lauxlib.h> #include <lauxlib.h>
#include <lua.h> #include <lua.h>
#define luaC_newlibtable(L, l) \ #define luaC_newlibtable(L, l) \
lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1) lua_createtable(L, 0, sizeof(l) / sizeof((l)[0]) - 1)
#define luaC_newlib(L, l) \ #define luaC_newlib(L, l) (luaC_newlibtable(L, l), luaC_setfuncs(L, l, 0))
(luaC_newlibtable(L, l), luaC_setfuncs(L, l, 0))
void luaC_setfuncs(lua_State *L, const luaL_Reg *l, int nup); void luaC_setfuncs(lua_State *L, const luaL_Reg *l, int nup);

View file

@ -17,10 +17,38 @@
#include "desktop/view.h" #include "desktop/view.h"
#include "input/cursor.h" #include "input/cursor.h"
#include "luak/kiwmi_lua_callback.h" #include "luak/kiwmi_lua_callback.h"
#include "luak/kiwmi_output.h"
#include "luak/kiwmi_view.h" #include "luak/kiwmi_view.h"
#include "luak/lua_compat.h" #include "luak/lua_compat.h"
#include "luak/luak.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 static int
l_kiwmi_cursor_pos(lua_State *L) 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[] = { static const luaL_Reg kiwmi_cursor_methods[] = {
{"on", luaK_callback_register_dispatch}, {"on", luaK_callback_register_dispatch},
{"output_at_pos", l_kiwmi_cursor_output_at_pos},
{"pos", l_kiwmi_cursor_pos}, {"pos", l_kiwmi_cursor_pos},
{"view_at_pos", l_kiwmi_cursor_view_at_pos}, {"view_at_pos", l_kiwmi_cursor_view_at_pos},
{NULL, NULL}, {NULL, NULL},

View file

@ -14,6 +14,7 @@
#include <lauxlib.h> #include <lauxlib.h>
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "desktop/view.h" #include "desktop/view.h"
@ -70,6 +71,37 @@ l_kiwmi_server_focused_view(lua_State *L)
return 1; 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 static int
l_kiwmi_server_quit(lua_State *L) 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 *obj =
*(struct kiwmi_object **)luaL_checkudata(L, 1, "kiwmi_server"); *(struct kiwmi_object **)luaL_checkudata(L, 1, "kiwmi_server");
luaL_checktype(L, 2, LUA_TNUMBER); // x luaL_checktype(L, 2, LUA_TNUMBER); // lx
luaL_checktype(L, 3, LUA_TNUMBER); // y luaL_checktype(L, 3, LUA_TNUMBER); // ly
struct kiwmi_server *server = obj->object; struct kiwmi_server *server = obj->object;
double x = lua_tonumber(L, 2); double lx = lua_tonumber(L, 2);
double y = lua_tonumber(L, 3); double ly = lua_tonumber(L, 3);
struct wlr_surface *surface; struct wlr_surface *surface;
double sx; double sx;
double sy; double sy;
struct kiwmi_view *view = struct kiwmi_view *view =
view_at(&server->desktop, x, y, &surface, &sx, &sy); view_at(&server->desktop, lx, ly, &surface, &sx, &sy);
if (view) { if (view) {
lua_pushcfunction(L, luaK_kiwmi_view_new); lua_pushcfunction(L, luaK_kiwmi_view_new);
@ -214,6 +246,7 @@ static const luaL_Reg kiwmi_server_methods[] = {
{"cursor", l_kiwmi_server_cursor}, {"cursor", l_kiwmi_server_cursor},
{"focused_view", l_kiwmi_server_focused_view}, {"focused_view", l_kiwmi_server_focused_view},
{"on", luaK_callback_register_dispatch}, {"on", luaK_callback_register_dispatch},
{"output_at", l_kiwmi_server_output_at},
{"quit", l_kiwmi_server_quit}, {"quit", l_kiwmi_server_quit},
{"schedule", l_kiwmi_server_schedule}, {"schedule", l_kiwmi_server_schedule},
{"spawn", l_kiwmi_server_spawn}, {"spawn", l_kiwmi_server_spawn},

View file

@ -21,6 +21,10 @@ Returns a reference to the cursor object.
Returns the currently focused view. Returns the currently focused view.
#### kiwmi:output_at(lx, ly)
Returns the output at a specified position
#### kiwmi:on(event, callback) #### kiwmi:on(event, callback)
Used to register event listeners. Used to register event listeners.
@ -43,7 +47,7 @@ Spawn a new process.
Stops an interactive move or resize. Stops an interactive move or resize.
#### kiwmi:view_at(x, y) #### kiwmi:view_at(lx, ly)
Get the view at a specified position. Get the view at a specified position.
@ -70,6 +74,10 @@ A reference to the cursor object.
### Methods ### Methods
#### cursor:output_at_pos()
Returns the output at the cursor position or `nil` if there is none.
#### cursor:on(event, callback) #### cursor:on(event, callback)
Used to register event listeners. 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). 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. Moves the output to a specified position.
This is referring to the top-left corner. This is referring to the top-left corner.
@ -257,7 +265,7 @@ Starts an interactive move.
Starts an interactive resize. Starts an interactive resize.
Takes a table containing the edges, that the resize is happening on. 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. Moves the view to the specified position.