[Workspaces] snapshot: fix coordinates for the minimized apps. (#35455)

This commit is contained in:
Laszlo Nemeth 2024-10-23 11:34:20 +02:00 committed by GitHub
parent f33855aaaa
commit c3fe541139
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 5 deletions

View File

@ -168,7 +168,7 @@ namespace SnapshotUtils
return false;
}
std::vector<WorkspacesData::WorkspacesProject::Application> GetApps(const std::function<unsigned int(HWND)> getMonitorNumberFromWindowHandle)
std::vector<WorkspacesData::WorkspacesProject::Application> GetApps(const std::function<unsigned int(HWND)> getMonitorNumberFromWindowHandle, const std::function<WorkspacesData::WorkspacesProject::Monitor::MonitorRect(unsigned int)> getMonitorRect)
{
std::vector<WorkspacesData::WorkspacesProject::Application> apps{};
@ -249,6 +249,19 @@ namespace SnapshotUtils
continue;
}
bool isMinimized = WindowUtils::IsMinimized(window);
unsigned int monitorNumber = getMonitorNumberFromWindowHandle(window);
if (isMinimized)
{
// set the screen area as position, the values we get for the minimized windows are out of the screens' area
WorkspacesData::WorkspacesProject::Monitor::MonitorRect monitorRect = getMonitorRect(monitorNumber);
rect.left = monitorRect.left;
rect.top = monitorRect.top;
rect.right = monitorRect.left + monitorRect.width;
rect.bottom = monitorRect.top + monitorRect.height;
}
WorkspacesData::WorkspacesProject::Application app{
.name = data.value().name,
.title = title,
@ -258,7 +271,7 @@ namespace SnapshotUtils
.commandLineArgs = L"", // GetCommandLineArgs(pid, wbemHelper),
.isElevated = IsProcessElevated(pid),
.canLaunchElevated = data.value().canLaunchElevated,
.isMinimized = WindowUtils::IsMinimized(window),
.isMinimized = isMinimized,
.isMaximized = WindowUtils::IsMaximized(window),
.position = WorkspacesData::WorkspacesProject::Application::Position{
.x = rect.left,
@ -266,7 +279,7 @@ namespace SnapshotUtils
.width = rect.right - rect.left,
.height = rect.bottom - rect.top,
},
.monitor = getMonitorNumberFromWindowHandle(window),
.monitor = monitorNumber,
};
apps.push_back(app);

View File

@ -4,5 +4,5 @@
namespace SnapshotUtils
{
std::vector<WorkspacesData::WorkspacesProject::Application> GetApps(const std::function<unsigned int(HWND)> getMonitorNumberFromWindowHandle);
std::vector<WorkspacesData::WorkspacesProject::Application> GetApps(const std::function<unsigned int(HWND)> getMonitorNumberFromWindowHandle, const std::function<WorkspacesData::WorkspacesProject::Monitor::MonitorRect(unsigned int)> getMonitorRect);
};

View File

@ -65,7 +65,15 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdLine, int cm
}
return monitorNumber;
});
}, [&](unsigned int monitorId) -> WorkspacesData::WorkspacesProject::Monitor::MonitorRect {
for (const auto& monitor : project.monitors)
{
if (monitor.number == monitorId)
{
return monitor.monitorRectDpiUnaware;
}
}
return project.monitors[0].monitorRectDpiUnaware; });
JsonUtils::Write(WorkspacesData::TempWorkspacesFile(), project);
Logger::trace(L"WorkspacesProject {}:{} created", project.name, project.id);