Merge pull request #209 from tonybanters/zigv16
Browse files
Zig Version 0.16.0 Updates
+1 −0 .gitignore
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | zig-out/ |
| 3 | 3 | .zig-cache/ |
| 4 | 4 | .direnv/ |
| 5 | +zig-pkg/ | |
| 5 | 6 | |
| 6 | 7 | # Nix |
| 7 | 8 | result |
+18 −17 build.zig
| @@ -13,6 +13,7 @@ pub fn build(b: *std.Build) void { | ||
| 13 | 13 | .root_source_file = b.path("src/main.zig"), |
| 14 | 14 | .target = target, |
| 15 | 15 | .optimize = optimize, |
| 16 | + .link_libc = true, | |
| 16 | 17 | }), |
| 17 | 18 | }); |
| 18 | 19 | |
| @@ -27,12 +28,12 @@ pub fn build(b: *std.Build) void { | ||
| 27 | 28 | exe.use_lld = false; |
| 28 | 29 | |
| 29 | 30 | const lua = buildLua(b, lua_dep, target, optimize); |
| 30 | - exe.linkLibrary(lua); | |
| 31 | - exe.linkSystemLibrary("X11"); | |
| 32 | - exe.linkSystemLibrary("Xinerama"); | |
| 33 | - exe.linkSystemLibrary("Xft"); | |
| 34 | - exe.linkSystemLibrary("fontconfig"); | |
| 35 | - exe.linkLibC(); | |
| 31 | + | |
| 32 | + exe.root_module.linkLibrary(lua); | |
| 33 | + exe.root_module.linkSystemLibrary("X11", .{}); | |
| 34 | + exe.root_module.linkSystemLibrary("Xinerama", .{}); | |
| 35 | + exe.root_module.linkSystemLibrary("Xft", .{}); | |
| 36 | + exe.root_module.linkSystemLibrary("fontconfig", .{}); | |
| 36 | 37 | |
| 37 | 38 | b.installArtifact(exe); |
| 38 | 39 | |
| @@ -60,16 +61,16 @@ pub fn build(b: *std.Build) void { | ||
| 60 | 61 | .root_source_file = b.path("src/main.zig"), |
| 61 | 62 | .target = target, |
| 62 | 63 | .optimize = optimize, |
| 64 | + .link_libc = true, | |
| 63 | 65 | }), |
| 64 | 66 | }); |
| 65 | 67 | src_main_unit_tests.use_lld = false; |
| 66 | 68 | src_main_unit_tests.root_module.addIncludePath(lua_headers); |
| 67 | - src_main_unit_tests.linkLibrary(lua); | |
| 68 | - src_main_unit_tests.linkSystemLibrary("X11"); | |
| 69 | - src_main_unit_tests.linkSystemLibrary("Xinerama"); | |
| 70 | - src_main_unit_tests.linkSystemLibrary("Xft"); | |
| 71 | - src_main_unit_tests.linkSystemLibrary("fontconfig"); | |
| 72 | - src_main_unit_tests.linkLibC(); | |
| 69 | + src_main_unit_tests.root_module.linkLibrary(lua); | |
| 70 | + src_main_unit_tests.root_module.linkSystemLibrary("X11", .{}); | |
| 71 | + src_main_unit_tests.root_module.linkSystemLibrary("Xinerama", .{}); | |
| 72 | + src_main_unit_tests.root_module.linkSystemLibrary("Xft", .{}); | |
| 73 | + src_main_unit_tests.root_module.linkSystemLibrary("fontconfig", .{}); | |
| 73 | 74 | test_step.dependOn(&b.addRunArtifact(src_main_unit_tests).step); |
| 74 | 75 | |
| 75 | 76 | const lua_config_tests = b.addTest(.{ |
| @@ -77,6 +78,7 @@ pub fn build(b: *std.Build) void { | ||
| 77 | 78 | .root_source_file = b.path("tests/lua_config_tests.zig"), |
| 78 | 79 | .target = target, |
| 79 | 80 | .optimize = optimize, |
| 81 | + .link_libc = true, | |
| 80 | 82 | }), |
| 81 | 83 | }); |
| 82 | 84 | lua_config_tests.use_lld = false; |
| @@ -88,8 +90,7 @@ pub fn build(b: *std.Build) void { | ||
| 88 | 90 | }); |
| 89 | 91 | lua_config_module.addIncludePath(lua_headers); |
| 90 | 92 | lua_config_tests.root_module.addImport("lua", lua_config_module); |
| 91 | - lua_config_tests.linkLibrary(lua); | |
| 92 | - lua_config_tests.linkLibC(); | |
| 93 | + lua_config_tests.root_module.linkLibrary(lua); | |
| 93 | 94 | test_step.dependOn(&b.addRunArtifact(lua_config_tests).step); |
| 94 | 95 | |
| 95 | 96 | const xephyr_step = b.step("xephyr", "Run in Xephyr (1280x800 on :2)"); |
| @@ -172,11 +173,11 @@ fn buildLua(b: *std.Build, lua_dep: *std.Build.Dependency, target: std.Build.Res | ||
| 172 | 173 | .root_module = b.createModule(.{ |
| 173 | 174 | .target = target, |
| 174 | 175 | .optimize = optimize, |
| 176 | + .link_libc = true, | |
| 175 | 177 | }), |
| 176 | 178 | }); |
| 177 | - lua.linkLibC(); | |
| 178 | - lua.addIncludePath(lua_src.path("src/")); | |
| 179 | - lua.addCSourceFiles(.{ | |
| 179 | + lua.root_module.addIncludePath(lua_src.path("src/")); | |
| 180 | + lua.root_module.addCSourceFiles(.{ | |
| 180 | 181 | .root = lua_src.path("src/"), |
| 181 | 182 | .files = &.{ |
| 182 | 183 | "lapi.c", |
+2 −2 build.zig.zon
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | .{ |
| 2 | 2 | .name = .oxwm, |
| 3 | - .version = "0.11.4", | |
| 3 | + .version = "0.12.0", | |
| 4 | 4 | .fingerprint = 0x4b9ef3753914924d, // Changing this has security and trust implications. |
| 5 | - .minimum_zig_version = "0.15.2", | |
| 5 | + .minimum_zig_version = "0.16.0", | |
| 6 | 6 | .dependencies = .{ |
| 7 | 7 | .lua = .{ |
| 8 | 8 | .url = "https://www.lua.org/ftp/lua-5.4.8.tar.gz", |
+3 −3 flake.lock
| @@ -2,11 +2,11 @@ | ||
| 2 | 2 | "nodes": { |
| 3 | 3 | "nixpkgs": { |
| 4 | 4 | "locked": { |
| 5 | - "lastModified": 1771008912, | |
| 6 | - "narHash": "sha256-gf2AmWVTs8lEq7z/3ZAsgnZDhWIckkb+ZnAo5RzSxJg=", | |
| 5 | + "lastModified": 1778443072, | |
| 6 | + "narHash": "sha256-zi7/fsqM/kFdNuED//4WOCUtezGtKKqRNORjMvfwjnA=", | |
| 7 | 7 | "owner": "NixOS", |
| 8 | 8 | "repo": "nixpkgs", |
| 9 | - "rev": "a82ccc39b39b621151d6732718e3e250109076fa", | |
| 9 | + "rev": "da5ad661ba4e5ef59ba743f0d112cbc30e474f32", | |
| 10 | 10 | "type": "github" |
| 11 | 11 | }, |
| 12 | 12 | "original": { |
+4 −4 src/animations.zig
| @@ -30,23 +30,23 @@ pub const ScrollAnimation = struct { | ||
| 30 | 30 | easing: Easing = .ease_out, |
| 31 | 31 | active: bool = false, |
| 32 | 32 | |
| 33 | - pub fn start(self: *ScrollAnimation, from: i32, to: i32, config: AnimationConfig) void { | |
| 33 | + pub fn start(self: *ScrollAnimation, io: std.Io, from: i32, to: i32, config: AnimationConfig) void { | |
| 34 | 34 | if (from == to) { |
| 35 | 35 | self.active = false; |
| 36 | 36 | return; |
| 37 | 37 | } |
| 38 | 38 | self.start_value = from; |
| 39 | 39 | self.end_value = to; |
| 40 | - self.start_time = std.time.milliTimestamp(); | |
| 40 | + self.start_time = std.Io.Timestamp.now(io, .awake).toMilliseconds(); | |
| 41 | 41 | self.duration_ms = config.duration_ms; |
| 42 | 42 | self.easing = config.easing; |
| 43 | 43 | self.active = true; |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - pub fn update(self: *ScrollAnimation) ?i32 { | |
| 46 | + pub fn update(self: *ScrollAnimation, io: std.Io) ?i32 { | |
| 47 | 47 | if (!self.active) return null; |
| 48 | 48 | |
| 49 | - const now = std.time.milliTimestamp(); | |
| 49 | + const now = std.Io.Timestamp.now(io, .awake).toMilliseconds(); | |
| 50 | 50 | const elapsed = now - self.start_time; |
| 51 | 51 | |
| 52 | 52 | if (elapsed >= @as(i64, @intCast(self.duration_ms))) { |
+3 −3 src/bar/bar.zig
| @@ -11,7 +11,7 @@ const Block = blocks_mod.Block; | ||
| 11 | 11 | pub const Systray = systray_mod.Systray; |
| 12 | 12 | |
| 13 | 13 | fn getLayoutSymbol(layout_index: u32, config: config_mod.Config) []const u8 { |
| 14 | - const layout = std.meta.intToEnum(config_mod.Layouts, layout_index) catch return "[?]"; | |
| 14 | + const layout = std.enums.fromInt(config_mod.Layouts, layout_index) orelse return "[?]"; | |
| 15 | 15 | return switch (layout) { |
| 16 | 16 | .tiling => config.layout_tile_symbol, |
| 17 | 17 | .monocle => config.layout_monocle_symbol, |
| @@ -303,10 +303,10 @@ pub const Bar = struct { | ||
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /// Updates all blocks and marks the bar dirty if any block changed. |
| 306 | - pub fn updateBlocks(self: *Bar) void { | |
| 306 | + pub fn updateBlocks(self: *Bar, io: std.Io, gpa: std.mem.Allocator) void { | |
| 307 | 307 | var changed = false; |
| 308 | 308 | for (self.blocks.items) |*block| { |
| 309 | - if (block.update()) changed = true; | |
| 309 | + if (block.update(io, gpa)) changed = true; | |
| 310 | 310 | } |
| 311 | 311 | if (changed) self.needs_redraw = true; |
| 312 | 312 | } |
+11 −11 src/bar/blocks/battery.zig
| @@ -27,11 +27,11 @@ pub const Battery = struct { | ||
| 27 | 27 | }; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - pub fn content(self: *Battery, buffer: []u8) []const u8 { | |
| 30 | + pub fn content(self: *Battery, io: std.Io, buffer: []u8) []const u8 { | |
| 31 | 31 | var path_buf: [128]u8 = undefined; |
| 32 | 32 | |
| 33 | - const capacity = self.readBatteryFile(&path_buf, "capacity") orelse return buffer[0..0]; | |
| 34 | - const status = self.readBatteryStatus(&path_buf) orelse return buffer[0..0]; | |
| 33 | + const capacity = self.readBatteryFile(io, &path_buf, "capacity") orelse return buffer[0..0]; | |
| 34 | + const status = self.readBatteryStatus(io, &path_buf) orelse return buffer[0..0]; | |
| 35 | 35 | |
| 36 | 36 | const format = switch (status) { |
| 37 | 37 | .charging => self.format_charging, |
| @@ -47,14 +47,14 @@ pub const Battery = struct { | ||
| 47 | 47 | |
| 48 | 48 | const Status = enum { charging, discharging, full }; |
| 49 | 49 | |
| 50 | - fn readBatteryStatus(self: *Battery, path_buf: *[128]u8) ?Status { | |
| 50 | + fn readBatteryStatus(self: *Battery, io: std.Io, path_buf: *[128]u8) ?Status { | |
| 51 | 51 | const path = std.fmt.bufPrint(path_buf, "/sys/class/power_supply/{s}/status", .{self.battery_name}) catch return null; |
| 52 | 52 | |
| 53 | - const file = std.fs.openFileAbsolute(path, .{}) catch return null; | |
| 54 | - defer file.close(); | |
| 53 | + const file = std.Io.Dir.openFileAbsolute(io, path, .{}) catch return null; | |
| 54 | + defer file.close(io); | |
| 55 | 55 | |
| 56 | 56 | var buf: [32]u8 = undefined; |
| 57 | - const len = file.read(&buf) catch return null; | |
| 57 | + const len = file.readStreaming(io, &.{&buf}) catch return null; | |
| 58 | 58 | const status_str = std.mem.trim(u8, buf[0..len], " \n\r\t"); |
| 59 | 59 | |
| 60 | 60 | if (std.mem.eql(u8, status_str, "Charging")) return .charging; |
| @@ -64,14 +64,14 @@ pub const Battery = struct { | ||
| 64 | 64 | return .discharging; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - fn readBatteryFile(self: *Battery, path_buf: *[128]u8, file_name: []const u8) ?u8 { | |
| 67 | + fn readBatteryFile(self: *Battery, io: std.Io, path_buf: *[128]u8, file_name: []const u8) ?u8 { | |
| 68 | 68 | const path = std.fmt.bufPrint(path_buf, "/sys/class/power_supply/{s}/{s}", .{ self.battery_name, file_name }) catch return null; |
| 69 | 69 | |
| 70 | - const file = std.fs.openFileAbsolute(path, .{}) catch return null; | |
| 71 | - defer file.close(); | |
| 70 | + const file = std.Io.Dir.openFileAbsolute(io, path, .{}) catch return null; | |
| 71 | + defer file.close(io); | |
| 72 | 72 | |
| 73 | 73 | var buf: [16]u8 = undefined; |
| 74 | - const len = file.read(&buf) catch return null; | |
| 74 | + const len = file.readStreaming(io, &.{&buf}) catch return null; | |
| 75 | 75 | const value_str = std.mem.trim(u8, buf[0..len], " \n\r\t"); |
| 76 | 76 | |
| 77 | 77 | return std.fmt.parseInt(u8, value_str, 10) catch null; |
+7 −6 src/bar/blocks/blocks.zig
| @@ -104,11 +104,12 @@ pub const Block = struct { | ||
| 104 | 104 | }; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - pub fn update(self: *Block) bool { | |
| 107 | + pub fn update(self: *Block, io: std.Io, gpa: std.mem.Allocator) bool { | |
| 108 | 108 | const interval_secs = self.interval(); |
| 109 | 109 | if (interval_secs == 0) return false; |
| 110 | 110 | |
| 111 | - const now = std.time.timestamp(); | |
| 111 | + // .awake (monotonic) for interval bookkeeping, not .real (wall-clock) — std.Io rework gives us a clock enum now, and a wall-clock backstep would stretch intervals. | |
| 112 | + const now = std.Io.Timestamp.now(io, .awake).toSeconds(); | |
| 112 | 113 | if (now - self.last_update < @as(i64, @intCast(interval_secs))) { |
| 113 | 114 | return false; |
| 114 | 115 | } |
| @@ -118,10 +119,10 @@ pub const Block = struct { | ||
| 118 | 119 | const result = switch (self.data) { |
| 119 | 120 | .static => |*s| s.content(&self.cached_content), |
| 120 | 121 | .datetime => |*d| d.content(&self.cached_content), |
| 121 | - .ram => |*r| r.content(&self.cached_content), | |
| 122 | - .shell => |*s| s.content(&self.cached_content), | |
| 123 | - .battery => |*b| b.content(&self.cached_content), | |
| 124 | - .cpu_temp => |*c| c.content(&self.cached_content), | |
| 122 | + .ram => |*r| r.content(io, &self.cached_content), | |
| 123 | + .shell => |*s| s.content(io, gpa, &self.cached_content), | |
| 124 | + .battery => |*b| b.content(io, &self.cached_content), | |
| 125 | + .cpu_temp => |*c| c.content(io, &self.cached_content), | |
| 125 | 126 | }; |
| 126 | 127 | |
| 127 | 128 | self.cached_len = result.len; |
+28 −24 src/bar/blocks/cpu_temp.zig
| @@ -8,6 +8,7 @@ pub const CpuTemp = struct { | ||
| 8 | 8 | color: c_ulong, |
| 9 | 9 | cached_path: [128]u8, |
| 10 | 10 | cached_path_len: usize, |
| 11 | + detection_attempted: bool, | |
| 11 | 12 | |
| 12 | 13 | pub fn init( |
| 13 | 14 | format: []const u8, |
| @@ -15,19 +16,18 @@ pub const CpuTemp = struct { | ||
| 15 | 16 | interval_secs: u64, |
| 16 | 17 | color: c_ulong, |
| 17 | 18 | ) CpuTemp { |
| 18 | - var self = CpuTemp{ | |
| 19 | + return .{ | |
| 19 | 20 | .format = format, |
| 20 | 21 | .device = device, |
| 21 | 22 | .interval_secs = interval_secs, |
| 22 | 23 | .color = color, |
| 23 | 24 | .cached_path = undefined, |
| 24 | 25 | .cached_path_len = 0, |
| 26 | + .detection_attempted = false, | |
| 25 | 27 | }; |
| 26 | - self.detectPath(); | |
| 27 | - return self; | |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - fn detectPath(self: *CpuTemp) void { | |
| 30 | + fn detectPath(self: *CpuTemp, io: std.Io) void { | |
| 31 | 31 | if (self.device.len > 0 and self.device[0] == '/') { |
| 32 | 32 | if (self.device.len <= self.cached_path.len) { |
| 33 | 33 | @memcpy(self.cached_path[0..self.device.len], self.device); |
| @@ -37,45 +37,45 @@ pub const CpuTemp = struct { | ||
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | if (self.device.len > 0) { |
| 40 | - if (self.tryPath("/sys/class/thermal/{s}/temp", self.device)) return; | |
| 41 | - if (self.tryPath("/sys/class/hwmon/{s}/temp1_input", self.device)) return; | |
| 40 | + if (self.tryPath(io, "/sys/class/thermal/{s}/temp", self.device)) return; | |
| 41 | + if (self.tryPath(io, "/sys/class/hwmon/{s}/temp1_input", self.device)) return; | |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - if (self.findHwmonCpu()) return; | |
| 44 | + if (self.findHwmonCpu(io)) return; | |
| 45 | 45 | |
| 46 | - if (self.tryPath("/sys/class/thermal/{s}/temp", "thermal_zone0")) return; | |
| 46 | + if (self.tryPath(io, "/sys/class/thermal/{s}/temp", "thermal_zone0")) return; | |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - fn tryPath(self: *CpuTemp, comptime fmt: []const u8, device: []const u8) bool { | |
| 49 | + fn tryPath(self: *CpuTemp, io: std.Io, comptime fmt: []const u8, device: []const u8) bool { | |
| 50 | 50 | const path = std.fmt.bufPrint(&self.cached_path, fmt, .{device}) catch return false; |
| 51 | - const file = std.fs.openFileAbsolute(path, .{}) catch return false; | |
| 52 | - file.close(); | |
| 51 | + const file = std.Io.Dir.openFileAbsolute(io, path, .{}) catch return false; | |
| 52 | + file.close(io); | |
| 53 | 53 | self.cached_path_len = path.len; |
| 54 | 54 | return true; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - fn findHwmonCpu(self: *CpuTemp) bool { | |
| 58 | - var dir = std.fs.openDirAbsolute("/sys/class/hwmon", .{ .iterate = true }) catch return false; | |
| 59 | - defer dir.close(); | |
| 57 | + fn findHwmonCpu(self: *CpuTemp, io: std.Io) bool { | |
| 58 | + var dir = std.Io.Dir.openDirAbsolute(io, "/sys/class/hwmon", .{ .iterate = true }) catch return false; | |
| 59 | + defer dir.close(io); | |
| 60 | 60 | |
| 61 | 61 | var iter = dir.iterate(); |
| 62 | - while (iter.next() catch null) |entry| { | |
| 62 | + while (iter.next(io) catch null) |entry| { | |
| 63 | 63 | if (entry.kind != .directory and entry.kind != .sym_link) continue; |
| 64 | 64 | |
| 65 | 65 | var name_path: [128]u8 = undefined; |
| 66 | 66 | const name_path_str = std.fmt.bufPrint(&name_path, "/sys/class/hwmon/{s}/name", .{entry.name}) catch continue; |
| 67 | 67 | |
| 68 | - const name_file = std.fs.openFileAbsolute(name_path_str, .{}) catch continue; | |
| 69 | - defer name_file.close(); | |
| 68 | + const name_file = std.Io.Dir.openFileAbsolute(io, name_path_str, .{}) catch continue; | |
| 69 | + defer name_file.close(io); | |
| 70 | 70 | |
| 71 | 71 | var name_buf: [32]u8 = undefined; |
| 72 | - const name_len = name_file.read(&name_buf) catch continue; | |
| 72 | + const name_len = name_file.readStreaming(io, &.{&name_buf}) catch continue; | |
| 73 | 73 | const name = std.mem.trim(u8, name_buf[0..name_len], " \n\r\t"); |
| 74 | 74 | |
| 75 | 75 | if (std.mem.eql(u8, name, "coretemp") or std.mem.eql(u8, name, "k10temp")) { |
| 76 | 76 | const temp_path = std.fmt.bufPrint(&self.cached_path, "/sys/class/hwmon/{s}/temp1_input", .{entry.name}) catch continue; |
| 77 | - const temp_file = std.fs.openFileAbsolute(temp_path, .{}) catch continue; | |
| 78 | - temp_file.close(); | |
| 77 | + const temp_file = std.Io.Dir.openFileAbsolute(io, temp_path, .{}) catch continue; | |
| 78 | + temp_file.close(io); | |
| 79 | 79 | self.cached_path_len = temp_path.len; |
| 80 | 80 | return true; |
| 81 | 81 | } |
| @@ -83,15 +83,19 @@ pub const CpuTemp = struct { | ||
| 83 | 83 | return false; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - pub fn content(self: *CpuTemp, buffer: []u8) []const u8 { | |
| 86 | + pub fn content(self: *CpuTemp, io: std.Io, buffer: []u8) []const u8 { | |
| 87 | + if (!self.detection_attempted) { | |
| 88 | + self.detectPath(io); | |
| 89 | + self.detection_attempted = true; | |
| 90 | + } | |
| 87 | 91 | if (self.cached_path_len == 0) return buffer[0..0]; |
| 88 | 92 | |
| 89 | 93 | const path = self.cached_path[0..self.cached_path_len]; |
| 90 | - const file = std.fs.openFileAbsolute(path, .{}) catch return buffer[0..0]; | |
| 91 | - defer file.close(); | |
| 94 | + const file = std.Io.Dir.openFileAbsolute(io, path, .{}) catch return buffer[0..0]; | |
| 95 | + defer file.close(io); | |
| 92 | 96 | |
| 93 | 97 | var temp_buf: [16]u8 = undefined; |
| 94 | - const len = file.read(&temp_buf) catch return buffer[0..0]; | |
| 98 | + const len = file.readStreaming(io, &.{&temp_buf}) catch return buffer[0..0]; | |
| 95 | 99 | const temp_str = std.mem.trim(u8, temp_buf[0..len], " \n\r\t"); |
| 96 | 100 | |
| 97 | 101 | const millidegrees = std.fmt.parseInt(i32, temp_str, 10) catch return buffer[0..0]; |
+4 −4 src/bar/blocks/ram.zig
| @@ -13,12 +13,12 @@ pub const Ram = struct { | ||
| 13 | 13 | }; |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | - pub fn content(self: *Ram, buffer: []u8) []const u8 { | |
| 17 | - const file = std.fs.openFileAbsolute("/proc/meminfo", .{}) catch return buffer[0..0]; | |
| 18 | - defer file.close(); | |
| 16 | + pub fn content(self: *Ram, io: std.Io, buffer: []u8) []const u8 { | |
| 17 | + const file = std.Io.Dir.openFileAbsolute(io, "/proc/meminfo", .{}) catch return buffer[0..0]; | |
| 18 | + defer file.close(io); | |
| 19 | 19 | |
| 20 | 20 | var read_buffer: [512]u8 = undefined; |
| 21 | - const bytes_read = file.read(&read_buffer) catch return buffer[0..0]; | |
| 21 | + const bytes_read = file.readStreaming(io, &.{&read_buffer}) catch return buffer[0..0]; | |
| 22 | 22 | const file_content = read_buffer[0..bytes_read]; |
| 23 | 23 | |
| 24 | 24 | var total: u64 = 0; |
+4 −5 src/bar/blocks/shell.zig
| @@ -16,14 +16,13 @@ pub const Shell = struct { | ||
| 16 | 16 | }; |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | - pub fn content(self: *Shell, buffer: []u8) []const u8 { | |
| 19 | + pub fn content(self: *Shell, io: std.Io, gpa: std.mem.Allocator, buffer: []u8) []const u8 { | |
| 20 | 20 | var cmd_output: [256]u8 = undefined; |
| 21 | - const result = std.process.Child.run(.{ | |
| 22 | - .allocator = std.heap.page_allocator, | |
| 21 | + const result = std.process.run(gpa, io, .{ | |
| 23 | 22 | .argv = &.{ "/bin/sh", "-c", self.command }, |
| 24 | 23 | }) catch return buffer[0..0]; |
| 25 | - defer std.heap.page_allocator.free(result.stdout); | |
| 26 | - defer std.heap.page_allocator.free(result.stderr); | |
| 24 | + defer gpa.free(result.stdout); | |
| 25 | + defer gpa.free(result.stderr); | |
| 27 | 26 | |
| 28 | 27 | var cmd_len = @min(result.stdout.len, cmd_output.len); |
| 29 | 28 | @memcpy(cmd_output[0..cmd_len], result.stdout[0..cmd_len]); |
+5 −5 src/config/config.zig
| @@ -218,11 +218,11 @@ pub const Config = struct { | ||
| 218 | 218 | scheme_occupied: ColorScheme = .{ .foreground = 0x0db9d7, .background = 0x1a1b26, .border = 0x0db9d7 }, |
| 219 | 219 | scheme_urgent: ColorScheme = .{ .foreground = 0xf7768e, .background = 0x1a1b26, .border = 0xf7768e }, |
| 220 | 220 | |
| 221 | - keybinds: std.ArrayListUnmanaged(Keybind) = .{}, | |
| 222 | - rules: std.ArrayListUnmanaged(Rule) = .{}, | |
| 223 | - blocks: std.ArrayListUnmanaged(Block) = .{}, | |
| 224 | - buttons: std.ArrayListUnmanaged(MouseButton) = .{}, | |
| 225 | - autostart: std.ArrayListUnmanaged([]const u8) = .{}, | |
| 221 | + keybinds: std.ArrayListUnmanaged(Keybind) = .empty, | |
| 222 | + rules: std.ArrayListUnmanaged(Rule) = .empty, | |
| 223 | + blocks: std.ArrayListUnmanaged(Block) = .empty, | |
| 224 | + buttons: std.ArrayListUnmanaged(MouseButton) = .empty, | |
| 225 | + autostart: std.ArrayListUnmanaged([]const u8) = .empty, | |
| 226 | 226 | |
| 227 | 227 | pub fn init(allocator: std.mem.Allocator) Config { |
| 228 | 228 | return Config{ |
+2 −2 src/config/lua.zig
| @@ -71,8 +71,8 @@ pub fn loadFile(path: []const u8) bool { | ||
| 71 | 71 | return true; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | -pub fn loadConfig() bool { | |
| 75 | - const home = std.posix.getenv("HOME") orelse return false; | |
| 74 | +pub fn loadConfig(env: *std.process.Environ.Map) bool { | |
| 75 | + const home = env.get("HOME") orelse return false; | |
| 76 | 76 | var path_buf: [512]u8 = undefined; |
| 77 | 77 | const path = std.fmt.bufPrint(&path_buf, "{s}/.config/oxwm/config.lua", .{home}) catch return false; |
| 78 | 78 | return loadFile(path); |
+4 −4 src/keyboard/chord.zig
| @@ -22,19 +22,19 @@ pub const ChordState = struct { | ||
| 22 | 22 | /// |
| 23 | 23 | /// Returns `false` if the sequence is already at maximum length, in which |
| 24 | 24 | /// case the caller should call `reset` before retrying. |
| 25 | - pub fn push(self: *ChordState, key: config.KeyPress) bool { | |
| 25 | + pub fn push(self: *ChordState, io: std.Io, key: config.KeyPress) bool { | |
| 26 | 26 | if (self.index >= max_chord_len) return false; |
| 27 | 27 | self.keys[self.index] = key; |
| 28 | 28 | self.index += 1; |
| 29 | - self.last_timestamp = std.time.milliTimestamp(); | |
| 29 | + self.last_timestamp = std.Io.Timestamp.now(io, .awake).toMilliseconds(); | |
| 30 | 30 | |
| 31 | 31 | return true; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /// Returns true if the sequence has timed out and should be reset. |
| 35 | - pub fn isTimedOut(self: *const ChordState) bool { | |
| 35 | + pub fn isTimedOut(self: *const ChordState, io: std.Io) bool { | |
| 36 | 36 | if (self.index == 0) return false; |
| 37 | - return (std.time.milliTimestamp() - self.last_timestamp) >= timeout_ms; | |
| 37 | + return (std.Io.Timestamp.now(io, .awake).toMilliseconds() - self.last_timestamp) >= timeout_ms; | |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /// Clears the sequence and releases the keyboard grab if one is held. |
+28 −33 src/main.zig
| @@ -9,17 +9,16 @@ const lua = @import("config/lua.zig"); | ||
| 9 | 9 | |
| 10 | 10 | const WindowManager = window_manager.WindowManager; |
| 11 | 11 | |
| 12 | -pub fn main() !void { | |
| 13 | - var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | |
| 14 | - const allocator = gpa.allocator(); | |
| 15 | - defer _ = gpa.deinit(); | |
| 12 | +pub fn main(init: std.process.Init) !void { | |
| 13 | + const allocator = init.gpa; | |
| 14 | + const env = init.environ_map; | |
| 16 | 15 | |
| 17 | - const default_config_path = try getConfigPath(allocator); | |
| 16 | + const default_config_path = try getConfigPath(allocator, env); | |
| 18 | 17 | defer allocator.free(default_config_path); |
| 19 | 18 | |
| 20 | 19 | var config_path: []const u8 = default_config_path; |
| 21 | 20 | var validate_mode: bool = false; |
| 22 | - var args = std.process.args(); | |
| 21 | + var args = init.minimal.args.iterate(); | |
| 23 | 22 | _ = args.skip(); |
| 24 | 23 | while (args.next()) |arg| { |
| 25 | 24 | if (std.mem.eql(u8, arg, "-c") or std.mem.eql(u8, arg, "--config")) { |
| @@ -31,7 +30,7 @@ pub fn main() !void { | ||
| 31 | 30 | std.debug.print("v{s}\n", .{build_options.version}); |
| 32 | 31 | return; |
| 33 | 32 | } else if (std.mem.eql(u8, arg, "--init")) { |
| 34 | - initConfig(allocator); | |
| 33 | + initConfig(allocator, init.io, env); | |
| 35 | 34 | return; |
| 36 | 35 | } else if (std.mem.eql(u8, arg, "--validate")) { |
| 37 | 36 | validate_mode = true; |
| @@ -40,7 +39,7 @@ pub fn main() !void { | ||
| 40 | 39 | } |
| 41 | 40 | |
| 42 | 41 | if (validate_mode) { |
| 43 | - try validateConfig(allocator, config_path); | |
| 42 | + try validateConfig(allocator, init.io, config_path); | |
| 44 | 43 | return; |
| 45 | 44 | } |
| 46 | 45 | |
| @@ -49,11 +48,11 @@ pub fn main() !void { | ||
| 49 | 48 | var config = config_mod.Config.init(allocator); |
| 50 | 49 | |
| 51 | 50 | if (lua.init(&config)) { |
| 52 | - const loaded = if (std.fs.cwd().statFile(config_path)) |_| blk: { | |
| 51 | + const loaded = if (std.Io.Dir.cwd().statFile(init.io, config_path, .{})) |_| blk: { | |
| 53 | 52 | break :blk lua.loadFile(config_path); |
| 54 | 53 | } else |_| blk: { |
| 55 | - initConfig(allocator); | |
| 56 | - break :blk lua.loadConfig(); | |
| 54 | + initConfig(allocator, init.io, env); | |
| 55 | + break :blk lua.loadConfig(env); | |
| 57 | 56 | }; |
| 58 | 57 | |
| 59 | 58 | if (loaded) { |
| @@ -67,7 +66,7 @@ pub fn main() !void { | ||
| 67 | 66 | config_mod.initializeDefaultConfig(&config); |
| 68 | 67 | } |
| 69 | 68 | |
| 70 | - var wm = WindowManager.init(allocator, config, config_path) catch |err| { | |
| 69 | + var wm = WindowManager.init(allocator, config, config_path, env, init.io) catch |err| { | |
| 71 | 70 | std.debug.print("failed to start window manager: {}\n", .{err}); |
| 72 | 71 | return; |
| 73 | 72 | }; |
| @@ -114,33 +113,33 @@ fn printHelp() void { | ||
| 114 | 113 | , .{}); |
| 115 | 114 | } |
| 116 | 115 | |
| 117 | -fn initConfig(allocator: std.mem.Allocator) void { | |
| 118 | - const config_path = getConfigPath(allocator) catch return; | |
| 116 | +fn initConfig(allocator: std.mem.Allocator, io: std.Io, env: *std.process.Environ.Map) void { | |
| 117 | + const config_path = getConfigPath(allocator, env) catch return; | |
| 119 | 118 | defer allocator.free(config_path); |
| 120 | 119 | |
| 121 | 120 | const template = @embedFile("templates/config.lua"); |
| 122 | 121 | |
| 123 | 122 | if (std.fs.path.dirname(config_path)) |dir_path| { |
| 124 | - var root = std.fs.openDirAbsolute("/", .{}) catch |err| { | |
| 123 | + var root = std.Io.Dir.openDirAbsolute(io, "/", .{}) catch |err| { | |
| 125 | 124 | std.debug.print("error: could not open root directory: {}\n", .{err}); |
| 126 | 125 | return; |
| 127 | 126 | }; |
| 128 | - defer root.close(); | |
| 127 | + defer root.close(io); | |
| 129 | 128 | |
| 130 | - const relative_path = std.mem.trimLeft(u8, dir_path, "/"); | |
| 131 | - root.makePath(relative_path) catch |err| { | |
| 129 | + const relative_path = std.mem.trimStart(u8, dir_path, "/"); | |
| 130 | + root.createDirPath(io, relative_path) catch |err| { | |
| 132 | 131 | std.debug.print("error: could not create config directory: {}\n", .{err}); |
| 133 | 132 | return; |
| 134 | 133 | }; |
| 135 | 134 | } |
| 136 | 135 | |
| 137 | - const file = std.fs.createFileAbsolute(config_path, .{}) catch |err| { | |
| 136 | + const file = std.Io.Dir.createFileAbsolute(io, config_path, .{}) catch |err| { | |
| 138 | 137 | std.debug.print("error: could not create config file: {}\n", .{err}); |
| 139 | 138 | return; |
| 140 | 139 | }; |
| 141 | - defer file.close(); | |
| 140 | + defer file.close(io); | |
| 142 | 141 | |
| 143 | - _ = file.writeAll(template) catch |err| { | |
| 142 | + file.writeStreamingAll(io, template) catch |err| { | |
| 144 | 143 | std.debug.print("error: could not write config file: {}\n", .{err}); |
| 145 | 144 | return; |
| 146 | 145 | }; |
| @@ -150,19 +149,15 @@ fn initConfig(allocator: std.mem.Allocator) void { | ||
| 150 | 149 | std.debug.print("No compilation needed - changes take effect immediately!\n", .{}); |
| 151 | 150 | } |
| 152 | 151 | |
| 153 | -fn getConfigPath(allocator: std.mem.Allocator) ![]u8 { | |
| 154 | - const config_home = std.posix.getenv("XDG_CONFIG_HOME") orelse blk: { | |
| 155 | - const home = std.posix.getenv("HOME") orelse return error.CouldNotGetHomeDir; | |
| 156 | - break :blk try std.fs.path.join(allocator, &.{ home, ".config" }); | |
| 157 | - }; | |
| 158 | - // TODO: wtf is this shit | |
| 159 | - defer if (std.posix.getenv("XDG_CONFIG_HOME") == null) allocator.free(config_home); | |
| 160 | - | |
| 161 | - const config_path = try std.fs.path.join(allocator, &.{ config_home, "oxwm", "config.lua" }); | |
| 162 | - return config_path; | |
| 152 | +fn getConfigPath(allocator: std.mem.Allocator, env: *std.process.Environ.Map) ![]u8 { | |
| 153 | + if (env.get("XDG_CONFIG_HOME")) |xdg| { | |
| 154 | + return std.fs.path.join(allocator, &.{ xdg, "oxwm", "config.lua" }); | |
| 155 | + } | |
| 156 | + const home = env.get("HOME") orelse return error.CouldNotGetHomeDir; | |
| 157 | + return std.fs.path.join(allocator, &.{ home, ".config", "oxwm", "config.lua" }); | |
| 163 | 158 | } |
| 164 | 159 | |
| 165 | -fn validateConfig(allocator: std.mem.Allocator, config_path: []const u8) !void { | |
| 160 | +fn validateConfig(allocator: std.mem.Allocator, io: std.Io, config_path: []const u8) !void { | |
| 166 | 161 | var config = config_mod.Config.init(allocator); |
| 167 | 162 | defer config.deinit(); |
| 168 | 163 | |
| @@ -172,7 +167,7 @@ fn validateConfig(allocator: std.mem.Allocator, config_path: []const u8) !void { | ||
| 172 | 167 | } |
| 173 | 168 | defer lua.deinit(); |
| 174 | 169 | |
| 175 | - _ = std.fs.cwd().statFile(config_path) catch |err| { | |
| 170 | + _ = std.Io.Dir.cwd().statFile(io, config_path, .{}) catch |err| { | |
| 176 | 171 | std.debug.print("error: config file not found: {s}\n", .{config_path}); |
| 177 | 172 | std.debug.print(" {}\n", .{err}); |
| 178 | 173 | std.process.exit(1); |
+26 −23 src/wm/actions.zig
| @@ -16,56 +16,59 @@ const WindowManager = wm_mod.WindowManager; | ||
| 16 | 16 | |
| 17 | 17 | const snap_distance: i32 = 32; |
| 18 | 18 | |
| 19 | +// execvpeZ removed in zig 0.16 std lib rework (codeberg.org/ziglang/zig/issues/31694) with no replacement | |
| 20 | +extern "c" fn execvp(file: [*:0]const u8, argv: [*:null]const ?[*:0]const u8) c_int; | |
| 21 | + | |
| 19 | 22 | pub fn spawnChildSetup(wm: *WindowManager) void { |
| 20 | 23 | _ = std.c.setsid(); |
| 21 | - if (wm.x11_fd >= 0) std.posix.close(@intCast(wm.x11_fd)); | |
| 24 | + if (wm.x11_fd >= 0) _ = std.c.close(@intCast(wm.x11_fd)); | |
| 22 | 25 | const sigchld_handler = std.posix.Sigaction{ |
| 23 | 26 | .handler = .{ .handler = std.posix.SIG.DFL }, |
| 24 | 27 | .mask = std.mem.zeroes(std.posix.sigset_t), |
| 25 | 28 | .flags = 0, |
| 26 | 29 | }; |
| 27 | - std.posix.sigaction(std.posix.SIG.CHLD, &sigchld_handler, null); | |
| 30 | + std.posix.sigaction(.CHLD, &sigchld_handler, null); | |
| 28 | 31 | } |
| 29 | 32 | |
| 30 | 33 | pub fn spawnCommand(wm: *WindowManager, cmd: []const u8) void { |
| 31 | 34 | std.debug.print("running cmd: {s}\n", .{cmd}); |
| 32 | - const pid = std.posix.fork() catch return; | |
| 35 | + const pid = std.c.fork(); | |
| 36 | + if (pid < 0) return; | |
| 33 | 37 | if (pid == 0) { |
| 34 | - const grandchild = std.posix.fork() catch std.posix.exit(1); | |
| 35 | - if (grandchild != 0) std.posix.exit(0); | |
| 38 | + const grandchild = std.c.fork(); | |
| 39 | + if (grandchild < 0) std.c._exit(1); | |
| 40 | + if (grandchild != 0) std.c._exit(0); | |
| 36 | 41 | spawnChildSetup(wm); |
| 37 | 42 | var cmd_buf: [1024]u8 = undefined; |
| 38 | - if (cmd.len >= cmd_buf.len) { | |
| 39 | - std.posix.exit(1); | |
| 40 | - } | |
| 43 | + if (cmd.len >= cmd_buf.len) std.c._exit(1); | |
| 41 | 44 | @memcpy(cmd_buf[0..cmd.len], cmd); |
| 42 | 45 | cmd_buf[cmd.len] = 0; |
| 43 | 46 | const argv = [_:null]?[*:0]const u8{ "sh", "-c", @ptrCast(&cmd_buf) }; |
| 44 | - _ = std.posix.execvpeZ("sh", &argv, std.c.environ) catch {}; | |
| 45 | - std.posix.exit(1); | |
| 47 | + _ = execvp("sh", &argv); | |
| 48 | + std.c._exit(1); | |
| 46 | 49 | } |
| 47 | - _ = std.posix.waitpid(pid, 0); | |
| 50 | + _ = std.c.waitpid(pid, null, 0); | |
| 48 | 51 | } |
| 49 | 52 | |
| 50 | 53 | pub fn spawnTerminal(wm: *WindowManager) void { |
| 51 | - const pid = std.posix.fork() catch return; | |
| 54 | + const pid = std.c.fork(); | |
| 55 | + if (pid < 0) return; | |
| 52 | 56 | if (pid == 0) { |
| 53 | - const grandchild = std.posix.fork() catch std.posix.exit(1); | |
| 54 | - if (grandchild != 0) std.posix.exit(0); | |
| 57 | + const grandchild = std.c.fork(); | |
| 58 | + if (grandchild < 0) std.c._exit(1); | |
| 59 | + if (grandchild != 0) std.c._exit(0); | |
| 55 | 60 | spawnChildSetup(wm); |
| 56 | 61 | var term_buf: [256]u8 = undefined; |
| 57 | 62 | const terminal = wm.config.terminal; |
| 58 | - if (terminal.len >= term_buf.len) { | |
| 59 | - std.posix.exit(1); | |
| 60 | - } | |
| 63 | + if (terminal.len >= term_buf.len) std.c._exit(1); | |
| 61 | 64 | @memcpy(term_buf[0..terminal.len], terminal); |
| 62 | 65 | term_buf[terminal.len] = 0; |
| 63 | 66 | const term_ptr: [*:0]const u8 = @ptrCast(&term_buf); |
| 64 | 67 | const argv = [_:null]?[*:0]const u8{term_ptr}; |
| 65 | - _ = std.posix.execvpeZ(term_ptr, &argv, std.c.environ) catch {}; | |
| 66 | - std.posix.exit(1); | |
| 68 | + _ = execvp(term_ptr, &argv); | |
| 69 | + std.c._exit(1); | |
| 67 | 70 | } |
| 68 | - _ = std.posix.waitpid(pid, 0); | |
| 71 | + _ = std.c.waitpid(pid, null, 0); | |
| 69 | 72 | } |
| 70 | 73 | |
| 71 | 74 | pub fn movestack(direction: i32, wm: *WindowManager) void { |
| @@ -764,7 +767,7 @@ pub fn reloadLoadConfig(wm: *WindowManager) void { | ||
| 764 | 767 | const loaded = if (wm.config_path) |path| |
| 765 | 768 | lua.loadFile(path) |
| 766 | 769 | else |
| 767 | - lua.loadConfig(); | |
| 770 | + lua.loadConfig(wm.env); | |
| 768 | 771 | |
| 769 | 772 | if (loaded) { |
| 770 | 773 | if (wm.config_path) |path| { |
| @@ -799,9 +802,9 @@ pub fn executeAction(action: config_mod.Action, int_arg: i32, str_arg: ?[]const | ||
| 799 | 802 | } |
| 800 | 803 | } |
| 801 | 804 | }, |
| 802 | - .focus_next => focusstack(int_arg, wm), | |
| 805 | + .focus_next => focusstack(if (int_arg == 0) 1 else int_arg, wm), | |
| 803 | 806 | .focus_prev => focusstack(-1, wm), |
| 804 | - .move_next => movestack(int_arg, wm), | |
| 807 | + .move_next => movestack(if (int_arg == 0) 1 else int_arg, wm), | |
| 805 | 808 | .move_prev => movestack(-1, wm), |
| 806 | 809 | .resize_master => setmfact(@as(f32, @floatFromInt(int_arg)) / 1000.0, wm), |
| 807 | 810 | .inc_master => incnmaster(1, wm), |
+3 −3 src/wm/core.zig
| @@ -402,7 +402,7 @@ pub fn tickAnimations(wm: *WindowManager) void { | ||
| 402 | 402 | if (!wm.scroll_animation.isActive()) return; |
| 403 | 403 | |
| 404 | 404 | const monitor = wm.selected_monitor orelse return; |
| 405 | - if (wm.scroll_animation.update()) |new_offset| { | |
| 405 | + if (wm.scroll_animation.update(wm.io)) |new_offset| { | |
| 406 | 406 | monitor.scroll_offset = new_offset; |
| 407 | 407 | arrange(monitor, wm); |
| 408 | 408 | } |
| @@ -430,7 +430,7 @@ pub fn scrollLayout(direction: i32, wm: *WindowManager) void { | ||
| 430 | 430 | var target = current + direction * scroll_step; |
| 431 | 431 | target = @max(0, @min(target, max_scroll)); |
| 432 | 432 | |
| 433 | - wm.scroll_animation.start(monitor.scroll_offset, target, wm.animation_config); | |
| 433 | + wm.scroll_animation.start(wm.io, monitor.scroll_offset, target, wm.animation_config); | |
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | pub fn scrollToWindow(client: *Client, animate: bool, wm: *WindowManager) void { |
| @@ -440,7 +440,7 @@ pub fn scrollToWindow(client: *Client, animate: bool, wm: *WindowManager) void { | ||
| 440 | 440 | const target = scrolling.getTargetScrollForWindow(monitor, client); |
| 441 | 441 | |
| 442 | 442 | if (animate) { |
| 443 | - wm.scroll_animation.start(monitor.scroll_offset, target, wm.animation_config); | |
| 443 | + wm.scroll_animation.start(wm.io, monitor.scroll_offset, target, wm.animation_config); | |
| 444 | 444 | } else { |
| 445 | 445 | monitor.scroll_offset = target; |
| 446 | 446 | arrange(monitor, wm); |
+2 −2 src/wm/handlers.zig
| @@ -134,11 +134,11 @@ fn handleKeyPress(event: *xlib.XKeyEvent, wm: *WindowManager) void { | ||
| 134 | 134 | |
| 135 | 135 | const clean_state = event.state & ~@as(c_uint, xlib.LockMask | xlib.Mod2Mask); |
| 136 | 136 | |
| 137 | - if (wm.chord.isTimedOut()) { | |
| 137 | + if (wm.chord.isTimedOut(wm.io)) { | |
| 138 | 138 | wm.chord.reset(wm.display.handle); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - _ = wm.chord.push(.{ .mod_mask = clean_state, .keysym = keysym }); | |
| 141 | + _ = wm.chord.push(wm.io, .{ .mod_mask = clean_state, .keysym = keysym }); | |
| 142 | 142 | |
| 143 | 143 | for (wm.config.keybinds.items) |keybind| { |
| 144 | 144 | if (keybind.key_count == 0) continue; |
+6 −2 src/wm/wm.zig
| @@ -52,6 +52,8 @@ pub const Cursors = struct { | ||
| 52 | 52 | |
| 53 | 53 | pub const WindowManager = struct { |
| 54 | 54 | allocator: mem.Allocator, |
| 55 | + env: *std.process.Environ.Map, | |
| 56 | + io: std.Io, | |
| 55 | 57 | |
| 56 | 58 | /// The connection to the X server. |
| 57 | 59 | display: Display, |
| @@ -94,7 +96,7 @@ pub const WindowManager = struct { | ||
| 94 | 96 | /// |
| 95 | 97 | /// Returns an error if the display cannot be opened or another WM is |
| 96 | 98 | /// already running. |
| 97 | - pub fn init(allocator: mem.Allocator, config: Config, config_path: ?[]const u8) !WindowManager { | |
| 99 | + pub fn init(allocator: mem.Allocator, config: Config, config_path: ?[]const u8, env: *std.process.Environ.Map, io: std.Io) !WindowManager { | |
| 98 | 100 | var display = try Display.open(); |
| 99 | 101 | errdefer display.close(); |
| 100 | 102 | |
| @@ -111,6 +113,8 @@ pub const WindowManager = struct { | ||
| 111 | 113 | |
| 112 | 114 | var wm = WindowManager{ |
| 113 | 115 | .allocator = allocator, |
| 116 | + .env = env, | |
| 117 | + .io = io, | |
| 114 | 118 | .display = display, |
| 115 | 119 | .x11_fd = x11_fd, |
| 116 | 120 | .wm_check_window = atoms_result.check_window, |
| @@ -680,7 +684,7 @@ pub const WindowManager = struct { | ||
| 680 | 684 | |
| 681 | 685 | var current_bar = self.bars; |
| 682 | 686 | while (current_bar) |bar| { |
| 683 | - bar.updateBlocks(); | |
| 687 | + bar.updateBlocks(self.io, self.allocator); | |
| 684 | 688 | bar.draw(self.display.handle, self.config); |
| 685 | 689 | current_bar = bar.next; |
| 686 | 690 | } |