mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-13 18:17:39 -04:00
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
This commit is contained in:
parent
8ce9d9e39e
commit
9ba59477a1
5 changed files with 14 additions and 8 deletions
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,9 @@ 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;
|
||||
if (SDL_GetCurrentDisplayMode(0, &sdl_dm) || h <= sdl_dm.h)
|
||||
SDL_SetWindowSize(sdlWindow, w, h);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue