summaryrefslogtreecommitdiff
path: root/tests/wayland/test_state.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-13 23:41:31 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-13 23:41:31 +0300
commit76073fe5fad8799e5850805f2f090af2cb62c741 (patch)
tree9658019babe4760a3634bdab4da0731a10e42e68 /tests/wayland/test_state.c
parentdd1775a9927922c14f8679ccbc4d3ca8d5917e20 (diff)
Simplify the public event and CPU API
Applications now need far less ceremony: hello.c is a 20-line loop that handles REFRESH, CLOSE and QUIT and draws into the surface's own pixels. - Fold GEOMETRY, STATE and FOCUS into one WINDOW event carrying size, scale and state; unchanged values send nothing. - Guarantee REFRESH once a window has a size and after every resize, never at size zero. - Merge DROP_HOVER into DROP with over/leave/data actions and give drag and drop actions enums. - Keep event strings valid until the next wait and drop yasl_event_release; empty or failed waits report NONE. - Replace copy-in presentation with a lent pixel buffer: yasl_cpu_pixels and yasl_cpu_present. - Remove yasl_poll_event, yasl_cpu_read_pixels, unused event fields and comments that restated names. - Wayland: resize floating windows in request_size instead of reporting it unsupported, and stop marking new GPU surfaces as Vulkan so yasl_vulkan_create_surface no longer fails with NATIVE_WINDOW_IN_USE. Also includes the in-progress public API refactor that was uncommitted in the tree (removal of the app/loop layer, new surface, GL and Vulkan entry points). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/wayland/test_state.c')
-rw-r--r--tests/wayland/test_state.c61
1 files changed, 48 insertions, 13 deletions
diff --git a/tests/wayland/test_state.c b/tests/wayland/test_state.c
index 2da26e5..1ce9189 100644
--- a/tests/wayland/test_state.c
+++ b/tests/wayland/test_state.c
@@ -1,6 +1,20 @@
-#include "../../src/platform/wayland/shell.c"
+#include "platform/wayland/internal.h"
#include <assert.h>
+static uint32_t acknowledged_serial;
+static unsigned acknowledge_count;
+static void test_ack_configure(struct xdg_surface *surface, uint32_t serial);
+#define xdg_surface_ack_configure test_ack_configure
+#include "../../src/platform/wayland/shell.c"
+#undef xdg_surface_ack_configure
+
+static void test_ack_configure(struct xdg_surface *surface, uint32_t serial)
+{
+ (void)surface;
+ acknowledged_serial = serial;
+ acknowledge_count++;
+}
+
struct notifications {
int count;
uint32_t state;
@@ -9,7 +23,7 @@ struct notifications {
static void state_changed(struct yasl_surface *surface, uint32_t state, void *ud)
{
struct notifications *notifications = ud;
- assert(yasl_surface_state(surface) == state);
+ assert(yasl_private_surface_state(surface) == state);
notifications->count++;
notifications->state = state;
}
@@ -24,33 +38,33 @@ 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_STATE_CSD};
- wayland_surface_set_callbacks(&surface, &(struct yasl_window_cbs){
+ struct wayland_surface surface = {.base.state = YASL_PRIVATE_STATE_CSD};
+ wayland_surface_set_callbacks(&surface, &(struct yasl_private_window_cbs){
.state = state_changed}, &notifications);
- assert(yasl_surface_state(&surface.base) == YASL_STATE_CSD);
+ 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));
assert(notifications.count == 1);
- assert(notifications.state == (YASL_STATE_CSD | YASL_STATE_FULLSCREEN | YASL_STATE_ACTIVATED));
+ assert(notifications.state == (YASL_PRIVATE_STATE_CSD | YASL_PRIVATE_STATE_FULLSCREEN | YASL_PRIVATE_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));
+ assert(notifications.state == (YASL_PRIVATE_STATE_FULLSCREEN | YASL_PRIVATE_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));
+ assert(notifications.state == (YASL_PRIVATE_STATE_MAXIMIZED | YASL_PRIVATE_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));
+ assert(notifications.state == (YASL_PRIVATE_STATE_CSD | YASL_PRIVATE_STATE_MAXIMIZED | YASL_PRIVATE_STATE_SUSPENDED));
/* Each tiled edge maps to the same portable flag; changing edges alone
* leaves the reported state unchanged. */
@@ -59,17 +73,38 @@ int main(void)
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));
+ assert(notifications.state == (YASL_PRIVATE_STATE_CSD | YASL_PRIVATE_STATE_TILED));
}
configure(&surface, edges, 0);
assert(notifications.count == 6);
- assert(notifications.state == YASL_STATE_CSD);
+ assert(notifications.state == YASL_PRIVATE_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(yasl_private_surface_state(&surface.base) ==
+ (YASL_PRIVATE_STATE_CSD | YASL_PRIVATE_STATE_FULLSCREEN | YASL_PRIVATE_STATE_ACTIVATED));
assert(notifications.count == 6);
+
+ /* External presentation has no SHM commit callback to acknowledge xdg
+ * configures. Apply geometry and acknowledge before renderer submission. */
+ struct wayland_surface gpu = {
+ .base.presenter = YASL_PRIVATE_PRESENTER_VULKAN,
+ .width = 0, .height = 0,
+ .logical_width = 64, .logical_height = 64,
+ .req_width = 64, .req_height = 64,
+ .scale_120 = YASL_PRIVATE_SCALE_UNIT,
+ .pending_scale_120 = 180,
+ };
+ acknowledge_count = 0;
+ xdg_surface_configure(&gpu, (struct xdg_surface *)&gpu, 1234);
+ assert(acknowledge_count == 1 && acknowledged_serial == 1234);
+ assert(!gpu.has_pending_serial && !gpu.size_pending);
+ assert(gpu.configured && gpu.width == 96 && gpu.height == 96);
+
+ /* CPU presentation keeps its existing deferred ack with the SHM commit. */
+ 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);
return 0;
}