mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[FancyZones] Bypass restriction on SetForegroundWindow (#14383)
Co-authored-by: float4 <float4-unspecified-mail>
This commit is contained in:
@@ -594,19 +594,17 @@ ZoneSet::CycleTabs(HWND window, bool reverse) noexcept
|
|||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
auto next = GetNextTab(indexSet, window, reverse);
|
auto next = GetNextTab(indexSet, window, reverse);
|
||||||
if (next == NULL)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto success = SetForegroundWindow(next);
|
// Determine whether the window still exists
|
||||||
if (!success && GetLastError() == ERROR_INVALID_WINDOW_HANDLE)
|
if (!IsWindow(next))
|
||||||
{
|
{
|
||||||
// Dismiss the encountered window since it was probably closed
|
// Dismiss the encountered window since it was probably closed
|
||||||
DismissWindow(next);
|
DismissWindow(next);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SwitchToWindow(next);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -369,6 +369,22 @@ namespace FancyZonesUtils
|
|||||||
::SetWindowPlacement(window, &placement);
|
::SetWindowPlacement(window, &placement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SwitchToWindow(HWND window) noexcept
|
||||||
|
{
|
||||||
|
// Check if the window is minimized
|
||||||
|
if (IsIconic(window))
|
||||||
|
{
|
||||||
|
// Show the window since SetForegroundWindow fails on minimized windows
|
||||||
|
ShowWindow(window, SW_RESTORE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is a hack to bypass the restriction on setting the foreground window
|
||||||
|
INPUT inputs[1] = { { .type = INPUT_MOUSE } };
|
||||||
|
SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
|
||||||
|
|
||||||
|
SetForegroundWindow(window);
|
||||||
|
}
|
||||||
|
|
||||||
bool HasNoVisibleOwner(HWND window) noexcept
|
bool HasNoVisibleOwner(HWND window) noexcept
|
||||||
{
|
{
|
||||||
auto owner = GetWindow(window, GW_OWNER);
|
auto owner = GetWindow(window, GW_OWNER);
|
||||||
|
|||||||
@@ -195,6 +195,8 @@ namespace FancyZonesUtils
|
|||||||
// Parameter rect must be in screen coordinates (e.g. obtained from GetWindowRect)
|
// Parameter rect must be in screen coordinates (e.g. obtained from GetWindowRect)
|
||||||
void SizeWindowToRect(HWND window, RECT rect) noexcept;
|
void SizeWindowToRect(HWND window, RECT rect) noexcept;
|
||||||
|
|
||||||
|
void SwitchToWindow(HWND window) noexcept;
|
||||||
|
|
||||||
bool HasNoVisibleOwner(HWND window) noexcept;
|
bool HasNoVisibleOwner(HWND window) noexcept;
|
||||||
bool IsStandardWindow(HWND window);
|
bool IsStandardWindow(HWND window);
|
||||||
bool IsCandidateForLastKnownZone(HWND window, const std::vector<std::wstring>& excludedApps) noexcept;
|
bool IsCandidateForLastKnownZone(HWND window, const std::vector<std::wstring>& excludedApps) noexcept;
|
||||||
|
|||||||
Reference in New Issue
Block a user