From d80056a233350a05ee0271190ebd3159b66d43d8 Mon Sep 17 00:00:00 2001 From: Duilio Protti Date: Sun, 3 Jul 2016 11:27:20 -0300 Subject: [PATCH] Escape key exits full-screen --- src/display.c | 14 +++++++++++--- src/display.h | 2 ++ src/infinity.c | 4 +++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/display.c b/src/display.c index 1d0b4d2..b23d11b 100644 --- a/src/display.c +++ b/src/display.c @@ -458,12 +458,20 @@ void curve(t_effect *current_effect) current_effect->x_curve = k; } +static gboolean is_in_fullscreen(void) { + return (gboolean) SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN; +} + void display_toggle_fullscreen(void) { - Uint32 is_fullscreen = SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN; - if (SDL_SetWindowFullscreen(window, is_fullscreen ? 0 : SDL_WINDOW_FULLSCREEN) < 0) + if (SDL_SetWindowFullscreen(window, is_in_fullscreen() ? 0 : SDL_WINDOW_FULLSCREEN) < 0) g_warning("Infinity cannot change fullscreen mode: %s", SDL_GetError()); - SDL_ShowCursor(is_fullscreen); + SDL_ShowCursor(is_in_fullscreen()); +} + +void display_exit_fullscreen_if_needed(void) { + if (is_in_fullscreen()) + display_toggle_fullscreen(); } inline void display_save_effect(t_effect *effect) diff --git a/src/display.h b/src/display.h index 773f765..64d1b15 100644 --- a/src/display.h +++ b/src/display.h @@ -83,6 +83,8 @@ void curve(t_effect *current_effect); */ void display_toggle_fullscreen(void); +void display_exit_fullscreen_if_needed(void); + void display_save_effect(t_effect *effect); void display_load_random_effect(t_effect *effect); diff --git a/src/infinity.c b/src/infinity.c index 08c015a..116549a 100644 --- a/src/infinity.c +++ b/src/infinity.c @@ -266,7 +266,9 @@ static void check_events() case SDLK_b: player->next(); break; case SDLK_F11: - display_toggle_fullscreen(); break; + display_toggle_fullscreen(); break; + case SDLK_ESCAPE: + display_exit_fullscreen_if_needed(); break; case SDLK_F12: if (t_last_color > 32) { t_last_color = 0;