diff --git a/src/c.zig b/src/c.zig index 30d7340..30a91a6 100644 --- a/src/c.zig +++ b/src/c.zig @@ -2,6 +2,7 @@ pub usingnamespace @cImport({ @cDefine("WLR_USE_UNSTABLE", {}); @cInclude("time.h"); @cInclude("stdlib.h"); + @cInclude("unistd.h"); @cInclude("wayland-server-core.h"); //@cInclude("wlr/backend.h"); //@cInclude("wlr/render/wlr_renderer.h"); diff --git a/src/command.zig b/src/command.zig index 7aac7f6..6b4ec07 100644 --- a/src/command.zig +++ b/src/command.zig @@ -1,6 +1,7 @@ const std = @import("std"); const c = @import("c.zig"); +const Log = @import("log.zig").Log; const Server = @import("server.zig").Server; const ViewStack = @import("view_stack.zig").ViewStack; @@ -8,6 +9,7 @@ pub const Arg = union { int: i32, uint: u32, float: f64, + cstr: [*:0]const u8, none: void, }; @@ -107,9 +109,13 @@ pub fn toggleFocusedViewTags(server: *Server, arg: Arg) void { /// Spawn a program. /// TODO: make this take a program as a paramter and spawn that pub fn spawn(server: *Server, arg: Arg) void { - const argv = [_][]const u8{ "/bin/sh", "-c", "alacritty" }; - const child = std.ChildProcess.init(&argv, std.heap.c_allocator) catch unreachable; - std.ChildProcess.spawn(child) catch unreachable; + const cmd = arg.cstr; + if (c.fork() == 0) { + const terminator: ?*u8 = null; + if (c.execl("/bin/sh", "/bin/sh", "-c", cmd, terminator) == -1) { + Log.Error.log("Failed to execute command {}", .{cmd}); + } + } } /// Close the focused view, if any. diff --git a/src/config.zig b/src/config.zig index 1434f07..4159203 100644 --- a/src/config.zig +++ b/src/config.zig @@ -50,7 +50,7 @@ pub const Config = struct { try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_h, .modifiers = mod | c.WLR_MODIFIER_SHIFT, .command = command.modifyMasterCount, .arg = .{ .int = 1 } }); try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_l, .modifiers = mod | c.WLR_MODIFIER_SHIFT, .command = command.modifyMasterCount, .arg = .{ .int = -1 } }); - try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_Return, .modifiers = mod | c.WLR_MODIFIER_SHIFT, .command = command.spawn, .arg = .{ .none = {} } }); + try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_Return, .modifiers = mod | c.WLR_MODIFIER_SHIFT, .command = command.spawn, .arg = .{ .cstr = "alacritty" } }); try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_1, .modifiers = mod | c.WLR_MODIFIER_SHIFT, .command = command.setFocusedViewTags, .arg = .{ .uint = 1 << 0 } }); try self.keybinds.append(Keybind{ .keysym = c.XKB_KEY_2, .modifiers = mod | c.WLR_MODIFIER_SHIFT, .command = command.setFocusedViewTags, .arg = .{ .uint = 1 << 1 } }); diff --git a/src/keyboard.zig b/src/keyboard.zig index af2786f..83bc745 100644 --- a/src/keyboard.zig +++ b/src/keyboard.zig @@ -17,7 +17,7 @@ pub const Keyboard = struct { pub fn init(self: *Self, seat: *Seat, device: *c.wlr_input_device) !void { self.seat = seat; self.device = device; - self.wlr_keyboard = device.unnamed_133.keyboard; + self.wlr_keyboard = device.unnamed_136.keyboard; // We need to prepare an XKB keymap and assign it to the keyboard. This // assumes the defaults (e.g. layout = "us"). @@ -78,7 +78,7 @@ pub const Keyboard = struct { @alignCast(@alignOf(*c.wlr_event_keyboard_key), data), ); - const wlr_keyboard: *c.wlr_keyboard = keyboard.device.unnamed_133.keyboard; + const wlr_keyboard: *c.wlr_keyboard = keyboard.device.unnamed_136.keyboard; // Translate libinput keycode -> xkbcommon const keycode = event.keycode + 8; diff --git a/src/server.zig b/src/server.zig index c729fd3..94d4ff7 100644 --- a/src/server.zig +++ b/src/server.zig @@ -4,6 +4,7 @@ const command = @import("command.zig"); const Config = @import("config.zig").Config; const DecorationManager = @import("decoration_manager.zig").DecorationManager; +const Log = @import("log.zig").Log; const Output = @import("output.zig").Output; const Root = @import("root.zig").Root; const Seat = @import("seat.zig").Seat; @@ -105,8 +106,7 @@ pub const Server = struct { return error.CantStartBackend; } - // Set the WAYLAND_DISPLAY environment variable to our socket and run the - // startup command if requested. */ + // Set the WAYLAND_DISPLAY environment variable to our socket if (c.setenv("WAYLAND_DISPLAY", socket, 1) == -1) { return error.CantSetEnv; }