summaryrefslogtreecommitdiff
path: root/tests/wayland/test_state.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/wayland/test_state.c')
-rw-r--r--tests/wayland/test_state.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/tests/wayland/test_state.c b/tests/wayland/test_state.c
index 1ce9189..c02e01b 100644
--- a/tests/wayland/test_state.c
+++ b/tests/wayland/test_state.c
@@ -20,12 +20,15 @@ struct notifications {
uint32_t state;
};
-static void state_changed(struct yasl_surface *surface, uint32_t state, void *ud)
+static void collect(struct yasl_private_display *display, struct notifications *notifications)
{
- struct notifications *notifications = ud;
- assert(yasl_private_surface_state(surface) == state);
- notifications->count++;
- notifications->state = state;
+ struct yasl_private_event event;
+ while (yasl_private_display_poll_event(display, &event)) {
+ assert(event.type == YASL_PRIVATE_EVENT_WINDOW_STATE);
+ assert(yasl_private_surface_state(event.surface) == event.state.flags);
+ notifications->count++;
+ notifications->state = event.state.flags;
+ }
}
static void configure(struct wayland_surface *surface, uint32_t *states, size_t count)
@@ -38,31 +41,39 @@ static void configure(struct wayland_surface *surface, uint32_t *states, size_t
int main(void)
{
struct notifications notifications = {0};
- struct wayland_surface surface = {.base.state = YASL_PRIVATE_STATE_CSD};
- wayland_surface_set_callbacks(&surface, &(struct yasl_private_window_cbs){
- .state = state_changed}, &notifications);
+ const struct yasl_private_backend_ops ops = {0};
+ struct yasl_private_display display = {.ops = &ops};
+ struct wayland_surface surface = {.base = {.display = &display, .state = YASL_PRIVATE_STATE_CSD}};
+ assert(yasl_private_events_open(&display));
+ assert(yasl_private_events_register(&surface.base));
assert(yasl_private_surface_state(&surface.base) == YASL_PRIVATE_STATE_CSD);
uint32_t fullscreen[] = {XDG_TOPLEVEL_STATE_FULLSCREEN,
XDG_TOPLEVEL_STATE_ACTIVATED, XDG_TOPLEVEL_STATE_FULLSCREEN, 31, UINT32_MAX};
configure(&surface, fullscreen, sizeof(fullscreen) / sizeof(*fullscreen));
+ collect(&display, &notifications);
assert(notifications.count == 1);
assert(notifications.state == (YASL_PRIVATE_STATE_CSD | YASL_PRIVATE_STATE_FULLSCREEN | YASL_PRIVATE_STATE_ACTIVATED));
configure(&surface, fullscreen, sizeof(fullscreen) / sizeof(*fullscreen));
+ collect(&display, &notifications);
assert(notifications.count == 1);
/* Decoration changes preserve the other flags and do not notify twice. */
toplevel_decoration_configure(&surface, NULL, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
+ collect(&display, &notifications);
assert(notifications.count == 2);
assert(notifications.state == (YASL_PRIVATE_STATE_FULLSCREEN | YASL_PRIVATE_STATE_ACTIVATED));
toplevel_decoration_configure(&surface, NULL, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
+ collect(&display, &notifications);
assert(notifications.count == 2);
uint32_t maximized[] = {XDG_TOPLEVEL_STATE_MAXIMIZED, XDG_TOPLEVEL_STATE_SUSPENDED};
configure(&surface, maximized, sizeof(maximized) / sizeof(*maximized));
+ collect(&display, &notifications);
assert(notifications.count == 3);
assert(notifications.state == (YASL_PRIVATE_STATE_MAXIMIZED | YASL_PRIVATE_STATE_SUSPENDED));
toplevel_decoration_configure(&surface, NULL, ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE);
+ collect(&display, &notifications);
assert(notifications.count == 4);
assert(notifications.state == (YASL_PRIVATE_STATE_CSD | YASL_PRIVATE_STATE_MAXIMIZED | YASL_PRIVATE_STATE_SUSPENDED));
@@ -72,19 +83,21 @@ int main(void)
XDG_TOPLEVEL_STATE_TILED_TOP, XDG_TOPLEVEL_STATE_TILED_BOTTOM};
for (size_t i = 0; i < sizeof(edges) / sizeof(*edges); i++) {
configure(&surface, &edges[i], 1);
+ collect(&display, &notifications);
assert(notifications.count == 5);
assert(notifications.state == (YASL_PRIVATE_STATE_CSD | YASL_PRIVATE_STATE_TILED));
}
configure(&surface, edges, 0);
+ collect(&display, &notifications);
assert(notifications.count == 6);
assert(notifications.state == YASL_PRIVATE_STATE_CSD);
- /* State still advances when applications have not installed callbacks. */
- wayland_surface_set_callbacks(&surface, NULL, NULL);
+ /* The authoritative state advances with the queued notification. */
configure(&surface, fullscreen, sizeof(fullscreen) / sizeof(*fullscreen));
assert(yasl_private_surface_state(&surface.base) ==
(YASL_PRIVATE_STATE_CSD | YASL_PRIVATE_STATE_FULLSCREEN | YASL_PRIVATE_STATE_ACTIVATED));
- assert(notifications.count == 6);
+ collect(&display, &notifications);
+ assert(notifications.count == 7);
/* External presentation has no SHM commit callback to acknowledge xdg
* configures. Apply geometry and acknowledge before renderer submission. */
@@ -106,5 +119,7 @@ int main(void)
struct wayland_surface cpu = {.base.presenter = YASL_PRIVATE_PRESENTER_CPU};
xdg_surface_configure(&cpu, (struct xdg_surface *)&cpu, 5678);
assert(acknowledge_count == 1 && cpu.has_pending_serial && cpu.want_draw);
+ yasl_private_events_unregister(&surface.base);
+ yasl_private_events_close(&display);
return 0;
}