sdl: make window resizable, enable high DPI

Tested on Linux, MacOS, and Windows.

On MacOS and Windows, we constrain the window's aspect
ratio by adjusting the size when responding to resize
events.

On Linux, I've not found a way to do so, that doesn't
result in fairly stuttery behavior and weird jumpy
behavior of the resize handle, possibly depending
on your window manager. So, black bars are displayed
around the content.
Maybe someone, at some point, finds a way.
(SDL3 seems to have SDL_SetWindowAspectRatio)

When the window is in fullscreen, black bars are
display necessarily, of course, on all systems,
unless the player GUI has exactly the same aspect
ratio as the screen...

Change-Id: I535e6617497611ea57a4c19e08e552f990859cfe
This commit is contained in:
Christian Soffke 2023-08-27 01:17:34 +02:00
parent 79191bf9bb
commit 60f3283f48
5 changed files with 127 additions and 30 deletions

View file

@ -31,6 +31,7 @@
#include "backlight.h"
#include "system.h"
#include "button-sdl.h"
#include "lcd-sdl.h"
#include "sim_tasks.h"
#include "buttonmap.h"
#include "debug.h"
@ -240,6 +241,17 @@ static bool event_handler(SDL_Event *event)
sdl_app_has_input_focus = 1;
else if (event->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
sdl_app_has_input_focus = 0;
else if(event->window.event == SDL_WINDOWEVENT_RESIZED)
{
sdl_window_needs_update();
#if !defined (__APPLE__) && !defined(__WIN32)
static unsigned long last_tick;
if (TIME_AFTER(current_tick, last_tick + HZ/20) && !button_queue_full())
button_queue_post(SDLK_UNKNOWN, 0); /* update window on main thread */
else
last_tick = current_tick;
#endif
}
break;
case SDL_KEYDOWN:
case SDL_KEYUP: