mirror of
https://github.com/MezzalunaWM/Mezzaluna.git
synced 2026-03-07 19:49:53 -05:00
Merge branch 'hook-w-arbitrary-args' into dev
This commit is contained in:
commit
3f946d4f5c
5 changed files with 46 additions and 25 deletions
|
|
@ -43,6 +43,14 @@ mez.input.add_keymap("alt", "v", {
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
mez.input.add_keymap("alt", "v", {
|
||||||
|
press = function ()
|
||||||
|
local view = mez.view.get_focused_id()
|
||||||
|
mez.view.set_position(view, 100, 100)
|
||||||
|
mez.view.set_size(view, 100, 100)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
for i = 1, 12 do
|
for i = 1, 12 do
|
||||||
mez.input.add_keymap("ctrl|alt", "XF86Switch_VT_"..i, {
|
mez.input.add_keymap("ctrl|alt", "XF86Switch_VT_"..i, {
|
||||||
press = function() mez.api.change_vt(i) end
|
press = function() mez.api.change_vt(i) end
|
||||||
|
|
@ -59,7 +67,7 @@ end
|
||||||
-- })
|
-- })
|
||||||
|
|
||||||
mez.hook.add("ViewMapPre", {
|
mez.hook.add("ViewMapPre", {
|
||||||
callback = function()
|
callback = function(v)
|
||||||
print("hello world")
|
mez.view.set_size(v, 1000, 1000)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ const Input = @import("input.zig");
|
||||||
const Api = @import("api.zig");
|
const Api = @import("api.zig");
|
||||||
const View = @import("view.zig");
|
const View = @import("view.zig");
|
||||||
const Hook = @import("hook.zig");
|
const Hook = @import("hook.zig");
|
||||||
|
const View = @import("view.zig");
|
||||||
|
|
||||||
const gpa = std.heap.c_allocator;
|
const gpa = std.heap.c_allocator;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,12 +41,12 @@ pub fn put(self: *Events, key: []const u8, hook: *const Hook) !void {
|
||||||
// TODO: figure out deletion
|
// TODO: figure out deletion
|
||||||
// pub fn del(self: *Events, key: ???) !void {}
|
// pub fn del(self: *Events, key: ???) !void {}
|
||||||
|
|
||||||
pub fn exec(self: *Events, event: []const u8) void {
|
pub fn exec(self: *Events, event: []const u8, args: anytype) void {
|
||||||
if (self.events.get(event)) |e| {
|
if (self.events.get(event)) |e| {
|
||||||
var node = e.first;
|
var node = e.first;
|
||||||
while (node) |n| : (node = n.next) {
|
while (node) |n| : (node = n.next) {
|
||||||
const data: *Node = @fieldParentPtr("node", n);
|
const data: *Node = @fieldParentPtr("node", n);
|
||||||
data.hook.callback();
|
data.hook.callback(args);
|
||||||
|
|
||||||
// FIXME: not sure why but for some reason our ll doesn't seem to want to
|
// FIXME: not sure why but for some reason our ll doesn't seem to want to
|
||||||
// admit that there's nothing after the first node.
|
// admit that there's nothing after the first node.
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,13 @@ options: struct {
|
||||||
lua_cb_ref_idx: i32,
|
lua_cb_ref_idx: i32,
|
||||||
},
|
},
|
||||||
|
|
||||||
pub fn callback(self: *const Hook) void {
|
pub fn callback(self: *const Hook, args: anytype) void {
|
||||||
|
const ArgsType = @TypeOf(args);
|
||||||
|
const args_type_info = @typeInfo(ArgsType);
|
||||||
|
if (args_type_info != .@"struct") {
|
||||||
|
@compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
|
||||||
|
}
|
||||||
|
|
||||||
const t = Lua.state.rawGetIndex(zlua.registry_index, self.options.lua_cb_ref_idx);
|
const t = Lua.state.rawGetIndex(zlua.registry_index, self.options.lua_cb_ref_idx);
|
||||||
if (t != zlua.LuaType.function) {
|
if (t != zlua.LuaType.function) {
|
||||||
std.log.err("Failed to call hook, it doesn't have a callback.", .{});
|
std.log.err("Failed to call hook, it doesn't have a callback.", .{});
|
||||||
|
|
@ -25,8 +31,14 @@ pub fn callback(self: *const Hook) void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: we need to send some data along with the callback, this data will
|
// allow passing any arguments to the lua hook
|
||||||
// change based on the event which the user is hooking into
|
var i: u8 = 0;
|
||||||
Lua.state.call(.{ .args = 0, .results = 0 });
|
inline for (args, 1..) |field, k| {
|
||||||
|
try Lua.state.pushAny(field);
|
||||||
|
i = k;
|
||||||
|
}
|
||||||
|
|
||||||
|
Lua.state.protectedCall(.{ .args = i }) catch {
|
||||||
|
};
|
||||||
Lua.state.pop(-1);
|
Lua.state.pop(-1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ fn handleMap(listener: *wl.Listener(void)) void {
|
||||||
const view: *View = @fieldParentPtr("map", listener);
|
const view: *View = @fieldParentPtr("map", listener);
|
||||||
std.log.debug("Mapping view '{s}'", .{view.xdg_toplevel.title orelse "(unnamed)"});
|
std.log.debug("Mapping view '{s}'", .{view.xdg_toplevel.title orelse "(unnamed)"});
|
||||||
|
|
||||||
server.events.exec("ViewMapPre");
|
server.events.exec("ViewMapPre", .{view.id});
|
||||||
|
|
||||||
view.xdg_toplevel.events.request_fullscreen.add(&view.request_fullscreen);
|
view.xdg_toplevel.events.request_fullscreen.add(&view.request_fullscreen);
|
||||||
view.xdg_toplevel.events.request_move.add(&view.request_move);
|
view.xdg_toplevel.events.request_move.add(&view.request_move);
|
||||||
|
|
@ -155,7 +155,7 @@ fn handleMap(listener: *wl.Listener(void)) void {
|
||||||
|
|
||||||
view.mapped = true;
|
view.mapped = true;
|
||||||
|
|
||||||
server.events.exec("ViewMapPost");
|
server.events.exec("ViewMapPost", .{view.id});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handleUnmap(listener: *wl.Listener(void)) void {
|
fn handleUnmap(listener: *wl.Listener(void)) void {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue