Use and store restored window position after minimizing the window

This commit is contained in:
2023-10-14 16:44:21 +03:00
parent 1a5606a45c
commit dca6baee49
3 changed files with 31 additions and 8 deletions

View File

@@ -472,19 +472,13 @@ namespace FlaxEditor.Modules
{
writer.WriteStartElement("Bounds");
{
var isMaximized = win.IsMaximized;
var isMinimized = win.IsMinimized;
if (isMinimized)
win.Restore(); // Restore window back to desktop to get proper client bounds
var bounds = win.ClientBounds;
if (isMinimized)
win.Minimize();
writer.WriteAttributeString("X", bounds.X.ToString(CultureInfo.InvariantCulture));
writer.WriteAttributeString("Y", bounds.Y.ToString(CultureInfo.InvariantCulture));
writer.WriteAttributeString("Width", bounds.Width.ToString(CultureInfo.InvariantCulture));
writer.WriteAttributeString("Height", bounds.Height.ToString(CultureInfo.InvariantCulture));
writer.WriteAttributeString("IsMaximized", isMaximized.ToString());
writer.WriteAttributeString("IsMinimized", isMinimized.ToString());
writer.WriteAttributeString("IsMaximized", win.IsMaximized.ToString());
writer.WriteAttributeString("IsMinimized", win.IsMinimized.ToString());
}
writer.WriteEndElement();
}

View File

@@ -532,6 +532,12 @@ Float2 WindowsWindow::ClientToScreen(const Float2& clientPos) const
{
ASSERT(HasHWND());
if (_minimized)
{
// Return cached position when window is not on screen
return _minimizedScreenPosition + clientPos;
}
POINT p;
p.x = static_cast<LONG>(clientPos.X);
p.y = static_cast<LONG>(clientPos.Y);
@@ -1109,6 +1115,28 @@ LRESULT WindowsWindow::WndProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
if (SIZE_MINIMIZED == wParam)
{
// Get the minimized window position in workspace coordinates
WINDOWPLACEMENT placement;
placement.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(_handle, &placement);
// Calculate client offsets from window borders and title bar
RECT winRect = { 0, 0, static_cast<LONG>(_clientSize.X), static_cast<LONG>(_clientSize.Y) };
LONG style = GetWindowLong(_handle, GWL_STYLE);
LONG exStyle = GetWindowLong(_handle, GWL_EXSTYLE);
AdjustWindowRectEx(&winRect, style, FALSE, exStyle);
// Calculate monitor offsets from taskbar position
const HMONITOR monitor = MonitorFromWindow(_handle, MONITOR_DEFAULTTONEAREST);
MONITORINFO monitorInfo;
monitorInfo.cbSize = sizeof(MONITORINFO);
GetMonitorInfoW(monitor, &monitorInfo);
// Convert the workspace coordinates to screen space and store it
_minimizedScreenPosition = Float2(
static_cast<float>(placement.rcNormalPosition.left + monitorInfo.rcWork.left - monitorInfo.rcMonitor.left - winRect.left),
static_cast<float>(placement.rcNormalPosition.top + monitorInfo.rcWork.top - monitorInfo.rcMonitor.top - winRect.top));
_minimized = true;
_maximized = false;
}

View File

@@ -32,6 +32,7 @@ private:
Windows::HANDLE _monitor = nullptr;
Windows::LONG _clipCursorRect[4];
int32 _regionWidth = 0, _regionHeight = 0;
Float2 _minimizedScreenPosition = Float2::Zero;
public: