From 358b4ca896dd75c76b694c595947ae53988780e6 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 24 Jul 2024 18:59:01 -0700 Subject: [PATCH] terminal/kitty: parse relative placement fields --- src/terminal/kitty/graphics_command.zig | 20 ++++++++++++++++++++ src/terminal/kitty/graphics_exec.zig | 9 ++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/terminal/kitty/graphics_command.zig b/src/terminal/kitty/graphics_command.zig index fe9a4520f..810a8df55 100644 --- a/src/terminal/kitty/graphics_command.zig +++ b/src/terminal/kitty/graphics_command.zig @@ -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; } }; diff --git a/src/terminal/kitty/graphics_exec.zig b/src/terminal/kitty/graphics_exec.zig index 2859d3f0f..b8924d56f 100644 --- a/src/terminal/kitty/graphics_exec.zig +++ b/src/terminal/kitty/graphics_exec.zig @@ -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.