From 0c5413eb3aed898dc9d566b765a58cb5dfc4505f Mon Sep 17 00:00:00 2001 From: Janis Date: Mon, 12 Dec 2022 22:54:16 +0100 Subject: [PATCH] initial commit --- .gitignore | 2 ++ .gitmodules | 3 +++ build.zig | 34 +++++++++++++++++++++++++++++ deps/zig-wayland | 1 + src/main.zig | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 build.zig create mode 160000 deps/zig-wayland create mode 100644 src/main.zig diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d864d9e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/zig-cache/ +/zig-out/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..6b5fe4b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "deps/zig-wayland"] + path = deps/zig-wayland + url = https://github.com/ifreund/zig-wayland.git diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..7ab9733 --- /dev/null +++ b/build.zig @@ -0,0 +1,34 @@ +const std = @import("std"); + +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 + // means any target is allowed, and the default is native. Other options + // for restricting supported target set are available. + const target = b.standardTargetOptions(.{}); + + // Standard release options allow the person running `zig build` to select + // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. + const mode = b.standardReleaseOptions(); + + const exe = b.addExecutable("zlurp", "src/main.zig"); + exe.setTarget(target); + exe.setBuildMode(mode); + exe.install(); + + const run_cmd = exe.run(); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } + + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); + + const exe_tests = b.addTest("src/main.zig"); + exe_tests.setTarget(target); + exe_tests.setBuildMode(mode); + + const test_step = b.step("test", "Run unit tests"); + test_step.dependOn(&exe_tests.step); +} diff --git a/deps/zig-wayland b/deps/zig-wayland new file mode 160000 index 0000000..cf165f4 --- /dev/null +++ b/deps/zig-wayland @@ -0,0 +1 @@ +Subproject commit cf165f481ed093f182edef39dbea398e937df4dc diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..5837faf --- /dev/null +++ b/src/main.zig @@ -0,0 +1,57 @@ +const std = @import("std"); + +const VecN = std.meta.Vector; + +const Rgba32 = union { + comps: struct { r: u32, g: u32, b: u32, a: u32 }, + rgba: u64, +}; + +const State = struct { + colors: struct { background: Rgba32, border: Rgba32, selection: Rgba32, choice: Rgba32 }, + border_weight: u8, + display_dimensions: bool, + restrict_selection: bool, + fixed_aspect_ratio: bool, + aspect_ratio: f32, + // font_family +}; + +fn defaultState() State { + return State{ + .colors = .{ + .background = .{ .rgba = 0xFFFFFF40 }, + .border = .{ .rgba = 0x000000FF }, + .selection = .{ .rgba = 0x00000000 }, + .choice = .{ .rgba = 0xFFFFFF40 }, + }, + .border_weight = 2, + .display_dimensions = false, + .restrict_selection = false, + .fixed_aspect_ratio = false, + .aspect_ratio = 0, + }; +} + +pub fn main() !void { + // Prints to stderr (it's a shortcut based on `std.io.getStdErr()`) + std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); + + // stdout is for the actual output of your application, for example if you + // are implementing gzip, then only the compressed bytes should be sent to + // stdout, not any debugging messages. + const stdout_file = std.io.getStdOut().writer(); + var bw = std.io.bufferedWriter(stdout_file); + const stdout = bw.writer(); + + try stdout.print("Run `zig build test` to run the tests.\n", .{}); + + try bw.flush(); // don't forget to flush! +} + +test "simple test" { + var list = std.ArrayList(i32).init(std.testing.allocator); + defer list.deinit(); // try commenting this out and see if zig detects the memory leak! + try list.append(42); + try std.testing.expectEqual(@as(i32, 42), list.pop()); +}