diff --git a/almost_apple_moutains.jpg b/almost_apple_moutains.jpg deleted file mode 100644 index ee9a034..0000000 Binary files a/almost_apple_moutains.jpg and /dev/null differ diff --git a/build.zig b/build.zig index 5201d6e..a6e07c3 100644 --- a/build.zig +++ b/build.zig @@ -20,8 +20,6 @@ pub fn build(b: *std.Build) void { // subprocessing your CLI tool. // The below is copied from tinywl - // TODO: Ensure versioning is correct - // TODO: Ensure paths for system protocols are correct const scanner = Scanner.create(b, .{}); scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml"); scanner.addSystemProtocol("stable/tablet/tablet-v2.xml"); diff --git a/runtime/share/mezzaluna/master.lua b/runtime/share/mezzaluna/master.lua index 60312ef..afb361d 100644 --- a/runtime/share/mezzaluna/master.lua +++ b/runtime/share/mezzaluna/master.lua @@ -6,6 +6,43 @@ mez.input.add_keymap("alt", "g", { end }) +mez.input.add_keymap("alt", "i", { + press = function () + local coroutine = require("coroutine") + print(coroutine) + local co = coroutine.create(function () + print("starting coroutine") + local view_id = mez.view.get_focused_id() + + local size = mez.view.get_size(view_id) + local pos = mez.view.get_position(view_id) + local res = mez.output.get_resolution(0) + + local x_pos = pos.x + local y_pos = pos.y + local x_vel = 10 + local y_vel = 10 + + while true do + x_pos = x_pos + x_vel + y_pos = y_pos + y_vel + + if x_pos + size.width > res.width or x_pos < 0 then + x_vel = x_vel * -1 + end + + if y_pos + size.height > res.height or y_pos < 0 then + y_vel = y_vel * -1 + end + + print("(" .. x_pos .. ", " .. y_pos .. ")") + mez.view.set_position(view_id, x_pos, y_pos) + end + end) + coroutine.resume(co) + end +}) + local master = function() local config = { tag_count = 5, diff --git a/src/lua/View.zig b/src/lua/View.zig index 090fbe8..e91110d 100644 --- a/src/lua/View.zig +++ b/src/lua/View.zig @@ -109,10 +109,34 @@ pub fn set_position(L: *zlua.Lua) i32 { return 1; } -// ---Resize the view by it's top left corner +// ---Get the position of the view // ---@param view_id view_id 0 maps to focused view -// ---@param width number width for view -// ---@param height number height for view +// ---@return { x: integer, y: integer }? Position of the view +pub fn get_position(L: *zlua.Lua) i32 { + const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L); + const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id); + if (view) |v| { + L.newTable(); + + _ = L.pushString("x"); + L.pushInteger(@intCast(v.xdg_toplevel.base.geometry.x)); + L.setTable(-3); + + _ = L.pushString("y"); + L.pushInteger(@intCast(v.xdg_toplevel.base.geometry.y)); + L.setTable(-3); + + return 1; + } + + L.pushNil(); + return 1; +} + +// ---Set the size of the spesified view. Will be resized relative to +// the view's top left corner. +// ---@param view_id view_id 0 maps to focused view +// ---@return pub fn set_size(L: *zlua.Lua) i32 { const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L); // We use u32s here to enforce a minimum size of zero. The call to resize a @@ -131,6 +155,9 @@ pub fn set_size(L: *zlua.Lua) i32 { return 1; } +// ---Get the size of the view +// ---@param view_id view_id 0 maps to focused view +// ---@return { width: integer, height: integer }? Size of the view pub fn get_size(L: *zlua.Lua) i32 { const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L); const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id);