diff --git a/SDL/gui.c b/SDL/gui.c index a492840..deb3ebb 100644 --- a/SDL/gui.c +++ b/SDL/gui.c @@ -2132,6 +2132,20 @@ void convert_mouse_coordinates(signed *x, signed *y) } } +void update_swap_interval(void) +{ + SDL_DisplayMode mode; + SDL_GetCurrentDisplayMode(SDL_GetWindowDisplayIndex(window), &mode); + if (mode.refresh_rate >= 60) { + if (SDL_GL_SetSwapInterval(1)) { + SDL_GL_SetSwapInterval(0); + } + } + else { + SDL_GL_SetSwapInterval(0); + } +} + void run_gui(bool is_running) { SDL_ShowCursor(SDL_ENABLE); @@ -2355,6 +2369,9 @@ void run_gui(bool is_running) } } switch (event.type) { + case SDL_DISPLAYEVENT: + update_swap_interval(); + break; case SDL_QUIT: { if (!is_running) { exit(0); @@ -2370,6 +2387,13 @@ void run_gui(bool is_running) update_viewport(); render_texture(NULL, NULL); } + if (event.window.type == SDL_WINDOWEVENT_MOVED +#if SDL_COMPILEDVERSION > 2018 + || event.window.type == SDL_WINDOWEVENT_DISPLAY_CHANGED +#endif + ) { + update_swap_interval(); + } break; } case SDL_DROPFILE: { @@ -2514,6 +2538,7 @@ void run_gui(bool is_running) else { SDL_SetWindowFullscreen(window, 0); } + update_swap_interval(); update_viewport(); } else if (event_hotkey_code(&event) == SDL_SCANCODE_O) { diff --git a/SDL/gui.h b/SDL/gui.h index 8f7cf03..86577e0 100644 --- a/SDL/gui.h +++ b/SDL/gui.h @@ -66,3 +66,4 @@ extern unsigned osd_countdown; extern unsigned osd_text_lines; void convert_mouse_coordinates(signed *x, signed *y); const GB_palette_t *current_dmg_palette(void); +void update_swap_interval(void); diff --git a/SDL/main.c b/SDL/main.c index d4dd9b7..00bf8ee 100644 --- a/SDL/main.c +++ b/SDL/main.c @@ -207,6 +207,9 @@ static void handle_events(GB_gameboy_t *gb) SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { + case SDL_DISPLAYEVENT: + update_swap_interval(); + break; case SDL_QUIT: pending_command = GB_SDL_QUIT_COMMAND; break; @@ -227,6 +230,13 @@ static void handle_events(GB_gameboy_t *gb) if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { update_viewport(); } + if (event.window.type == SDL_WINDOWEVENT_MOVED +#if SDL_COMPILEDVERSION > 2018 + || event.window.type == SDL_WINDOWEVENT_DISPLAY_CHANGED +#endif + ) { + update_swap_interval(); + } break; } case SDL_MOUSEBUTTONDOWN: @@ -428,12 +438,13 @@ static void handle_events(GB_gameboy_t *gb) case SDL_SCANCODE_F: if (event.key.keysym.mod & MODIFIER) { - if ((SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_DESKTOP) == false) { + if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN_DESKTOP)) { SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); } else { SDL_SetWindowFullscreen(window, 0); } + update_swap_interval(); update_viewport(); } break; @@ -1128,6 +1139,7 @@ int main(int argc, char **argv) if (gl_context) { glGetIntegerv(GL_MAJOR_VERSION, &major); glGetIntegerv(GL_MINOR_VERSION, &minor); + update_swap_interval(); } if (gl_context && major * 0x100 + minor < 0x302) {