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