mirror of
https://github.com/MezzalunaWM/Mezzaluna.git
synced 2026-03-07 19:49:53 -05:00
Merge 299222a1a7 into e3e7ecd7e1
This commit is contained in:
commit
014aac1943
2 changed files with 63 additions and 0 deletions
|
|
@ -334,4 +334,10 @@ local master = function()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
mez.input.add_keymap("alt", "x", {
|
||||||
|
press = function()
|
||||||
|
mez.input.send_key("a", "press")
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
master()
|
master()
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,14 @@ const Input = @This();
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const zlua = @import("zlua");
|
const zlua = @import("zlua");
|
||||||
const xkb = @import("xkbcommon");
|
const xkb = @import("xkbcommon");
|
||||||
|
const wl = @import("wayland").server.wl;
|
||||||
const wlr = @import("wlroots");
|
const wlr = @import("wlroots");
|
||||||
|
|
||||||
const Keymap = @import("../types/Keymap.zig");
|
const Keymap = @import("../types/Keymap.zig");
|
||||||
const Mousemap = @import("../types/Mousemap.zig");
|
const Mousemap = @import("../types/Mousemap.zig");
|
||||||
const Utils = @import("../Utils.zig");
|
const Utils = @import("../Utils.zig");
|
||||||
const LuaUtils = @import("LuaUtils.zig");
|
const LuaUtils = @import("LuaUtils.zig");
|
||||||
|
const c = @import("../C.zig").c;
|
||||||
|
|
||||||
const c = @import("../C.zig").c;
|
const c = @import("../C.zig").c;
|
||||||
const server = &@import("../main.zig").server;
|
const server = &@import("../main.zig").server;
|
||||||
|
|
@ -179,3 +181,58 @@ pub fn set_cursor_type(L: *zlua.Lua) i32 {
|
||||||
|
|
||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue