[AlwaysOnTop] Return topmost if it was lost (#21297)

This commit is contained in:
Seraphima Zykova
2022-10-21 18:56:51 +02:00
committed by GitHub
parent 9c21e2dc14
commit 4da866aaa3

View File

@@ -312,13 +312,14 @@ void AlwaysOnTop::RegisterLLKH()
void AlwaysOnTop::SubscribeToEvents() void AlwaysOnTop::SubscribeToEvents()
{ {
// subscribe to windows events // subscribe to windows events
std::array<DWORD, 6> events_to_subscribe = { std::array<DWORD, 7> events_to_subscribe = {
EVENT_OBJECT_LOCATIONCHANGE, EVENT_OBJECT_LOCATIONCHANGE,
EVENT_SYSTEM_MINIMIZESTART, EVENT_SYSTEM_MINIMIZESTART,
EVENT_SYSTEM_MINIMIZEEND, EVENT_SYSTEM_MINIMIZEEND,
EVENT_SYSTEM_MOVESIZEEND, EVENT_SYSTEM_MOVESIZEEND,
EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND,
EVENT_OBJECT_DESTROY EVENT_OBJECT_DESTROY,
EVENT_OBJECT_FOCUS,
}; };
for (const auto event : events_to_subscribe) for (const auto event : events_to_subscribe)
@@ -413,11 +414,11 @@ void AlwaysOnTop::HandleWinHookEvent(WinHookEvent* data) noexcept
return; return;
} }
// fix for the https://github.com/microsoft/PowerToys/issues/15300
// check if the window was closed, since for some EVENT_OBJECT_DESTROY doesn't work
std::vector<HWND> toErase{}; std::vector<HWND> toErase{};
for (const auto& [window, border] : m_topmostWindows) for (const auto& [window, border] : m_topmostWindows)
{ {
// check if the window was closed, since for some EVENT_OBJECT_DESTROY doesn't work
// fixes https://github.com/microsoft/PowerToys/issues/15300
bool visible = IsWindowVisible(window); bool visible = IsWindowVisible(window);
if (!visible) if (!visible)
{ {
@@ -484,6 +485,20 @@ void AlwaysOnTop::HandleWinHookEvent(WinHookEvent* data) noexcept
RefreshBorders(); RefreshBorders();
} }
break; break;
case EVENT_OBJECT_FOCUS:
{
for (const auto& [window, border] : m_topmostWindows)
{
// check if topmost was reset
// fixes https://github.com/microsoft/PowerToys/issues/19168
if (!IsTopmost(window))
{
Logger::trace(L"A window no longer has Topmost set and it should. Setting topmost again.");
PinTopmostWindow(window);
}
}
}
break;
default: default:
break; break;
} }