summaryrefslogtreecommitdiff
path: root/src/cocoa
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-11 23:39:17 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-11 23:39:17 +0300
commit608b49052178ea74f593c925cdeedf352aa1c357 (patch)
treef6f5d886c2af5f0d34fbcfd4a33cd5209c68ee9e /src/cocoa
parent5bbcd2c036dd19d3293d9abc4d44014a5108a5ed (diff)
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
Diffstat (limited to 'src/cocoa')
-rw-r--r--src/cocoa/window.m26
1 files changed, 24 insertions, 2 deletions
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);