parent
5d159d7818
commit
bd1137acd7
4 changed files with 73 additions and 105 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
.zig-cache
|
||||
zig-out
|
||||
dam
|
||||
*.o
|
||||
*-protocol.*
|
||||
|
|
61
Makefile
Normal file
61
Makefile
Normal file
|
@ -0,0 +1,61 @@
|
|||
.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
|
94
build.zig
94
build.zig
|
@ -1,94 +0,0 @@
|
|||
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"),
|
||||
.flags = &.{"-D_GNU_SOURCE"},
|
||||
});
|
||||
|
||||
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,
|
||||
});
|
||||
}
|
||||
};
|
18
dam.c
18
dam.c
|
@ -155,20 +155,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 && *bar->title != '\0') {
|
||||
drwl_setscheme(bar->drw, colors[bar->selected ? SchemeSel : SchemeNorm]);
|
||||
|
|
Loading…
Add table
Reference in a new issue