Fix environment of spawned processes
std.ChildProcess isn't handling environment variables set at runtime properly, so just use libc directly.
This commit is contained in:
parent
b2fbdf2d87
commit
3332e0ab2b
5 changed files with 15 additions and 8 deletions
|
@ -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");
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 } });
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue