From 5206933399775e5ff46baefbbb3a776c2a9bb84c Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Mon, 12 Oct 2026 10:53:22 +0300 Subject: feat: add type-safe native platform headers and portable drag support - Add include/yasl/native/{wayland,cocoa,x11}.h with type-safe handle accessors. - Unify drag-and-drop and window carry support across Wayland, X11, and Cocoa. - Preserve full ABI compatibility for capability flags. - Install native headers conditionally based on enabled backend. - Include missing tablet example and backend test suites. --- tests/common/test_tablet_example.c | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/common/test_tablet_example.c (limited to 'tests/common/test_tablet_example.c') diff --git a/tests/common/test_tablet_example.c b/tests/common/test_tablet_example.c new file mode 100644 index 0000000..1658174 --- /dev/null +++ b/tests/common/test_tablet_example.c @@ -0,0 +1,53 @@ +#define main tablet_example_main +#include "../../examples/tablet.c" +#undef main +#include + +static void pointer(struct app *app, enum yasl_pointer_kind kind, + enum yasl_pointer_device device, int button, int x, int y, uint16_t pressure) +{ + struct yasl_input_event event = {.kind = YASL_INPUT_MOUSE, .mouse = { + .kind = kind, .device = device, .button = button, .pos = {x, y}, .pen.pressure = pressure}}; + input(app, &event); +} + +static uint32_t pixel(const struct app *app, int x, int y) +{ + return app->canvas[(size_t)y * app->geometry.size.x + x]; +} + +int main(void) +{ + struct app app = {0}; + assert(resize_canvas(&app, (struct yasl_geometry){{400, 300}, 120})); + pointer(&app, YASL_PTR_MOTION, YASL_PTR_DEV_PEN, 3, 80, 160, 65535); + assert(pixel(&app, 80, 160) == PAPER); /* Hover never paints. */ + pointer(&app, YASL_PTR_PRESS, YASL_PTR_DEV_PEN, 2, 80, 160, 65535); + assert(!app.down && pixel(&app, 80, 160) == PAPER); /* Side button isn't the tip. */ + pointer(&app, YASL_PTR_PRESS, YASL_PTR_DEV_PEN, 0, 80, 160, 0); + assert(app.down && pixel(&app, 80, 160) == INK && pixel(&app, 90, 160) == PAPER); + pointer(&app, YASL_PTR_MOTION, YASL_PTR_DEV_PEN, 0, 80, 160, 65535); + assert(pixel(&app, 100, 160) == INK); /* Stationary pressure widens brush. */ + pointer(&app, YASL_PTR_MOTION, YASL_PTR_DEV_PEN, 0, 180, 160, 20000); + assert(pixel(&app, 130, 160) == INK); /* Segments are continuous. */ + pointer(&app, YASL_PTR_RELEASE, YASL_PTR_DEV_PEN, 0, 180, 160, 0); + pointer(&app, YASL_PTR_MOTION, YASL_PTR_DEV_PEN, 3, 250, 160, 65535); + assert(!app.down && pixel(&app, 250, 160) == PAPER); + pointer(&app, YASL_PTR_PRESS, YASL_PTR_DEV_ERASER, 0, 80, 160, 65535); + assert(pixel(&app, 80, 160) == PAPER && pixel(&app, 130, 160) == INK); + struct yasl_input_event reset = {.kind = YASL_INPUT_RESET}; + input(&app, &reset); + pointer(&app, YASL_PTR_MOTION, YASL_PTR_DEV_ERASER, 0, 130, 160, 65535); + assert(!app.down && pixel(&app, 130, 160) == INK); + pointer(&app, YASL_PTR_PRESS, YASL_PTR_DEV_MOUSE, 0, 300, 200, 0); + assert(pixel(&app, 300, 200) == INK); + struct yasl_input_event blur = {.kind = YASL_INPUT_FOCUS, .focus.focused = false}; + input(&app, &blur); + assert(!app.down); + assert(resize_canvas(&app, (struct yasl_geometry){{800, 600}, 240})); + assert(pixel(&app, 600, 400) == INK && !app.previous); /* DPI preserves logical drawing. */ + clear_canvas(&app); + assert(pixel(&app, 600, 400) == PAPER); + free(app.canvas); + return 0; +} -- cgit v1.2.3