commit b03a9523463068f7f8aaf8ac63f7efc873e2877e
parent 808900456e850ace23a37b40ba00cbdd71254236
Author: Andrea Feletto <andrea@andreafeletto.com>
Date: Wed, 19 Jan 2022 19:08:21 +0100
render tags with label
Diffstat:
6 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/.gitmodules b/.gitmodules
@@ -4,3 +4,6 @@
[submodule "deps/zig-pixman"]
path = deps/zig-pixman
url = https://github.com/ifreund/zig-pixman
+[submodule "deps/zig-fcft"]
+ path = deps/zig-fcft
+ url = https://git.sr.ht/~andreafeletto/zig-fcft
diff --git a/build.zig b/build.zig
@@ -20,6 +20,11 @@ pub fn build(b: *std.build.Builder) void {
.name = "pixman",
.path = .{ .path = "deps/zig-pixman/pixman.zig" },
};
+ const fcft = Pkg{
+ .name = "fcft",
+ .path = .{ .path = "deps/zig-fcft/fcft.zig" },
+ .dependencies = &[_]Pkg{ pixman },
+ };
const exe = b.addExecutable("levee", "src/main.zig");
exe.setTarget(target);
@@ -35,6 +40,9 @@ pub fn build(b: *std.build.Builder) void {
exe.addPackage(pixman);
exe.linkSystemLibrary("pixman-1");
+ exe.addPackage(fcft);
+ exe.linkSystemLibrary("fcft");
+
exe.install();
const run_cmd = exe.run();
diff --git a/deps/zig-fcft b/deps/zig-fcft
@@ -0,0 +1 @@
+Subproject commit f219bd63c29b0547cd494df7d02e55953855248e
diff --git a/src/config.zig b/src/config.zig
@@ -1,3 +1,4 @@
+const fcft = @import("fcft");
const pixman = @import("pixman");
pub const Config = struct {
@@ -5,8 +6,11 @@ pub const Config = struct {
backgroundColor: pixman.Color,
foregroundColor: pixman.Color,
border: u15,
+ font: *fcft.Font,
+
+ pub fn init() !Config {
+ var font_names = [_][*:0]const u8{"monospace:size=14"};
- pub fn init() Config {
return Config{
.height = 32,
.backgroundColor = .{
@@ -22,6 +26,7 @@ pub const Config = struct {
.alpha = 0xffff,
},
.border = 2,
+ .font = try fcft.Font.fromName(&font_names, null),
};
}
};
diff --git a/src/main.zig b/src/main.zig
@@ -18,7 +18,7 @@ pub fn main() anyerror!void {
std.log.info("initialization", .{});
var state: State = undefined;
state.allocator = arena.allocator();
- state.config = Config.init();
+ state.config = try Config.init();
state.wayland = try Wayland.init(&state);
state.loop = try Loop.init(&state);
diff --git a/src/render.zig b/src/render.zig
@@ -1,3 +1,4 @@
+const fcft = @import("fcft");
const pixman = @import("pixman");
const Buffer = @import("shm.zig").Buffer;
@@ -84,4 +85,24 @@ fn renderTag(
if (!tag.focused and tag.occupied) {
_ = pixman.Image.fillRectangles(.over, pix, inner_color, 1, &inner);
}
+
+ const glyph_color = if (tag.focused) blk: {
+ break :blk &state.config.backgroundColor;
+ } else blk: {
+ break :blk &state.config.foregroundColor;
+ };
+ const font = state.config.font;
+ var char = pixman.Image.createSolidFill(glyph_color).?;
+ const glyph = try fcft.Glyph.rasterize(font, tag.label, .default);
+ const x = offset + @divFloor(size - glyph.width, 2);
+ const y = @divFloor(size - glyph.height, 2);
+ pixman.Image.composite32(
+ .over,
+ char,
+ glyph.pix,
+ pix,
+ 0, 0, 0, 0,
+ x, y,
+ glyph.width, glyph.height,
+ );
}