summaryrefslogtreecommitdiff
path: root/tests/common
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-13 16:57:59 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-13 16:57:59 +0300
commitcbd1fc7ee6dced7ad6beecd5b9ad56a7f977f0c4 (patch)
treec139512cba169031becf6cc2bc2b0429a2e1546a /tests/common
parentefca84e8b5204c4d5ce28113474df0bf0b67dbf3 (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 'tests/common')
-rw-r--r--tests/common/test_contracts.c40
-rw-r--r--tests/common/test_input_alloc.c10
2 files changed, 50 insertions, 0 deletions
diff --git a/tests/common/test_contracts.c b/tests/common/test_contracts.c
index 7c1ab06..654eb1e 100644
--- a/tests/common/test_contracts.c
+++ b/tests/common/test_contracts.c
@@ -143,6 +143,45 @@ static bool native_frame(struct yasl_surface *s, const struct yasl_framebuffer *
return true;
}
+static uint32_t push_buttons(struct input_queue *q, enum yasl_event_type type,
+ enum yasl_pointer_button button)
+{
+ struct yasl_event ev = {.type = type, .pointer.button = button};
+ assert(input_queue_push(q, &ev));
+ assert(input_queue_pop(q, &ev));
+ return ev.pointer.buttons;
+}
+
+static void test_held_buttons(void)
+{
+ const uint32_t primary = YASL_BUTTON_BIT(YASL_BUTTON_PRIMARY);
+ const uint32_t secondary = YASL_BUTTON_BIT(YASL_BUTTON_SECONDARY);
+ struct input_queue q = {0};
+ assert(push_buttons(&q, YASL_EVENT_POINTER_MOTION, 0) == 0);
+ assert(push_buttons(&q, YASL_EVENT_POINTER_DOWN, YASL_BUTTON_PRIMARY) == primary);
+ assert(push_buttons(&q, YASL_EVENT_POINTER_MOTION, 0) == primary);
+ assert(push_buttons(&q, YASL_EVENT_POINTER_DOWN, YASL_BUTTON_SECONDARY) == (primary | secondary));
+ assert(push_buttons(&q, YASL_EVENT_POINTER_UP, YASL_BUTTON_PRIMARY) == secondary);
+ assert(push_buttons(&q, YASL_EVENT_POINTER_SCROLL, 0) == secondary);
+ /* X11 and Cocoa keep the press across leave; the release still follows. */
+ assert(push_buttons(&q, YASL_EVENT_POINTER_LEAVE, 0) == secondary);
+ assert(push_buttons(&q, YASL_EVENT_POINTER_UP, YASL_BUTTON_SECONDARY) == 0);
+ /* A release without a press leaves nothing held. */
+ assert(push_buttons(&q, YASL_EVENT_POINTER_UP, YASL_BUTTON_MIDDLE) == 0);
+
+ assert(push_buttons(&q, YASL_EVENT_POINTER_DOWN, YASL_BUTTON_PRIMARY) == primary);
+ struct yasl_event reset = {.type = YASL_EVENT_INPUT_RESET};
+ assert(input_queue_push(&q, &reset));
+ assert(input_queue_pop(&q, &reset));
+ assert(push_buttons(&q, YASL_EVENT_POINTER_MOTION, 0) == 0);
+
+ q.leave_ends_press = true;
+ assert(push_buttons(&q, YASL_EVENT_POINTER_DOWN, YASL_BUTTON_PRIMARY) == primary);
+ assert(push_buttons(&q, YASL_EVENT_POINTER_LEAVE, 0) == 0);
+ assert(push_buttons(&q, YASL_EVENT_POINTER_MOTION, 0) == 0);
+ input_queue_clear(&q);
+}
+
static void test_native(void)
{
const struct yasl_backend_ops ops = {.display_caps = native_caps,
@@ -332,6 +371,7 @@ int main(void)
test_timing_clock();
test_surface_state();
test_queue();
+ test_held_buttons();
test_validation();
test_native();
test_scale();
diff --git a/tests/common/test_input_alloc.c b/tests/common/test_input_alloc.c
index b999a62..7aba4b2 100644
--- a/tests/common/test_input_alloc.c
+++ b/tests/common/test_input_alloc.c
@@ -46,6 +46,16 @@ int main(void)
assert(input_queue_pop(&q, &out) && out.type == YASL_EVENT_INPUT_RESET);
assert(input_queue_pop(&q, &out) && out.key.action == YASL_KEY_RELEASE);
input_queue_clear(&q);
+
+ /* A lost event clears held buttons along with the stream. */
+ in = (struct yasl_event){.surface = surface, .type = YASL_EVENT_POINTER_DOWN};
+ assert(input_queue_push(&q, &in) && q.buttons);
+ for (size_t i = 1; i < q.capacity; i++) assert(input_queue_push(&q, &in));
+ allocations = 0;
+ assert(!input_queue_push(&q, &in));
+ allocations = -1;
+ assert(!q.buttons);
+ input_queue_clear(&q);
}
return 0;
}