Skip to content

Commit

Permalink
[FancyZones] Use accent color and theme (#14158)
Browse files Browse the repository at this point in the history
* use accent color and theme

* typo

* Updated FZ color UX (#14171)

Co-authored-by: Laute <Niels.Laute@philips.com>

* fix resources

* rebase fix

* label updated

Co-authored-by: Niels Laute <niels.laute@live.nl>
Co-authored-by: Laute <Niels.Laute@philips.com>
  • Loading branch information
3 people committed Nov 4, 2021
1 parent 3ead98a commit e19ecd2
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 57 deletions.
59 changes: 53 additions & 6 deletions src/modules/fancyzones/FancyZonesLib/FancyZones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "CallTracer.h"

#include <FancyZonesLib/SecondaryMouseButtonsHook.h>
#include <winrt/Windows.UI.ViewManagement.h>

enum class DisplayChangeType
{
Expand Down Expand Up @@ -81,6 +82,13 @@ struct FancyZones : public winrt::implements<FancyZones, IFancyZones, IFancyZone
{
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));
}

Expand Down Expand Up @@ -173,6 +181,7 @@ struct FancyZones : public winrt::implements<FancyZones, IFancyZones, IFancyZone
std::vector<HMONITOR> GetMonitorsSorted() noexcept;
HMONITOR WorkAreaKeyFromWindow(HWND window) noexcept;

bool GetSystemTheme() const noexcept;
ZoneColors GetZoneColors() const noexcept;

const HINSTANCE m_hinstance{};
Expand Down Expand Up @@ -214,6 +223,8 @@ struct FancyZones : public winrt::implements<FancyZones, IFancyZones, IFancyZone
};

std::function<void()> FancyZones::disableModuleCallback = {};
COLORREF currentAccentColor;
COLORREF currentBackgroundColor;

// IFancyZones
IFACEMETHODIMP_(void)
Expand Down Expand Up @@ -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<IFancyZones> MakeFancyZones(HINSTANCE hinstance,
Expand Down
5 changes: 4 additions & 1 deletion src/modules/fancyzones/FancyZonesLib/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
</data>
<data name="Cant_Drag_Elevated" xml:space="preserve">
<value>We've detected an application running with administrator privileges. This will prevent certain interactions with these applications.</value>
<comment>administrator is context of user account.</comment>
<comment>administrator is context of user account.</comment>
</data>
<data name="Cant_Drag_Elevated_Learn_More" xml:space="preserve">
<value>Learn more</value>
Expand Down Expand Up @@ -263,4 +263,7 @@
<data name="Setting_Description_FlashZonesOnQuickSwitch" xml:space="preserve">
<value>Flash zones when switching layout</value>
</data>
<data name="Setting_Description_System_Theme" xml:space="preserve">
<value>Use system theme</value>
</data>
</root>
4 changes: 3 additions & 1 deletion src/modules/fancyzones/FancyZonesLib/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -80,7 +81,7 @@ struct FancyZonesSettings : winrt::implements<FancyZonesSettings, IFancyZonesSet
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 },
Expand All @@ -98,6 +99,7 @@ struct FancyZonesSettings : winrt::implements<FancyZonesSettings, IFancyZonesSet
{ 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 },
};
};

Expand Down
1 change: 1 addition & 0 deletions src/modules/fancyzones/FancyZonesLib/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions src/modules/fancyzones/FancyZonesLib/ZoneColors.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ struct ZoneColors
COLORREF primaryColor;
COLORREF borderColor;
COLORREF highlightColor;
COLORREF textColor;
int highlightOpacity;
};
17 changes: 10 additions & 7 deletions src/modules/fancyzones/FancyZonesLib/ZoneWindowDrawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -144,13 +142,15 @@ ZoneWindowDrawing::RenderResult ZoneWindowDrawing::Render()

for (auto drawableRect : m_sceneRects)
{
ID2D1SolidColorBrush* textBrush = nullptr;
ID2D1SolidColorBrush* borderBrush = nullptr;
ID2D1SolidColorBrush* fillBrush = nullptr;

// Need to copy the rect from m_sceneRects
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);

Expand All @@ -174,18 +174,18 @@ 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)
{
textFormat->Release();
}

if (textBrush)
{
textBrush->Release();
}

// The lock must be released here, as EndDraw() will wait for vertical sync
lock.unlock();

Expand Down Expand Up @@ -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;
Expand All @@ -313,6 +314,7 @@ void ZoneWindowDrawing::DrawActiveZoneSet(const IZoneSet::ZonesMap& zones,
.rect = ConvertRect(zone->GetZoneRect()),
.borderColor = borderColor,
.fillColor = inactiveColor,
.textColor = textColor,
.id = zone->Id()
};

Expand All @@ -334,6 +336,7 @@ void ZoneWindowDrawing::DrawActiveZoneSet(const IZoneSet::ZonesMap& zones,
.rect = ConvertRect(zone->GetZoneRect()),
.borderColor = borderColor,
.fillColor = highlightColor,
.textColor = textColor,
.id = zone->Id()
};

Expand Down
1 change: 1 addition & 0 deletions src/modules/fancyzones/FancyZonesLib/ZoneWindowDrawing.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ZoneWindowDrawing
D2D1_RECT_F rect;
D2D1_COLOR_F borderColor;
D2D1_COLOR_F fillColor;
D2D1_COLOR_F textColor;
ZoneIndex id;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public FZConfigProperties()
FancyzonesExcludedApps = new StringProperty();
FancyzonesInActiveColor = new StringProperty(ConfigDefaults.DefaultFancyZonesInActiveColor);
FancyzonesBorderColor = new StringProperty(ConfigDefaults.DefaultFancyzonesBorderColor);
FancyzonesSystemTheme = new BoolProperty(true);
}

[JsonPropertyName("fancyzones_shiftDrag")]
Expand Down Expand Up @@ -126,6 +127,9 @@ public FZConfigProperties()
[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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public FancyZonesViewModel(SettingsUtils settingsUtils, ISettingsRepository<Gene
_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;
Expand Down Expand Up @@ -126,6 +127,7 @@ public FancyZonesViewModel(SettingsUtils settingsUtils, ISettingsRepository<Gene
private bool _useCursorPosEditorStartupScreen;
private bool _showOnAllMonitors;
private bool _makeDraggedWindowTransparent;
private bool _systemTheme;

private int _highlightOpacity;
private string _excludedApps;
Expand Down Expand Up @@ -520,6 +522,24 @@ public bool MakeDraggedWindowsTransparent
}
}

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
Expand Down

0 comments on commit e19ecd2

Please sign in to comment.