From 98f0d51157fa2a2b8ccaae54ed4850a88d223d01 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Tue, 13 Oct 2026 15:05:06 +0300 Subject: Simplify surface state, examples, and library installation --- tests/x11/test_tablet_native.c | 49 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'tests/x11/test_tablet_native.c') diff --git a/tests/x11/test_tablet_native.c b/tests/x11/test_tablet_native.c index f12ec7f..078606a 100644 --- a/tests/x11/test_tablet_native.c +++ b/tests/x11/test_tablet_native.c @@ -55,6 +55,49 @@ static int connect_tool(const char *path) return fd; } +static void native_draw(struct yasl_surface *surface, struct yasl_frame *frame, void *ud) +{ + struct yasl_frame_context context = { + .surface = surface, .size = frame->target.size, + .scale_120 = yasl_surface_geometry(surface).scale_120, + .cpu = {.pixels = frame->target.pixels, + .stride_bytes = frame->target.size.x * (int)sizeof(uint32_t)}, + .internal_handle = frame, + }; + draw(ud, surface, &context); +} + +static void native_configure(struct yasl_surface *surface, struct yasl_geometry geometry, void *ud) +{ + input(ud, &(struct yasl_event){.surface = surface, .type = YASL_EVENT_WINDOW_RESIZE, + .resize = {.size = geometry.size, .scale_120 = geometry.scale_120}}); +} + +static void native_input(struct app *app, const struct yasl_input_event *raw) +{ + struct yasl_event event = {.surface = raw->surface}; + if (raw->kind == YASL_INPUT_RESET) event.type = YASL_EVENT_INPUT_RESET; + else if (raw->kind == YASL_INPUT_FOCUS) { + event.type = YASL_EVENT_WINDOW_FOCUS; + event.focus.focused = raw->focus.focused; + } else if (raw->kind == YASL_INPUT_MOUSE) { + if (raw->mouse.kind == YASL_PTR_MOTION) { + event.type = YASL_EVENT_MOUSE_MOTION; + event.mouse_motion.pos = raw->mouse.pos; + event.mouse_motion.device = raw->mouse.device; + event.mouse_motion.pen = raw->mouse.pen; + } else if (raw->mouse.kind == YASL_PTR_PRESS || raw->mouse.kind == YASL_PTR_RELEASE) { + event.type = YASL_EVENT_MOUSE_BUTTON; + event.mouse_button.pos = raw->mouse.pos; + event.mouse_button.device = raw->mouse.device; + event.mouse_button.button = raw->mouse.button; + event.mouse_button.pressed = raw->mouse.kind == YASL_PTR_PRESS; + event.mouse_button.pen = raw->mouse.pen; + } else if (raw->mouse.kind == YASL_PTR_LEAVE) event.type = YASL_EVENT_MOUSE_LEAVE; + } + input(app, &event); +} + static void pump(int fd, struct yasl_display *display, struct yasl_surface *surface, struct app *app) { xf86ITEventWaitForSync sync = {{sizeof(sync), XF86IT_EVENT_WAIT_FOR_SYNC}}; @@ -68,7 +111,7 @@ static void pump(int fd, struct yasl_display *display, struct yasl_surface *surf assert(yasl_display_dispatch(display, 0) == 0); struct yasl_input_event event; while (yasl_surface_input_poll(surface, &event)) { - input(app, &event); + native_input(app, &event); yasl_surface_schedule_redraw(surface); } yasl_display_flush(display); @@ -99,14 +142,14 @@ static void set_eraser_property(Display *display) int main(int argc, char **argv) { assert(argc == 3); /* pen socket, eraser socket */ - struct app app = {.running = true, .tablet_supported = true, .backend = YASL_BACKEND_X11}; + struct app app = {.tablet_supported = true, .backend = YASL_BACKEND_X11}; struct yasl_display_spec ds = {.backend = YASL_BACKEND_X11}; struct yasl_display *display = yasl_display_open(NULL, &ds); assert(display && (yasl_display_caps(display) & YASL_CAP_TABLET)); struct yasl_window_spec ss = {.title = "YASL native pressure test", .size = {500, 400}}; struct yasl_surface *surface = yasl_surface_create_toplevel(display, &ss); assert(surface); - struct yasl_window_cbs cbs = {.draw = draw, .configure = configure}; + struct yasl_window_cbs cbs = {.draw = native_draw, .configure = native_configure}; yasl_surface_set_callbacks(surface, &cbs, &app); yasl_surface_schedule_redraw(surface); Display *x = yasl_display_get_native_handle(display); -- cgit v1.2.3