From f6bfe676324f6a0632a22c287675169893ef2ff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ed=C3=AAnis=20Freindorfer=20Azevedo?= Date: Tue, 4 Jun 2019 23:29:40 -0300 Subject: [PATCH] Have better support for maximized window. Currently, if we maximize the window, our windowPosition{X,Y} become 0. When reopening the app, we have a window with the same size of a maximized, but without this property toggled on. This is not intuitive for users, since it is expected to have the last non-maximized size to be restored. --- src/common/ConfigManager.cpp | 6 +++-- src/common/ConfigManager.h | 5 ++-- src/wx/opts.cpp | 1 + src/wx/wxvbam.cpp | 45 ++++++++++++++++++++++++++++-------- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/common/ConfigManager.cpp b/src/common/ConfigManager.cpp index 7b68f4ae..03e910cd 100644 --- a/src/common/ConfigManager.cpp +++ b/src/common/ConfigManager.cpp @@ -243,8 +243,9 @@ int videoOption; int vsync; int wasPaused = 0; uint32_t windowHeight; -int windowPositionX; -int windowPositionY; +int windowMaximized; +int windowPositionX, bkpPosX = 0; +int windowPositionY, bkpPosY = 0; uint32_t windowWidth; int winFlashSize; int winGbBorderOn; @@ -555,6 +556,7 @@ void LoadConfig() videoOption = ReadPref("video", 2); // VIDEO_3X = 2 vsync = ReadPref("vsync", false); windowHeight = ReadPref("windowHeight", 0); + windowMaximized = ReadPref("windowMaximized", 0); windowPositionX = ReadPref("windowX", -1); windowPositionY = ReadPref("windowY", -1); windowWidth = ReadPref("windowWidth", 0); diff --git a/src/common/ConfigManager.h b/src/common/ConfigManager.h index 0ad42024..d7fbe81d 100644 --- a/src/common/ConfigManager.h +++ b/src/common/ConfigManager.h @@ -133,8 +133,9 @@ extern int videoOption; extern int vsync; extern int wasPaused; extern uint32_t windowHeight; -extern int windowPositionX; -extern int windowPositionY; +extern int windowMaximized; +extern int windowPositionX, bkpPosX; +extern int windowPositionY, bkpPosY; extern uint32_t windowWidth; extern int winFlashSize; extern int winGbBorderOn; diff --git a/src/wx/opts.cpp b/src/wx/opts.cpp index 957a391f..cd098b3f 100644 --- a/src/wx/opts.cpp +++ b/src/wx/opts.cpp @@ -277,6 +277,7 @@ opt_desc opts[] = { /// Geometry INTOPT("geometry/fullScreen", "Fullscreen", wxTRANSLATE("Enter fullscreen mode at startup"), fullScreen, 0, 1), + INTOPT("geometry/isMaximized", "Maximized", wxTRANSLATE("Window maximized"), windowMaximized, 0, 1), UINTOPT("geometry/windowHeight", "Height", wxTRANSLATE("Window height at startup"), windowHeight, 0, 99999), UINTOPT("geometry/windowWidth", "Width", wxTRANSLATE("Window width at startup"), windowWidth, 0, 99999), INTOPT("geometry/windowX", "X", wxTRANSLATE("Window axis X position at startup"), windowPositionX, -1, 99999), diff --git a/src/wx/wxvbam.cpp b/src/wx/wxvbam.cpp index 084ccc84..a59ecc5d 100644 --- a/src/wx/wxvbam.cpp +++ b/src/wx/wxvbam.cpp @@ -408,6 +408,7 @@ bool wxvbamApp::OnInit() int width = windowWidth; int height = windowHeight; int isFullscreen = fullScreen; + int isMaximized = windowMaximized; frame = wxDynamicCast(xr->LoadFrame(NULL, wxT("MainFrame")), MainFrame); if (!frame) { @@ -422,9 +423,13 @@ bool wxvbamApp::OnInit() if (x >= 0 && y >= 0 && width > 0 && height > 0) frame->SetSize(x, y, width, height); + if (isMaximized) + frame->Maximize(); + if (isFullscreen && wxGetApp().pending_load != wxEmptyString) frame->ShowFullScreen(isFullscreen); frame->Show(true); + return true; } @@ -706,7 +711,7 @@ EVT_SIZE(MainFrame::OnSize) // This is a feature most people don't like, and it causes problems with // keyboard game keys on mac, so we will disable it for now. // -// On Winodws, there will still be a pause because of how the windows event +// On Windows, there will still be a pause because of how the windows event // model works, in addition the audio will loop with SDL, so we still pause on // Windows, TODO: this needs to be fixed properly // @@ -761,10 +766,20 @@ void MainFrame::OnMove(wxMoveEvent& event) (void)event; // unused params wxPoint pos = GetScreenPosition(); int x = pos.x, y = pos.y; - if (x >= 0 && y >= 0 && !IsFullScreen()) + if (!IsFullScreen() && !IsMaximized()) { - windowPositionX = x; - windowPositionY = y; + if (x >= 0 && y >= 0) + { + bkpPosX = windowPositionX; + bkpPosY = windowPositionY; + windowPositionX = x; + windowPositionY = y; + } + } + else + { + windowPositionX = bkpPosX; + windowPositionY = bkpPosY; } update_opts(); } @@ -777,16 +792,26 @@ void MainFrame::OnSize(wxSizeEvent& event) int height = pos.GetHeight(), width = pos.GetWidth(); int x = windowPos.x, y = windowPos.y; bool isFullscreen = IsFullScreen(); - if (height > 0 && width > 0 && !isFullscreen) + bool isMaximized = IsMaximized(); + if (!isFullscreen && !isMaximized) { - windowHeight = height; - windowWidth = width; + if (height > 0 && width > 0) + { + windowHeight = height; + windowWidth = width; + } + if (x >= 0 && y >= 0) + { + windowPositionX = x; + windowPositionY = y; + } } - if (x >= 0 && y >= 0 && !isFullscreen) + else { - windowPositionX = x; - windowPositionY = y; + windowPositionX = bkpPosX; + windowPositionY = bkpPosY; } + windowMaximized = isMaximized; fullScreen = isFullscreen; update_opts(); }