Escape key exits full-screen

This commit is contained in:
Duilio Protti 2016-07-03 11:27:20 -03:00
parent d7ec106875
commit d80056a233
3 changed files with 16 additions and 4 deletions

View File

@ -458,12 +458,20 @@ void curve(t_effect *current_effect)
current_effect->x_curve = k; current_effect->x_curve = k;
} }
static gboolean is_in_fullscreen(void) {
return (gboolean) SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN;
}
void display_toggle_fullscreen(void) void display_toggle_fullscreen(void)
{ {
Uint32 is_fullscreen = SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN; if (SDL_SetWindowFullscreen(window, is_in_fullscreen() ? 0 : SDL_WINDOW_FULLSCREEN) < 0)
if (SDL_SetWindowFullscreen(window, is_fullscreen ? 0 : SDL_WINDOW_FULLSCREEN) < 0)
g_warning("Infinity cannot change fullscreen mode: %s", SDL_GetError()); 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) inline void display_save_effect(t_effect *effect)

View File

@ -83,6 +83,8 @@ void curve(t_effect *current_effect);
*/ */
void display_toggle_fullscreen(void); void display_toggle_fullscreen(void);
void display_exit_fullscreen_if_needed(void);
void display_save_effect(t_effect *effect); void display_save_effect(t_effect *effect);
void display_load_random_effect(t_effect *effect); void display_load_random_effect(t_effect *effect);

View File

@ -267,6 +267,8 @@ static void check_events()
player->next(); break; player->next(); break;
case SDLK_F11: case SDLK_F11:
display_toggle_fullscreen(); break; display_toggle_fullscreen(); break;
case SDLK_ESCAPE:
display_exit_fullscreen_if_needed(); break;
case SDLK_F12: case SDLK_F12:
if (t_last_color > 32) { if (t_last_color > 32) {
t_last_color = 0; t_last_color = 0;