terminal/kitty: parse relative placement fields

This commit is contained in:
Mitchell Hashimoto
2024-07-24 18:59:01 -07:00
parent 2c0f9bfc28
commit 358b4ca896
2 changed files with 28 additions and 1 deletions

View File

@ -462,6 +462,10 @@ pub const Display = struct {
rows: u32 = 0, // r
cursor_movement: CursorMovement = .after, // C
virtual_placement: bool = false, // U
parent_id: u32 = 0, // P
parent_placement_id: u32 = 0, // Q
horizontal_offset: u32 = 0, // H
vertical_offset: u32 = 0, // V
z: i32 = 0, // z
pub const CursorMovement = enum {
@ -537,6 +541,22 @@ pub const Display = struct {
result.z = @bitCast(v);
}
if (kv.get('P')) |v| {
result.parent_id = v;
}
if (kv.get('Q')) |v| {
result.parent_placement_id = v;
}
if (kv.get('H')) |v| {
result.horizontal_offset = v;
}
if (kv.get('V')) |v| {
result.vertical_offset = v;
}
return result;
}
};

View File

@ -187,7 +187,14 @@ fn display(
// Location where the placement will go.
const location: ImageStorage.Placement.Location = location: {
// Virtual placements are not tracked
if (d.virtual_placement) break :location .{ .virtual = {} };
if (d.virtual_placement) {
if (d.parent_id > 0) {
result.message = "EINVAL: virtual placement cannot refer to a parent";
return result;
}
break :location .{ .virtual = {} };
}
// Track a new pin for our cursor. The cursor is always tracked but we
// don't want this one to move with the cursor.