summaryrefslogtreecommitdiff
path: root/src/wire.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/wire.zig')
-rw-r--r--src/wire.zig26
1 files changed, 6 insertions, 20 deletions
diff --git a/src/wire.zig b/src/wire.zig
index e39e25b4..65b93bf1 100644
--- a/src/wire.zig
+++ b/src/wire.zig
@@ -396,11 +396,6 @@ fn clientTag(msg: ClientMsg) ClientTag {
};
}
-/// Does the build this frontend was compiled with carry pixel dimensions in a
-/// resize? The FIELD is comptime-conditional (pardes.zig `CellPixels`); the
-/// WIRE is not.
-const has_cell_pixels = @hasField(pardes.CellPixels, "w");
-
fn putMetrics(w: *std.Io.Writer, metrics: ?pardes.RowMetrics) Error!void {
try w.writeByte(@intFromBool(metrics != null));
if (metrics) |m| {
@@ -525,11 +520,8 @@ pub fn encodeClient(out: []u8, msg: ClientMsg) Error![]const u8 {
.resize => |rs| {
try w.writeInt(u16, rs.cols, .little);
try w.writeInt(u16, rs.rows, .little);
- // The conventional 1:2 cell aspect when this build has no
- // pixels of its own, which is the same default the field
- // carries where it exists.
- try w.writeInt(u16, if (comptime has_cell_pixels) rs.cell_pixels.w else 8, .little);
- try w.writeInt(u16, if (comptime has_cell_pixels) rs.cell_pixels.h else 16, .little);
+ try w.writeInt(u16, rs.cell_pixels.w, .little);
+ try w.writeInt(u16, rs.cell_pixels.h, .little);
try putMetrics(&w, rs.row_metrics);
},
.paste => |b| try putSlice32(&w, b),
@@ -605,10 +597,7 @@ pub fn decodeClient(tag: u8, payload: []const u8) Error!ClientMsg {
.resize => blk: {
var ev: pardes.Event = .{ .resize = .{ .cols = try getCols(&r), .rows = try getRows(&r) } };
const px_w = try r.takeInt(u16, .little);
- const px_h = try r.takeInt(u16, .little);
- // Read either way — the bytes are on the wire — and kept only by a
- // build that has somewhere to keep them.
- if (comptime has_cell_pixels) ev.resize.cell_pixels = .{ .w = px_w, .h = px_h };
+ ev.resize.cell_pixels = .{ .w = px_w, .h = try r.takeInt(u16, .little) };
ev.resize.row_metrics = try getMetrics(&r);
break :blk .{ .event = ev };
},
@@ -727,12 +716,9 @@ test "detached wire: every Event variant round-trips" {
const got = (try roundClient(&buf, .{ .event = .{ .resize = .{ .cols = 56, .rows = 14 } } })).event.resize;
try testing.expectEqual(@as(u16, 56), got.cols);
try testing.expectEqual(@as(u16, 14), got.rows);
- // Pixels travel whether or not this build has them; where it does, the
- // conventional 1:2 default survives the trip.
- if (comptime has_cell_pixels) {
- try testing.expectEqual(@as(u16, 8), got.cell_pixels.w);
- try testing.expectEqual(@as(u16, 16), got.cell_pixels.h);
- }
+ // The conventional 1:2 default survives the trip.
+ try testing.expectEqual(@as(u16, 8), got.cell_pixels.w);
+ try testing.expectEqual(@as(u16, 16), got.cell_pixels.h);
}
try testing.expectEqualStrings("clip", (try roundClient(&buf, .{ .event = .{ .paste = "clip" } })).event.paste);
try testing.expectEqualStrings("Look /x", (try roundClient(&buf, .{ .event = .{ .command = "Look /x" } })).event.command);