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
optimising code
  • Loading branch information
donlaci committed Feb 21, 2025
commit e3b6f0faacd636047b123816a79230f83f797b7e
13 changes: 6 additions & 7 deletions src/modules/Workspaces/WorkspacesSnapshotTool/SnapshotUtils.cpp
Original file line number Diff line number Diff line change
@@ -49,10 +49,14 @@ namespace SnapshotUtils

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

for (const auto window : windows)
{
if (WindowFilter::FilterPopup(window))
{
continue;
}

// filter by window rect size
RECT rect = WindowUtils::GetWindowRect(window);
if (rect.right - rect.left <= 0 || rect.bottom - rect.top <= 0)
@@ -97,7 +101,7 @@ namespace SnapshotUtils
// 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 : additionalWindows)
for (auto otherWindow : windows)
{
DWORD otherPid{};
GetWindowThreadProcessId(otherWindow, &otherPid);
@@ -111,11 +115,6 @@ namespace SnapshotUtils
}
}

if (WindowFilter::FilterPopup(window))
{
continue;
}

auto data = Utils::Apps::GetApp(processPath, pid, installedApps);
if (!data.has_value() || data->name.empty())
{
Original file line number Diff line number Diff line change
@@ -162,6 +162,11 @@ std::optional<WindowWithDistance> WindowArranger::GetNearestWindow(const Workspa

for (HWND window : m_windowsBefore)
{
if (WindowFilter::FilterPopup(window))
{
continue;
}

if (std::find(movedWindows.begin(), movedWindows.end(), window) != movedWindows.end())
{
continue;
@@ -180,7 +185,7 @@ std::optional<WindowWithDistance> WindowArranger::GetNearestWindow(const Workspa
// 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)
for (auto otherWindow : m_windowsBefore)
{
DWORD otherPid{};
GetWindowThreadProcessId(otherWindow, &otherPid);
@@ -260,7 +265,6 @@ 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,7 +23,6 @@ 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;
36 changes: 0 additions & 36 deletions src/modules/Workspaces/workspaces-common/WindowFilter.h
Original file line number Diff line number Diff line change
@@ -62,40 +62,4 @@ namespace WindowFilter

return true;
}

// 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 properties 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);

if (!WindowUtils::HasStyle(style, WS_VISIBLE))
{
return false;
}

if (!IsWindowVisible(window))
{
return false;
}

if (WindowUtils::HasStyle(exStyle, WS_EX_TOOLWINDOW))
{
return false;
}

if (!WindowUtils::IsRoot(window))
{
// child windows such as buttons, combo boxes, etc.
return false;
}

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

return true;
}
}