diff --git a/src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.cpp b/src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.cpp index 0b23addc12..c2dbe6e955 100644 --- a/src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.cpp +++ b/src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.cpp @@ -12,6 +12,7 @@ namespace NonLocalizable { const static wchar_t* TOOL_WINDOW_CLASS_NAME = L"AlwaysOnTopWindow"; + const static wchar_t* WINDOW_IS_PINNED_PROP = L"AlwaysOnTop_Pinned"; } // TODO: move to common utils @@ -227,7 +228,7 @@ void AlwaysOnTop::StartTrackingTopmostWindows() for (HWND window : result) { - if (IsTopmost(window)) + if (IsPinned(window)) { AssignBorder(window); } @@ -315,13 +316,24 @@ bool AlwaysOnTop::IsTopmost(HWND window) const noexcept return (exStyle & WS_EX_TOPMOST) == WS_EX_TOPMOST; } +bool AlwaysOnTop::IsPinned(HWND window) const noexcept +{ + auto handle = GetProp(window, NonLocalizable::WINDOW_IS_PINNED_PROP); + return (handle != NULL); +} + bool AlwaysOnTop::PinTopmostWindow(HWND window) const noexcept { + if (!SetProp(window, NonLocalizable::WINDOW_IS_PINNED_PROP, (HANDLE)1)) + { + Logger::error(L"SetProp failed"); + } return SetWindowPos(window, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); } bool AlwaysOnTop::UnpinTopmostWindow(HWND window) const noexcept { + RemoveProp(window, NonLocalizable::WINDOW_IS_PINNED_PROP); return SetWindowPos(window, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); } diff --git a/src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.h b/src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.h index 10fa78579d..ed6e5e7fcb 100644 --- a/src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.h +++ b/src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.h @@ -64,6 +64,7 @@ private: bool IsTracked(HWND window) const noexcept; bool IsTopmost(HWND window) const noexcept; + bool IsPinned(HWND window) const noexcept; bool PinTopmostWindow(HWND window) const noexcept; bool UnpinTopmostWindow(HWND window) const noexcept;