rename recapture

This commit is contained in:
Romain Vimont 2022-01-01 12:16:26 +01:00
parent 62ff6df278
commit 058322b6cb
2 changed files with 15 additions and 16 deletions

View file

@ -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;

View file

@ -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;
};