From e19ecd2ba1e0ff53244cf0c411ab1167ce518098 Mon Sep 17 00:00:00 2001 From: Davide Giacometti Date: Thu, 4 Nov 2021 15:30:06 +0100 Subject: [PATCH] [FancyZones] Use accent color and theme (#14158) * use accent color and theme * typo * Updated FZ color UX (#14171) Co-authored-by: Laute * fix resources * rebase fix * label updated Co-authored-by: Niels Laute Co-authored-by: Laute --- .../fancyzones/FancyZonesLib/FancyZones.cpp | 59 ++++++++++++++-- .../fancyzones/FancyZonesLib/Resources.resx | 5 +- .../fancyzones/FancyZonesLib/Settings.cpp | 4 +- .../fancyzones/FancyZonesLib/Settings.h | 1 + .../fancyzones/FancyZonesLib/ZoneColors.h | 1 + .../FancyZonesLib/ZoneWindowDrawing.cpp | 17 +++-- .../FancyZonesLib/ZoneWindowDrawing.h | 1 + .../FZConfigProperties.cs | 4 ++ .../ViewModels/FancyZonesViewModel.cs | 20 ++++++ .../Strings/en-us/Resources.resw | 44 +++++++----- .../Views/FancyZonesPage.xaml | 68 ++++++++++++------- .../Views/FancyZonesPage.xaml.cs | 5 ++ 12 files changed, 172 insertions(+), 57 deletions(-) diff --git a/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp b/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp index 38645b6562..39e5ad66a5 100644 --- a/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp +++ b/src/modules/fancyzones/FancyZonesLib/FancyZones.cpp @@ -28,6 +28,7 @@ #include "CallTracer.h" #include +#include enum class DisplayChangeType { @@ -81,6 +82,13 @@ public: { monitor = NULL; } + + // If accent color or theme is changed need to update colors for zones + if (m_settings->GetSettings()->systemTheme && GetSystemTheme()) + { + m_workAreaHandler.UpdateZoneColors(GetZoneColors()); + } + m_windowMoveHandler.MoveSizeStart(window, monitor, ptScreen, m_workAreaHandler.GetWorkAreasByDesktopId(m_currentDesktopId)); } @@ -173,6 +181,7 @@ private: std::vector GetMonitorsSorted() noexcept; HMONITOR WorkAreaKeyFromWindow(HWND window) noexcept; + bool GetSystemTheme() const noexcept; ZoneColors GetZoneColors() const noexcept; const HINSTANCE m_hinstance{}; @@ -214,6 +223,8 @@ private: }; std::function FancyZones::disableModuleCallback = {}; +COLORREF currentAccentColor; +COLORREF currentBackgroundColor; // IFancyZones IFACEMETHODIMP_(void) @@ -1332,14 +1343,50 @@ HMONITOR FancyZones::WorkAreaKeyFromWindow(HWND window) noexcept } } +bool FancyZones::GetSystemTheme() const noexcept +{ + winrt::Windows::UI::ViewManagement::UISettings settings; + auto accentValue = settings.GetColorValue(winrt::Windows::UI::ViewManagement::UIColorType::Accent); + auto accentColor = RGB(accentValue.R, accentValue.G, accentValue.B); + + auto backgroundValue = settings.GetColorValue(winrt::Windows::UI::ViewManagement::UIColorType::Background); + auto backgroundColor = RGB(backgroundValue.R, backgroundValue.G, backgroundValue.B); + + if (currentAccentColor != accentColor || currentBackgroundColor != backgroundColor) + { + currentAccentColor = accentColor; + currentBackgroundColor = backgroundColor; + return true; + } + + return false; +} + ZoneColors FancyZones::GetZoneColors() const noexcept { - return ZoneColors { - .primaryColor = FancyZonesUtils::HexToRGB(m_settings->GetSettings()->zoneColor), - .borderColor = FancyZonesUtils::HexToRGB(m_settings->GetSettings()->zoneBorderColor), - .highlightColor = FancyZonesUtils::HexToRGB(m_settings->GetSettings()->zoneHighlightColor), - .highlightOpacity = m_settings->GetSettings()->zoneHighlightOpacity - }; + if (m_settings->GetSettings()->systemTheme) + { + GetSystemTheme(); + auto textColor = currentBackgroundColor == RGB(0, 0, 0) ? RGB(255, 255, 255) : RGB(0, 0, 0); + + return ZoneColors{ + .primaryColor = currentBackgroundColor, + .borderColor = currentAccentColor, + .highlightColor = currentAccentColor, + .textColor = textColor, + .highlightOpacity = m_settings->GetSettings()->zoneHighlightOpacity + }; + } + else + { + return ZoneColors{ + .primaryColor = FancyZonesUtils::HexToRGB(m_settings->GetSettings()->zoneColor), + .borderColor = FancyZonesUtils::HexToRGB(m_settings->GetSettings()->zoneBorderColor), + .highlightColor = FancyZonesUtils::HexToRGB(m_settings->GetSettings()->zoneHighlightColor), + .textColor = RGB(0, 0, 0), + .highlightOpacity = m_settings->GetSettings()->zoneHighlightOpacity + }; + } } winrt::com_ptr MakeFancyZones(HINSTANCE hinstance, diff --git a/src/modules/fancyzones/FancyZonesLib/Resources.resx b/src/modules/fancyzones/FancyZonesLib/Resources.resx index 1575de1130..2d073710b5 100644 --- a/src/modules/fancyzones/FancyZonesLib/Resources.resx +++ b/src/modules/fancyzones/FancyZonesLib/Resources.resx @@ -219,7 +219,7 @@ We've detected an application running with administrator privileges. This will prevent certain interactions with these applications. - administrator is context of user account. + administrator is context of user account. Learn more @@ -263,4 +263,7 @@ Flash zones when switching layout + + Use system theme + \ No newline at end of file diff --git a/src/modules/fancyzones/FancyZonesLib/Settings.cpp b/src/modules/fancyzones/FancyZonesLib/Settings.cpp index 5b4b932fb1..84ff97376f 100644 --- a/src/modules/fancyzones/FancyZonesLib/Settings.cpp +++ b/src/modules/fancyzones/FancyZonesLib/Settings.cpp @@ -28,6 +28,7 @@ namespace NonLocalizable const wchar_t SpanZonesAcrossMonitorsID[] = L"fancyzones_span_zones_across_monitors"; const wchar_t MakeDraggedWindowTransparentID[] = L"fancyzones_makeDraggedWindowTransparent"; + const wchar_t SystemTheme[] = L"fancyzones_systemTheme"; const wchar_t ZoneColorID[] = L"fancyzones_zoneColor"; const wchar_t ZoneBorderColorID[] = L"fancyzones_zoneBorderColor"; const wchar_t ZoneHighlightColorID[] = L"fancyzones_zoneHighlightColor"; @@ -80,7 +81,7 @@ private: PCWSTR name; bool* value; int resourceId; - } m_configBools[17] = { + } m_configBools[18] = { { NonLocalizable::ShiftDragID, &m_settings.shiftDrag, IDS_SETTING_DESCRIPTION_SHIFTDRAG }, { NonLocalizable::MouseSwitchID, &m_settings.mouseSwitch, IDS_SETTING_DESCRIPTION_MOUSESWITCH }, { NonLocalizable::OverrideSnapHotKeysID, &m_settings.overrideSnapHotkeys, IDS_SETTING_DESCRIPTION_OVERRIDE_SNAP_HOTKEYS }, @@ -98,6 +99,7 @@ private: { NonLocalizable::SpanZonesAcrossMonitorsID, &m_settings.spanZonesAcrossMonitors, IDS_SETTING_DESCRIPTION_SPAN_ZONES_ACROSS_MONITORS }, { NonLocalizable::MakeDraggedWindowTransparentID, &m_settings.makeDraggedWindowTransparent, IDS_SETTING_DESCRIPTION_MAKE_DRAGGED_WINDOW_TRANSPARENT }, { NonLocalizable::WindowSwitchingToggleID, &m_settings.windowSwitching, IDS_SETTING_WINDOW_SWITCHING_TOGGLE_LABEL }, + { NonLocalizable::SystemTheme, &m_settings.systemTheme, IDS_SETTING_DESCRIPTION_SYSTEM_THEME }, }; }; diff --git a/src/modules/fancyzones/FancyZonesLib/Settings.h b/src/modules/fancyzones/FancyZonesLib/Settings.h index 1aa5f4b381..033f4e4c92 100644 --- a/src/modules/fancyzones/FancyZonesLib/Settings.h +++ b/src/modules/fancyzones/FancyZonesLib/Settings.h @@ -32,6 +32,7 @@ struct Settings bool showZonesOnAllMonitors = false; bool spanZonesAcrossMonitors = false; bool makeDraggedWindowTransparent = true; + bool systemTheme = true; std::wstring zoneColor = L"#AACDFF"; std::wstring zoneBorderColor = L"#FFFFFF"; std::wstring zoneHighlightColor = L"#008CFF"; diff --git a/src/modules/fancyzones/FancyZonesLib/ZoneColors.h b/src/modules/fancyzones/FancyZonesLib/ZoneColors.h index 867adbe261..33a6934ed7 100644 --- a/src/modules/fancyzones/FancyZonesLib/ZoneColors.h +++ b/src/modules/fancyzones/FancyZonesLib/ZoneColors.h @@ -6,5 +6,6 @@ struct ZoneColors COLORREF primaryColor; COLORREF borderColor; COLORREF highlightColor; + COLORREF textColor; int highlightOpacity; }; diff --git a/src/modules/fancyzones/FancyZonesLib/ZoneWindowDrawing.cpp b/src/modules/fancyzones/FancyZonesLib/ZoneWindowDrawing.cpp index caabd0cadf..f23193843c 100644 --- a/src/modules/fancyzones/FancyZonesLib/ZoneWindowDrawing.cpp +++ b/src/modules/fancyzones/FancyZonesLib/ZoneWindowDrawing.cpp @@ -131,10 +131,8 @@ ZoneWindowDrawing::RenderResult ZoneWindowDrawing::Render() // Draw backdrop m_renderTarget->Clear(D2D1::ColorF(0.f, 0.f, 0.f, 0.f)); - ID2D1SolidColorBrush* textBrush = nullptr; IDWriteTextFormat* textFormat = nullptr; - m_renderTarget->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black, animationAlpha), &textBrush); auto writeFactory = GetWriteFactory(); if (writeFactory) @@ -144,6 +142,7 @@ ZoneWindowDrawing::RenderResult ZoneWindowDrawing::Render() for (auto drawableRect : m_sceneRects) { + ID2D1SolidColorBrush* textBrush = nullptr; ID2D1SolidColorBrush* borderBrush = nullptr; ID2D1SolidColorBrush* fillBrush = nullptr; @@ -151,6 +150,7 @@ ZoneWindowDrawing::RenderResult ZoneWindowDrawing::Render() drawableRect.borderColor.a *= animationAlpha; drawableRect.fillColor.a *= animationAlpha; + m_renderTarget->CreateSolidColorBrush(drawableRect.textColor, &textBrush); m_renderTarget->CreateSolidColorBrush(drawableRect.borderColor, &borderBrush); m_renderTarget->CreateSolidColorBrush(drawableRect.fillColor, &fillBrush); @@ -174,6 +174,11 @@ ZoneWindowDrawing::RenderResult ZoneWindowDrawing::Render() textFormat->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_CENTER); m_renderTarget->DrawTextW(idStr.c_str(), (UINT32)idStr.size(), textFormat, drawableRect.rect, textBrush); } + + if (textBrush) + { + textBrush->Release(); + } } if (textFormat) @@ -181,11 +186,6 @@ ZoneWindowDrawing::RenderResult ZoneWindowDrawing::Render() textFormat->Release(); } - if (textBrush) - { - textBrush->Release(); - } - // The lock must be released here, as EndDraw() will wait for vertical sync lock.unlock(); @@ -289,6 +289,7 @@ void ZoneWindowDrawing::DrawActiveZoneSet(const IZoneSet::ZonesMap& zones, auto borderColor = ConvertColor(colors.borderColor); auto inactiveColor = ConvertColor(colors.primaryColor); auto highlightColor = ConvertColor(colors.highlightColor); + auto textColor = ConvertColor(colors.textColor); inactiveColor.a = colors.highlightOpacity / 100.f; highlightColor.a = colors.highlightOpacity / 100.f; @@ -313,6 +314,7 @@ void ZoneWindowDrawing::DrawActiveZoneSet(const IZoneSet::ZonesMap& zones, .rect = ConvertRect(zone->GetZoneRect()), .borderColor = borderColor, .fillColor = inactiveColor, + .textColor = textColor, .id = zone->Id() }; @@ -334,6 +336,7 @@ void ZoneWindowDrawing::DrawActiveZoneSet(const IZoneSet::ZonesMap& zones, .rect = ConvertRect(zone->GetZoneRect()), .borderColor = borderColor, .fillColor = highlightColor, + .textColor = textColor, .id = zone->Id() }; diff --git a/src/modules/fancyzones/FancyZonesLib/ZoneWindowDrawing.h b/src/modules/fancyzones/FancyZonesLib/ZoneWindowDrawing.h index ee5322e55e..8b78e36884 100644 --- a/src/modules/fancyzones/FancyZonesLib/ZoneWindowDrawing.h +++ b/src/modules/fancyzones/FancyZonesLib/ZoneWindowDrawing.h @@ -20,6 +20,7 @@ class ZoneWindowDrawing D2D1_RECT_F rect; D2D1_COLOR_F borderColor; D2D1_COLOR_F fillColor; + D2D1_COLOR_F textColor; ZoneIndex id; }; diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/FZConfigProperties.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/FZConfigProperties.cs index f873c4ff52..78aed832ee 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/FZConfigProperties.cs +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/FZConfigProperties.cs @@ -46,6 +46,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library FancyzonesExcludedApps = new StringProperty(); FancyzonesInActiveColor = new StringProperty(ConfigDefaults.DefaultFancyZonesInActiveColor); FancyzonesBorderColor = new StringProperty(ConfigDefaults.DefaultFancyzonesBorderColor); + FancyzonesSystemTheme = new BoolProperty(true); } [JsonPropertyName("fancyzones_shiftDrag")] @@ -126,6 +127,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library [JsonPropertyName("fancyzones_zoneColor")] public StringProperty FancyzonesInActiveColor { get; set; } + [JsonPropertyName("fancyzones_systemTheme")] + public BoolProperty FancyzonesSystemTheme { get; set; } + // converts the current to a json string. public string ToJsonString() { diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/FancyZonesViewModel.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/FancyZonesViewModel.cs index 7e163d1982..29d3650449 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/FancyZonesViewModel.cs +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/FancyZonesViewModel.cs @@ -88,6 +88,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels _makeDraggedWindowTransparent = Settings.Properties.FancyzonesMakeDraggedWindowTransparent.Value; _highlightOpacity = Settings.Properties.FancyzonesHighlightOpacity.Value; _excludedApps = Settings.Properties.FancyzonesExcludedApps.Value; + _systemTheme = Settings.Properties.FancyzonesSystemTheme.Value; EditorHotkey = Settings.Properties.FancyzonesEditorHotkey.Value; _windowSwitching = Settings.Properties.FancyzonesWindowSwitching.Value; NextTabHotkey = Settings.Properties.FancyzonesNextTabHotkey.Value; @@ -126,6 +127,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels private bool _useCursorPosEditorStartupScreen; private bool _showOnAllMonitors; private bool _makeDraggedWindowTransparent; + private bool _systemTheme; private int _highlightOpacity; private string _excludedApps; @@ -520,6 +522,24 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels } } + public bool SystemTheme + { + get + { + return _systemTheme; + } + + set + { + if (value != _systemTheme) + { + _systemTheme = value; + Settings.Properties.FancyzonesSystemTheme.Value = value; + NotifyPropertyChanged(); + } + } + } + // For the following setters we use OrdinalIgnoreCase string comparison since // we expect value to be a hex code. public string ZoneHighlightColor diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw index 252a8fa8c8..1395c4ea3d 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Strings/en-us/Resources.resw @@ -408,7 +408,7 @@ Use centralized keyboard hook - + Try this if there are issues with the shortcut @@ -444,13 +444,13 @@ Excludes an application from snapping to zones and will only react to Windows Snap - add one application name per line - Zone opacity + Opacity Open layout editor Shortcut to launch the FancyZones layout editor application - + Window switching @@ -520,10 +520,10 @@ When using multiple displays - + Where the mouse pointer is - + With active focus @@ -536,7 +536,7 @@ Zones - Zone highlight color + Highlight color During zone layout changes, windows assigned to a zone will match new size/positions @@ -595,13 +595,13 @@ Show PowerRename in - + Press shift + right-click on files to open the extended menu - + Default and extended context menu - + Extended context menu only @@ -646,10 +646,10 @@ Enable auto-complete for the search and replace fields - Zone border color + Border color - Zone inactive color + Inactive color Shows a help overlay with Windows shortcuts. @@ -939,10 +939,10 @@ Used as the 'modified timestamp' in the file properties - + Original file timestamp - + Timestamp of resize action @@ -1015,9 +1015,6 @@ Made with 💗 by Microsoft and the PowerToys community. Filename parameters - - App theme - Dark Dark refers to color, not weight @@ -1724,4 +1721,19 @@ From there, simply click on a Markdown file, PDF file or SVG icon in the File Ex Do not activate when Game Mode is on "Game mode" is the Windows feature to prevent notification when playing a game. + + Custom colors + + + Windows default + + + App theme + + + Customize the way zones look + + + Zone appearance + \ No newline at end of file diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/FancyZonesPage.xaml b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/FancyZonesPage.xaml index 9a83f979b6..bacad57cb7 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/FancyZonesPage.xaml +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/FancyZonesPage.xaml @@ -13,6 +13,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - @@ -235,11 +256,6 @@ - - - - - diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/FancyZonesPage.xaml.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/FancyZonesPage.xaml.cs index ea85cd2c85..f81034dd4c 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/FancyZonesPage.xaml.cs +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI/Views/FancyZonesPage.xaml.cs @@ -19,5 +19,10 @@ namespace Microsoft.PowerToys.Settings.UI.Views ViewModel = new FancyZonesViewModel(settingsUtils, SettingsRepository.GetInstance(settingsUtils), SettingsRepository.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage); DataContext = ViewModel; } + + private void OpenColorsSettings_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) + { + Helpers.StartProcessHelper.Start(Helpers.StartProcessHelper.ColorsSettings); + } } }