[AlwaysOnTop] Show borders only for AOT-pinned windows (#15801)

* set prop on aot-pinned window

* address pr comments
This commit is contained in:
Seraphima Zykova
2022-01-27 19:53:05 +03:00
committed by GitHub
parent 03c36b4f65
commit 91d36b4b47
2 changed files with 14 additions and 1 deletions

View File

@@ -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);
}

View File

@@ -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;