(Windows) Saves/remembers window size now too - still some edge case

when clicking maximize button - you need to then move the window
slightly in order for x/y position to be saved - just clicking maximize
alone is not enough
This commit is contained in:
twinaphex 2018-11-25 09:50:08 +01:00
parent cc4f834d74
commit 5313c50b0e
3 changed files with 54 additions and 11 deletions

View File

@ -1675,6 +1675,8 @@ static struct config_uint_setting *populate_settings_uint(settings_t *settings,
SETTING_UINT("video_stream_scale_factor", &settings->uints.video_stream_scale_factor, true, 1, false); SETTING_UINT("video_stream_scale_factor", &settings->uints.video_stream_scale_factor, true, 1, false);
SETTING_UINT("video_windowed_position_x", &settings->uints.window_position_x, true, 0, false); SETTING_UINT("video_windowed_position_x", &settings->uints.window_position_x, true, 0, false);
SETTING_UINT("video_windowed_position_y", &settings->uints.window_position_y, true, 0, false); SETTING_UINT("video_windowed_position_y", &settings->uints.window_position_y, true, 0, false);
SETTING_UINT("video_windowed_position_width", &settings->uints.window_position_width, true, 0, false);
SETTING_UINT("video_windowed_position_height", &settings->uints.window_position_height, true, 0, false);
*size = count; *size = count;

View File

@ -443,6 +443,8 @@ typedef struct settings
unsigned window_position_x; unsigned window_position_x;
unsigned window_position_y; unsigned window_position_y;
unsigned window_position_width;
unsigned window_position_height;
} uints; } uints;
struct struct

View File

@ -200,6 +200,8 @@ static bool g_win32_quit = false;
static int g_win32_pos_x = CW_USEDEFAULT; static int g_win32_pos_x = CW_USEDEFAULT;
static int g_win32_pos_y = CW_USEDEFAULT; static int g_win32_pos_y = CW_USEDEFAULT;
static unsigned g_win32_pos_width = 0;
static unsigned g_win32_pos_height = 0;
unsigned g_win32_resize_width = 0; unsigned g_win32_resize_width = 0;
unsigned g_win32_resize_height = 0; unsigned g_win32_resize_height = 0;
@ -617,8 +619,21 @@ static LRESULT win32_handle_keyboard_event(HWND hwnd, UINT message,
} }
#endif #endif
static void win32_set_position_from_config(void)
{
settings_t *settings = config_get_ptr();
if (!settings->bools.video_window_save_positions)
return;
g_win32_pos_x = settings->uints.window_position_x;
g_win32_pos_y = settings->uints.window_position_y;
g_win32_pos_width = settings->uints.window_position_width;
g_win32_pos_height= settings->uints.window_position_height;
}
static void win32_save_position(void) static void win32_save_position(void)
{ {
RECT rect;
WINDOWPLACEMENT placement; WINDOWPLACEMENT placement;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
memset(&placement, 0, sizeof(placement)); memset(&placement, 0, sizeof(placement));
@ -628,10 +643,18 @@ static void win32_save_position(void)
g_win32_pos_x = placement.rcNormalPosition.left; g_win32_pos_x = placement.rcNormalPosition.left;
g_win32_pos_y = placement.rcNormalPosition.top; g_win32_pos_y = placement.rcNormalPosition.top;
if (GetWindowRect(main_window.hwnd, &rect))
{
g_win32_pos_width = rect.right - rect.left;
g_win32_pos_height = rect.bottom - rect.top;
}
if (settings && settings->bools.video_window_save_positions) if (settings && settings->bools.video_window_save_positions)
{ {
settings->uints.window_position_x = g_win32_pos_x; settings->uints.window_position_x = g_win32_pos_x;
settings->uints.window_position_y = g_win32_pos_y; settings->uints.window_position_y = g_win32_pos_y;
settings->uints.window_position_width = g_win32_pos_width;
settings->uints.window_position_height= g_win32_pos_height;
} }
} }
@ -652,6 +675,7 @@ static LRESULT CALLBACK WndProcCommon(bool *quit, HWND hwnd, UINT message,
*quit = true; *quit = true;
break; break;
} }
win32_save_position();
break; break;
case WM_DROPFILES: case WM_DROPFILES:
{ {
@ -935,17 +959,16 @@ bool win32_window_create(void *data, unsigned style,
#endif #endif
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
#ifndef _XBOX #ifndef _XBOX
if (settings->bools.video_window_save_positions) win32_set_position_from_config();
{
g_win32_pos_x = settings->uints.window_position_x;
g_win32_pos_y = settings->uints.window_position_y;
}
main_window.hwnd = CreateWindowEx(0, main_window.hwnd = CreateWindowEx(0,
"RetroArch", "RetroArch", "RetroArch", "RetroArch",
style, style,
fullscreen ? mon_rect->left : g_win32_pos_x, fullscreen ? mon_rect->left : g_win32_pos_x,
fullscreen ? mon_rect->top : g_win32_pos_y, fullscreen ? mon_rect->top : g_win32_pos_y,
width, height, (settings->bools.video_window_save_positions) ? g_win32_pos_width :
width,
(settings->bools.video_window_save_positions) ? g_win32_pos_height :
height,
NULL, NULL, NULL, data); NULL, NULL, NULL, data);
if (!main_window.hwnd) if (!main_window.hwnd)
return false; return false;
@ -1161,9 +1184,10 @@ void win32_set_style(MONITORINFOEX *current_mon, HMONITOR *hm_to_use,
RECT *rect, RECT *mon_rect, DWORD *style) RECT *rect, RECT *mon_rect, DWORD *style)
{ {
#if !defined(_XBOX) #if !defined(_XBOX)
bool position_set_from_config = false;
settings_t *settings = config_get_ptr();
if (fullscreen) if (fullscreen)
{ {
settings_t *settings = config_get_ptr();
/* Windows only reports the refresh rates for modelines as /* Windows only reports the refresh rates for modelines as
* an integer, so video_refresh_rate needs to be rounded. Also, account * an integer, so video_refresh_rate needs to be rounded. Also, account
* for black frame insertion using video_refresh_rate set to half * for black frame insertion using video_refresh_rate set to half
@ -1198,9 +1222,24 @@ void win32_set_style(MONITORINFOEX *current_mon, HMONITOR *hm_to_use,
AdjustWindowRect(rect, *style, FALSE); AdjustWindowRect(rect, *style, FALSE);
if (settings->bools.video_window_save_positions)
{
win32_set_position_from_config();
if (g_win32_pos_width != 0 && g_win32_pos_height != 0)
position_set_from_config = true;
}
if (position_set_from_config)
{
g_win32_resize_width = *width = g_win32_pos_width;
g_win32_resize_height = *height = g_win32_pos_height;
}
else
{
g_win32_resize_width = *width = rect->right - rect->left; g_win32_resize_width = *width = rect->right - rect->left;
g_win32_resize_height = *height = rect->bottom - rect->top; g_win32_resize_height = *height = rect->bottom - rect->top;
} }
}
#endif #endif
} }