diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 15:05:06 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 15:05:06 +0300 |
| commit | 98f0d51157fa2a2b8ccaae54ed4850a88d223d01 (patch) | |
| tree | 90b03d0930986620d95eb0f45c07b96e1331783c /tests/wayland/test_state.c | |
| parent | 339e1ad7adb8340732ee856d0f6f0d2c7f1455d1 (diff) | |
Simplify surface state, examples, and library installation
Diffstat (limited to 'tests/wayland/test_state.c')
| -rw-r--r-- | tests/wayland/test_state.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/wayland/test_state.c b/tests/wayland/test_state.c new file mode 100644 index 0000000..2da26e5 --- /dev/null +++ b/tests/wayland/test_state.c @@ -0,0 +1,75 @@ +#include "../../src/platform/wayland/shell.c" +#include <assert.h> + +struct notifications { + int count; + uint32_t state; +}; + +static void state_changed(struct yasl_surface *surface, uint32_t state, void *ud) +{ + struct notifications *notifications = ud; + assert(yasl_surface_state(surface) == state); + notifications->count++; + notifications->state = state; +} + +static void configure(struct wayland_surface *surface, uint32_t *states, size_t count) +{ + struct wl_array array = {.size = count * sizeof(*states), .data = states}; + toplevel_configure(surface, NULL, 640, 480, &array); + assert(surface->req_width == 640 && surface->req_height == 480); +} + +int main(void) +{ + struct notifications notifications = {0}; + struct wayland_surface surface = {.base.state = YASL_STATE_CSD}; + wayland_surface_set_callbacks(&surface, &(struct yasl_window_cbs){ + .state = state_changed}, ¬ifications); + assert(yasl_surface_state(&surface.base) == YASL_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)); + assert(notifications.count == 1); + assert(notifications.state == (YASL_STATE_CSD | YASL_STATE_FULLSCREEN | YASL_STATE_ACTIVATED)); + configure(&surface, fullscreen, sizeof(fullscreen) / sizeof(*fullscreen)); + 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); + assert(notifications.count == 2); + assert(notifications.state == (YASL_STATE_FULLSCREEN | YASL_STATE_ACTIVATED)); + toplevel_decoration_configure(&surface, NULL, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); + assert(notifications.count == 2); + + uint32_t maximized[] = {XDG_TOPLEVEL_STATE_MAXIMIZED, XDG_TOPLEVEL_STATE_SUSPENDED}; + configure(&surface, maximized, sizeof(maximized) / sizeof(*maximized)); + assert(notifications.count == 3); + assert(notifications.state == (YASL_STATE_MAXIMIZED | YASL_STATE_SUSPENDED)); + toplevel_decoration_configure(&surface, NULL, ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE); + assert(notifications.count == 4); + assert(notifications.state == (YASL_STATE_CSD | YASL_STATE_MAXIMIZED | YASL_STATE_SUSPENDED)); + + /* Each tiled edge maps to the same portable flag; changing edges alone + * leaves the reported state unchanged. */ + uint32_t edges[] = {XDG_TOPLEVEL_STATE_TILED_LEFT, XDG_TOPLEVEL_STATE_TILED_RIGHT, + 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); + assert(notifications.count == 5); + assert(notifications.state == (YASL_STATE_CSD | YASL_STATE_TILED)); + } + configure(&surface, edges, 0); + assert(notifications.count == 6); + assert(notifications.state == YASL_STATE_CSD); + + /* State still advances when applications have not installed callbacks. */ + wayland_surface_set_callbacks(&surface, NULL, NULL); + configure(&surface, fullscreen, sizeof(fullscreen) / sizeof(*fullscreen)); + assert(yasl_surface_state(&surface.base) == + (YASL_STATE_CSD | YASL_STATE_FULLSCREEN | YASL_STATE_ACTIVATED)); + assert(notifications.count == 6); + return 0; +} |
