summaryrefslogtreecommitdiff
path: root/examples/game.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-13 23:52:22 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-13 23:52:22 +0300
commit563b23a33726289387193b85d90fb569631ee05f (patch)
treeddf438338034b5ab2690b531684906999e56df44 /examples/game.c
parent76073fe5fad8799e5850805f2f090af2cb62c741 (diff)
Reconnect to a restarted Wayland compositor
Windows now outlive the compositor. On connection loss YASL sends DISPLAY_LOST instead of closing every window, retries the connection on a loop timer, rebuilds each toplevel with its title, size, state and GL context, and sends DISPLAY_RESTORED. CPU windows keep their pixels; GPU renderers drop Vulkan surfaces and GL objects on loss and rebuild them on restore. - Free the dead connection's objects on the next wait, after the application has released GPU objects built on them. - Report a lost connection as an event rather than a failed wait. - Refuse window and Vulkan surface creation while offline with the new YASL_ERROR_DISCONNECTED. - Close popups, cancel drags and fail pending clipboard requests on loss. - Print only protocol errors, not ordinary disconnects. - Examples survive a restart; game.c rebinds its GL context. - Add an end-to-end test that kills Weston under CPU, GL and Vulkan windows and requires them to recover. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'examples/game.c')
-rw-r--r--examples/game.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/examples/game.c b/examples/game.c
index 79beb7c..0be4461 100644
--- a/examples/game.c
+++ b/examples/game.c
@@ -29,15 +29,20 @@ int main(int argc, char **argv)
}
yasl_gl_swap_interval(s, 1);
int result = 0, frames = 0;
+ bool online = true;
for (bool running = true; running;) {
+ /* Drain events before each frame; while the display is gone, block until it returns. */
yasl_event e;
- int n;
- while ((n = yasl_wait_event(&e, 0)) > 0) {
- if (e.type == YASL_EVENT_CLOSE || e.type == YASL_EVENT_QUIT ||
- (e.type == YASL_EVENT_KEY && e.key.key == YASL_KEY_ESCAPE)) running = false;
- if (e.type == YASL_EVENT_DISPLAY_LOST) { result = 1; running = false; }
- }
+ int n = yasl_wait_event(&e, online ? 0 : -1);
if (n < 0) { result = 1; break; }
+ if (e.type == YASL_EVENT_CLOSE || e.type == YASL_EVENT_QUIT ||
+ (e.type == YASL_EVENT_KEY && e.key.key == YASL_KEY_ESCAPE)) running = false;
+ if (e.type == YASL_EVENT_DISPLAY_LOST) online = false;
+ if (e.type == YASL_EVENT_DISPLAY_RESTORED) {
+ /* The context is new: bind it again and restore GL state here. */
+ online = yasl_gl_make_current(s) && yasl_gl_swap_interval(s, 1);
+ }
+ if (n > 0 || !online || !running) continue;
int w, h;
yasl_surface_get_framebuffer_size(s, &w, &h);
viewport(0, 0, w, h);