Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Workspaces] Fix case: monitor not present at launch #37005

Merged
merged 4 commits into from
Feb 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/modules/Workspaces/WorkspacesWindowArranger/WindowArranger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ namespace PlacementHelper
else
{
placement.showCmd = SW_RESTORE;

ScreenToWorkAreaCoords(window, monitor, rect);
placement.rcNormalPosition = rect;
}

ScreenToWorkAreaCoords(window, monitor, rect);
placement.rcNormalPosition = rect;
placement.flags |= WPF_ASYNCWINDOWPLACEMENT;

auto result = ::SetWindowPlacement(window, &placement);
Expand Down Expand Up @@ -430,9 +429,11 @@ bool WindowArranger::moveWindow(HWND window, const WorkspacesData::WorkspacesPro
Logger::error(L"No monitor saved for launching the app");
return false;
}
UINT snapDPI = snapMonitorIter->dpi;

bool launchMinimized = app.isMinimized;
bool launchMaximized = app.isMaximized;
RECT rect = app.position.toRect();

HMONITOR currentMonitor{};
UINT currentDpi = DPIAware::DEFAULT_DPI;
Expand All @@ -446,12 +447,18 @@ bool WindowArranger::moveWindow(HWND window, const WorkspacesData::WorkspacesPro
{
currentMonitor = MonitorFromPoint(POINT{ 0, 0 }, MONITOR_DEFAULTTOPRIMARY);
DPIAware::GetScreenDPIForMonitor(currentMonitor, currentDpi);
snapDPI = DPIAware::DEFAULT_DPI;
launchMinimized = true;
launchMaximized = false;
MONITORINFOEX monitorInfo;
monitorInfo.cbSize = sizeof(monitorInfo);
if (GetMonitorInfo(currentMonitor, &monitorInfo))
{
rect = monitorInfo.rcWork;
}
}

RECT rect = app.position.toRect();
float mult = static_cast<float>(snapMonitorIter->dpi) / currentDpi;
float mult = static_cast<float>(snapDPI) / currentDpi;
rect.left = static_cast<long>(std::round(rect.left * mult));
rect.right = static_cast<long>(std::round(rect.right * mult));
rect.top = static_cast<long>(std::round(rect.top * mult));
Expand Down
Loading