Skip to content

Commit 8a5db66

Browse files
authored
feat: remember window position and startup states #123
feat: remember window position and startup states
2 parents 5999e84 + fb2f21b commit 8a5db66

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
@@ -191,7 +191,7 @@ struct AppConfig {
191191

192192
// --- Window Lock Behaviors ---
193193
bool KeepWindowSizeOnNav = false;
194-
bool RememberLastWindowSize = false;
194+
bool RememberLastWindowSizeAndPosition = false;
195195
bool UpscaleSmallImagesWhenLocked = false;
196196

197197
bool ShowBorderIndicator = true;

QuickView/SettingsOverlay.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,16 +1542,16 @@ void SettingsOverlay::BuildMenu() {
15421542
g_runtime.LockWindowSize = g_config.LockWindowSize;
15431543
g_toolbar.SetLockState(g_runtime.LockWindowSize);
15441544
if (!g_config.LockWindowSize) {
1545-
g_config.RememberLastWindowSize = false;
1545+
g_config.RememberLastWindowSizeAndPosition = false;
15461546
}
15471547
SaveConfig();
15481548
};
15491549
tabVisuals.items.push_back(itemLockWindow);
15501550

15511551
tabVisuals.items.push_back({ AppStrings::Settings_Label_KeepWindowSizeOnNav, OptionType::Toggle, &g_config.KeepWindowSizeOnNav });
1552-
SettingsItem itemRememberWindow = { AppStrings::Settings_Label_RememberLastWindowSize, OptionType::Toggle, &g_config.RememberLastWindowSize };
1552+
SettingsItem itemRememberWindow = { AppStrings::Settings_Label_RememberLastWindowSizeAndPosition, OptionType::Toggle, &g_config.RememberLastWindowSizeAndPosition };
15531553
itemRememberWindow.onChange = []() {
1554-
if (g_config.RememberLastWindowSize) {
1554+
if (g_config.RememberLastWindowSizeAndPosition) {
15551555
g_config.LockWindowSize = true;
15561556
g_runtime.LockWindowSize = true;
15571557
g_toolbar.SetLockState(true);

QuickView/main.cpp

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

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

53895389
WritePrivateProfileStringW(L"View", L"ExifPanelMode", std::to_wstring(g_config.ExifPanelMode).c_str(), iniPath.c_str());
@@ -5607,7 +5607,7 @@ void LoadConfig() {
56075607

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

56135613
g_config.ExifPanelMode = GetPrivateProfileIntW(L"View", L"ExifPanelMode", 0, iniPath.c_str());
@@ -7046,9 +7046,14 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, [[maybe_unused]] LPWSTR lpCm
70467046
int screenH = GetSystemMetrics(SM_CYSCREEN);
70477047
int winW = 800;
70487048
int winH = 600;
7049+
int xPos = (screenW - winW) / 2;
7050+
int yPos = (screenH - winH) / 2;
7051+
7052+
bool startFullscreen = false;
7053+
bool startMaximized = false;
70497054

7050-
// Load last window size if RememberLastWindowSize is true
7051-
if (g_config.RememberLastWindowSize && g_config.LockWindowSize) {
7055+
// Load last window size and position if RememberLastWindowSizeAndPosition is true
7056+
if (g_config.RememberLastWindowSizeAndPosition) {
70527057
std::wstring iniPath = GetConfigPath();
70537058
if (g_config.PortableMode) {
70547059
wchar_t exePath[MAX_PATH];
@@ -7058,19 +7063,45 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, [[maybe_unused]] LPWSTR lpCm
70587063
if (lastSlash != std::wstring::npos) exeDir = exeDir.substr(0, lastSlash);
70597064
iniPath = exeDir + L"\\QuickView.ini";
70607065
}
7066+
7067+
startFullscreen = GetPrivateProfileIntW(L"View", L"LastWindowWasFullscreen", 0, iniPath.c_str()) != 0;
7068+
startMaximized = GetPrivateProfileIntW(L"View", L"LastWindowWasMaximized", 0, iniPath.c_str()) != 0;
7069+
70617070
int savedW = GetPrivateProfileIntW(L"View", L"LastWindowW", 0, iniPath.c_str());
70627071
int savedH = GetPrivateProfileIntW(L"View", L"LastWindowH", 0, iniPath.c_str());
7072+
int savedX = GetPrivateProfileIntW(L"View", L"LastWindowX", -10000, iniPath.c_str());
7073+
int savedY = GetPrivateProfileIntW(L"View", L"LastWindowY", -10000, iniPath.c_str());
7074+
70637075
if (savedW > 0 && savedH > 0) {
70647076
winW = savedW;
70657077
winH = savedH;
70667078
}
7067-
}
70687079

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

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

70767107
// [Phase 0] Start Named Pipe server on Master process.
@@ -7968,20 +7999,30 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
79687999
if (!CheckUnsavedChanges(hwnd)) return 0;
79698000

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

0 commit comments

Comments
 (0)