mzteriver: better border colors and reinit support

This commit is contained in:
LordMZTE 2024-03-20 19:37:54 +01:00
parent 5ba7cc86f6
commit 336fe9d864
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
3 changed files with 53 additions and 28 deletions

View file

@ -7,15 +7,26 @@ pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
const cg_opt = try common.confgenGet(struct { nvidia: bool = false, term: struct { command: [:0]const u8 }, commands: struct { const cg_opt = try common.confgenGet(struct {
file_manager: [:0]const u8, catppuccin: struct {
browser: [:0]const u8, red: [:0]const u8,
}, cursor: struct { sky: [:0]const u8,
theme: [:0]const u8, },
size: u32, nvidia: bool = false,
} }, "../..", b.allocator); term: struct { command: [:0]const u8 },
commands: struct {
file_manager: [:0]const u8,
browser: [:0]const u8,
},
cursor: struct {
theme: [:0]const u8,
size: u32,
},
}, "../..", b.allocator);
const opts = b.addOptions(); const opts = b.addOptions();
opts.addOption([:0]const u8, "catppuccin_red", cg_opt.catppuccin.red);
opts.addOption([:0]const u8, "catppuccin_sky", cg_opt.catppuccin.sky);
opts.addOption(bool, "nvidia", cg_opt.nvidia); opts.addOption(bool, "nvidia", cg_opt.nvidia);
opts.addOption([:0]const u8, "term_command", cg_opt.term.command); opts.addOption([:0]const u8, "term_command", cg_opt.term.command);
opts.addOption([:0]const u8, "file_manager_command", cg_opt.commands.file_manager); opts.addOption([:0]const u8, "file_manager_command", cg_opt.commands.file_manager);

View file

@ -5,7 +5,7 @@ const log = std.log.scoped(.mzteriver);
const Connection = @import("Connection.zig"); const Connection = @import("Connection.zig");
pub fn init(alloc: std.mem.Allocator) !void { pub fn init(alloc: std.mem.Allocator, initial: bool) !void {
const con = try Connection.init(); const con = try Connection.init();
defer con.deinit(); defer con.deinit();
@ -145,8 +145,8 @@ pub fn init(alloc: std.mem.Allocator) !void {
try con.runCommand(&.{ "set-repeat", "50", "300" }); try con.runCommand(&.{ "set-repeat", "50", "300" });
try con.runCommand(&.{ "border-color-focused", "0x880000" }); try con.runCommand(&.{ "border-color-focused", "0x" ++ opts.catppuccin_red });
try con.runCommand(&.{ "border-color-unfocused", "0x660000" }); try con.runCommand(&.{ "border-color-unfocused", "0x" ++ opts.catppuccin_sky });
try con.runCommand(&.{ "hide-cursor", "when-typing", "enabled" }); try con.runCommand(&.{ "hide-cursor", "when-typing", "enabled" });
@ -170,7 +170,10 @@ pub fn init(alloc: std.mem.Allocator) !void {
); );
defer alloc.free(init_path); defer alloc.free(init_path);
var init_child = std.process.Child.init(&.{init_path}, alloc); var init_child = std.process.Child.init(
&.{ init_path, if (initial) "init" else "reinit" },
alloc,
);
const term = init_child.spawnAndWait() catch |e| switch (e) { const term = init_child.spawnAndWait() catch |e| switch (e) {
error.FileNotFound => b: { error.FileNotFound => b: {
log.info("no river_init", .{}); log.info("no river_init", .{});
@ -184,7 +187,7 @@ pub fn init(alloc: std.mem.Allocator) !void {
return error.InitBorked; return error.InitBorked;
} }
log.info("configuration finished, spawning processes", .{}); log.info("configuration finished, initial: {}", .{initial});
// tell confgenfs we're now using river // tell confgenfs we're now using river
confgenfs: { confgenfs: {
@ -205,21 +208,25 @@ pub fn init(alloc: std.mem.Allocator) !void {
); );
} }
var child_arena = std.heap.ArenaAllocator.init(alloc); if (initial) {
defer child_arena.deinit(); std.log.info("spawning processes", .{});
// spawn background processes var child_arena = std.heap.ArenaAllocator.init(alloc);
inline for (.{ defer child_arena.deinit();
.{"wlbg"},
.{"waybar"}, // spawn background processes
.{ "dbus-update-activation-environment", "DISPLAY", "XAUTHORITY", "WAYLAND_DISPLAY", "XDG_CURRENT_DESKTOP" }, inline for (.{
.{ "systemctl", "--user", "import-environment", "DISPLAY", "XAUTHORITY", "WAYLAND_DISPLAY", "XDG_CURRENT_DESKTOP" }, .{"wlbg"},
.{ "rivertile", "-view-padding", "6", "-outer-padding", "6" }, .{"waybar"},
}) |argv| { .{ "dbus-update-activation-environment", "DISPLAY", "XAUTHORITY", "WAYLAND_DISPLAY", "XDG_CURRENT_DESKTOP" },
// TODO: wonk .{ "systemctl", "--user", "import-environment", "DISPLAY", "XAUTHORITY", "WAYLAND_DISPLAY", "XDG_CURRENT_DESKTOP" },
// We use an arena here to prevent leaks because process.Child apparently doesn't support .{ "rivertile", "-view-padding", "6", "-outer-padding", "6" },
// detaching. }) |argv| {
var child = std.process.Child.init(&argv, child_arena.allocator()); // TODO: wonk
try child.spawn(); // We use an arena here to prevent leaks because process.Child apparently doesn't support
// detaching.
var child = std.process.Child.init(&argv, child_arena.allocator());
try child.spawn();
}
} }
} }

View file

@ -3,6 +3,8 @@ const opts = @import("opts");
const log = std.log.scoped(.mzteriver); const log = std.log.scoped(.mzteriver);
const init = @import("init.zig").init;
pub const std_options = std.Options{ pub const std_options = std.Options{
.log_level = switch (@import("builtin").mode) { .log_level = switch (@import("builtin").mode) {
.Debug => .debug, .Debug => .debug,
@ -21,7 +23,12 @@ pub fn main() !void {
(std.os.argv.len >= 2 and std.mem.orderZ(u8, std.os.argv[1], "init") == .eq)) (std.os.argv.len >= 2 and std.mem.orderZ(u8, std.os.argv[1], "init") == .eq))
{ {
log.info("running in init mode", .{}); log.info("running in init mode", .{});
try @import("init.zig").init(alloc); try init(alloc, true);
} else if (std.mem.endsWith(u8, std.mem.span(std.os.argv[0]), "reinit") or
(std.os.argv.len >= 2 and std.mem.orderZ(u8, std.os.argv[1], "reinit") == .eq))
{
log.info("running in reinit mode", .{});
try init(alloc, false);
} else { } else {
log.info("running in launch mode", .{}); log.info("running in launch mode", .{});