Skip to content

Commit

Permalink
[AlwaysOnTop] Return topmost if it was lost (#21297)
Browse files Browse the repository at this point in the history
  • Loading branch information
SeraphimaZykova committed Oct 21, 2022
1 parent 9c21e2d commit 4da866a
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.cpp
Expand Up @@ -312,13 +312,14 @@ void AlwaysOnTop::RegisterLLKH()
void AlwaysOnTop::SubscribeToEvents()
{
// subscribe to windows events
std::array<DWORD, 6> events_to_subscribe = {
std::array<DWORD, 7> events_to_subscribe = {
EVENT_OBJECT_LOCATIONCHANGE,
EVENT_SYSTEM_MINIMIZESTART,
EVENT_SYSTEM_MINIMIZEEND,
EVENT_SYSTEM_MOVESIZEEND,
EVENT_SYSTEM_FOREGROUND,
EVENT_OBJECT_DESTROY
EVENT_OBJECT_DESTROY,
EVENT_OBJECT_FOCUS,
};

for (const auto event : events_to_subscribe)
Expand Down Expand Up @@ -413,11 +414,11 @@ void AlwaysOnTop::HandleWinHookEvent(WinHookEvent* data) noexcept
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{};
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);
if (!visible)
{
Expand Down Expand Up @@ -484,6 +485,20 @@ void AlwaysOnTop::HandleWinHookEvent(WinHookEvent* data) noexcept
RefreshBorders();
}
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:
break;
}
Expand Down

0 comments on commit 4da866a

Please sign in to comment.