From 299222a1a715105ef534e1e649a04714a8fb846c Mon Sep 17 00:00:00 2001 From: Squibid Date: Fri, 9 Jan 2026 14:37:51 -0500 Subject: [PATCH 1/3] input sim! --- runtime/share/mezzaluna/master.lua | 6 ++++ src/lua/Input.zig | 57 ++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/runtime/share/mezzaluna/master.lua b/runtime/share/mezzaluna/master.lua index ae71be8..fba9f3f 100644 --- a/runtime/share/mezzaluna/master.lua +++ b/runtime/share/mezzaluna/master.lua @@ -312,6 +312,12 @@ local master = function() end end +mez.input.add_keymap("alt", "x", { + press = function() + mez.input.send_key("a", "press") + end +}) + master() function print_table(tbl, indent, seen) diff --git a/src/lua/Input.zig b/src/lua/Input.zig index 896de35..dd72d60 100644 --- a/src/lua/Input.zig +++ b/src/lua/Input.zig @@ -3,11 +3,13 @@ const Input = @This(); const std = @import("std"); const zlua = @import("zlua"); const xkb = @import("xkbcommon"); +const wl = @import("wayland").server.wl; const wlr = @import("wlroots"); const Keymap = @import("../types/Keymap.zig"); const Utils = @import("../Utils.zig"); const LuaUtils = @import("LuaUtils.zig"); +const c = @import("../C.zig").c; const server = &@import("../main.zig").server; @@ -110,3 +112,58 @@ pub fn set_repeat_info(L: *zlua.Lua) i32 { server.seat.keyboard_group.keyboard.setRepeatInfo(rate, delay); return 0; } + +/// FIXME: this doesn't work just yet, and I'm not sure how we can get the +/// correct time. +fn getTimeMs() u32 { + const now = std.posix.clock_gettime(.MONOTONIC) catch unreachable; + return @intCast(now.sec * 1000 + @divTrunc(now.nsec, 1000000)); +} + +pub fn send_key(L: *zlua.Lua) i32 { + const key = L.checkString(1); + const state = L.checkString(2); + + var pressed: u32 = 1; + if (std.mem.eql(u8, state, "press")) { + pressed = 1; + } if (std.mem.eql(u8, state, "release")) { + pressed = 0; + } + + const keysym = xkb.Keysym.fromName(key, .no_flags); + + server.seat.wlr_seat.keyboardSendKey( + getTimeMs(), + keysym.toUTF32(), + pressed, + ); + + return 0; +} + +pub fn send_pointer_motion(L: *zlua.Lua) i32 { + const sx = L.checkNumber(1); + const sy = L.checkNumber(2); + + server.seat.wlr_seat.pointerSendMotion(getTimeMs(), sx, sy); + + return 0; +} + +pub fn send_pointer_button(L: *zlua.Lua) i32 { + const button = L.checkString(1); + const state = L.checkString(2); + + var pressed: wl.Pointer.ButtonState = .pressed; + if (std.mem.eql(u8, state, "press")) { + pressed = .pressed; + } if (std.mem.eql(u8, state, "release")) { + pressed = .released; + } + + const mousesym = c.libevdev_event_code_from_name(c.EV_KEY, button); + _ = server.seat.wlr_seat.pointerSendButton(0, @intCast(mousesym), pressed); + + return 0; +} From 826aa0ca8728ba44555d011d8fa98a351bf683ee Mon Sep 17 00:00:00 2001 From: Harrison DiAmbrosio Date: Mon, 9 Mar 2026 10:16:57 -0400 Subject: [PATCH 2/3] added pointer warp, maybe --- runtime/share/mezzaluna/master.lua | 4 +--- src/lua/Input.zig | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/runtime/share/mezzaluna/master.lua b/runtime/share/mezzaluna/master.lua index fba9f3f..1c55ca8 100644 --- a/runtime/share/mezzaluna/master.lua +++ b/runtime/share/mezzaluna/master.lua @@ -1,8 +1,6 @@ mez.input.add_keymap("alt", "g", { press = function () - for _, id in ipairs(mez.view.get_all_ids()) do - print(id) - end + mez.input.send_pointer_button("press") end }) diff --git a/src/lua/Input.zig b/src/lua/Input.zig index dd72d60..914c30d 100644 --- a/src/lua/Input.zig +++ b/src/lua/Input.zig @@ -133,10 +133,10 @@ pub fn send_key(L: *zlua.Lua) i32 { const keysym = xkb.Keysym.fromName(key, .no_flags); - server.seat.wlr_seat.keyboardSendKey( + server.seat.wlr_seat.keyboardNotifyKey( getTimeMs(), keysym.toUTF32(), - pressed, + .pressed, ); return 0; @@ -146,7 +146,8 @@ pub fn send_pointer_motion(L: *zlua.Lua) i32 { const sx = L.checkNumber(1); const sy = L.checkNumber(2); - server.seat.wlr_seat.pointerSendMotion(getTimeMs(), sx, sy); + server.seat.wlr_seat.pointerNotifyMotion(getTimeMs(), sx, sy); + server.seat.wlr_seat.pointerNotifyFrame(); return 0; } @@ -160,10 +161,23 @@ pub fn send_pointer_button(L: *zlua.Lua) i32 { pressed = .pressed; } if (std.mem.eql(u8, state, "release")) { pressed = .released; + } else { + return 0; } const mousesym = c.libevdev_event_code_from_name(c.EV_KEY, button); - _ = server.seat.wlr_seat.pointerSendButton(0, @intCast(mousesym), pressed); + _ = server.seat.wlr_seat.pointerNotifyButton(getTimeMs(), @intCast(mousesym), pressed); return 0; } + +// ---@param x number x position of cursor +// ---@param y number y position of cursor +pub fn warp_pointer(L: *zlua.Lua) i32 { + const x = L.checkNumber(1); + const y = L.checkNumber(2); + + server.seat.wlr_seat.pointerWarp(x, y); + server.seat.wlr_seat.pointerNotifyFrame(); + return 0; +} From e76b8790d0f469070b13fabd3f478397753686dd Mon Sep 17 00:00:00 2001 From: Squibid Date: Thu, 12 Mar 2026 18:01:49 -0400 Subject: [PATCH 3/3] calculate the correct time for events, they still aren't working though --- src/lua/Input.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua/Input.zig b/src/lua/Input.zig index 914c30d..feb2bed 100644 --- a/src/lua/Input.zig +++ b/src/lua/Input.zig @@ -117,7 +117,7 @@ pub fn set_repeat_info(L: *zlua.Lua) i32 { /// correct time. fn getTimeMs() u32 { const now = std.posix.clock_gettime(.MONOTONIC) catch unreachable; - return @intCast(now.sec * 1000 + @divTrunc(now.nsec, 1000000)); + return @intCast(now.sec * std.time.ms_per_s + @divTrunc(now.nsec, std.time.ns_per_ms)); } pub fn send_key(L: *zlua.Lua) i32 {