mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[AlwaysOnTop] Inaccurate border position fix (#16206)
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include "FrameDrawer.h"
|
||||
|
||||
#include <dwmapi.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
size_t D2DRectUHash(D2D1_SIZE_U rect)
|
||||
@@ -66,8 +67,7 @@ bool FrameDrawer::CreateRenderTargets(const RECT& clientRect)
|
||||
bool FrameDrawer::Init()
|
||||
{
|
||||
RECT clientRect;
|
||||
|
||||
if (!GetClientRect(m_window, &clientRect))
|
||||
if (!SUCCEEDED(DwmGetWindowAttribute(m_window, DWMWA_EXTENDED_FRAME_BOUNDS, &clientRect, sizeof(clientRect))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ void FrameDrawer::Show()
|
||||
Render();
|
||||
}
|
||||
|
||||
void FrameDrawer::SetBorderRect(RECT windowRect, COLORREF color, float thickness)
|
||||
void FrameDrawer::SetBorderRect(RECT windowRect, COLORREF color, int thickness)
|
||||
{
|
||||
const auto newSceneRect = DrawableRect{
|
||||
.rect = ConvertRect(windowRect),
|
||||
@@ -99,8 +99,7 @@ void FrameDrawer::SetBorderRect(RECT windowRect, COLORREF color, float thickness
|
||||
const bool needsRedraw = colorUpdated || thicknessUpdated;
|
||||
|
||||
RECT clientRect;
|
||||
|
||||
if (!GetClientRect(m_window, &clientRect))
|
||||
if (!SUCCEEDED(DwmGetWindowAttribute(m_window, DWMWA_EXTENDED_FRAME_BOUNDS, &clientRect, sizeof(clientRect))))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -186,7 +185,8 @@ void FrameDrawer::Render()
|
||||
|
||||
if (m_borderBrush)
|
||||
{
|
||||
m_renderTarget->DrawRectangle(m_sceneRect.rect, m_borderBrush.get(), m_sceneRect.thickness);
|
||||
// The border stroke is centered on the line.
|
||||
m_renderTarget->DrawRectangle(m_sceneRect.rect, m_borderBrush.get(), static_cast<float>(m_sceneRect.thickness * 2));
|
||||
}
|
||||
|
||||
m_renderTarget->EndDraw();
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
|
||||
void Show();
|
||||
void Hide();
|
||||
void SetBorderRect(RECT windowRect, COLORREF color, float thickness);
|
||||
void SetBorderRect(RECT windowRect, COLORREF color, int thickness);
|
||||
|
||||
private:
|
||||
bool CreateRenderTargets(const RECT& clientRect);
|
||||
@@ -27,7 +27,7 @@ private:
|
||||
{
|
||||
D2D1_RECT_F rect;
|
||||
D2D1_COLOR_F borderColor;
|
||||
float thickness;
|
||||
int thickness;
|
||||
};
|
||||
|
||||
static ID2D1Factory* GetD2DFactory();
|
||||
|
||||
@@ -118,7 +118,7 @@ void AlwaysOnTopSettings::LoadSettings()
|
||||
auto val = *jsonVal;
|
||||
if (m_settings.frameThickness != val)
|
||||
{
|
||||
m_settings.frameThickness = static_cast<float>(val);
|
||||
m_settings.frameThickness = val;
|
||||
NotifyObservers(SettingId::FrameThickness);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ struct Settings
|
||||
bool enableSound = true;
|
||||
bool blockInGameMode = true;
|
||||
bool frameAccentColor = true;
|
||||
float frameThickness = 15.0f;
|
||||
int frameThickness = 15;
|
||||
COLORREF frameColor = RGB(0, 173, 239);
|
||||
std::vector<std::wstring> excludedApps{};
|
||||
};
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
#include "WindowBorder.h"
|
||||
|
||||
#include <dwmapi.h>
|
||||
#include "winrt/Windows.Foundation.h"
|
||||
|
||||
#include <FrameDrawer.h>
|
||||
#include <Settings.h>
|
||||
#include "winrt/Windows.Foundation.h"
|
||||
|
||||
// Non-Localizable strings
|
||||
namespace NonLocalizable
|
||||
@@ -21,7 +21,7 @@ std::optional<RECT> GetFrameRect(HWND window)
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
int border = static_cast<int>(AlwaysOnTopSettings::settings().frameThickness / 2);
|
||||
int border = AlwaysOnTopSettings::settings().frameThickness;
|
||||
rect.top -= border;
|
||||
rect.left -= border;
|
||||
rect.right += border;
|
||||
@@ -122,8 +122,8 @@ bool WindowBorder::Init(HINSTANCE hinstance)
|
||||
, m_window
|
||||
, windowRect.left
|
||||
, windowRect.top
|
||||
, windowRect.right - windowRect.left - static_cast<int>(AlwaysOnTopSettings::settings().frameThickness)
|
||||
, windowRect.bottom - windowRect.top - static_cast<int>(AlwaysOnTopSettings::settings().frameThickness)
|
||||
, windowRect.right - windowRect.left
|
||||
, windowRect.bottom - windowRect.top
|
||||
, SWP_NOMOVE | SWP_NOSIZE);
|
||||
|
||||
m_frameDrawer = FrameDrawer::Create(m_window);
|
||||
|
||||
Reference in New Issue
Block a user