diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-12 10:53:22 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-12 10:53:22 +0300 |
| commit | 5206933399775e5ff46baefbbb3a776c2a9bb84c (patch) | |
| tree | e7549216ac626c1f3ac22345f79fbf80cc5a90fb /tests/common | |
| parent | 881fb6cb1d64868132287bd9637f4ae1cbc3504c (diff) | |
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.
Diffstat (limited to 'tests/common')
| -rw-r--r-- | tests/common/test_backends.c | 18 | ||||
| -rw-r--r-- | tests/common/test_tablet_example.c | 53 |
2 files changed, 71 insertions, 0 deletions
diff --git a/tests/common/test_backends.c b/tests/common/test_backends.c index 605dac0..4c99646 100644 --- a/tests/common/test_backends.c +++ b/tests/common/test_backends.c @@ -1,5 +1,11 @@ #define _POSIX_C_SOURCE 200809L #include "yasl/native.h" +#if YASL_HAS_WAYLAND +#include "yasl/native/wayland.h" +#endif +#if YASL_HAS_X11 +#include "yasl/native/x11.h" +#endif #include "yasl/loop.h" #include "yasl/yasl.h" @@ -145,6 +151,8 @@ static void x11_behavior(struct yasl_loop *loop, struct yasl_display *d, struct Display *native = yasl_display_get_native_handle(d); Window window = (Window)(uintptr_t)yasl_surface_get_native_handle(w->surface); assert(native && window); + assert(yasl_x11_display_get_display(d) == native); + assert(yasl_x11_surface_get_window(w->surface) == (uintptr_t)window); XSync(native, False); XImage *image = XGetImage(native, window, 0, 0, 1, 1, AllPlanes, ZPixmap); assert(image && (XGetPixel(image, 0, 0) & 0xffffff) == 0x4080c0); @@ -282,6 +290,16 @@ int main(int argc, char **argv) struct yasl_display *b = yasl_display_open(loop, &spec); assert(a && b); struct window wa = create(a), wb = create(b); +#if YASL_HAS_WAYLAND + assert(yasl_wayland_display_get_wl_display(a) != NULL); + assert(yasl_wayland_surface_get_wl_surface(wa.surface) != NULL); + assert(!yasl_x11_display_get_display(a)); +#endif +#if YASL_HAS_X11 + assert(yasl_x11_display_get_display(b) != NULL); + assert(yasl_x11_surface_get_window(wb.surface) != 0); + assert(!yasl_wayland_display_get_wl_display(b)); +#endif attach(&wa); attach(&wb); pump(loop, a, b); 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 <assert.h> + +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; +} |
