Add exec command and store wlr socket

This commit is contained in:
2023-12-24 16:33:31 +01:00
parent 5d77caec66
commit 89516fdd7d
4 changed files with 20 additions and 0 deletions

1
.gitignore vendored
View File

@@ -5,3 +5,4 @@ zig-out/
/build/
/build-*/
/docgen_tmp/
vgcore*

View File

@@ -81,6 +81,8 @@
if inShell
then [
zls-overlay.packages.${system}.default
valgrind
gdb
]
else []
);

13
src/commands.zig Normal file
View File

@@ -0,0 +1,13 @@
const std = @import("std");
const gpa = std.heap.c_allocator;
const serv = @import("server.zig");
pub fn exec(server: *serv.Server, cmd: [:0]const u8) !void {
var child = std.ChildProcess.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", server.socket);
child.env_map = &env_map;
try child.spawn();
}

View File

@@ -20,6 +20,7 @@ pub const Server = struct {
cursor: *wlr.Cursor,
cursor_mgr: *wlr.XcursorManager,
socket: [:0]const u8,
events: events.Events,
pub fn init(self: *Server) !void {
@@ -29,6 +30,8 @@ pub const Server = struct {
const output_layout = try wlr.OutputLayout.create();
const scene = try wlr.Scene.create();
var buf: [11]u8 = undefined;
self.* = Server{
.wl_server = wl_server,
.backend = backend,
@@ -42,6 +45,7 @@ pub const Server = struct {
.cursor = try wlr.Cursor.create(),
.cursor_mgr = try wlr.XcursorManager.create(null, 24),
.events = undefined,
.socket = try wl_server.addSocketAuto(&buf),
};
errdefer self.destroy();