[AlwaysOnTop] Inaccurate border position fix (#16206)

This commit is contained in:
Seraphima Zykova
2022-02-10 20:24:29 +03:00
committed by GitHub
parent 8c64a0b6f8
commit ddcb065b22
5 changed files with 15 additions and 15 deletions

View File

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