mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
always on top accent color borders (#15709)
This commit is contained in:
committed by
GitHub
parent
2ccf492707
commit
2182aabe35
@@ -38,7 +38,7 @@ bool isExcluded(HWND window)
|
||||
}
|
||||
|
||||
AlwaysOnTop::AlwaysOnTop() :
|
||||
SettingsObserver({SettingId::FrameEnabled, SettingId::Hotkey, SettingId::ExcludeApps}),
|
||||
SettingsObserver({SettingId::FrameEnabled, SettingId::Hotkey, SettingId::ExcludeApps, SettingId::FrameAccentColor}),
|
||||
m_hinstance(reinterpret_cast<HINSTANCE>(&__ImageBase))
|
||||
{
|
||||
s_instance = this;
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace NonLocalizable
|
||||
const static wchar_t* FrameColorID = L"frame-color";
|
||||
const static wchar_t* BlockInGameModeID = L"do-not-activate-on-game-mode";
|
||||
const static wchar_t* ExcludedAppsID = L"excluded-apps";
|
||||
const static wchar_t* FrameAccentColor = L"frame-accent-color";
|
||||
}
|
||||
|
||||
// TODO: move to common utils
|
||||
@@ -42,6 +43,14 @@ inline COLORREF HexToRGB(std::wstring_view hex, const COLORREF fallbackColor = R
|
||||
|
||||
AlwaysOnTopSettings::AlwaysOnTopSettings()
|
||||
{
|
||||
m_uiSettings.ColorValuesChanged([&](winrt::Windows::UI::ViewManagement::UISettings const& settings,
|
||||
winrt::Windows::Foundation::IInspectable const& args)
|
||||
{
|
||||
if (m_settings.frameAccentColor)
|
||||
{
|
||||
NotifyObservers(SettingId::FrameAccentColor);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
AlwaysOnTopSettings& AlwaysOnTopSettings::instance()
|
||||
@@ -167,6 +176,16 @@ void AlwaysOnTopSettings::LoadSettings()
|
||||
NotifyObservers(SettingId::ExcludeApps);
|
||||
}
|
||||
}
|
||||
|
||||
if (const auto jsonVal = values.get_bool_value(NonLocalizable::FrameAccentColor))
|
||||
{
|
||||
auto val = *jsonVal;
|
||||
if (m_settings.frameAccentColor != val)
|
||||
{
|
||||
m_settings.frameAccentColor = val;
|
||||
NotifyObservers(SettingId::FrameAccentColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
#include <SettingsConstants.h>
|
||||
|
||||
#include <winrt/Windows.UI.ViewManagement.h>
|
||||
|
||||
class SettingsObserver;
|
||||
|
||||
// Needs to be kept in sync with src\settings-ui\Settings.UI.Library\AlwaysOnTopProperties.cs
|
||||
@@ -16,6 +18,7 @@ struct Settings
|
||||
bool enableFrame = true;
|
||||
bool enableSound = true;
|
||||
bool blockInGameMode = true;
|
||||
bool frameAccentColor = true;
|
||||
float frameThickness = 15.0f;
|
||||
COLORREF frameColor = RGB(0, 173, 239);
|
||||
std::vector<std::wstring> excludedApps{};
|
||||
@@ -42,6 +45,7 @@ private:
|
||||
AlwaysOnTopSettings();
|
||||
~AlwaysOnTopSettings() = default;
|
||||
|
||||
winrt::Windows::UI::ViewManagement::UISettings m_uiSettings;
|
||||
Settings m_settings;
|
||||
std::unique_ptr<FileWatcher> m_settingsFileWatcher;
|
||||
std::unordered_set<SettingsObserver*> m_observers;
|
||||
|
||||
@@ -8,5 +8,6 @@ enum class SettingId
|
||||
FrameThickness,
|
||||
FrameColor,
|
||||
BlockInGameMode,
|
||||
ExcludeApps
|
||||
ExcludeApps,
|
||||
FrameAccentColor
|
||||
};
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <FrameDrawer.h>
|
||||
#include <Settings.h>
|
||||
#include "winrt/Windows.Foundation.h"
|
||||
|
||||
// Non-Localizable strings
|
||||
namespace NonLocalizable
|
||||
@@ -30,7 +31,7 @@ std::optional<RECT> GetFrameRect(HWND window)
|
||||
}
|
||||
|
||||
WindowBorder::WindowBorder(HWND window) :
|
||||
SettingsObserver({SettingId::FrameColor, SettingId::FrameThickness}),
|
||||
SettingsObserver({SettingId::FrameColor, SettingId::FrameThickness, SettingId::FrameAccentColor }),
|
||||
m_window(nullptr),
|
||||
m_trackingWindow(window),
|
||||
m_frameDrawer(nullptr)
|
||||
@@ -38,7 +39,7 @@ WindowBorder::WindowBorder(HWND window) :
|
||||
}
|
||||
|
||||
WindowBorder::WindowBorder(WindowBorder&& other) :
|
||||
SettingsObserver({ SettingId::FrameColor, SettingId::FrameThickness }),
|
||||
SettingsObserver({ SettingId::FrameColor, SettingId::FrameThickness, SettingId::FrameAccentColor }),
|
||||
m_window(other.m_window),
|
||||
m_trackingWindow(other.m_trackingWindow),
|
||||
m_frameDrawer(std::move(other.m_frameDrawer))
|
||||
@@ -152,7 +153,20 @@ void WindowBorder::UpdateBorderProperties() const
|
||||
|
||||
RECT windowRect = windowRectOpt.value();
|
||||
RECT frameRect{ 0, 0, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top };
|
||||
m_frameDrawer->SetBorderRect(frameRect, AlwaysOnTopSettings::settings().frameColor, AlwaysOnTopSettings::settings().frameThickness);
|
||||
|
||||
COLORREF color;
|
||||
if (AlwaysOnTopSettings::settings().frameAccentColor)
|
||||
{
|
||||
winrt::Windows::UI::ViewManagement::UISettings settings;
|
||||
auto accentValue = settings.GetColorValue(winrt::Windows::UI::ViewManagement::UIColorType::Accent);
|
||||
color = RGB(accentValue.R, accentValue.G, accentValue.B);
|
||||
}
|
||||
else
|
||||
{
|
||||
color = AlwaysOnTopSettings::settings().frameColor;
|
||||
}
|
||||
|
||||
m_frameDrawer->SetBorderRect(frameRect, color, AlwaysOnTopSettings::settings().frameThickness);
|
||||
}
|
||||
|
||||
void WindowBorder::Show() const
|
||||
@@ -216,6 +230,11 @@ void WindowBorder::SettingsUpdate(SettingId id)
|
||||
}
|
||||
break;
|
||||
|
||||
case SettingId::FrameAccentColor:
|
||||
{
|
||||
UpdateBorderProperties();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user