vt: add mouse encoding C API

Expose the internal mouse encoding functionality through the C API,
following the same pattern as the existing key encoding API. This
allows external consumers of libvt to encode mouse events into
terminal escape sequences (X10, UTF-8, SGR, URxvt, SGR-Pixels).

The API is split into two opaque handle types: GhosttyMouseEvent
for building normalized mouse events (action, button, modifiers,
position) and GhosttyMouseEncoder for converting those events into
escape sequences. The encoder is configured via a setopt interface
supporting tracking mode, output format, renderer geometry, button
state, and optional motion deduplication by last cell.

Encoder state can also be bulk-configured from a terminal handle
via ghostty_mouse_encoder_setopt_from_terminal. Failed encodes due
to insufficient buffer space report the required size without
mutating deduplication state.
This commit is contained in:
Mitchell Hashimoto
2026-03-15 20:02:39 -07:00
parent 79e023b65e
commit 9b35c2bb65
9 changed files with 1166 additions and 1 deletions

View File

@@ -4,7 +4,7 @@ const std = @import("std");
/// from ButtonState because button state is simply the current state
/// of a mouse button but an action is something that triggers via
/// an GUI event and supports more.
pub const Action = enum { press, release, motion };
pub const Action = enum(c_int) { press, release, motion };
/// The state of a mouse button.
///