Skip to content

Commit fb2f21b

Browse files
committed
feat: remember window position, fullscreen and maximized states on startup
- Updated AppStrings settings text for all languages to reflect the new functionality. - Modified `WM_CLOSE` to record `LastWindowWasFullscreen`, `LastWindowWasMaximized`, `LastWindowX`, and `LastWindowY` in `QuickView.ini`. - `GetWindowPlacement` is used to reliably determine the bounds rather than picking up full-screen dimensions from maximized states. - On startup, the configuration triggers checking of saved `LastWindow` settings. - Restored coordinate visibility is verified across displays using `MonitorFromRect` (better handling negative coords). - Applied `SW_MAXIMIZE` to `nCmdShow` during bootstrapping for smooth loading of maximized windows. - Fullscreen mode dynamically triggers upon creation.
1 parent e3c36a9 commit fb2f21b

5 files changed

Lines changed: 85 additions & 44 deletions

File tree

QuickView/AppStrings.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ const wchar_t *Settings_Label_WindowMinSize = nullptr;
244244
const wchar_t *Settings_Label_WindowMaxSizePercent = nullptr;
245245
const wchar_t *Settings_Label_ShowBorderIndicator = nullptr;
246246
const wchar_t *Settings_Label_KeepWindowSizeOnNav = nullptr;
247-
const wchar_t *Settings_Label_RememberLastWindowSize = nullptr;
247+
const wchar_t *Settings_Label_RememberLastWindowSizeAndPosition = nullptr;
248248
const wchar_t *Settings_Label_UpscaleSmallImagesWhenLocked = nullptr;
249249
const wchar_t *Settings_Label_EnableSmoothScaling = nullptr;
250250
const wchar_t *Settings_Label_ExifMode = nullptr;
@@ -844,8 +844,8 @@ struct EN {
844844
L"Show Edge Indicators";
845845
static constexpr const wchar_t *Settings_Label_KeepWindowSizeOnNav =
846846
L"Keep window size on navigation";
847-
static constexpr const wchar_t *Settings_Label_RememberLastWindowSize =
848-
L"Remember last window size";
847+
static constexpr const wchar_t *Settings_Label_RememberLastWindowSizeAndPosition =
848+
L"Remember last window size and position";
849849
static constexpr const wchar_t *Settings_Label_UpscaleSmallImagesWhenLocked =
850850
L"Adapt small images";
851851
static constexpr const wchar_t *Settings_Label_EnableSmoothScaling =
@@ -1270,8 +1270,8 @@ struct CN {
12701270
L"显示边界指示器";
12711271
static constexpr const wchar_t *Settings_Label_KeepWindowSizeOnNav =
12721272
L"导航时保持窗口尺寸不变";
1273-
static constexpr const wchar_t *Settings_Label_RememberLastWindowSize =
1274-
L"记住最后窗口尺寸";
1273+
static constexpr const wchar_t *Settings_Label_RememberLastWindowSizeAndPosition =
1274+
L"记住最后窗口位置和尺寸";
12751275
static constexpr const wchar_t *Settings_Label_UpscaleSmallImagesWhenLocked =
12761276
L"小于窗口尺寸图片适应窗口";
12771277
static constexpr const wchar_t *Settings_Label_EnableSmoothScaling =
@@ -1933,8 +1933,8 @@ struct TW {
19331933
L"顯示邊界指示器";
19341934
static constexpr const wchar_t *Settings_Label_KeepWindowSizeOnNav =
19351935
L"導航時保持視窗尺寸不變";
1936-
static constexpr const wchar_t *Settings_Label_RememberLastWindowSize =
1937-
L"記住最後視窗尺寸";
1936+
static constexpr const wchar_t *Settings_Label_RememberLastWindowSizeAndPosition =
1937+
L"記住最後視窗位置和尺寸";
19381938
static constexpr const wchar_t *Settings_Label_UpscaleSmallImagesWhenLocked =
19391939
L"小於視窗尺寸圖片適應視窗";
19401940
static constexpr const wchar_t *Settings_Label_EnableSmoothScaling =
@@ -2507,8 +2507,8 @@ struct JA {
25072507
L"エッジインジケーターを表示";
25082508
static constexpr const wchar_t *Settings_Label_KeepWindowSizeOnNav =
25092509
L"ナビゲーション時にウィンドウサイズを保持";
2510-
static constexpr const wchar_t *Settings_Label_RememberLastWindowSize =
2511-
L"最後のウィンドウサイズを記憶";
2510+
static constexpr const wchar_t *Settings_Label_RememberLastWindowSizeAndPosition =
2511+
L"最後のウィンドウの位置とサイズを記憶";
25122512
static constexpr const wchar_t *Settings_Label_UpscaleSmallImagesWhenLocked =
25132513
L"小さな画像をウィンドウに合わせる";
25142514
static constexpr const wchar_t *Settings_Label_EnableSmoothScaling =
@@ -3169,8 +3169,8 @@ struct RU {
31693169
L"Показывать индикаторы границ";
31703170
static constexpr const wchar_t *Settings_Label_KeepWindowSizeOnNav =
31713171
L"Не менять размер окна при навигации";
3172-
static constexpr const wchar_t *Settings_Label_RememberLastWindowSize =
3173-
L"Запоминать последний размер окна";
3172+
static constexpr const wchar_t *Settings_Label_RememberLastWindowSizeAndPosition =
3173+
L"Запоминать последние размер и положение окна";
31743174
static constexpr const wchar_t *Settings_Label_UpscaleSmallImagesWhenLocked =
31753175
L"Адаптировать мелкие изображения";
31763176
static constexpr const wchar_t *Settings_Label_EnableSmoothScaling =
@@ -3767,8 +3767,8 @@ struct DE {
37673767
L"Randindikatoren anzeigen";
37683768
static constexpr const wchar_t *Settings_Label_KeepWindowSizeOnNav =
37693769
L"Fenstergröße bei Navigation beibehalten";
3770-
static constexpr const wchar_t *Settings_Label_RememberLastWindowSize =
3771-
L"Letzte Fenstergröße merken";
3770+
static constexpr const wchar_t *Settings_Label_RememberLastWindowSizeAndPosition =
3771+
L"Letzte Fensterposition und -größe merken";
37723772
static constexpr const wchar_t *Settings_Label_UpscaleSmallImagesWhenLocked =
37733773
L"Kleine Bilder anpassen";
37743774
static constexpr const wchar_t *Settings_Label_EnableSmoothScaling =
@@ -4378,8 +4378,8 @@ struct ES {
43784378
L"Mostrar indicadores de borde";
43794379
static constexpr const wchar_t *Settings_Label_KeepWindowSizeOnNav =
43804380
L"Mantener el tamaño de la ventana al navegar";
4381-
static constexpr const wchar_t *Settings_Label_RememberLastWindowSize =
4382-
L"Recordar el último tamaño de ventana";
4381+
static constexpr const wchar_t *Settings_Label_RememberLastWindowSizeAndPosition =
4382+
L"Recordar el último tamaño y posición de la ventana";
43834383
static constexpr const wchar_t *Settings_Label_UpscaleSmallImagesWhenLocked =
43844384
L"Adaptar imágenes pequeñas";
43854385
static constexpr const wchar_t *Settings_Label_EnableSmoothScaling =
@@ -4931,8 +4931,8 @@ template <typename T> void ApplyT() {
49314931
Settings_Label_WindowMaxSizePercent = T::Settings_Label_WindowMaxSizePercent;
49324932
Settings_Label_ShowBorderIndicator = T::Settings_Label_ShowBorderIndicator;
49334933
Settings_Label_KeepWindowSizeOnNav = T::Settings_Label_KeepWindowSizeOnNav;
4934-
Settings_Label_RememberLastWindowSize =
4935-
T::Settings_Label_RememberLastWindowSize;
4934+
Settings_Label_RememberLastWindowSizeAndPosition =
4935+
T::Settings_Label_RememberLastWindowSizeAndPosition;
49364936
Settings_Label_UpscaleSmallImagesWhenLocked =
49374937
T::Settings_Label_UpscaleSmallImagesWhenLocked;
49384938
Settings_Label_EnableSmoothScaling = T::Settings_Label_EnableSmoothScaling;
@@ -5483,8 +5483,8 @@ struct FR {
54835483
L"Show Edge Indicators";
54845484
static constexpr const wchar_t *Settings_Label_KeepWindowSizeOnNav =
54855485
L"Keep window size on navigation";
5486-
static constexpr const wchar_t *Settings_Label_RememberLastWindowSize =
5487-
L"Remember last window size";
5486+
static constexpr const wchar_t *Settings_Label_RememberLastWindowSizeAndPosition =
5487+
L"Remember last window size and position";
54885488
static constexpr const wchar_t *Settings_Label_UpscaleSmallImagesWhenLocked =
54895489
L"Adapt small images";
54905490
static constexpr const wchar_t *Settings_Label_EnableSmoothScaling =

QuickView/AppStrings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ namespace AppStrings {
259259
extern const wchar_t* Settings_Label_ShowBorderIndicator;
260260

261261
extern const wchar_t* Settings_Label_KeepWindowSizeOnNav;
262-
extern const wchar_t* Settings_Label_RememberLastWindowSize;
262+
extern const wchar_t* Settings_Label_RememberLastWindowSizeAndPosition;
263263
extern const wchar_t* Settings_Label_UpscaleSmallImagesWhenLocked;
264264
extern const wchar_t* Settings_Label_EnableSmoothScaling; // New
265265
extern const wchar_t* Settings_Label_ExifMode;

QuickView/EditState.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ struct AppConfig {
185185

186186
// --- Window Lock Behaviors ---
187187
bool KeepWindowSizeOnNav = false;
188-
bool RememberLastWindowSize = false;
188+
bool RememberLastWindowSizeAndPosition = false;
189189
bool UpscaleSmallImagesWhenLocked = false;
190190

191191
bool ShowBorderIndicator = true;

QuickView/SettingsOverlay.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,16 +1526,16 @@ void SettingsOverlay::BuildMenu() {
15261526
g_runtime.LockWindowSize = g_config.LockWindowSize;
15271527
g_toolbar.SetLockState(g_runtime.LockWindowSize);
15281528
if (!g_config.LockWindowSize) {
1529-
g_config.RememberLastWindowSize = false;
1529+
g_config.RememberLastWindowSizeAndPosition = false;
15301530
}
15311531
SaveConfig();
15321532
};
15331533
tabVisuals.items.push_back(itemLockWindow);
15341534

15351535
tabVisuals.items.push_back({ AppStrings::Settings_Label_KeepWindowSizeOnNav, OptionType::Toggle, &g_config.KeepWindowSizeOnNav });
1536-
SettingsItem itemRememberWindow = { AppStrings::Settings_Label_RememberLastWindowSize, OptionType::Toggle, &g_config.RememberLastWindowSize };
1536+
SettingsItem itemRememberWindow = { AppStrings::Settings_Label_RememberLastWindowSizeAndPosition, OptionType::Toggle, &g_config.RememberLastWindowSizeAndPosition };
15371537
itemRememberWindow.onChange = []() {
1538-
if (g_config.RememberLastWindowSize) {
1538+
if (g_config.RememberLastWindowSizeAndPosition) {
15391539
g_config.LockWindowSize = true;
15401540
g_runtime.LockWindowSize = true;
15411541
g_toolbar.SetLockState(true);

QuickView/main.cpp

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5380,7 +5380,7 @@ void SaveConfig() {
53805380

53815381
// Window Lock Behaviors
53825382
WritePrivateProfileStringW(L"View", L"KeepWindowSizeOnNav", g_config.KeepWindowSizeOnNav ? L"1" : L"0", iniPath.c_str());
5383-
WritePrivateProfileStringW(L"View", L"RememberLastWindowSize", g_config.RememberLastWindowSize ? L"1" : L"0", iniPath.c_str());
5383+
WritePrivateProfileStringW(L"View", L"RememberLastWindowSizeAndPosition", g_config.RememberLastWindowSizeAndPosition ? L"1" : L"0", iniPath.c_str());
53845384
WritePrivateProfileStringW(L"View", L"UpscaleSmallImagesWhenLocked", g_config.UpscaleSmallImagesWhenLocked ? L"1" : L"0", iniPath.c_str());
53855385

53865386
WritePrivateProfileStringW(L"View", L"ExifPanelMode", std::to_wstring(g_config.ExifPanelMode).c_str(), iniPath.c_str());
@@ -5604,7 +5604,7 @@ void LoadConfig() {
56045604

56055605
// Window Lock Behaviors
56065606
g_config.KeepWindowSizeOnNav = GetPrivateProfileIntW(L"View", L"KeepWindowSizeOnNav", 0, iniPath.c_str()) != 0;
5607-
g_config.RememberLastWindowSize = GetPrivateProfileIntW(L"View", L"RememberLastWindowSize", 0, iniPath.c_str()) != 0;
5607+
g_config.RememberLastWindowSizeAndPosition = GetPrivateProfileIntW(L"View", L"RememberLastWindowSizeAndPosition", 0, iniPath.c_str()) != 0;
56085608
g_config.UpscaleSmallImagesWhenLocked = GetPrivateProfileIntW(L"View", L"UpscaleSmallImagesWhenLocked", 0, iniPath.c_str()) != 0;
56095609

56105610
g_config.ExifPanelMode = GetPrivateProfileIntW(L"View", L"ExifPanelMode", 0, iniPath.c_str());
@@ -7043,9 +7043,14 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int nCmdSh
70437043
int screenH = GetSystemMetrics(SM_CYSCREEN);
70447044
int winW = 800;
70457045
int winH = 600;
7046+
int xPos = (screenW - winW) / 2;
7047+
int yPos = (screenH - winH) / 2;
7048+
7049+
bool startFullscreen = false;
7050+
bool startMaximized = false;
70467051

7047-
// Load last window size if RememberLastWindowSize is true
7048-
if (g_config.RememberLastWindowSize && g_config.LockWindowSize) {
7052+
// Load last window size and position if RememberLastWindowSizeAndPosition is true
7053+
if (g_config.RememberLastWindowSizeAndPosition) {
70497054
std::wstring iniPath = GetConfigPath();
70507055
if (g_config.PortableMode) {
70517056
wchar_t exePath[MAX_PATH];
@@ -7055,19 +7060,45 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int nCmdSh
70557060
if (lastSlash != std::wstring::npos) exeDir = exeDir.substr(0, lastSlash);
70567061
iniPath = exeDir + L"\\QuickView.ini";
70577062
}
7063+
7064+
startFullscreen = GetPrivateProfileIntW(L"View", L"LastWindowWasFullscreen", 0, iniPath.c_str()) != 0;
7065+
startMaximized = GetPrivateProfileIntW(L"View", L"LastWindowWasMaximized", 0, iniPath.c_str()) != 0;
7066+
70587067
int savedW = GetPrivateProfileIntW(L"View", L"LastWindowW", 0, iniPath.c_str());
70597068
int savedH = GetPrivateProfileIntW(L"View", L"LastWindowH", 0, iniPath.c_str());
7069+
int savedX = GetPrivateProfileIntW(L"View", L"LastWindowX", -10000, iniPath.c_str());
7070+
int savedY = GetPrivateProfileIntW(L"View", L"LastWindowY", -10000, iniPath.c_str());
7071+
70607072
if (savedW > 0 && savedH > 0) {
70617073
winW = savedW;
70627074
winH = savedH;
70637075
}
7064-
}
70657076

7066-
int xPos = (screenW - winW) / 2;
7067-
int yPos = (screenH - winH) / 2;
7077+
if (savedX != -10000 && savedY != -10000) {
7078+
// Basic sanity check to ensure window is on screen
7079+
RECT testRect = { savedX, savedY, savedX + savedW, savedY + savedH };
7080+
HMONITOR hMon = MonitorFromRect(&testRect, MONITOR_DEFAULTTONULL);
7081+
if (hMon != NULL) {
7082+
xPos = savedX;
7083+
yPos = savedY;
7084+
}
7085+
}
7086+
}
70687087

70697088
HWND hwnd = CreateWindowExW(WS_EX_NOREDIRECTIONBITMAP, g_szClassName, g_szWindowTitle, WS_OVERLAPPEDWINDOW, xPos, yPos, winW, winH, nullptr, nullptr, hInstance, nullptr);
70707089
if (!hwnd) return 0;
7090+
7091+
if (g_config.RememberLastWindowSizeAndPosition) {
7092+
if (startMaximized) {
7093+
nCmdShow = SW_MAXIMIZE;
7094+
}
7095+
if (startFullscreen && g_config.OpenFullScreenMode == 0) {
7096+
// We set g_isFullScreen to true. But wait, WM_COMMAND IDM_FULLSCREEN toggles.
7097+
// Let's just post a message to trigger it.
7098+
PostMessage(hwnd, WM_COMMAND, IDM_FULLSCREEN, 0);
7099+
}
7100+
}
7101+
70717102
RefreshWindowDpi(hwnd);
70727103

70737104
// [Phase 0] Start Named Pipe server on Master process.
@@ -7965,20 +7996,30 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
79657996
if (!CheckUnsavedChanges(hwnd)) return 0;
79667997

79677998
// Save Last Window Size
7968-
if (g_config.RememberLastWindowSize && g_config.LockWindowSize && !IsZoomed(hwnd) && !IsIconic(hwnd) && !g_isFullScreen) {
7969-
RECT rc;
7970-
if (GetWindowRect(hwnd, &rc)) {
7971-
std::wstring iniPath = GetConfigPath();
7972-
if (g_config.PortableMode) {
7973-
wchar_t exePath[MAX_PATH];
7974-
GetModuleFileNameW(nullptr, exePath, MAX_PATH);
7975-
std::wstring exeDir = exePath;
7976-
size_t lastSlash = exeDir.find_last_of(L"\\/");
7977-
if (lastSlash != std::wstring::npos) exeDir = exeDir.substr(0, lastSlash);
7978-
iniPath = exeDir + L"\\QuickView.ini";
7999+
if (g_config.RememberLastWindowSizeAndPosition && !IsIconic(hwnd)) {
8000+
std::wstring iniPath = GetConfigPath();
8001+
if (g_config.PortableMode) {
8002+
wchar_t exePath[MAX_PATH];
8003+
GetModuleFileNameW(nullptr, exePath, MAX_PATH);
8004+
std::wstring exeDir = exePath;
8005+
size_t lastSlash = exeDir.find_last_of(L"\\/");
8006+
if (lastSlash != std::wstring::npos) exeDir = exeDir.substr(0, lastSlash);
8007+
iniPath = exeDir + L"\\QuickView.ini";
8008+
}
8009+
8010+
WritePrivateProfileStringW(L"View", L"LastWindowWasFullscreen", g_isFullScreen ? L"1" : L"0", iniPath.c_str());
8011+
WritePrivateProfileStringW(L"View", L"LastWindowWasMaximized", IsZoomed(hwnd) ? L"1" : L"0", iniPath.c_str());
8012+
8013+
if (!g_isFullScreen) {
8014+
WINDOWPLACEMENT wp = { sizeof(WINDOWPLACEMENT) };
8015+
if (GetWindowPlacement(hwnd, &wp)) {
8016+
int w = wp.rcNormalPosition.right - wp.rcNormalPosition.left;
8017+
int h = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top;
8018+
WritePrivateProfileStringW(L"View", L"LastWindowW", std::to_wstring(w).c_str(), iniPath.c_str());
8019+
WritePrivateProfileStringW(L"View", L"LastWindowH", std::to_wstring(h).c_str(), iniPath.c_str());
8020+
WritePrivateProfileStringW(L"View", L"LastWindowX", std::to_wstring(wp.rcNormalPosition.left).c_str(), iniPath.c_str());
8021+
WritePrivateProfileStringW(L"View", L"LastWindowY", std::to_wstring(wp.rcNormalPosition.top).c_str(), iniPath.c_str());
79798022
}
7980-
WritePrivateProfileStringW(L"View", L"LastWindowW", std::to_wstring(rc.right - rc.left).c_str(), iniPath.c_str());
7981-
WritePrivateProfileStringW(L"View", L"LastWindowH", std::to_wstring(rc.bottom - rc.top).c_str(), iniPath.c_str());
79828023
}
79838024
}
79848025

0 commit comments

Comments
 (0)