mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
[AlwaysOnTop] Improve performance and power consumption (#15993)
This commit is contained in:
@@ -31,18 +31,10 @@ std::optional<RECT> GetFrameRect(HWND window)
|
||||
}
|
||||
|
||||
WindowBorder::WindowBorder(HWND window) :
|
||||
SettingsObserver({SettingId::FrameColor, SettingId::FrameThickness, SettingId::FrameAccentColor }),
|
||||
m_window(nullptr),
|
||||
m_trackingWindow(window),
|
||||
m_frameDrawer(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
WindowBorder::WindowBorder(WindowBorder&& other) :
|
||||
SettingsObserver({ SettingId::FrameColor, SettingId::FrameThickness, SettingId::FrameAccentColor }),
|
||||
m_window(other.m_window),
|
||||
m_trackingWindow(other.m_trackingWindow),
|
||||
m_frameDrawer(std::move(other.m_frameDrawer))
|
||||
m_window(nullptr),
|
||||
m_trackingWindow(window),
|
||||
m_frameDrawer(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -72,6 +64,12 @@ std::unique_ptr<WindowBorder> WindowBorder::Create(HWND window, HINSTANCE hinsta
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr uint32_t REFRESH_BORDER_TIMER_ID = 123;
|
||||
constexpr uint32_t REFRESH_BORDER_INTERVAL = 100;
|
||||
}
|
||||
|
||||
bool WindowBorder::Init(HINSTANCE hinstance)
|
||||
{
|
||||
if (!m_trackingWindow)
|
||||
@@ -136,6 +134,8 @@ bool WindowBorder::Init(HINSTANCE hinstance)
|
||||
|
||||
UpdateBorderProperties();
|
||||
m_frameDrawer->Show();
|
||||
m_timer_id = SetTimer(m_window, REFRESH_BORDER_TIMER_ID, REFRESH_BORDER_INTERVAL, nullptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ void WindowBorder::UpdateBorderPosition() const
|
||||
}
|
||||
|
||||
RECT rect = rectOpt.value();
|
||||
SetWindowPos(m_window, m_trackingWindow, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOREDRAW);
|
||||
SetWindowPos(m_window, m_trackingWindow, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOREDRAW | SWP_NOACTIVATE);
|
||||
}
|
||||
|
||||
void WindowBorder::UpdateBorderProperties() const
|
||||
@@ -170,7 +170,9 @@ void WindowBorder::UpdateBorderProperties() const
|
||||
return;
|
||||
}
|
||||
|
||||
RECT windowRect = windowRectOpt.value();
|
||||
const RECT windowRect = windowRectOpt.value();
|
||||
SetWindowPos(m_window, m_trackingWindow, windowRect.left, windowRect.top, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top, SWP_NOREDRAW | SWP_NOACTIVATE);
|
||||
|
||||
RECT frameRect{ 0, 0, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top };
|
||||
|
||||
COLORREF color;
|
||||
@@ -192,8 +194,22 @@ LRESULT WindowBorder::WndProc(UINT message, WPARAM wparam, LPARAM lparam) noexce
|
||||
{
|
||||
switch (message)
|
||||
{
|
||||
case WM_TIMER:
|
||||
{
|
||||
switch (wparam)
|
||||
{
|
||||
case REFRESH_BORDER_TIMER_ID:
|
||||
KillTimer(m_window, m_timer_id);
|
||||
m_timer_id = SetTimer(m_window, REFRESH_BORDER_TIMER_ID, REFRESH_BORDER_INTERVAL, nullptr);
|
||||
UpdateBorderPosition();
|
||||
UpdateBorderProperties();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case WM_NCDESTROY:
|
||||
{
|
||||
KillTimer(m_window, m_timer_id);
|
||||
::DefWindowProc(m_window, message, wparam, lparam);
|
||||
SetWindowLongPtr(m_window, GWLP_USERDATA, 0);
|
||||
}
|
||||
@@ -231,7 +247,7 @@ void WindowBorder::SettingsUpdate(SettingId id)
|
||||
UpdateBorderProperties();
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case SettingId::FrameColor:
|
||||
{
|
||||
UpdateBorderProperties();
|
||||
@@ -246,5 +262,4 @@ void WindowBorder::SettingsUpdate(SettingId id)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user