Add kiwmi:output_at, cursor:output_at_pos, use lx, ly more consistenty
This commit is contained in:
parent
3b22a7ab88
commit
540f931d2d
4 changed files with 81 additions and 12 deletions
|
@ -12,10 +12,9 @@
|
|||
#include <lua.h>
|
||||
|
||||
#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) \
|
||||
(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);
|
||||
|
||||
|
|
|
@ -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},
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <lauxlib.h>
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/types/wlr_cursor.h>
|
||||
#include <wlr/types/wlr_output_layout.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
||||
#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},
|
||||
|
|
14
lua_docs.md
14
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.
|
||||
|
||||
|
|
Loading…
Reference in a new issue