summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Soffke <christian.soffke@gmail.com>2024-12-29 15:29:29 +0100
committerChristian Soffke <christian.soffke@gmail.com>2024-12-30 01:08:12 +0100
commit9ba59477a1b42cad9eeff3678b2f56a6f54e2f75 (patch)
treee1efcd3a4146d9cd6aa5db91726bb09d501aa557
parent8ce9d9e39e56e4aba2eacb4499758c21d879c41d (diff)
downloadrockbox-9ba59477a1.tar.gz
rockbox-9ba59477a1.zip
sdl: improve window resizing on macOS
This enables smooth resizing of the window using a fixed aspect ratio, instead of snapping into the correct aspect ratio only when the resize operation has finished, by using an SDL event filter that gets events delivered during the resize operation (whereas SDL_PollEvent blocks until done on macOS). Change-Id: Ie6614e4b6f49a24469c5ee6a69721c9fbd440dae
-rw-r--r--firmware/drivers/button_queue.c4
-rw-r--r--firmware/target/hosted/sdl/button-sdl.c8
-rw-r--r--firmware/target/hosted/sdl/button-sdl.h3
-rw-r--r--firmware/target/hosted/sdl/system-sdl.c3
-rw-r--r--firmware/target/hosted/sdl/window-sdl.c4
5 files changed, 14 insertions, 8 deletions
diff --git a/firmware/drivers/button_queue.c b/firmware/drivers/button_queue.c
index 68748d1fc0..85ad251443 100644
--- a/firmware/drivers/button_queue.c
+++ b/firmware/drivers/button_queue.c
@@ -23,7 +23,7 @@
#include "kernel.h"
#include "button.h"
#ifdef HAVE_SDL
-#include "button-sdl.h"
+#include "SDL.h"
#include "window-sdl.h"
#endif
@@ -101,7 +101,7 @@ static inline void button_queue_wait(struct queue_event *evp, int timeout)
unsigned long curr_tick, remaining;
while(true)
{
- handle_sdl_events(); /* Includes window updates after resize events */
+ SDL_PumpEvents();
queue_wait_w_tmo(&button_queue, evp, TIMEOUT_NOBLOCK);
if (evp->id != SYS_TIMEOUT || timeout == TIMEOUT_NOBLOCK)
return;
diff --git a/firmware/target/hosted/sdl/button-sdl.c b/firmware/target/hosted/sdl/button-sdl.c
index 7364aefd3a..369a5b209f 100644
--- a/firmware/target/hosted/sdl/button-sdl.c
+++ b/firmware/target/hosted/sdl/button-sdl.c
@@ -382,11 +382,11 @@ static bool event_handler(SDL_Event *event)
}
#ifdef __APPLE__
-void handle_sdl_events(void)
+int sdl_event_filter(void *userdata, SDL_Event * event)
{
- SDL_Event event;
- while(SDL_PollEvent(&event))
- event_handler(&event);
+ (void) userdata;
+ event_handler(event);
+ return 0;
}
#endif
diff --git a/firmware/target/hosted/sdl/button-sdl.h b/firmware/target/hosted/sdl/button-sdl.h
index dd6322c884..1dfc0b7828 100644
--- a/firmware/target/hosted/sdl/button-sdl.h
+++ b/firmware/target/hosted/sdl/button-sdl.h
@@ -25,11 +25,12 @@
#include <stdbool.h>
#include "config.h"
+#include "SDL.h"
extern int sdl_app_has_input_focus;
#ifdef __APPLE__
-void handle_sdl_events(void);
+int sdl_event_filter(void *userdata, SDL_Event * event);
#endif
bool button_hold(void);
diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c
index 98e610b3b1..af067d8e86 100644
--- a/firmware/target/hosted/sdl/system-sdl.c
+++ b/firmware/target/hosted/sdl/system-sdl.c
@@ -33,6 +33,7 @@
#include "system-sdl.h"
#include "sim-ui-defines.h"
#include "window-sdl.h"
+#include "button-sdl.h"
#include "lcd-bitmap.h"
#ifdef HAVE_REMOTE_LCD
#include "lcd-remote-bitmap.h"
@@ -235,6 +236,8 @@ void system_init(void)
SDL_SemWait(s);
/* cleanup */
SDL_DestroySemaphore(s);
+#else
+ SDL_AddEventWatch(sdl_event_filter, NULL);
#endif
}
diff --git a/firmware/target/hosted/sdl/window-sdl.c b/firmware/target/hosted/sdl/window-sdl.c
index cbb38386c1..fce800d471 100644
--- a/firmware/target/hosted/sdl/window-sdl.c
+++ b/firmware/target/hosted/sdl/window-sdl.c
@@ -81,8 +81,10 @@ static void restore_aspect_ratio(int w, int h)
SDL_GetWindowSize(sdlWindow, &w, &h);
if (w != original_width || h != original_height)
{
+ SDL_DisplayMode sdl_dm;
h = w * aspect_ratio;
- SDL_SetWindowSize(sdlWindow, w, h);
+ if (SDL_GetCurrentDisplayMode(0, &sdl_dm) || h <= sdl_dm.h)
+ SDL_SetWindowSize(sdlWindow, w, h);
}
}
#endif