This example demonstrates how to use synthetic selection gesture events to derive drag and deep-press selection snapshots.
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
}
.value = { .coordinate = { .x = x, .y = y } },
};
return ref;
}
static void print_selection(
const char *label,
uint8_t *buf = NULL;
size_t len = 0;
terminal, NULL, opts, &buf, &len);
printf("%s: ", label);
fwrite(buf, 1, len, stdout);
printf("\n");
}
return event;
}
int main() {
.cols = 20,
.rows = 4,
.max_scrollback = 100,
};
vt_write(terminal, "hello world\r\nsecond line");
.columns = 20,
.cell_width = 10,
.padding_left = 0,
.screen_height = 40,
};
gesture, terminal, press, NULL);
gesture, terminal, drag, &selection);
print_selection(terminal, "drag", &selection);
gesture, terminal, release, NULL);
bool dragged = false;
printf("dragged: %s\n", dragged ? "true" : "false");
gesture, terminal, press, NULL);
gesture, terminal, deep_press, &selection);
print_selection(terminal, "deep press", &selection);
return 0;
}
GHOSTTY_API void ghostty_free(const GhosttyAllocator *allocator, uint8_t *ptr, size_t len)
@ GHOSTTY_POINT_TAG_ACTIVE
GHOSTTY_API GhosttyResult ghostty_selection_gesture_event_new(const GhosttyAllocator *allocator, GhosttySelectionGestureEvent *out_event, GhosttySelectionGestureEventType type)
struct GhosttySelectionGestureImpl * GhosttySelectionGesture
GHOSTTY_API GhosttyResult ghostty_selection_gesture_event(GhosttySelectionGesture gesture, GhosttyTerminal terminal, GhosttySelectionGestureEvent event, GhosttySelection *out_selection)
GHOSTTY_API GhosttyResult ghostty_selection_gesture_get(GhosttySelectionGesture gesture, GhosttyTerminal terminal, GhosttySelectionGestureData data, void *value)
struct GhosttySelectionGestureEventImpl * GhosttySelectionGestureEvent
GHOSTTY_API GhosttyResult ghostty_selection_gesture_event_set(GhosttySelectionGestureEvent event, GhosttySelectionGestureEventOption option, const void *value)
GHOSTTY_API void ghostty_selection_gesture_event_free(GhosttySelectionGestureEvent event)
GHOSTTY_API GhosttyResult ghostty_terminal_selection_format_alloc(GhosttyTerminal terminal, const GhosttyAllocator *allocator, GhosttyTerminalSelectionFormatOptions options, uint8_t **out_ptr, size_t *out_len)
GHOSTTY_API GhosttyResult ghostty_selection_gesture_new(const GhosttyAllocator *allocator, GhosttySelectionGesture *out_gesture)
GHOSTTY_API void ghostty_selection_gesture_reset(GhosttySelectionGesture gesture, GhosttyTerminal terminal)
GHOSTTY_API void ghostty_selection_gesture_free(GhosttySelectionGesture gesture, GhosttyTerminal terminal)
GhosttySelectionGestureEventType
@ GHOSTTY_SELECTION_GESTURE_DATA_DRAGGED
@ GHOSTTY_SELECTION_GESTURE_EVENT_OPT_GEOMETRY
@ GHOSTTY_SELECTION_GESTURE_EVENT_OPT_REF
@ GHOSTTY_SELECTION_GESTURE_EVENT_OPT_POSITION
@ GHOSTTY_SELECTION_GESTURE_EVENT_TYPE_PRESS
@ GHOSTTY_SELECTION_GESTURE_EVENT_TYPE_DEEP_PRESS
@ GHOSTTY_SELECTION_GESTURE_EVENT_TYPE_RELEASE
@ GHOSTTY_SELECTION_GESTURE_EVENT_TYPE_DRAG
struct GhosttyTerminalImpl * GhosttyTerminal
GHOSTTY_API GhosttyResult ghostty_terminal_new(const GhosttyAllocator *allocator, GhosttyTerminal *terminal, GhosttyTerminalOptions options)
GHOSTTY_API void ghostty_terminal_free(GhosttyTerminal terminal)
GHOSTTY_API void ghostty_terminal_vt_write(GhosttyTerminal terminal, const uint8_t *data, size_t len)
GHOSTTY_API GhosttyResult ghostty_terminal_grid_ref(GhosttyTerminal terminal, GhosttyPoint point, GhosttyGridRef *out_ref)
#define GHOSTTY_INIT_SIZED(type)