From c3fe541139a62916013f5fb0a71a7485770694e6 Mon Sep 17 00:00:00 2001 From: Laszlo Nemeth <57342539+donlaci@users.noreply.github.com> Date: Wed, 23 Oct 2024 11:34:20 +0200 Subject: [PATCH] [Workspaces] snapshot: fix coordinates for the minimized apps. (#35455) --- .../WorkspacesSnapshotTool/SnapshotUtils.cpp | 19 ++++++++++++++++--- .../WorkspacesSnapshotTool/SnapshotUtils.h | 2 +- .../WorkspacesSnapshotTool/main.cpp | 10 +++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/modules/Workspaces/WorkspacesSnapshotTool/SnapshotUtils.cpp b/src/modules/Workspaces/WorkspacesSnapshotTool/SnapshotUtils.cpp index 4642a5952e..519f2ccfa8 100644 --- a/src/modules/Workspaces/WorkspacesSnapshotTool/SnapshotUtils.cpp +++ b/src/modules/Workspaces/WorkspacesSnapshotTool/SnapshotUtils.cpp @@ -168,7 +168,7 @@ namespace SnapshotUtils return false; } - std::vector GetApps(const std::function getMonitorNumberFromWindowHandle) + std::vector GetApps(const std::function getMonitorNumberFromWindowHandle, const std::function getMonitorRect) { std::vector 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); diff --git a/src/modules/Workspaces/WorkspacesSnapshotTool/SnapshotUtils.h b/src/modules/Workspaces/WorkspacesSnapshotTool/SnapshotUtils.h index 1009c60d3c..df95bbadf3 100644 --- a/src/modules/Workspaces/WorkspacesSnapshotTool/SnapshotUtils.h +++ b/src/modules/Workspaces/WorkspacesSnapshotTool/SnapshotUtils.h @@ -4,5 +4,5 @@ namespace SnapshotUtils { - std::vector GetApps(const std::function getMonitorNumberFromWindowHandle); + std::vector GetApps(const std::function getMonitorNumberFromWindowHandle, const std::function getMonitorRect); }; diff --git a/src/modules/Workspaces/WorkspacesSnapshotTool/main.cpp b/src/modules/Workspaces/WorkspacesSnapshotTool/main.cpp index b736ce238e..8a99ea6ef5 100644 --- a/src/modules/Workspaces/WorkspacesSnapshotTool/main.cpp +++ b/src/modules/Workspaces/WorkspacesSnapshotTool/main.cpp @@ -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);