From 058322b6cbae8fb466c5c3517a11a50798424d48 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sat, 1 Jan 2022 12:16:26 +0100 Subject: [PATCH] rename recapture --- app/src/screen.c | 25 ++++++++++++------------- app/src/screen.h | 6 +++--- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/app/src/screen.c b/app/src/screen.c index 89a96625..ca43f0e7 100644 --- a/app/src/screen.c +++ b/app/src/screen.c @@ -366,7 +366,7 @@ screen_init(struct screen *screen, const struct screen_params *params) { screen->maximized = false; screen->event_failed = false; screen->mouse_captured = false; - screen->uncapture_key_pressed = 0; + screen->mouse_capture_key_pressed = 0; static const struct sc_video_buffer_callbacks cbs = { .on_new_frame = sc_video_buffer_on_new_frame, @@ -755,7 +755,7 @@ screen_resize_to_pixel_perfect(struct screen *screen) { } static inline bool -screen_is_uncapture_key(SDL_Keycode key) { +screen_is_mouse_capture_key(SDL_Keycode key) { return key == SDLK_LALT || key == SDLK_LGUI || key == SDLK_RGUI; } @@ -811,14 +811,14 @@ screen_handle_event(struct screen *screen, SDL_Event *event) { case SDL_KEYDOWN: if (screen->im.mp->relative_mode) { SDL_Keycode key = event->key.keysym.sym; - if (screen_is_uncapture_key(key)) { - if (!screen->uncapture_key_pressed) { - screen->uncapture_key_pressed = key; + if (screen_is_mouse_capture_key(key)) { + if (!screen->mouse_capture_key_pressed) { + screen->mouse_capture_key_pressed = key; return true; } else { - // Another uncapture key has been pressed, cancel mouse - // uncapture - screen->uncapture_key_pressed = 0; + // Another mouse capture key has been pressed, cancel + // mouse (un)capture + screen->mouse_capture_key_pressed = 0; // Do not return, the event must be forwarded to the // input manager } @@ -828,11 +828,10 @@ screen_handle_event(struct screen *screen, SDL_Event *event) { case SDL_KEYUP: if (screen->im.mp->relative_mode) { SDL_Keycode key = event->key.keysym.sym; - SDL_Keycode uncapture_key_pressed = - screen->uncapture_key_pressed; - screen->uncapture_key_pressed = 0; - if (key == uncapture_key_pressed) { - // An uncapture key has been pressed then released: + SDL_Keycode cap = screen->mouse_capture_key_pressed; + screen->mouse_capture_key_pressed = 0; + if (key == cap) { + // A mouse capture key has been pressed then released: // toggle the capture mouse mode screen_capture_mouse(screen, !screen->mouse_captured); return true; diff --git a/app/src/screen.h b/app/src/screen.h index ca32496f..f0e15a7d 100644 --- a/app/src/screen.h +++ b/app/src/screen.h @@ -52,9 +52,9 @@ struct screen { bool event_failed; // in case SDL_PushEvent() returned an error bool mouse_captured; // only relevant in relative mouse mode - // To disable mouse capture, an uncapture key (LALT, LGUI or RGUI) must be - // pressed. This variable tracks the pressed mod key. - SDL_Keycode uncapture_key_pressed; + // To enable/disable mouse capture, a mouse capture key (LALT, LGUI or + // RGUI) must be pressed. This variable tracks the pressed capture key. + SDL_Keycode mouse_capture_key_pressed; AVFrame *frame; };