![]() |
libghostty
|
Utilities for encoding mouse events into terminal escape sequences, supporting X10, UTF-8, SGR, URxvt, and SGR-Pixels mouse protocols.
For a complete working example, see example/c-vt-mouse-encode in the repository.
When you have a GhosttyTerminal, you can sync its tracking mode and output format into the encoder automatically:
Typedefs | |
| typedef struct GhosttyMouseEncoder * | GhosttyMouseEncoder |
| typedef struct GhosttyMouseEvent * | GhosttyMouseEvent |
Enumerations | |
| 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 } |
| enum | GhosttyMouseFormat |
| enum | GhosttyMouseEncoderOption { GHOSTTY_MOUSE_ENCODER_OPT_EVENT = 0 , GHOSTTY_MOUSE_ENCODER_OPT_FORMAT = 1 , GHOSTTY_MOUSE_ENCODER_OPT_SIZE = 2 , GHOSTTY_MOUSE_ENCODER_OPT_ANY_BUTTON_PRESSED = 3 , GHOSTTY_MOUSE_ENCODER_OPT_TRACK_LAST_CELL = 4 } |
| enum | GhosttyMouseAction { GHOSTTY_MOUSE_ACTION_PRESS = 0 , GHOSTTY_MOUSE_ACTION_RELEASE = 1 , GHOSTTY_MOUSE_ACTION_MOTION = 2 } |
| enum | GhosttyMouseButton |
Data Structures | |
| struct | GhosttyMouseEncoderSize |
| struct | GhosttyMousePosition |
| typedef struct GhosttyMouseEncoder* 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 GhosttyMouseEvent* 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 46 of file mouse/event.h.
Mouse encoder option identifiers.
These values are used with ghostty_mouse_encoder_setopt() to configure the behavior of the mouse encoder.
| Enumerator | |
|---|---|
| GHOSTTY_MOUSE_ENCODER_OPT_EVENT | Mouse tracking mode (value: GhosttyMouseTrackingMode). |
| GHOSTTY_MOUSE_ENCODER_OPT_FORMAT | Mouse output format (value: GhosttyMouseFormat). |
| GHOSTTY_MOUSE_ENCODER_OPT_SIZE | Renderer size context (value: GhosttyMouseEncoderSize). |
| GHOSTTY_MOUSE_ENCODER_OPT_ANY_BUTTON_PRESSED | Whether any mouse button is currently pressed (value: bool). |
| GHOSTTY_MOUSE_ENCODER_OPT_TRACK_LAST_CELL | Whether to enable motion deduplication by last cell (value: bool). |
Definition at line 108 of file mouse/encoder.h.
| enum GhosttyMouseFormat |
Mouse output format.
Definition at line 55 of file mouse/encoder.h.
Mouse tracking mode.
Definition at line 33 of file mouse/encoder.h.
| GhosttyResult ghostty_mouse_encoder_encode | ( | GhosttyMouseEncoder | encoder, |
| GhosttyMouseEvent | event, | ||
| char * | out_buf, | ||
| size_t | out_buf_size, | ||
| size_t * | out_len ) |
Encode a mouse event into a terminal escape sequence.
Not all mouse events produce output. In such cases this returns GHOSTTY_SUCCESS with out_len set to 0.
If the output buffer is too small, this returns GHOSTTY_OUT_OF_MEMORY and out_len contains the required size.
| encoder | The encoder handle, must not be NULL |
| event | The mouse event to encode, must not be NULL |
| out_buf | Buffer to write encoded bytes to, or NULL to query required size |
| out_buf_size | Size of out_buf in bytes |
| out_len | Pointer to store bytes written (or required bytes on failure) |
| void ghostty_mouse_encoder_free | ( | GhosttyMouseEncoder | encoder | ) |
Free a mouse encoder instance.
| encoder | The encoder handle to free (may be NULL) |
| GhosttyResult ghostty_mouse_encoder_new | ( | const GhosttyAllocator * | allocator, |
| GhosttyMouseEncoder * | encoder ) |
Create a new mouse encoder instance.
| Memory Management | Pointer to allocator, or NULL to use the default allocator |
| encoder | Pointer to store the created encoder handle |
| void ghostty_mouse_encoder_reset | ( | GhosttyMouseEncoder | encoder | ) |
Reset internal encoder state.
This clears motion deduplication state (last tracked cell).
| encoder | The encoder handle (may be NULL) |
| void ghostty_mouse_encoder_setopt | ( | GhosttyMouseEncoder | encoder, |
| GhosttyMouseEncoderOption | option, | ||
| const void * | value ) |
Set an option on the mouse encoder.
A null pointer value does nothing. It does not reset to defaults.
| encoder | The encoder handle, must not be NULL |
| option | The option to set |
| value | Pointer to option value (type depends on option) |
| void ghostty_mouse_encoder_setopt_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 does not modify size or any-button state.
| encoder | The encoder handle, must not be NULL |
| Terminal | The terminal handle, must not be NULL |
| void ghostty_mouse_event_clear_button | ( | GhosttyMouseEvent | event | ) |
Clear the event button.
This sets the event button to "none".
| event | The event handle, must not be NULL |
| void ghostty_mouse_event_free | ( | GhosttyMouseEvent | event | ) |
Free a mouse event instance.
| event | The mouse event handle to free (may be NULL) |
| GhosttyMouseAction ghostty_mouse_event_get_action | ( | GhosttyMouseEvent | event | ) |
Get the event action.
| event | The event handle, must not be NULL |
| bool ghostty_mouse_event_get_button | ( | GhosttyMouseEvent | event, |
| GhosttyMouseButton * | out_button ) |
Get the event button.
| event | The event handle, must not be NULL |
| out_button | Output pointer for the button value (may be NULL) |
| GhosttyMods ghostty_mouse_event_get_mods | ( | GhosttyMouseEvent | event | ) |
Get keyboard modifiers held during the event.
| event | The event handle, must not be NULL |
| GhosttyMousePosition ghostty_mouse_event_get_position | ( | GhosttyMouseEvent | event | ) |
Get the event position in surface-space pixels.
| event | The event handle, must not be NULL |
| GhosttyResult ghostty_mouse_event_new | ( | const GhosttyAllocator * | allocator, |
| GhosttyMouseEvent * | event ) |
Create a new mouse event instance.
| Memory Management | Pointer to allocator, or NULL to use the default allocator |
| event | Pointer to store the created event handle |
| void ghostty_mouse_event_set_action | ( | GhosttyMouseEvent | event, |
| GhosttyMouseAction | action ) |
Set the event action.
| event | The event handle, must not be NULL |
| action | The action to set |
| void 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, must not be NULL |
| button | The button to set |
| void ghostty_mouse_event_set_mods | ( | GhosttyMouseEvent | event, |
| GhosttyMods | mods ) |
Set keyboard modifiers held during the event.
| event | The event handle, must not be NULL |
| mods | Modifier bitmask |
| void ghostty_mouse_event_set_position | ( | GhosttyMouseEvent | event, |
| GhosttyMousePosition | position ) |
Set the event position in surface-space pixels.
| event | The event handle, must not be NULL |
| position | The position to set |