summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/game.c17
-rw-r--r--examples/notepad.c4
-rw-r--r--examples/simple_window.c2
-rw-r--r--examples/tablet.c2
4 files changed, 13 insertions, 12 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);
diff --git a/examples/notepad.c b/examples/notepad.c
index 92b9d44..9134653 100644
--- a/examples/notepad.c
+++ b/examples/notepad.c
@@ -1464,10 +1464,6 @@ static void on_event(struct editor *ed, const yasl_event *ev)
ed->running = false; return;
case YASL_EVENT_QUIT:
ed->running = false; return;
- case YASL_EVENT_DISPLAY_LOST:
- ed->failed = true;
- ed->running = false;
- return;
case YASL_EVENT_WINDOW:
ed->surface_scale = ev->window.scale;
diff --git a/examples/simple_window.c b/examples/simple_window.c
index 114bfbf..cb12db1 100644
--- a/examples/simple_window.c
+++ b/examples/simple_window.c
@@ -14,7 +14,7 @@ int main(int argc, char **argv)
yasl_event e;
for (;;) {
int n = yasl_wait_event(&e, smoke ? 20 : -1);
- if (n < 0 || e.type == YASL_EVENT_DISPLAY_LOST) break;
+ if (n < 0) break;
if (e.type == YASL_EVENT_CLOSE || e.type == YASL_EVENT_QUIT ||
(e.type == YASL_EVENT_KEY && e.key.key == YASL_KEY_ESCAPE)) { result = 0; break; }
if (e.type == YASL_EVENT_POINTER) {
diff --git a/examples/tablet.c b/examples/tablet.c
index dad4b30..176a82b 100644
--- a/examples/tablet.c
+++ b/examples/tablet.c
@@ -55,7 +55,7 @@ int main(int argc, char **argv)
yasl_event e;
for (;;) {
int n = yasl_wait_event(&e, smoke ? 20 : -1);
- if (n < 0 || e.type == YASL_EVENT_DISPLAY_LOST) break;
+ if (n < 0) break;
if (smoke && frames && n == 0) { result = 0; break; }
bool escape = e.type == YASL_EVENT_KEY && e.key.action == YASL_KEY_PRESS && e.key.key == YASL_KEY_ESCAPE;
if (e.type == YASL_EVENT_CLOSE || e.type == YASL_EVENT_QUIT || escape) { result = 0; break; }