summaryrefslogtreecommitdiff
path: root/tests/wayland
diff options
context:
space:
mode:
Diffstat (limited to 'tests/wayland')
-rw-r--r--tests/wayland/test_app_input.c46
-rw-r--r--tests/wayland/test_cursor.c16
-rw-r--r--tests/wayland/test_input.c8
-rw-r--r--tests/wayland/test_keyboard.c60
-rw-r--r--tests/wayland/test_tablet.c52
5 files changed, 91 insertions, 91 deletions
diff --git a/tests/wayland/test_app_input.c b/tests/wayland/test_app_input.c
index c8c5687..843f38d 100644
--- a/tests/wayland/test_app_input.c
+++ b/tests/wayland/test_app_input.c
@@ -15,15 +15,15 @@ struct test_state {
static void push_key(struct yasl_surface *s)
{
- struct yasl_input_event ev = {
+ struct yasl_event ev = {
.surface = s,
- .kind = YASL_INPUT_KEY,
+ .type = YASL_EVENT_KEY,
.key = { .key = YASL_KEY_A, .action = YASL_KEY_PRESS },
};
assert(input_queue_push(&((struct wayland_surface *)s)->input, &ev));
}
-static int on_init(void *ud, struct yasl_display *d)
+static enum yasl_app_result on_init(void *ud, struct yasl_display *d)
{
struct test_state *state = ud;
if (state->end) {
@@ -39,42 +39,42 @@ static int on_init(void *ud, struct yasl_display *d)
assert(s);
struct input_queue *queue = &((struct wayland_surface *)s)->input;
input_queue_clear(queue);
- struct yasl_input_event event = {.surface = s, .kind = YASL_INPUT_MOUSE,
- .mouse = {.kind = YASL_PTR_PRESS, .device = YASL_PTR_DEV_ERASER,
+ struct yasl_event event = {.surface = s, .type = YASL_EVENT_POINTER_DOWN,
+ .pointer = {.device = YASL_PTR_DEV_ERASER, .button = YASL_BUTTON_PRIMARY,
.pos = {12, 34}, .pen = {.pressure = 50000, .tilt_x = -20, .tilt_y = 30}}};
assert(input_queue_push(queue, &event));
- event.mouse.kind = YASL_PTR_MOTION;
- event.mouse.pos = (struct yasl_vector2i){15, 39};
+ event.type = YASL_EVENT_POINTER_MOTION;
+ event.pointer.pos = (struct yasl_vector2i){15, 39};
assert(input_queue_push(queue, &event));
- struct yasl_input_event reset = {.surface = s, .kind = YASL_INPUT_RESET};
+ struct yasl_event reset = {.surface = s, .type = YASL_EVENT_INPUT_RESET};
assert(input_queue_push(queue, &reset));
- event.mouse.device = YASL_PTR_DEV_PEN;
- event.mouse.pos = (struct yasl_vector2i){100, 200};
+ event.pointer.device = YASL_PTR_DEV_PEN;
+ event.pointer.pos = (struct yasl_vector2i){100, 200};
assert(input_queue_push(queue, &event));
push_key(s);
push_key(s);
return YASL_APP_CONTINUE;
}
-static int on_event(void *ud, const struct yasl_event *ev)
+static enum yasl_app_result on_event(void *ud, const struct yasl_event *ev)
{
struct test_state *state = ud;
- if (ev->type == YASL_EVENT_MOUSE_BUTTON) {
- assert(ev->mouse_button.device == YASL_PTR_DEV_ERASER);
- assert(ev->mouse_button.pressed && ev->mouse_button.button == 0);
- assert(ev->mouse_button.pos.x == 12 && ev->mouse_button.pos.y == 34);
- assert(ev->mouse_button.pen.pressure == 50000);
- assert(ev->mouse_button.pen.tilt_x == -20 && ev->mouse_button.pen.tilt_y == 30);
+ if (ev->type == YASL_EVENT_POINTER_DOWN) {
+ assert(ev->pointer.device == YASL_PTR_DEV_ERASER);
+ assert(ev->pointer.button == YASL_BUTTON_PRIMARY);
+ assert(ev->pointer.pos.x == 12 && ev->pointer.pos.y == 34);
+ assert(ev->pointer.pen.pressure == 50000);
+ assert(ev->pointer.pen.tilt_x == -20 && ev->pointer.pen.tilt_y == 30);
state->buttons++;
- } else if (ev->type == YASL_EVENT_MOUSE_MOTION) {
+ } else if (ev->type == YASL_EVENT_POINTER_MOTION) {
if (!state->motions) {
- assert(ev->mouse_motion.device == YASL_PTR_DEV_ERASER);
- assert(ev->mouse_motion.delta.x == 3 && ev->mouse_motion.delta.y == 5);
+ assert(ev->pointer.device == YASL_PTR_DEV_ERASER);
+ assert(ev->pointer.delta.x == 3 && ev->pointer.delta.y == 5);
} else {
- assert(ev->mouse_motion.device == YASL_PTR_DEV_PEN);
- assert(!ev->mouse_motion.delta.x && !ev->mouse_motion.delta.y);
+ assert(ev->pointer.device == YASL_PTR_DEV_PEN);
+ assert(!ev->pointer.delta.x && !ev->pointer.delta.y);
}
- assert(ev->mouse_motion.pen.pressure == 50000);
+ assert(ev->pointer.pen.pressure == 50000);
state->motions++;
} else if (ev->type == YASL_EVENT_INPUT_RESET) {
state->resets++;
diff --git a/tests/wayland/test_cursor.c b/tests/wayland/test_cursor.c
index a4a522e..eb729a3 100644
--- a/tests/wayland/test_cursor.c
+++ b/tests/wayland/test_cursor.c
@@ -76,14 +76,14 @@ int main(void)
pointer_frame(&seat, seat.pointer);
tablet_tool_motion(&tool, tool.proxy, wl_fixed_from_int(56), wl_fixed_from_int(78));
tool_frame(&tool, tool.proxy, 0);
- struct yasl_input_event event;
- assert(yasl_surface_input_poll(&surface.base, &event));
- assert(event.kind == YASL_INPUT_MOUSE && event.mouse.device == YASL_PTR_DEV_MOUSE);
- assert(event.mouse.pos.x == 12 && event.mouse.pos.y == 34);
- assert(yasl_surface_input_poll(&surface.base, &event));
- assert(event.kind == YASL_INPUT_MOUSE && event.mouse.device == YASL_PTR_DEV_PEN);
- assert(event.mouse.pos.x == 56 && event.mouse.pos.y == 78);
- assert(!yasl_surface_input_poll(&surface.base, &event));
+ struct yasl_event event;
+ assert(yasl_surface_poll_event(&surface.base, &event));
+ assert(event.type == YASL_EVENT_POINTER_MOTION && event.pointer.device == YASL_PTR_DEV_MOUSE);
+ assert(event.pointer.pos.x == 12 && event.pointer.pos.y == 34);
+ assert(yasl_surface_poll_event(&surface.base, &event));
+ assert(event.type == YASL_EVENT_POINTER_MOTION && event.pointer.device == YASL_PTR_DEV_PEN);
+ assert(event.pointer.pos.x == 56 && event.pointer.pos.y == 78);
+ assert(!yasl_surface_poll_event(&surface.base, &event));
/* Each new entry needs a request with its own serial. */
pointer_leave(&seat, seat.pointer, 12, surface.surface);
diff --git a/tests/wayland/test_input.c b/tests/wayland/test_input.c
index feff2f3..f6112b6 100644
--- a/tests/wayland/test_input.c
+++ b/tests/wayland/test_input.c
@@ -41,10 +41,10 @@ int main(void)
for (int i = 0; i < 600; i++) {
char text[32];
snprintf(text, sizeof(text), "commit-%d", i);
- struct yasl_input_event event;
- assert(wayland_surface_input_poll(&w, &event));
- assert(event.kind == YASL_INPUT_TEXT && event.surface == &w.base);
- assert(strcmp(event.text.text, text) == 0);
+ struct yasl_event event;
+ assert(wayland_surface_poll_event(&w, &event));
+ assert(event.type == YASL_EVENT_TEXT && event.surface == &w.base);
+ assert(strcmp(event.text.data, text) == 0);
}
input_queue_clear(&w.input);
return 0;
diff --git a/tests/wayland/test_keyboard.c b/tests/wayland/test_keyboard.c
index 6921322..bce0a0c 100644
--- a/tests/wayland/test_keyboard.c
+++ b/tests/wayland/test_keyboard.c
@@ -1,18 +1,18 @@
#include "../../src/platform/wayland/keyboard.c"
#include <assert.h>
-static struct yasl_input_event next(struct wayland_surface *w, enum yasl_input_kind kind)
+static struct yasl_event next(struct wayland_surface *w, enum yasl_event_type type)
{
- struct yasl_input_event ev;
- assert(yasl_surface_input_poll(&w->base, &ev));
- assert(ev.kind == kind && ev.surface == &w->base);
+ struct yasl_event ev;
+ assert(yasl_surface_poll_event(&w->base, &ev));
+ assert(ev.type == type && ev.surface == &w->base);
return ev;
}
static void empty(struct wayland_surface *w)
{
- struct yasl_input_event ev;
- assert(!yasl_surface_input_poll(&w->base, &ev));
+ struct yasl_event ev;
+ assert(!yasl_surface_poll_event(&w->base, &ev));
}
static void layout(struct seat *s, const char *name, const char *variant)
@@ -59,65 +59,65 @@ int main(void)
xkb_compose_table_unref(table);
layout(&s, "us", NULL);
key(&s, KEY_A, true);
- struct yasl_input_event ev = next(&w, YASL_INPUT_KEY);
+ struct yasl_event ev = next(&w, YASL_EVENT_KEY);
assert(ev.key.key == YASL_KEY_A && ev.key.native_code == KEY_A);
assert(ev.key.codepoint == 'a' && ev.key.shifted == 'A' && !ev.key.mods);
- assert(strcmp(next(&w, YASL_INPUT_TEXT).text.text, "a") == 0);
+ assert(strcmp(next(&w, YASL_EVENT_TEXT).text.data, "a") == 0);
modifiers(&s, XKB_MOD_NAME_SHIFT);
key(&s, KEY_A, false); /* Modifier changes cannot change physical identity. */
- ev = next(&w, YASL_INPUT_KEY);
+ ev = next(&w, YASL_EVENT_KEY);
assert(ev.key.key == YASL_KEY_A && ev.key.action == YASL_KEY_RELEASE);
assert(ev.key.mods == YASL_MOD_SHIFT);
empty(&w);
key(&s, KEY_A, true);
- next(&w, YASL_INPUT_KEY);
- assert(strcmp(next(&w, YASL_INPUT_TEXT).text.text, "A") == 0);
+ next(&w, YASL_EVENT_KEY);
+ assert(strcmp(next(&w, YASL_EVENT_TEXT).text.data, "A") == 0);
modifiers(&s, XKB_MOD_NAME_CAPS);
key(&s, KEY_A, true);
- assert(next(&w, YASL_INPUT_KEY).key.mods == YASL_MOD_CAPS);
- assert(strcmp(next(&w, YASL_INPUT_TEXT).text.text, "A") == 0);
+ assert(next(&w, YASL_EVENT_KEY).key.mods == YASL_MOD_CAPS);
+ assert(strcmp(next(&w, YASL_EVENT_TEXT).text.data, "A") == 0);
const char *shortcuts[] = {XKB_MOD_NAME_CTRL, XKB_MOD_NAME_ALT, XKB_MOD_NAME_LOGO};
for (size_t i = 0; i < sizeof(shortcuts)/sizeof(shortcuts[0]); i++) {
modifiers(&s, shortcuts[i]);
key(&s, KEY_A, true);
- next(&w, YASL_INPUT_KEY);
+ next(&w, YASL_EVENT_KEY);
empty(&w); /* Shortcut characters never leak into committed text. */
}
layout(&s, "fr", NULL);
key(&s, KEY_A, true);
- ev = next(&w, YASL_INPUT_KEY);
+ ev = next(&w, YASL_EVENT_KEY);
assert(ev.key.key == YASL_KEY_A && ev.key.codepoint == 'q');
- assert(strcmp(next(&w, YASL_INPUT_TEXT).text.text, "q") == 0);
+ assert(strcmp(next(&w, YASL_EVENT_TEXT).text.data, "q") == 0);
layout(&s, "de", NULL);
modifiers(&s, "Mod5"); /* AltGr is text input, not an Alt shortcut. */
key(&s, KEY_E, true);
- assert(next(&w, YASL_INPUT_KEY).key.key == YASL_KEY_E);
- assert(strcmp(next(&w, YASL_INPUT_TEXT).text.text, "€") == 0);
+ assert(next(&w, YASL_EVENT_KEY).key.key == YASL_KEY_E);
+ assert(strcmp(next(&w, YASL_EVENT_TEXT).text.data, "€") == 0);
layout(&s, "us", "intl");
key(&s, KEY_APOSTROPHE, true);
- next(&w, YASL_INPUT_KEY);
+ next(&w, YASL_EVENT_KEY);
empty(&w);
key(&s, KEY_E, true);
- next(&w, YASL_INPUT_KEY);
- assert(strcmp(next(&w, YASL_INPUT_TEXT).text.text, "é") == 0);
+ next(&w, YASL_EVENT_KEY);
+ assert(strcmp(next(&w, YASL_EVENT_TEXT).text.data, "é") == 0);
assert(keyboard_dispatch_key(&s, &w, KEY_E, YASL_KEY_REPEAT));
- assert(next(&w, YASL_INPUT_KEY).key.action == YASL_KEY_REPEAT);
- assert(strcmp(next(&w, YASL_INPUT_TEXT).text.text, "e") == 0);
+ assert(next(&w, YASL_EVENT_KEY).key.action == YASL_KEY_REPEAT);
+ assert(strcmp(next(&w, YASL_EVENT_TEXT).text.data, "e") == 0);
key(&s, KEY_APOSTROPHE, true);
- next(&w, YASL_INPUT_KEY);
+ next(&w, YASL_EVENT_KEY);
keyboard_reset_keys(&s, &w);
key(&s, KEY_E, true);
- next(&w, YASL_INPUT_KEY);
- assert(strcmp(next(&w, YASL_INPUT_TEXT).text.text, "e") == 0);
+ next(&w, YASL_EVENT_KEY);
+ assert(strcmp(next(&w, YASL_EVENT_TEXT).text.data, "e") == 0);
key(&s, KEY_APOSTROPHE, true);
- next(&w, YASL_INPUT_KEY);
+ next(&w, YASL_EVENT_KEY);
s.ime_focus = &w;
text_input_listener.commit_string(&s, NULL, "字");
text_input_listener.done(&s, NULL, 0);
- assert(strcmp(next(&w, YASL_INPUT_TEXT).text.text, "字") == 0);
+ assert(strcmp(next(&w, YASL_EVENT_TEXT).text.data, "字") == 0);
key(&s, KEY_E, true);
- next(&w, YASL_INPUT_KEY);
- assert(strcmp(next(&w, YASL_INPUT_TEXT).text.text, "e") == 0);
+ next(&w, YASL_EVENT_KEY);
+ assert(strcmp(next(&w, YASL_EVENT_TEXT).text.data, "e") == 0);
empty(&w);
xkb_compose_state_unref(s.compose);
xkb_state_unref(s.xkb_state);
diff --git a/tests/wayland/test_tablet.c b/tests/wayland/test_tablet.c
index 8723df2..c76ddf8 100644
--- a/tests/wayland/test_tablet.c
+++ b/tests/wayland/test_tablet.c
@@ -1,12 +1,12 @@
#include "../../src/platform/wayland/pointer.c"
#include <assert.h>
-static struct yasl_mouse_event next(struct wayland_surface *surface)
+static struct yasl_event next(struct wayland_surface *surface)
{
- struct yasl_input_event event;
- assert(yasl_surface_input_poll(&surface->base, &event));
- assert(event.surface == &surface->base && event.kind == YASL_INPUT_MOUSE);
- return event.mouse;
+ struct yasl_event event;
+ assert(yasl_surface_poll_event(&surface->base, &event));
+ assert(event.surface == &surface->base);
+ return event;
}
int main(void)
@@ -22,38 +22,38 @@ int main(void)
tool_tilt(&tool, NULL, wl_fixed_from_int(-35), wl_fixed_from_int(42));
tablet_tool_down(&tool, NULL, 1);
tool_frame(&tool, NULL, 0);
- struct yasl_mouse_event ev = next(&surface);
- assert(ev.kind == YASL_PTR_MOTION && ev.device == YASL_PTR_DEV_PEN);
- assert(ev.pos.x == 150 && ev.pos.y == 180 && ev.pen.pressure == 32768);
- assert(ev.pen.tilt_x == -35 && ev.pen.tilt_y == 42);
+ struct yasl_event ev = next(&surface);
+ assert(ev.type == YASL_EVENT_POINTER_MOTION && ev.pointer.device == YASL_PTR_DEV_PEN);
+ assert(ev.pointer.pos.x == 150 && ev.pointer.pos.y == 180 && ev.pointer.pen.pressure == 32768);
+ assert(ev.pointer.pen.tilt_x == -35 && ev.pointer.pen.tilt_y == 42);
ev = next(&surface);
- assert(ev.kind == YASL_PTR_PRESS && ev.button == 0 && ev.pen.pressure == 32768);
+ assert(ev.type == YASL_EVENT_POINTER_DOWN && ev.pointer.button == YASL_BUTTON_PRIMARY && ev.pointer.pen.pressure == 32768);
/* Stationary pressure and tilt changes are still motion samples. */
tool_pressure(&tool, NULL, 100000);
tool_tilt(&tool, NULL, wl_fixed_from_int(-120), wl_fixed_from_int(120));
tool_frame(&tool, NULL, 0);
ev = next(&surface);
- assert(ev.kind == YASL_PTR_MOTION && ev.pen.pressure == 65535);
- assert(ev.pos.x == 150 && ev.pos.y == 180);
- assert(ev.pen.tilt_x == -90 && ev.pen.tilt_y == 90);
+ assert(ev.type == YASL_EVENT_POINTER_MOTION && ev.pointer.pen.pressure == 65535);
+ assert(ev.pointer.pos.x == 150 && ev.pointer.pos.y == 180);
+ assert(ev.pointer.pen.tilt_x == -90 && ev.pointer.pen.tilt_y == 90);
tablet_tool_up(&tool, NULL);
tool_frame(&tool, NULL, 0);
ev = next(&surface);
- assert(ev.kind == YASL_PTR_RELEASE && ev.button == 0 && !ev.pen.pressure);
+ assert(ev.type == YASL_EVENT_POINTER_UP && ev.pointer.button == YASL_BUTTON_PRIMARY && !ev.pointer.pen.pressure);
tool_type(&tool, NULL, ZWP_TABLET_TOOL_V2_TYPE_ERASER);
tool_pressure(&tool, NULL, 22000);
tool_frame(&tool, NULL, 0);
- assert(next(&surface).device == YASL_PTR_DEV_ERASER);
+ assert(next(&surface).pointer.device == YASL_PTR_DEV_ERASER);
tool_wheel(&tool, NULL, 0, 1);
tool_frame(&tool, NULL, 0);
ev = next(&surface);
- assert(ev.kind == YASL_PTR_SCROLL && ev.device == YASL_PTR_DEV_ERASER);
- assert(ev.scroll.x == 0 && ev.scroll.y == 1);
+ assert(ev.type == YASL_EVENT_POINTER_SCROLL && ev.pointer.device == YASL_PTR_DEV_ERASER);
+ assert(ev.pointer.scroll.x == 0 && ev.pointer.scroll.y == 1);
tablet_tool_proximity_out(&tool, NULL);
ev = next(&surface);
- assert(ev.kind == YASL_PTR_LEAVE && ev.device == YASL_PTR_DEV_ERASER && !ev.pen.pressure);
+ assert(ev.type == YASL_EVENT_POINTER_LEAVE && ev.pointer.device == YASL_PTR_DEV_ERASER && !ev.pointer.pen.pressure);
assert(!seat.tool && !seat.tablet_focus && !seat.tool_buttons);
assert(!(yasl_display_caps(&display.base) & YASL_CAP_TABLET));
display.tablet_mgr = (void *)&display; /* Capability depends on protocol availability. */
@@ -68,12 +68,12 @@ int main(void)
pointer_axis_value120(&seat, NULL, WL_POINTER_AXIS_HORIZONTAL_SCROLL, -60);
pointer_frame(&seat, NULL);
ev = next(&surface);
- assert(ev.kind == YASL_PTR_SCROLL && ev.device == YASL_PTR_DEV_MOUSE);
- assert(ev.scroll.x == -0.5 && ev.scroll.y == 0.25);
- struct yasl_input_event unused;
- assert(!yasl_surface_input_poll(&surface.base, &unused));
+ assert(ev.type == YASL_EVENT_POINTER_SCROLL && ev.pointer.device == YASL_PTR_DEV_MOUSE);
+ assert(ev.pointer.scroll.x == -0.5 && ev.pointer.scroll.y == 0.25);
+ struct yasl_event unused;
+ assert(!yasl_surface_poll_event(&surface.base, &unused));
pointer_frame(&seat, NULL);
- assert(!yasl_surface_input_poll(&surface.base, &unused));
+ assert(!yasl_surface_poll_event(&surface.base, &unused));
/* Stops preserve offsets from the same frame. Repeated tiny movements
* must be visible immediately rather than held until a whole detent. */
@@ -84,16 +84,16 @@ int main(void)
pointer_axis_stop(&seat, NULL, 0, WL_POINTER_AXIS_VERTICAL_SCROLL);
pointer_frame(&seat, NULL);
ev = next(&surface);
- assert(ev.scroll.x == -0.25 && ev.scroll.y == 0.125);
+ assert(ev.pointer.scroll.x == -0.25 && ev.pointer.scroll.y == 0.125);
}
pointer_axis_discrete(&seat, NULL, WL_POINTER_AXIS_HORIZONTAL_SCROLL, 2);
pointer_frame(&seat, NULL);
ev = next(&surface);
- assert(ev.scroll.x == 2 && ev.scroll.y == 0);
+ assert(ev.pointer.scroll.x == 2 && ev.pointer.scroll.y == 0);
pointer_axis_value120(&seat, NULL, WL_POINTER_AXIS_VERTICAL_SCROLL, 60);
seat_pointer_reset(&seat);
pointer_frame(&seat, NULL);
- assert(!yasl_surface_input_poll(&surface.base, &unused));
+ assert(!yasl_surface_poll_event(&surface.base, &unused));
input_queue_clear(&surface.input);
return 0;
}