summaryrefslogtreecommitdiff
path: root/examples/game.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-13 16:23:07 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-13 16:23:07 +0300
commit4a61a0f8a749831b74aca04302a30ebbbb6f5586 (patch)
tree0229c008d2c22de61cae36039ac8fdd9718e8c6a /examples/game.c
parent276a70a84fed5be229c12546df1ac393158a4ec9 (diff)
Track pointer capture by its result in the game example
The game assumed yasl_surface_set_pointer_mode() always succeeded, so on backends without relative mode it believed the pointer was captured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'examples/game.c')
-rw-r--r--examples/game.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/examples/game.c b/examples/game.c
index 065ff99..4517519 100644
--- a/examples/game.c
+++ b/examples/game.c
@@ -186,10 +186,11 @@ static enum yasl_app_result on_event(void *ud, const struct yasl_event *ev)
case YASL_KEY_E: game->key_e = down; break;
case YASL_KEY_SPACE:
if (ev->key.action == YASL_KEY_PRESS) {
- /* Toggle relative pointer mode */
- game->relative_mouse = !game->relative_mouse;
- yasl_surface_set_pointer_mode(game->surface,
- game->relative_mouse ? YASL_POINTER_RELATIVE : YASL_POINTER_NORMAL);
+ /* Toggle relative pointer mode; unsupported backends stay normal. */
+ game->relative_mouse = !game->relative_mouse &&
+ yasl_surface_set_pointer_mode(game->surface, YASL_POINTER_RELATIVE);
+ if (!game->relative_mouse)
+ yasl_surface_set_pointer_mode(game->surface, YASL_POINTER_NORMAL);
}
break;
case YASL_KEY_ESCAPE:
@@ -221,8 +222,8 @@ static enum yasl_app_result on_event(void *ud, const struct yasl_event *ev)
case YASL_EVENT_POINTER_DOWN:
if (!game->relative_mouse) {
/* Click window to capture cursor */
- game->relative_mouse = true;
- yasl_surface_set_pointer_mode(game->surface, YASL_POINTER_RELATIVE);
+ game->relative_mouse =
+ yasl_surface_set_pointer_mode(game->surface, YASL_POINTER_RELATIVE);
}
break;