Skip to content

Commit

Permalink
adding fancy zone opacity setting, enhancement #631
Browse files Browse the repository at this point in the history
  • Loading branch information
yodurr committed Dec 23, 2019
1 parent 8f0aa03 commit 0265e31
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/modules/fancyzones/lib/FancyZones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ struct FancyZones : public winrt::implements<FancyZones, IFancyZones, IFancyZone
}
return GUID_NULL;
}
IFACEMETHODIMP_(int) GetZoneHighlightOpacity() noexcept
{
return m_settings->GetSettings().zoneHighlightOpacity;
}

LRESULT WndProc(HWND, UINT, WPARAM, LPARAM) noexcept;
void OnDisplayChange(DisplayChangeType changeType) noexcept;
Expand Down Expand Up @@ -312,7 +316,6 @@ void FancyZones::ToggleEditor() noexcept
monitor = MonitorFromWindow(foregroundWindow, MONITOR_DEFAULTTOPRIMARY);
}


if (!monitor)
{
return;
Expand Down Expand Up @@ -343,7 +346,7 @@ void FancyZones::ToggleEditor() noexcept

const auto taskbar_x_offset = MulDiv(mi.rcWork.left - mi.rcMonitor.left, DPIAware::DEFAULT_DPI, dpi_x);
const auto taskbar_y_offset = MulDiv(mi.rcWork.top - mi.rcMonitor.top, DPIAware::DEFAULT_DPI, dpi_y);

// Do not scale window params by the dpi, that will be done in the editor - see LayoutModel.Apply
const auto x = mi.rcMonitor.left + taskbar_x_offset;
const auto y = mi.rcMonitor.top + taskbar_y_offset;
Expand Down
1 change: 1 addition & 0 deletions src/modules/fancyzones/lib/FancyZones.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface __declspec(uuid("{5C8D99D6-34B2-4F4A-A8E5-7483F6869775}")) IZoneWindow
IFACEMETHOD_(void, MoveWindowsOnActiveZoneSetChange)() = 0;
IFACEMETHOD_(COLORREF, GetZoneHighlightColor)() = 0;
IFACEMETHOD_(GUID, GetCurrentMonitorZoneSetId)(HMONITOR monitor) = 0;
IFACEMETHOD_(int, GetZoneHighlightOpacity)() = 0;
};

winrt::com_ptr<IFancyZones> MakeFancyZones(HINSTANCE hinstance, IFancyZonesSettings* settings) noexcept;
8 changes: 8 additions & 0 deletions src/modules/fancyzones/lib/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct FancyZonesSettings : winrt::implements<FancyZonesSettings, IFancyZonesSet
const std::wstring m_zoneHiglightName = L"fancyzones_zoneHighlightColor";
const std::wstring m_editorHotkeyName = L"fancyzones_editor_hotkey";
const std::wstring m_excludedAppsName = L"fancyzones_excluded_apps";
const std::wstring m_zoneHighlightOpacity = L"fancyzones_highlight_opacity";
};

IFACEMETHODIMP_(bool) FancyZonesSettings::GetConfig(_Out_ PWSTR buffer, _Out_ int *buffer_size) noexcept
Expand Down Expand Up @@ -76,6 +77,7 @@ IFACEMETHODIMP_(bool) FancyZonesSettings::GetConfig(_Out_ PWSTR buffer, _Out_ in
settings.add_bool_toogle(setting.name, setting.resourceId, *setting.value);
}

settings.add_int_spinner(m_zoneHighlightOpacity, IDS_SETTINGS_HIGHLIGHT_OPACITY, m_settings.zoneHighlightOpacity, 1, 255, 1);
settings.add_color_picker(m_zoneHiglightName, IDS_SETTING_DESCRIPTION_ZONEHIGHLIGHTCOLOR, m_settings.zoneHightlightColor);
settings.add_multiline_string(m_excludedAppsName, IDS_SETTING_EXCLCUDED_APPS_DESCRIPTION, m_settings.excludedApps);

Expand Down Expand Up @@ -153,6 +155,11 @@ void FancyZonesSettings::LoadSettings(PCWSTR config, bool fromFile) noexcept try
}
}
}

if (auto val = values.get_int_value(m_zoneHighlightOpacity))
{
m_settings.zoneHighlightOpacity = *val;
}
}
CATCH_LOG();

Expand All @@ -166,6 +173,7 @@ void FancyZonesSettings::SaveSettings() noexcept try
}

values.add_property(m_zoneHiglightName, m_settings.zoneHightlightColor);
values.add_property(m_zoneHighlightOpacity, m_settings.zoneHighlightOpacity);
values.add_property(m_editorHotkeyName, m_settings.editorHotkey.get_json());
values.add_property(m_excludedAppsName, m_settings.excludedApps);

Expand Down
1 change: 1 addition & 0 deletions src/modules/fancyzones/lib/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct Settings
bool appLastZone_moveWindows = false;
bool use_cursorpos_editor_startupscreen = true;
std::wstring zoneHightlightColor = L"#0078D7";
int zoneHighlightOpacity = 225;
PowerToysSettings::HotkeyObject editorHotkey = PowerToysSettings::HotkeyObject::from_settings(true, false, false, false, VK_OEM_3);
std::wstring excludedApps = L"";
std::vector<std::wstring> excludedAppsArray;
Expand Down
1 change: 1 addition & 0 deletions src/modules/fancyzones/lib/ZoneWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ void ZoneWindow::DrawActiveZoneSet(wil::unique_hdc& hdc, RECT const& clientRect)
if (m_highlightZone)
{
colorHighlight.fill = m_host->GetZoneHighlightColor();
colorHighlight.fillAlpha = m_host->GetZoneHighlightOpacity();
colorHighlight.border = RGB(
max(0, GetRValue(colorHighlight.fill) - 25),
max(0, GetGValue(colorHighlight.fill) - 25),
Expand Down
Binary file modified src/modules/fancyzones/lib/fancyzones.rc
Binary file not shown.
1 change: 1 addition & 0 deletions src/modules/fancyzones/lib/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
#define IDS_SETTING_LAUNCH_EDITOR_DESCRIPTION 113
#define IDS_SETTING_LAUNCH_EDITOR_HOTKEY_LABEL 114
#define IDS_SETTING_EXCLCUDED_APPS_DESCRIPTION 115
#define IDS_SETTINGS_HIGHLIGHT_OPACITY 116
5 changes: 5 additions & 0 deletions src/modules/fancyzones/tests/UnitTests/ZoneWindow.Spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ namespace FancyZonesUnitTests
{
return m_guid;
}
IFACEMETHODIMP_(int)
GetZoneHighlightOpacity() noexcept
{
return 225;
}

GUID m_guid;
};
Expand Down

0 comments on commit 0265e31

Please sign in to comment.