Skip to content

Commit 47fa043

Browse files
Persist window minimized state
1 parent 5ed5468 commit 47fa043

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

libs/s25main/Settings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ void Settings::LoadIngame()
350350
windows.persistentSettings[window.first].lastPos.x = iniWindow->getIntValue("pos_x");
351351
windows.persistentSettings[window.first].lastPos.y = iniWindow->getIntValue("pos_y");
352352
windows.persistentSettings[window.first].isOpen = iniWindow->getIntValue("is_open");
353+
windows.persistentSettings[window.first].isMinimized = iniWindow->getValue("is_minimized", false);
353354
}
354355
} catch(std::runtime_error& e)
355356
{
@@ -502,6 +503,7 @@ void Settings::SaveIngame()
502503
iniWindow->setValue("pos_x", windows.persistentSettings[window.first].lastPos.x);
503504
iniWindow->setValue("pos_y", windows.persistentSettings[window.first].lastPos.y);
504505
iniWindow->setValue("is_open", windows.persistentSettings[window.first].isOpen);
506+
iniWindow->setValue("is_minimized", windows.persistentSettings[window.first].isMinimized);
505507
}
506508

507509
bfs::path settingsPathIngame = RTTRCONFIG.ExpandPath(s25::resources::ingameOptions);

libs/s25main/Settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct PersistentWindowSettings
2626
{
2727
DrawPoint lastPos = DrawPoint::Invalid();
2828
bool isOpen = false;
29+
bool isMinimized = false;
2930
};
3031

3132
/// Configuration class

libs/s25main/ingameWindows/IngameWindow.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,18 @@ IngameWindow::IngameWindow(unsigned id, const DrawPoint& pos, const Extent& size
5050
// Save to settings that window is open
5151
SaveOpenStatus(true);
5252

53-
// Load last position or center the window
53+
// Load lastPos before it is overwritten when restoring minimized state
54+
const auto lastPos = (windowSettings_ ? windowSettings_->lastPos : DrawPoint::Invalid());
55+
56+
// Restore minimized state
57+
if(windowSettings_ && windowSettings_->isMinimized)
58+
SetMinimized();
59+
60+
// Restore last position or center the window
5461
if(pos == posLastOrCenter)
5562
{
56-
if(windowSettings_ && windowSettings_->lastPos.isValid())
57-
SetPos(windowSettings_->lastPos);
63+
if(lastPos.isValid())
64+
SetPos(lastPos);
5865
else
5966
MoveToCenter();
6067
} else if(pos == posCenter)
@@ -128,6 +135,10 @@ void IngameWindow::SetMinimized(bool minimized)
128135
fullSize.y = iwHeight + contentOffset.y + contentOffsetEnd.y;
129136
this->isMinimized_ = minimized;
130137
Resize(fullSize);
138+
139+
// if possible save the minimized state to settings
140+
if(windowSettings_)
141+
windowSettings_->isMinimized = isMinimized_;
131142
}
132143

133144
void IngameWindow::MouseLeftDown(const MouseCoords& mc)

0 commit comments

Comments
 (0)