mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
[Fancy Zones] Restore Console Applications (#12905)
This commit is contained in:
@@ -210,6 +210,28 @@ std::optional<std::vector<GUID>> VirtualDesktop::GetVirtualDesktopIds() const
|
||||
return GetVirtualDesktopIds(GetVirtualDesktopsRegKey());
|
||||
}
|
||||
|
||||
bool VirtualDesktop::IsWindowOnCurrentDesktop(HWND window) const
|
||||
{
|
||||
std::optional<GUID> id = GetDesktopId(window);
|
||||
return id.has_value();
|
||||
}
|
||||
|
||||
std::optional<GUID> VirtualDesktop::GetDesktopId(HWND window) const
|
||||
{
|
||||
GUID id;
|
||||
BOOL isWindowOnCurrentDesktop = false;
|
||||
if (m_vdManager->IsWindowOnCurrentVirtualDesktop(window, &isWindowOnCurrentDesktop) == S_OK && isWindowOnCurrentDesktop)
|
||||
{
|
||||
// Filter windows such as Windows Start Menu, Task Switcher, etc.
|
||||
if (m_vdManager->GetWindowDesktopId(window, &id) == S_OK && id != GUID_NULL)
|
||||
{
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<GUID> VirtualDesktop::GetDesktopIdByTopLevelWindows() const
|
||||
{
|
||||
using result_t = std::vector<HWND>;
|
||||
@@ -222,16 +244,13 @@ std::optional<GUID> VirtualDesktop::GetDesktopIdByTopLevelWindows() const
|
||||
};
|
||||
EnumWindows(callback, reinterpret_cast<LPARAM>(&result));
|
||||
|
||||
GUID id;
|
||||
BOOL isWindowOnCurrentDesktop = false;
|
||||
for (const auto window : result)
|
||||
{
|
||||
if (m_vdManager->IsWindowOnCurrentVirtualDesktop(window, &isWindowOnCurrentDesktop) == ERROR_SUCCESS && isWindowOnCurrentDesktop)
|
||||
std::optional<GUID> id = GetDesktopId(window);
|
||||
if (id.has_value())
|
||||
{
|
||||
if (m_vdManager->GetWindowDesktopId(window, &id) == ERROR_SUCCESS && id != GUID_NULL)
|
||||
{
|
||||
return id;
|
||||
}
|
||||
// Otherwise keep checking other windows
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user