diff --git a/README.md b/README.md index c2bffef..69c0143 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ ZigWindowsTilingWindowManager: Tiling window manager for windows, inspired by dw 1. Clone the repository using `git clone --recurse-submodules https://github.com/Nimaoth/zwtwm.git` 2. Install zig. I developed using zig version `0.8.0-dev.1140+9270aae07`, might not build with other versions. 3. For a release build (logs to file instead of console, ReleaseFast configuration), run `zig build --prefix dist -Drelease` -4. For a debug build (logs to the console, Debug configuration), run `zig build --prefix dist` +4. For a debug build (logs to the console, Debug configuration), run `zig build --prefix dist -Dconsole` 5. Use files in `/dist/bin` ## Configuration diff --git a/build.zig b/build.zig index 0ee469f..df2fb0d 100644 --- a/build.zig +++ b/build.zig @@ -1,5 +1,20 @@ const std = @import("std"); +const Guid = std.os.windows.GUID; + +pub extern "RPCRT4" fn UuidCreate( + Uuid: *Guid, +) callconv(std.os.windows.WINAPI) i32; + +pub extern "RPCRT4" fn UuidToStringA( + Uuid: *Guid, + StringUuid: *[*:0]u8, +) callconv(@import("std").os.windows.WINAPI) i32; + +pub extern "RPCRT4" fn RpcStringFreeA( + String: *[*:0]u8, +) callconv(@import("std").os.windows.WINAPI) i32; + pub fn build(b: *std.build.Builder) void { // Standard target options allows the person running `zig build` to choose // what target to build for. Here we do not override the defaults, which @@ -9,23 +24,30 @@ pub fn build(b: *std.build.Builder) void { // Standard release options allow the person running `zig build` to select // between Debug, ReleaseSafe - const release = b.option(bool, "release", "Optimizations on and safety on, log to file") orelse false; + const release = b.option(bool, "release", "Optimizations on and safety on.") orelse false; + const console = b.option(bool, "console", "Log to the console.") orelse false; + std.log.info("Building with release={}, console={}", .{ release, console }); var mode = if (release) std.builtin.Mode.ReleaseSafe else std.builtin.Mode.Debug; - mode = .Debug; b.is_release = mode != .Debug; b.release_mode = mode; + // Generate guid + var guid: Guid = undefined; + _ = UuidCreate(&guid); + var guidStringPtr: [*:0]u8 = undefined; + _ = UuidToStringA(&guid, &guidStringPtr); + const guidString = guidStringPtr[0..std.mem.len(guidStringPtr)]; + std.log.info("Using tray icon guid: {s}", .{guidString}); + defer _ = RpcStringFreeA(&guidStringPtr); + const exe = b.addExecutable(if (release) "zwtwm" else "zwtwm_debug", "src/main.zig"); - exe.addBuildOption(bool, "RUN_IN_CONSOLE", !release); - if (release) { - exe.addBuildOption([]const u8, "TRAY_GUID", "99b74174-d3a4-48ba-a886-9af100149755"); - } else { - exe.addBuildOption([]const u8, "TRAY_GUID", "b3e926bb-e7ee-4f2a-b513-0080167ec220"); - } - exe.subsystem = if (release) .Windows else .Console; + exe.addBuildOption(bool, "RUN_IN_CONSOLE", console); + exe.addBuildOption([]const u8, "TRAY_GUID", guidString); exe.addPackage(.{ .name = "zigwin32", .path = "./deps/custom_zigwin32/win32.zig" }); + exe.subsystem = if (!console) .Windows else .Console; + std.log.info("Using subsystem {}", .{exe.subsystem}); exe.setTarget(target); exe.setBuildMode(mode); exe.install();