![]() |
libghostty-vt 0.0.0
|
Encode mouse events with the X10, UTF-8, SGR, URxvt, or SGR-Pixels protocols. More...
Encode mouse events with the X10, UTF-8, SGR, URxvt, or SGR-Pixels protocols.
Encode mouse events into terminal escape sequences, in the X10, UTF-8, SGR, URxvt, and SGR-Pixels formats.
An encoder has to follow the terminal's modes. If you have a terminal, call ghostty_mouse_encoder_set_from_terminal() before you encode.
Full program: c-vt-encode-mouse/src/main.c
The Input guide explains which modes matter and when to sync them.
Typedefs | |
| typedef struct GhosttyMouseEncoderImpl * | GhosttyMouseEncoder |
| typedef struct GhosttyMouseEventImpl * | GhosttyMouseEvent |
Enumerations | |
| enum | GhosttyMouseShape |
| enum | GhosttyMouseTrackingMode { GHOSTTY_MOUSE_TRACKING_NONE = 0 , GHOSTTY_MOUSE_TRACKING_X10 = 1 , GHOSTTY_MOUSE_TRACKING_NORMAL = 2 , GHOSTTY_MOUSE_TRACKING_BUTTON = 3 , GHOSTTY_MOUSE_TRACKING_ANY = 4 , GHOSTTY_MOUSE_TRACKING_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE } |
| enum | GhosttyMouseFormat |
| enum | GhosttyMouseEncoderOption { GHOSTTY_MOUSE_ENCODER_OPT_INVALID = 0 , GHOSTTY_MOUSE_ENCODER_OPT_EVENT = 1 , GHOSTTY_MOUSE_ENCODER_OPT_FORMAT = 2 , GHOSTTY_MOUSE_ENCODER_OPT_SIZE = 3 , GHOSTTY_MOUSE_ENCODER_OPT_ANY_BUTTON_PRESSED = 4 , GHOSTTY_MOUSE_ENCODER_OPT_TRACK_LAST_CELL = 5 , GHOSTTY_MOUSE_ENCODER_OPT_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE } |
| enum | GhosttyMouseAction { GHOSTTY_MOUSE_ACTION_PRESS = 0 , GHOSTTY_MOUSE_ACTION_RELEASE = 1 , GHOSTTY_MOUSE_ACTION_MOTION = 2 , GHOSTTY_MOUSE_ACTION_MAX_VALUE = GHOSTTY_ENUM_MAX_VALUE } |
| enum | GhosttyMouseButton |
Data Structures | |
| struct | GhosttyMouseEncoderSize |
| struct | GhosttyMousePosition |
| typedef struct GhosttyMouseEncoderImpl* GhosttyMouseEncoder |
Opaque handle to a mouse encoder instance.
This handle represents a mouse encoder that converts normalized mouse events into terminal escape sequences.
Definition at line 26 of file mouse/encoder.h.
| typedef struct GhosttyMouseEventImpl* GhosttyMouseEvent |
Opaque handle to a mouse event.
This handle represents a normalized mouse input event containing action, button, modifiers, and surface-space position.
Definition at line 23 of file mouse/event.h.
| enum GhosttyMouseAction |
Mouse event action type.
| Enumerator | |
|---|---|
| GHOSTTY_MOUSE_ACTION_PRESS | Mouse button was pressed. |
| GHOSTTY_MOUSE_ACTION_RELEASE | Mouse button was released. |
| GHOSTTY_MOUSE_ACTION_MOTION | Mouse moved. |
Definition at line 30 of file mouse/event.h.
| enum GhosttyMouseButton |
Mouse button identity.
Definition at line 47 of file mouse/event.h.
Mouse encoder option identifiers.
These values are used with ghostty_mouse_encoder_set() to configure the behavior of the mouse encoder.
| Enumerator | |
|---|---|
| GHOSTTY_MOUSE_ENCODER_OPT_INVALID | Not a real option. ghostty_mouse_encoder_set() returns GHOSTTY_INVALID_VALUE for it. Its value is 0, so a zeroed or uninitialized variable is never mistaken for a real option. |
| GHOSTTY_MOUSE_ENCODER_OPT_EVENT | Mouse tracking mode (value: GhosttyMouseTrackingMode, default: GHOSTTY_MOUSE_TRACKING_NONE). |
| GHOSTTY_MOUSE_ENCODER_OPT_FORMAT | Mouse output format (value: GhosttyMouseFormat, default: GHOSTTY_MOUSE_FORMAT_X10). |
| GHOSTTY_MOUSE_ENCODER_OPT_SIZE | Renderer size context (value: GhosttyMouseEncoderSize, default: a 1x1 pixel screen with 1x1 pixel cells and no padding). |
| GHOSTTY_MOUSE_ENCODER_OPT_ANY_BUTTON_PRESSED | Whether any mouse button is currently pressed (value: bool, default: false). |
| GHOSTTY_MOUSE_ENCODER_OPT_TRACK_LAST_CELL | Whether to enable motion deduplication by last cell (value: bool, default: false). |
Definition at line 113 of file mouse/encoder.h.
| enum GhosttyMouseFormat |
Mouse output format.
Definition at line 56 of file mouse/encoder.h.
| enum GhosttyMouseShape |
Mouse tracking mode.
Definition at line 33 of file mouse/encoder.h.
| GHOSTTY_API GhosttyResult ghostty_mouse_encoder_encode | ( | GhosttyMouseEncoder | encoder, |
| GhosttyMouseEvent | event, | ||
| uint8_t * | buf, | ||
| size_t | buf_len, | ||
| size_t * | out_written ) |
Encode a mouse event into a terminal escape sequence.
Not all mouse events produce output. In such cases this returns GHOSTTY_SUCCESS with out_written set to 0.
If buf is too small, this returns GHOSTTY_OUT_OF_SPACE and sets out_written to the size needed. The buffer may then hold part of the sequence, which you should discard. To get the size without encoding anything, pass NULL for buf and 0 for buf_len. An event with no output still returns GHOSTTY_SUCCESS in that case, because it needs no space.
A 128-byte buffer is enough for typical events:
| encoder | The encoder handle, must not be NULL | |
| event | The mouse event to encode, must not be NULL | |
| buf | Buffer to write the sequence into. May be NULL if buf_len is 0. | |
| buf_len | Size of buf in bytes | |
| [out] | out_written | The number of bytes written, or the size needed if the result is GHOSTTY_OUT_OF_SPACE. Must not be NULL. |
| GHOSTTY_API void ghostty_mouse_encoder_free | ( | GhosttyMouseEncoder | encoder | ) |
Free a mouse encoder instance.
| encoder | The encoder handle to free (may be NULL) |
| GHOSTTY_API GhosttyResult ghostty_mouse_encoder_new | ( | const GhosttyAllocator * | allocator, |
| GhosttyMouseEncoder * | encoder ) |
Create a new mouse encoder instance.
| allocator | Pointer to allocator, or NULL to use the default allocator |
| encoder | Pointer to store the created encoder handle |
| GHOSTTY_API GhosttyResult ghostty_mouse_encoder_reset | ( | GhosttyMouseEncoder | encoder | ) |
Reset internal encoder state.
This clears motion deduplication state (last tracked cell).
| encoder | The encoder handle |
| GHOSTTY_API GhosttyResult ghostty_mouse_encoder_set | ( | GhosttyMouseEncoder | encoder, |
| GhosttyMouseEncoderOption | option, | ||
| const void * | value ) |
Set an option on the mouse encoder.
Passing NULL for value resets the option to its default, the same value a new encoder starts with. Each option's default is listed on GhosttyMouseEncoderOption.
| encoder | The encoder handle, must not be NULL |
| option | The option to set |
| value | Pointer to option value (type depends on option), or NULL to reset the option to its default |
| GHOSTTY_API GhosttyResult ghostty_mouse_encoder_set_from_terminal | ( | GhosttyMouseEncoder | encoder, |
| GhosttyTerminal | terminal ) |
Set encoder options from a terminal's current state.
This sets tracking mode and output format from terminal state. It also clears the last-cell state, as ghostty_mouse_encoder_reset() does, so the next motion event isn't dropped as a repeat of the last cell. It does not modify size or any-button state.
| encoder | The encoder handle |
| terminal | The terminal handle |
| GHOSTTY_API GhosttyResult ghostty_mouse_event_clear_button | ( | GhosttyMouseEvent | event | ) |
Clear the event button.
This sets the event button to "none".
| event | The event handle |
| GHOSTTY_API void ghostty_mouse_event_free | ( | GhosttyMouseEvent | event | ) |
Free a mouse event instance.
| event | The mouse event handle to free (may be NULL) |
| GHOSTTY_API GhosttyMouseAction ghostty_mouse_event_get_action | ( | GhosttyMouseEvent | event | ) |
Get the event action.
| event | The event handle |
| GHOSTTY_API GhosttyResult ghostty_mouse_event_get_button | ( | GhosttyMouseEvent | event, |
| GhosttyMouseButton * | out_button ) |
Get the event button.
A new event has no button, and ghostty_mouse_event_clear_button() removes the button from an event. Having no button is normal, for example when the mouse moves with no button held. It is not an error, so check for GHOSTTY_NO_VALUE separately:
| event | The event handle |
| out_button | Where to write the button. Must not be NULL. |
| GHOSTTY_API GhosttyMods ghostty_mouse_event_get_mods | ( | GhosttyMouseEvent | event | ) |
Get keyboard modifiers held during the event.
| event | The event handle |
| GHOSTTY_API GhosttyMousePosition ghostty_mouse_event_get_position | ( | GhosttyMouseEvent | event | ) |
Get the event position in surface-space pixels.
| event | The event handle |
| GHOSTTY_API GhosttyResult ghostty_mouse_event_new | ( | const GhosttyAllocator * | allocator, |
| GhosttyMouseEvent * | event ) |
Create a new mouse event instance.
| allocator | Pointer to allocator, or NULL to use the default allocator |
| event | Pointer to store the created event handle |
| GHOSTTY_API GhosttyResult ghostty_mouse_event_set_action | ( | GhosttyMouseEvent | event, |
| GhosttyMouseAction | action ) |
Set the event action.
| event | The event handle |
| action | The action to set |
| GHOSTTY_API GhosttyResult ghostty_mouse_event_set_button | ( | GhosttyMouseEvent | event, |
| GhosttyMouseButton | button ) |
Set the event button.
This sets a concrete button identity for the event. To represent "no button" (for motion events), use ghostty_mouse_event_clear_button().
| event | The event handle |
| button | The button to set |
| GHOSTTY_API GhosttyResult ghostty_mouse_event_set_mods | ( | GhosttyMouseEvent | event, |
| GhosttyMods | mods ) |
Set keyboard modifiers held during the event.
| event | The event handle |
| mods | Modifier bitmask |
| GHOSTTY_API GhosttyResult ghostty_mouse_event_set_position | ( | GhosttyMouseEvent | event, |
| GhosttyMousePosition | position ) |
Set the event position in surface-space pixels.
| event | The event handle |
| position | The position to set |