diff --git a/.gitignore b/.gitignore index d577a31..d8c8979 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -dam -*.o -*-protocol.* +.zig-cache +zig-out diff --git a/Makefile b/Makefile deleted file mode 100644 index 5484260..0000000 --- a/Makefile +++ /dev/null @@ -1,61 +0,0 @@ -.POSIX: - -PREFIX = /usr/local - -PKG_CONFIG = pkg-config - -PKGS = wayland-client fcft pixman-1 -INCS = `$(PKG_CONFIG) --cflags $(PKGS)` -LIBS = `$(PKG_CONFIG) --libs $(PKGS)` - -FPCFLAGS = -pedantic -Wall $(INCS) $(CPPFLAGS) $(CFLAGS) -LDLIBS = $(LIBS) - -SRC = dam.o xdg-shell-protocol.o wlr-layer-shell-unstable-v1-protocol.o \ - river-control-unstable-v1-protocol.o river-status-unstable-v1-protocol.o -OBJ = $(SRC:.c=.o) - -all: dam - -.c.o: - $(CC) -o $@ -c $(FPCFLAGS) -c $< - -dam.o: wlr-layer-shell-unstable-v1-protocol.h \ - river-control-unstable-v1-protocol.h river-status-unstable-v1-protocol.h - -dam: $(OBJ) - $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LDLIBS) - -WAYLAND_PROTOCOLS = `$(PKG_CONFIG) --variable=pkgdatadir wayland-protocols` -WAYLAND_SCANNER = `$(PKG_CONFIG) --variable=wayland_scanner wayland-scanner` - -xdg-shell-protocol.c: - $(WAYLAND_SCANNER) private-code $(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@ -xdg-shell-protocol.h: - $(WAYLAND_SCANNER) client-header $(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@ -wlr-layer-shell-unstable-v1-protocol.c: - $(WAYLAND_SCANNER) private-code wlr-layer-shell-unstable-v1.xml $@ -wlr-layer-shell-unstable-v1-protocol.h: - $(WAYLAND_SCANNER) client-header wlr-layer-shell-unstable-v1.xml $@ -wlr-layer-shell-unstable-v1-protocol.o: xdg-shell-protocol.o -river-control-unstable-v1-protocol.c: - $(WAYLAND_SCANNER) private-code river-control-unstable-v1.xml $@ -river-control-unstable-v1-protocol.h: - $(WAYLAND_SCANNER) client-header river-control-unstable-v1.xml $@ -river-status-unstable-v1-protocol.c: - $(WAYLAND_SCANNER) private-code river-status-unstable-v1.xml $@ -river-status-unstable-v1-protocol.h: - $(WAYLAND_SCANNER) client-header river-status-unstable-v1.xml $@ - -clean: - rm -f dam *.o *-protocol.* - -install: all - mkdir -p $(DESTDIR)$(PREFIX)/bin - cp -f dam $(DESTDIR)$(PREFIX)/bin - chmod 755 $(DESTDIR)$(PREFIX)/bin/dam - -uninstall: - rm -f $(DESTDIR)$(PREFIX)/bin/dam - -.PHONY: all clean install uninstall diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..74582f7 --- /dev/null +++ b/build.zig @@ -0,0 +1,93 @@ +const std = @import("std"); +const Build = std.Build; +const fs = std.fs; +const mem = std.mem; + +pub fn build(b: *Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const dam = b.addExecutable(.{ + .name = "dam", + .target = target, + .optimize = optimize, + }); + dam.addIncludePath(b.path("")); + dam.addCSourceFile(.{ + .file = b.path("dam.c"), + }); + + dam.linkLibC(); + dam.linkSystemLibrary("wayland-client"); + dam.linkSystemLibrary("fcft"); + dam.linkSystemLibrary("pixman-1"); + + const scanner = Scanner.create(b, .{}, dam); + scanner.addSystemProtocol("/stable/xdg-shell/xdg-shell.xml"); + scanner.addCustomProtocol("wlr-layer-shell-unstable-v1.xml"); + scanner.addCustomProtocol("river-control-unstable-v1.xml"); + scanner.addCustomProtocol("river-status-unstable-v1.xml"); + + b.installArtifact(dam); +} + +pub const Scanner = struct { + build: *Build, + wayland_protocols_path: []const u8, + wayland_scanner_path: []const u8, + compile: *Build.Step.Compile, + + const opts = struct { + wayland_protocols_path: ?[]const u8 = null, + wayland_scanner_path: ?[]const u8 = null, + }; + + pub fn create(b: *Build, opt: opts, c: *Build.Step.Compile) *Scanner { + const wayland_protocols_path = opt.wayland_protocols_path orelse blk: { + const pathr = b.run(&.{ "pkg-config", "--variable=pkgdatadir", "wayland-protocols" }); + break :blk mem.trim(u8, pathr, &std.ascii.whitespace); + }; + const scanner_path = opt.wayland_scanner_path orelse blk: { + const pathr = b.run(&.{ "pkg-config", "--variable=wayland_scanner", "wayland-scanner" }); + break :blk mem.trim(u8, pathr, &std.ascii.whitespace); + }; + + const scanner = b.allocator.create(Scanner) catch @panic("OOM"); + scanner.* = .{ + .wayland_protocols_path = wayland_protocols_path, + .wayland_scanner_path = scanner_path, + .build = b, + .compile = c, + }; + + return scanner; + } + + pub fn addSystemProtocol(scanner: *Scanner, relative_path: []const u8) void { + const full_path = scanner.build.pathJoin(&.{ scanner.wayland_protocols_path, relative_path }); + scanner.addCustomProtocol(full_path); + } + + pub fn addCustomProtocol(scanner: *Scanner, path: []const u8) void { + scanner.generateCHeader(path); + scanner.generateCode(path); + } + + fn generateCHeader(scanner: *Scanner, protocol: []const u8) void { + const cmd = scanner.build.addSystemCommand(&.{ "wayland-scanner", "client-header", protocol }); + const out_name = mem.concat(scanner.build.allocator, u8, &.{ fs.path.stem(protocol), "-protocol.h" }) catch @panic("OOM"); + + const c_header = cmd.addOutputFileArg(out_name); + scanner.compile.addIncludePath(c_header.dirname()); + } + + fn generateCode(scanner: *Scanner, protocol: []const u8) void { + const cmd = scanner.build.addSystemCommand(&.{ "wayland-scanner", "private-code", protocol }); + const out_name = mem.concat(scanner.build.allocator, u8, &.{ fs.path.stem(protocol), "-protocol.c" }) catch @panic("OOM"); + + const c_file = cmd.addOutputFileArg(out_name); + scanner.compile.addCSourceFile(.{ + .file = c_file, + }); + } +}; diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..1d49f91 --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,11 @@ +.{ + .name = "dam", + .version = "0.0.0", + .dependencies = .{ + .@"zig-wayland" = .{ + .url = "https://codeberg.org/ifreund/zig-wayland/archive/v0.2.0.tar.gz", + .hash = "1220687c8c47a48ba285d26a05600f8700d37fc637e223ced3aa8324f3650bf52242", + }, + }, + .paths = .{""}, +} diff --git a/dam.c b/dam.c index 4e141cc..7589b7a 100644 --- a/dam.c +++ b/dam.c @@ -154,20 +154,20 @@ bar_draw(Bar *bar) x += w; } + wl_list_for_each(seat, &seats, link) { + if (seat->bar != bar) + continue; + w = TEXTW(bar, seat->mode); + drwl_setscheme(bar->drw, colors[SchemeSel]); + x = drwl_text(bar->drw, x, 0, w, bar->height, bar->lrpad / 2, seat->mode, 0); + } + if (bar->layout) { w = TEXTW(bar, bar->layout); drwl_setscheme(bar->drw, colors[SchemeNorm]); x = drwl_text(bar->drw, x, 0, w, bar->height, bar->lrpad / 2, bar->layout, 0); } - - wl_list_for_each(seat, &seats, link) { - if (seat->bar != bar) - continue; - w = TEXTW(bar, seat->mode); - drwl_setscheme(bar->drw, colors[SchemeNorm]); - x = drwl_text(bar->drw, x, 0, w, bar->height, bar->lrpad / 2, seat->mode, 1); - } - + if ((w = bar->width - tw - x) > bar->height) { if (*bar->title != '\0') { drwl_setscheme(bar->drw, colors[bar->selected ? SchemeSel : SchemeNorm]);