Skip to content
Snippets Groups Projects
Commit eb17b48c authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Use SDL_GetWindowSizeInPixels, and don't resize when maximized

Fixes sourceforge issue 126 (finally!)

Apparently, macOS "maximized" is the same as "fullscreen" in SDL.
parent 04840ca1
No related branches found
No related tags found
No related merge requests found
Pipeline #6658 failed
......@@ -458,7 +458,7 @@ static void internal_setwinsize(struct video_stats *vs, bool force)
}
else {
pthread_mutex_lock(&win_mutex);
sdl.GetWindowSize(win, &w, &h);
sdl.GetWindowSizeInPixels(win, &w, &h);
pthread_mutex_unlock(&win_mutex);
if (w != vs->winwidth || h != vs->winheight)
changed = true;
......@@ -633,7 +633,7 @@ static void setup_surfaces(struct video_stats *vs)
// SDL2: This is slow sometimes... not sure why.
new_win = true;
if (sdl.CreateWindowAndRenderer(vs->winwidth, vs->winheight, flags, &win, &renderer) == 0) {
sdl.GetWindowSize(win, &idealw, &idealh);
sdl.GetWindowSizeInPixels(win, &idealw, &idealh);
vs->winwidth = idealw;
vs->winheight = idealh;
sdl.RenderClear(renderer);
......@@ -655,8 +655,11 @@ static void setup_surfaces(struct video_stats *vs)
}
else {
sdl_bughack_minsize(idealmw, idealmh, false);
// Don't change window size when maximized...
if ((sdl.GetWindowFlags(win) & SDL_WINDOW_MAXIMIZED) == 0) {
sdl.SetWindowSize(win, idealw, idealh);
sdl.GetWindowSize(win, &idealw, &idealh);
}
sdl.GetWindowSizeInPixels(win, &idealw, &idealh);
vs->winwidth = idealw;
vs->winheight = idealh;
if (internal_scaling) {
......@@ -704,7 +707,7 @@ static void sdl_add_key(unsigned int keyval, struct video_stats *vs)
int w, h;
// Get current window size
sdl.GetWindowSize(win, &w, &h);
sdl.GetWindowSizeInPixels(win, &w, &h);
// Limit to max window size if available
SDL_Rect r;
if (sdl.GetDisplayUsableBounds(0, &r) == 0) {
......@@ -1038,6 +1041,8 @@ void sdl_video_event_thread(void *data)
switch(ev.window.event) {
case SDL_WINDOWEVENT_SIZE_CHANGED:
// SDL2: User resized window
case SDL_WINDOWEVENT_MAXIMIZED:
case SDL_WINDOWEVENT_RESTORED:
case SDL_WINDOWEVENT_RESIZED:
pthread_mutex_lock(&sdl_mode_mutex);
if (sdl_mode) {
......
......@@ -78,6 +78,10 @@ int load_sdl_funcs(struct sdlfuncs *sdlf)
xp_dlclose(sdl_dll);
return(-1);
}
if((sdlf->GetWindowSizeInPixels=xp_dlsym(sdl_dll, SDL_GetWindowSizeInPixels))==NULL) {
xp_dlclose(sdl_dll);
return(-1);
}
if((sdlf->SetWindowIcon=xp_dlsym(sdl_dll, SDL_SetWindowIcon))==NULL) {
xp_dlclose(sdl_dll);
return(-1);
......
......@@ -25,6 +25,7 @@ struct sdlfuncs {
void (HACK_HACK_HACK *FreeSurface) (SDL_Surface *surface);
void (HACK_HACK_HACK *SetWindowTitle) (SDL_Window *window, const char *title);
void (HACK_HACK_HACK *GetWindowSize) (SDL_Window *window, int *w, int *h);
void (HACK_HACK_HACK *GetWindowSizeInPixels) (SDL_Window *window, int *w, int *h);
void (HACK_HACK_HACK *SetWindowIcon) (SDL_Window *win, SDL_Surface *icon);
int (HACK_HACK_HACK *ShowCursor) (int toggle);
Uint32 (HACK_HACK_HACK *WasInit) (Uint32 flags);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment