d9da3081
Read terminal font size from config
a73x 2026-04-09 06:51
Commit message
src/font.zig
| Old | New | ||
|---|---|---|---|
| @@ -1,5 +1,5 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const config = @import("config"); | 2 | pub const config = @import("config"); |
| 3 | const c = @cImport({ | 3 | const c = @cImport({ |
| 4 | @cInclude("fontconfig/fontconfig.h"); | 4 | @cInclude("fontconfig/fontconfig.h"); |
| 5 | @cInclude("ft2build.h"); | 5 | @cInclude("ft2build.h"); |
| @@ -45,10 +45,6 @@ pub fn lookupConfiguredFont(alloc: std.mem.Allocator) !FontLookup { | |||
| 45 | return .{ .path = dup, .index = index }; | 45 | return .{ .path = dup, .index = index }; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | pub fn lookupMonospace(alloc: std.mem.Allocator) !FontLookup { | ||
| 49 | return lookupConfiguredFont(alloc); | ||
| 50 | } | ||
| 51 | |||
| 52 | pub const Glyph = struct { | 48 | pub const Glyph = struct { |
| 53 | codepoint: u21, | 49 | codepoint: u21, |
| 54 | width: u32, | 50 | width: u32, |
src/main.zig
| Old | New | ||
|---|---|---|---|
| @@ -4,6 +4,7 @@ const pty = @import("pty"); | |||
| 4 | const wayland_client = @import("wayland-client"); | 4 | const wayland_client = @import("wayland-client"); |
| 5 | const renderer = @import("renderer"); | 5 | const renderer = @import("renderer"); |
| 6 | const font = @import("font"); | 6 | const font = @import("font"); |
| 7 | const config = font.config; | ||
| 7 | 8 | ||
| 8 | const c = @cImport({ | 9 | const c = @cImport({ |
| 9 | @cInclude("xkbcommon/xkbcommon-keysyms.h"); | 10 | @cInclude("xkbcommon/xkbcommon-keysyms.h"); |
| @@ -60,10 +61,10 @@ pub fn main() !void { | |||
| 60 | 61 | ||
| 61 | fn runTerminal(alloc: std.mem.Allocator) !void { | 62 | fn runTerminal(alloc: std.mem.Allocator) !void { |
| 62 | // === font first, to know cell size === | 63 | // === font first, to know cell size === |
| 63 | var font_lookup = try font.lookupMonospace(alloc); | 64 | var font_lookup = try font.lookupConfiguredFont(alloc); |
| 64 | defer font_lookup.deinit(alloc); | 65 | defer font_lookup.deinit(alloc); |
| 65 | 66 | ||
| 66 | const font_size: u32 = 16; | 67 | const font_size: u32 = config.font_size_px; |
| 67 | var face = try font.Face.init(alloc, font_lookup.path, font_lookup.index, font_size); | 68 | var face = try font.Face.init(alloc, font_lookup.path, font_lookup.index, font_size); |
| 68 | defer face.deinit(); | 69 | defer face.deinit(); |
| 69 | 70 | ||
| @@ -903,10 +904,10 @@ test "rebuildRowInstances emits expected instances for a colored glyph row" { | |||
| 903 | term.write("\x1b[31;44mA\x1b[0m"); | 904 | term.write("\x1b[31;44mA\x1b[0m"); |
| 904 | try term.snapshot(); | 905 | try term.snapshot(); |
| 905 | 906 | ||
| 906 | var lookup = try font.lookupMonospace(std.testing.allocator); | 907 | var lookup = try font.lookupConfiguredFont(std.testing.allocator); |
| 907 | defer lookup.deinit(std.testing.allocator); | 908 | defer lookup.deinit(std.testing.allocator); |
| 908 | 909 | ||
| 909 | var face = try font.Face.init(std.testing.allocator, lookup.path, lookup.index, 16); | 910 | var face = try font.Face.init(std.testing.allocator, lookup.path, lookup.index, config.font_size_px); |
| 910 | defer face.deinit(); | 911 | defer face.deinit(); |
| 911 | 912 | ||
| 912 | var atlas = try font.Atlas.init(std.testing.allocator, 256, 256); | 913 | var atlas = try font.Atlas.init(std.testing.allocator, 256, 256); |
| @@ -955,10 +956,10 @@ test "rebuildRowInstances replaces stale cached contents without layout dirtines | |||
| 955 | term.write("\x1b[31;44mA\x1b[0m"); | 956 | term.write("\x1b[31;44mA\x1b[0m"); |
| 956 | try term.snapshot(); | 957 | try term.snapshot(); |
| 957 | 958 | ||
| 958 | var lookup = try font.lookupMonospace(std.testing.allocator); | 959 | var lookup = try font.lookupConfiguredFont(std.testing.allocator); |
| 959 | defer lookup.deinit(std.testing.allocator); | 960 | defer lookup.deinit(std.testing.allocator); |
| 960 | 961 | ||
| 961 | var face = try font.Face.init(std.testing.allocator, lookup.path, lookup.index, 16); | 962 | var face = try font.Face.init(std.testing.allocator, lookup.path, lookup.index, config.font_size_px); |
| 962 | defer face.deinit(); | 963 | defer face.deinit(); |
| 963 | 964 | ||
| 964 | var atlas = try font.Atlas.init(std.testing.allocator, 256, 256); | 965 | var atlas = try font.Atlas.init(std.testing.allocator, 256, 256); |
| @@ -1147,6 +1148,10 @@ test "clearConsumedDirtyFlags clears only consumed partial rows after successful | |||
| 1147 | try std.testing.expectEqualSlices(bool, &.{ false, false, false, false }, dirty_rows[0..]); | 1148 | try std.testing.expectEqualSlices(bool, &.{ false, false, false, false }, dirty_rows[0..]); |
| 1148 | } | 1149 | } |
| 1149 | 1150 | ||
| 1151 | test "font module no longer exposes lookupMonospace compatibility wrapper" { | ||
| 1152 | try std.testing.expect(!@hasDecl(font, "lookupMonospace")); | ||
| 1153 | } | ||
| 1154 | |||
| 1150 | const RowInstanceCache = struct { | 1155 | const RowInstanceCache = struct { |
| 1151 | instances: std.ArrayListUnmanaged(renderer.Instance) = .empty, | 1156 | instances: std.ArrayListUnmanaged(renderer.Instance) = .empty, |
| 1152 | gpu_offset_instances: u32 = 0, | 1157 | gpu_offset_instances: u32 = 0, |
| @@ -1446,11 +1451,11 @@ fn runDrawSmokeTest(alloc: std.mem.Allocator) !void { | |||
| 1446 | defer ctx.deinit(); | 1451 | defer ctx.deinit(); |
| 1447 | std.debug.print("vulkan context created\n", .{}); | 1452 | std.debug.print("vulkan context created\n", .{}); |
| 1448 | 1453 | ||
| 1449 | // Load monospace font and create atlas | 1454 | // Load configured font and create atlas |
| 1450 | var font_lookup = try font.lookupMonospace(alloc); | 1455 | var font_lookup = try font.lookupConfiguredFont(alloc); |
| 1451 | defer font_lookup.deinit(alloc); | 1456 | defer font_lookup.deinit(alloc); |
| 1452 | 1457 | ||
| 1453 | const px_size: u32 = 16; | 1458 | const px_size: u32 = config.font_size_px; |
| 1454 | var face = try font.Face.init(alloc, font_lookup.path, font_lookup.index, px_size); | 1459 | var face = try font.Face.init(alloc, font_lookup.path, font_lookup.index, px_size); |
| 1455 | defer face.deinit(); | 1460 | defer face.deinit(); |
| 1456 | 1461 | ||