Skip to content

Commit

Permalink
[Workspaces] snapshot: fix coordinates for the minimized apps. (micro…
Browse files Browse the repository at this point in the history
  • Loading branch information
donlaci authored Oct 23, 2024
1 parent f33855a commit c3fe541
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
19 changes: 16 additions & 3 deletions src/modules/Workspaces/WorkspacesSnapshotTool/SnapshotUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{};

Expand Down Expand Up @@ -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,
Expand All @@ -258,15 +271,15 @@ 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,
.y = rect.top,
.width = rect.right - rect.left,
.height = rect.bottom - rect.top,
},
.monitor = getMonitorNumberFromWindowHandle(window),
.monitor = monitorNumber,
};

apps.push_back(app);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
10 changes: 9 additions & 1 deletion src/modules/Workspaces/WorkspacesSnapshotTool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c3fe541

Please sign in to comment.