mirror of
https://github.com/MezzalunaWM/Mezzaluna.git
synced 2026-03-08 04:57:32 -04:00
added process spawning
This commit is contained in:
parent
23ef0049f7
commit
2e2cfeebae
5 changed files with 47 additions and 249 deletions
|
|
@ -23,9 +23,10 @@ pub fn callback(self: *const Keymap) void {
|
|||
const t = Lua.state.rawGetIndex(zlua.registry_index, self.lua_ref_idx);
|
||||
if (t != zlua.LuaType.function) {
|
||||
std.log.err("Failed to call keybind, it doesn't have a callback.", .{});
|
||||
Lua.state.pop(1);
|
||||
return;
|
||||
}
|
||||
Lua.state.pushValue(1);
|
||||
|
||||
Lua.state.call(.{ .args = 0, .results = 0 });
|
||||
Lua.state.pop(-1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
const Api = @This();
|
||||
|
||||
const std = @import("std");
|
||||
const server = &@import("../main.zig").server;
|
||||
const Keymap = @import("../keymap.zig");
|
||||
|
||||
const zlua = @import("zlua");
|
||||
|
|
@ -9,9 +8,12 @@ const xkb = @import("xkbcommon");
|
|||
const wlr = @import("wlroots");
|
||||
|
||||
const gpa = std.heap.c_allocator;
|
||||
const server = &@import("../main.zig").server;
|
||||
const env_map = &@import("../main.zig").env_map;
|
||||
|
||||
pub fn add_keymap(L: *zlua.Lua) i32 {
|
||||
const nargs: i32 = L.getTop();
|
||||
|
||||
if (nargs < 3) {
|
||||
L.raiseErrorStr("Expected at least three arguments", .{});
|
||||
return 0;
|
||||
|
|
@ -23,6 +25,9 @@ pub fn add_keymap(L: *zlua.Lua) i32 {
|
|||
L.checkType(3, .function);
|
||||
|
||||
var keymap: Keymap = undefined;
|
||||
keymap.options = .{
|
||||
.on_release = false,
|
||||
};
|
||||
|
||||
const mod = L.toString(1) catch {
|
||||
L.raiseErrorStr("Lua error check your config", .{});
|
||||
|
|
@ -89,3 +94,27 @@ pub fn get_keybind(L: *zlua.Lua) i32 {
|
|||
_ = L;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pub fn spawn(L: *zlua.Lua) i32 {
|
||||
const nargs: i32 = L.getTop();
|
||||
|
||||
if (nargs < 1) {
|
||||
L.raiseErrorStr("Expected at least one arguments", .{});
|
||||
return 0;
|
||||
}
|
||||
|
||||
L.checkType(1, .string);
|
||||
|
||||
const cmd = L.toString(1) catch {
|
||||
L.raiseErrorStr("Lua error check your config", .{});
|
||||
return 0;
|
||||
};
|
||||
|
||||
var child = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", cmd }, gpa);
|
||||
child.env_map = env_map;
|
||||
child.spawn() catch {
|
||||
std.log.err("Unable to spawn process \"{s}\"", .{cmd});
|
||||
};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ const gpa = std.heap.c_allocator;
|
|||
|
||||
pub var server: Server = undefined;
|
||||
pub var lua: Lua = undefined;
|
||||
pub var env_map: std.process.EnvMap = undefined;
|
||||
|
||||
pub fn main() !void {
|
||||
wlr.log.init(.err, null);
|
||||
|
|
@ -21,15 +22,16 @@ pub fn main() !void {
|
|||
var buf: [11]u8 = undefined;
|
||||
const socket = try server.wl_server.addSocketAuto(&buf);
|
||||
|
||||
env_map = try std.process.getEnvMap(gpa);
|
||||
try env_map.put("WAYLAND_DISPLAY", socket);
|
||||
|
||||
if (std.os.argv.len >= 2) {
|
||||
const cmd = std.mem.span(std.os.argv[1]);
|
||||
var child = std.process.Child.init(&[_][]const u8{ "/bin/sh", "-c", cmd }, gpa);
|
||||
var env_map = try std.process.getEnvMap(gpa);
|
||||
defer env_map.deinit();
|
||||
try env_map.put("WAYLAND_DISPLAY", socket);
|
||||
child.env_map = &env_map;
|
||||
try child.spawn();
|
||||
}
|
||||
defer env_map.deinit();
|
||||
|
||||
std.log.info("Starting backend", .{});
|
||||
server.backend.start() catch |err| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue