diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 16:57:59 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 16:57:59 +0300 |
| commit | cbd1fc7ee6dced7ad6beecd5b9ad56a7f977f0c4 (patch) | |
| tree | c139512cba169031becf6cc2bc2b0429a2e1546a /src/common/input.c | |
| parent | efca84e8b5204c4d5ce28113474df0bf0b67dbf3 (diff) | |
Report held pointer buttons on every pointer event
Pointer events set button only on press and release, so wsap_term tracked
held buttons itself to tell a drag from a hover.
yasl_pointer_event.buttons now holds a YASL_BUTTON_BIT() mask of the buttons
held after each event. The common input queue tracks it from the DOWN and
UP events it queues, and clears it on INPUT_RESET and on allocation
failure. Wayland also clears it on leave, since the compositor sends leave
during a press only when it takes the pointer and no release follows. X11
and Cocoa keep it, because they deliver motion and the release to the
pressed window after leave.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'src/common/input.c')
| -rw-r--r-- | src/common/input.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/common/input.c b/src/common/input.c index 0b55f1f..ce3219c 100644 --- a/src/common/input.c +++ b/src/common/input.c @@ -33,6 +33,7 @@ bool input_queue_push(struct input_queue *q, const struct yasl_event *ev) owned[len] = '\0'; copy.text.data = owned; } + uint32_t buttons = q->buttons; switch (ev->type) { case YASL_EVENT_POINTER_MOTION: if (!q->relative) { @@ -41,19 +42,31 @@ bool input_queue_push(struct input_queue *q, const struct yasl_event *ev) ev->pointer.pos.y - q->last_pos.y} : (struct yasl_vector2d){0, 0}; } - [[fallthrough]]; + q->last_pos = ev->pointer.pos; + q->has_last_pos = true; + break; case YASL_EVENT_POINTER_DOWN: case YASL_EVENT_POINTER_UP: + if ((unsigned)ev->pointer.button < 32) { + uint32_t bit = YASL_BUTTON_BIT(ev->pointer.button); + buttons = ev->type == YASL_EVENT_POINTER_DOWN ? buttons | bit : buttons & ~bit; + } q->last_pos = ev->pointer.pos; q->has_last_pos = true; break; case YASL_EVENT_POINTER_LEAVE: + if (q->leave_ends_press) buttons = 0; + q->has_last_pos = false; + break; case YASL_EVENT_INPUT_RESET: + buttons = 0; q->has_last_pos = false; break; default: break; } + if (ev->type >= YASL_EVENT_POINTER_DOWN && ev->type <= YASL_EVENT_POINTER_LEAVE) + copy.pointer.buttons = buttons; if (q->count == q->capacity) { size_t capacity = q->capacity ? q->capacity * 2 : 32; if (capacity < q->capacity || capacity > SIZE_MAX / sizeof(*q->events)) @@ -74,6 +87,7 @@ bool input_queue_push(struct input_queue *q, const struct yasl_event *ev) } q->events[(q->head + q->count) & (q->capacity - 1)] = copy; q->count++; + q->buttons = buttons; return true; failed: @@ -84,6 +98,7 @@ failed: q->reset_surface = ev->surface; q->reset_pending = true; q->has_last_pos = false; + q->buttons = 0; return false; } |
