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 snapshotting minimized apps #37598

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix window arranger to work with the same windows as the snapshot tool.
  • Loading branch information
donlaci committed Feb 21, 2025
commit d4e469b56325a6284ff9c1ed272d3309bfddcf27
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ namespace SnapshotUtils

auto installedApps = Utils::Apps::GetAppsList();
auto windows = WindowEnumerator::Enumerate(WindowFilter::Filter);
auto additionalWindows = WindowEnumerator::Enumerate(WindowFilter::FilterAdditional);

for (const auto window : windows)
{
@@ -93,12 +94,10 @@ namespace SnapshotUtils
continue;
}

// fix for the packaged apps that are not caught when minimized, e.g., Settings.
// fix for the packaged apps that are not caught when minimized, e.g. Settings, Microsoft ToDo, ...
if (processPath.ends_with(NonLocalizable::ApplicationFrameHost))
{
auto minWindows = WindowEnumerator::Enumerate(WindowFilter::FilterMin);

for (auto otherWindow : minWindows)
for (auto otherWindow : additionalWindows)
{
DWORD otherPid{};
GetWindowThreadProcessId(otherWindow, &otherPid);
24 changes: 24 additions & 0 deletions src/modules/Workspaces/WorkspacesWindowArranger/WindowArranger.cpp
Original file line number Diff line number Diff line change
@@ -14,6 +14,11 @@
#include <WindowProperties/WorkspacesWindowPropertyUtils.h>
#include <WorkspacesLib/PwaHelper.h>

namespace NonLocalizable
{
const std::wstring ApplicationFrameHost = L"ApplicationFrameHost.exe";
}

namespace PlacementHelper
{
// When calculating the coordinates difference (== 'distance') between 2 windows, there are additional values added to the real distance
@@ -170,6 +175,24 @@ std::optional<WindowWithDistance> WindowArranger::GetNearestWindow(const Workspa

DWORD pid{};
GetWindowThreadProcessId(window, &pid);
std::wstring title = WindowUtils::GetWindowTitle(window);

// fix for the packaged apps that are not caught when minimized, e.g. Settings, Microsoft ToDo, ...
if (processPath.ends_with(NonLocalizable::ApplicationFrameHost))
{
for (auto otherWindow : m_windowsBeforeAdditional)
{
DWORD otherPid{};
GetWindowThreadProcessId(otherWindow, &otherPid);

// searching for the window with the same title but different PID
if (pid != otherPid && title == WindowUtils::GetWindowTitle(otherWindow))
{
processPath = get_process_path(otherPid);
break;
}
}
}

auto data = Utils::Apps::GetApp(processPath, pid, m_installedApps);
if (!data.has_value())
@@ -237,6 +260,7 @@ std::optional<WindowWithDistance> WindowArranger::GetNearestWindow(const Workspa
WindowArranger::WindowArranger(WorkspacesData::WorkspacesProject project) :
m_project(project),
m_windowsBefore(WindowEnumerator::Enumerate(WindowFilter::Filter)),
m_windowsBeforeAdditional(WindowEnumerator::Enumerate(WindowFilter::FilterAdditional)),
m_monitors(MonitorUtils::IdentifyMonitors()),
m_installedApps(Utils::Apps::GetAppsList()),
m_ipcHelper(IPCHelperStrings::WindowArrangerPipeName, IPCHelperStrings::LauncherArrangerPipeName, std::bind(&WindowArranger::receiveIpcMessage, this, std::placeholders::_1)),
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ class WindowArranger
private:
const WorkspacesData::WorkspacesProject m_project;
const std::vector<HWND> m_windowsBefore;
const std::vector<HWND> m_windowsBeforeAdditional;
const std::vector<WorkspacesData::WorkspacesProject::Monitor> m_monitors;
const Utils::Apps::AppList m_installedApps;
//const WindowCreationHandler m_windowCreationHandler;
9 changes: 3 additions & 6 deletions src/modules/Workspaces/workspaces-common/WindowFilter.h
Original file line number Diff line number Diff line change
@@ -63,7 +63,9 @@ namespace WindowFilter
return true;
}

inline bool FilterMin(HWND window)
// the FilterAdditional() filter method is similar to the Filter() method (above). It does not filter out the popup styled windows
// as some packaged apps in minimized state have the same style poperties and are filtered out, which end up in not being snapshotted
inline bool FilterAdditional(HWND window)
{
auto style = GetWindowLong(window, GWL_STYLE);
auto exStyle = GetWindowLong(window, GWL_EXSTYLE);
@@ -89,11 +91,6 @@ namespace WindowFilter
return false;
}

////if (WindowFilter::FilterPopup(window))
////{
//// return false;
////}

if (!VirtualDesktop::instance().IsWindowOnCurrentDesktop(window))
{
return false;