Merge pull request #1940 from ts-korhonen/master

Fix window resizing not always working
This commit is contained in:
Miran Grča 2021-12-17 21:35:09 +01:00 committed by GitHub
commit ae128ebb0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 18 deletions

View File

@ -28,6 +28,8 @@
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <stdatomic.h>
#ifndef _WIN32
#include <pwd.h>
#endif
@ -96,7 +98,7 @@
/* Stuff that used to be globally declared in plat.h but is now extern there
and declared here instead. */
int dopause; /* system is paused */
int doresize; /* screen resize requested */
atomic_flag doresize; /* screen resize requested */
volatile int is_quit; /* system exit requested */
uint64_t timer_freq;
char emu_version[200]; /* version ID string */
@ -1285,9 +1287,7 @@ set_screen_size(int x, int y)
/* If the resolution has changed, let the main thread handle it. */
if ((owsx != scrnsz_x) || (owsy != scrnsz_y))
doresize = 1;
else
doresize = 0;
atomic_flag_clear(&doresize);
}

View File

@ -63,13 +63,18 @@ extern int strnicmp(const char* s1, const char* s2, size_t n);
#ifdef __cplusplus
#include <atomic>
#define atomic_flag_t std::atomic_flag
extern "C" {
#else
#include <stdatomic.h>
#define atomic_flag_t atomic_flag
#endif
/* Global variables residing in the platform module. */
extern int dopause, /* system is paused */
doresize, /* screen resize requested */
mouse_capture; /* mouse is captured in app */
extern atomic_flag_t doresize; /* screen resize requested */
extern volatile int is_quit; /* system exit requested */
#ifdef MTR_ENABLED

View File

@ -18,6 +18,7 @@
#include <inttypes.h>
#include <dlfcn.h>
#include <wchar.h>
#include <stdatomic.h>
#include <86box/86box.h>
#include <86box/keyboard.h>
@ -531,12 +532,11 @@ main_thread(void *param)
SDL_Delay(1);
/* If needed, handle a screen resize. */
if (doresize && !video_fullscreen && !is_quit) {
if (!atomic_flag_test_and_set(&doresize) && !video_fullscreen && !is_quit) {
if (vid_resize & 2)
plat_resize(fixed_size_x, fixed_size_y);
else
plat_resize(scrnsz_x, scrnsz_y);
doresize = 0;
}
}

View File

@ -35,6 +35,7 @@
#include <direct.h>
#include <wchar.h>
#include <io.h>
#include <stdatomic.h>
#define HAVE_STDARG_H
#include <86box/86box.h>
#include <86box/config.h>
@ -549,12 +550,11 @@ main_thread(void *param)
// Sleep(1);
/* If needed, handle a screen resize. */
if (doresize && !video_fullscreen && !is_quit) {
if (!atomic_flag_test_and_set(&doresize) && !video_fullscreen && !is_quit) {
if (vid_resize & 2)
plat_resize(fixed_size_x, fixed_size_y);
else
plat_resize(scrnsz_x, scrnsz_y);
doresize = 0;
}
}
@ -1161,7 +1161,7 @@ plat_setfullscreen(int on)
video_fullscreen &= 1;
video_force_resize_set(1);
if (!(on & 1))
doresize = 1;
atomic_flag_clear(&doresize);
win_mouse_init();

View File

@ -133,7 +133,7 @@ SpecifyDimensionsDialogProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM
scrnsz_x = fixed_size_x;
scrnsz_y = fixed_size_y;
doresize = 1;
atomic_flag_clear(&doresize);
GetWindowRect(hwndMain, &r);

View File

@ -671,7 +671,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
scrnsz_x = unscaled_size_x;
scrnsz_y = unscaled_size_y;
doresize = 1;
atomic_flag_clear(&doresize);
config_save();
break;
@ -770,7 +770,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
reset_screen_size();
device_force_redraw();
video_force_resize_set(1);
doresize = 1;
atomic_flag_clear(&doresize);
config_save();
break;
@ -785,7 +785,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
case IDM_VID_HIDPI:
dpi_scale = !dpi_scale;
CheckMenuItem(hmenu, IDM_VID_HIDPI, dpi_scale ? MF_CHECKED : MF_UNCHECKED);
doresize = 1;
atomic_flag_clear(&doresize);
config_save();
break;
@ -946,7 +946,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
else
ResizeWindowByClientArea(hwndMain, temp_x, temp_y + sbar_height);
} else if (!user_resize)
doresize = 1;
atomic_flag_clear(&doresize);
break;
case WM_WINDOWPOSCHANGED:
@ -991,13 +991,13 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
if (temp_x != scrnsz_x || temp_y != scrnsz_y) {
scrnsz_x = temp_x;
scrnsz_y = temp_y;
doresize = 1;
atomic_flag_clear(&doresize);
}
} else {
if (rect.right != scrnsz_x || rect.bottom != scrnsz_y) {
scrnsz_x = rect.right;
scrnsz_y = rect.bottom;
doresize = 1;
atomic_flag_clear(&doresize);
}
}
@ -1159,7 +1159,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
/* If window is not resizable, then tell the main thread to
resize it, as sometimes, moves can mess up the window size. */
if (!vid_resize)
doresize = 1;
atomic_flag_clear(&doresize);
break;
}