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 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 {
catppuccin: struct {
red: [:0]const u8,
sky: [:0]const u8,
},
nvidia: bool = false,
term: struct { command: [:0]const u8 },
commands: struct {
file_manager: [:0]const u8,
browser: [:0]const u8,
}, cursor: struct {
},
cursor: struct {
theme: [:0]const u8,
size: u32,
} }, "../..", b.allocator);
},
}, "../..", b.allocator);
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([:0]const u8, "term_command", cg_opt.term.command);
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");
pub fn init(alloc: std.mem.Allocator) !void {
pub fn init(alloc: std.mem.Allocator, initial: bool) !void {
const con = try Connection.init();
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(&.{ "border-color-focused", "0x880000" });
try con.runCommand(&.{ "border-color-unfocused", "0x660000" });
try con.runCommand(&.{ "border-color-focused", "0x" ++ opts.catppuccin_red });
try con.runCommand(&.{ "border-color-unfocused", "0x" ++ opts.catppuccin_sky });
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);
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) {
error.FileNotFound => b: {
log.info("no river_init", .{});
@ -184,7 +187,7 @@ pub fn init(alloc: std.mem.Allocator) !void {
return error.InitBorked;
}
log.info("configuration finished, spawning processes", .{});
log.info("configuration finished, initial: {}", .{initial});
// tell confgenfs we're now using river
confgenfs: {
@ -205,6 +208,9 @@ pub fn init(alloc: std.mem.Allocator) !void {
);
}
if (initial) {
std.log.info("spawning processes", .{});
var child_arena = std.heap.ArenaAllocator.init(alloc);
defer child_arena.deinit();
@ -222,4 +228,5 @@ pub fn init(alloc: std.mem.Allocator) !void {
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 init = @import("init.zig").init;
pub const std_options = std.Options{
.log_level = switch (@import("builtin").mode) {
.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))
{
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 {
log.info("running in launch mode", .{});