Skip to content

Commit bc017d0

Browse files
Persist window minimized state
1 parent a3a11df commit bc017d0

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
@@ -54,11 +54,18 @@ IngameWindow::IngameWindow(unsigned id, const DrawPoint& pos, const Extent& size
5454
// Save to settings that window is open
5555
SaveOpenStatus(true);
5656

57-
// Load last position or center the window
57+
// Load lastPos before it is overwritten when restoring minimized state
58+
const auto lastPos = (windowSettings_ ? windowSettings_->lastPos : DrawPoint::Invalid());
59+
60+
// Restore minimized state
61+
if(windowSettings_ && windowSettings_->isMinimized)
62+
SetMinimized();
63+
64+
// Restore last position or center the window
5865
if(pos == posLastOrCenter)
5966
{
60-
if(windowSettings_ && windowSettings_->lastPos.isValid())
61-
SetPos(windowSettings_->lastPos);
67+
if(lastPos.isValid())
68+
SetPos(lastPos);
6269
else
6370
MoveToCenter();
6471
} else if(pos == posCenter)
@@ -132,6 +139,10 @@ void IngameWindow::SetMinimized(bool minimized)
132139
fullSize.y = iwHeight + contentOffset.y + contentOffsetEnd.y;
133140
this->isMinimized_ = minimized;
134141
Resize(fullSize);
142+
143+
// if possible save the minimized state to settings
144+
if(windowSettings_)
145+
windowSettings_->isMinimized = isMinimized_;
135146
}
136147

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

0 commit comments

Comments
 (0)