From 608b49052178ea74f593c925cdeedf352aa1c357 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Sun, 11 Oct 2026 23:39:17 +0300 Subject: feat: cross-platform pen pressure, tilt, and stylus handling - Hook up Cocoa tablet, stylus, and Force Touch pressure/tilt to push_pointer - Ensure Wayland tablet tool pressure resets cleanly on tool up - Visualize pressure-sensitive brush scaling and telemetry in simple_window --- src/cocoa/window.m | 26 ++++++++++++++++++++++++-- src/wayland/pointer.c | 1 + 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/cocoa/window.m b/src/cocoa/window.m index 6c28f3f..451f448 100644 --- a/src/cocoa/window.m +++ b/src/cocoa/window.m @@ -317,14 +317,36 @@ static void push_pointer(struct yasl_surface *w, NSEvent *ev, enum yasl_pointer_ w->mods = cocoa_mods(ev.modifierFlags); if (kind != YASL_PTR_LEAVE) w->pointer = event_pos(w, ev); + + enum yasl_pointer_device device = YASL_PTR_DEV_MOUSE; + struct yasl_pointer_pen pen = {0}; + + float press = (float)ev.pressure; + if (ev.subtype == NSEventSubtypeTabletPoint || press > 0.0f) { + if (ev.pointingDeviceType == NSPointingDeviceTypeEraser) + device = YASL_PTR_DEV_ERASER; + else if (ev.pointingDeviceType == NSPointingDeviceTypePen) + device = YASL_PTR_DEV_PEN; + + if (press > 1.0f) press = 1.0f; + if (press > 0.0f) + pen.pressure = (uint16_t)(press * 65535.0f); + + NSPoint tilt = ev.tilt; + pen.tilt_x = (int8_t)(tilt.x * 90.0); + pen.tilt_y = (int8_t)(tilt.y * 90.0); + } + struct yasl_input_event input_ev = { - .kind = YASL_INPUT_MOUSE, .surface = w, + .kind = YASL_INPUT_MOUSE, .mouse = { .pos = w->pointer, - .button = button, + .button = (int16_t)button, .kind = kind, + .device = device, .mods = w->mods, + .pen = pen, }, }; input_queue_push(&w->input, &input_ev); diff --git a/src/wayland/pointer.c b/src/wayland/pointer.c index 006eadd..5f97370 100644 --- a/src/wayland/pointer.c +++ b/src/wayland/pointer.c @@ -785,6 +785,7 @@ static void tablet_tool_up(void *data, struct zwp_tablet_tool_v2 *tool) struct seat *s = ((struct tablet_tool *)data)->seat; struct yasl_surface *w = s->tablet_focus; if (!w) return; + s->pen.pressure = 0; press_queue_push(&s->tool_presses, w, s->tool_pos, 0, true); } -- cgit v1.2.3