Fancy zones ui update( zone numbering as numbers, dragged window transaprency option, zone coloring customization) (#1666)

* Fancy zones ui update (#4)

* Draft of numeric fancyzones with numbers

* Added support for zone color configuration, improved zone number display

* Changed order of settings to more logical

* Added option to edit zone border color

* Trancparency of dragged window, transparency of displayed zones, changed font of zone numbers

* Fix for compilation

* Some refactor

* Introduced gdiplus to draw zone and zone index

* Fix for dissappering windows

* Some fixes

* another merge fix

* another merge fix

* Unit test merge fix

* Transparency with show zones on all fix

* indentation fix

* Fix for failing test

* Changed order of color pickers

* "Zone Opacity"

* Zone opacity (%)

* Added option to turn off dragged window transparency, changed default zones color values
This commit is contained in:
PrzemyslawTusinski
2020-03-25 15:38:44 +01:00
committed by GitHub
parent b835716e36
commit f8f7fe4f33
13 changed files with 783 additions and 589 deletions

View File

@@ -83,6 +83,28 @@ public:
IFACEMETHODIMP_(void) IFACEMETHODIMP_(void)
MoveWindowsOnActiveZoneSetChange() noexcept; MoveWindowsOnActiveZoneSetChange() noexcept;
IFACEMETHODIMP_(COLORREF) IFACEMETHODIMP_(COLORREF)
GetZoneColor() noexcept
{
// Skip the leading # and convert to long
const auto color = m_settings->GetSettings()->zoneColor;
const auto tmp = std::stol(color.substr(1), nullptr, 16);
const auto nR = (tmp & 0xFF0000) >> 16;
const auto nG = (tmp & 0xFF00) >> 8;
const auto nB = (tmp & 0xFF);
return RGB(nR, nG, nB);
}
IFACEMETHODIMP_(COLORREF)
GetZoneBorderColor() noexcept
{
// Skip the leading # and convert to long
const auto color = m_settings->GetSettings()->zoneBorderColor;
const auto tmp = std::stol(color.substr(1), nullptr, 16);
const auto nR = (tmp & 0xFF0000) >> 16;
const auto nG = (tmp & 0xFF00) >> 8;
const auto nB = (tmp & 0xFF);
return RGB(nR, nG, nB);
}
IFACEMETHODIMP_(COLORREF)
GetZoneHighlightColor() noexcept GetZoneHighlightColor() noexcept
{ {
// Skip the leading # and convert to long // Skip the leading # and convert to long
@@ -111,6 +133,12 @@ public:
return m_settings->GetSettings()->zoneHighlightOpacity; return m_settings->GetSettings()->zoneHighlightOpacity;
} }
IFACEMETHODIMP_(bool)
isMakeDraggedWindowTransparentActive() noexcept
{
return m_settings->GetSettings()->makeDraggedWindowTransparent;
}
LRESULT WndProc(HWND, UINT, WPARAM, LPARAM) noexcept; LRESULT WndProc(HWND, UINT, WPARAM, LPARAM) noexcept;
void OnDisplayChange(DisplayChangeType changeType) noexcept; void OnDisplayChange(DisplayChangeType changeType) noexcept;
void AddZoneWindow(HMONITOR monitor, PCWSTR deviceId) noexcept; void AddZoneWindow(HMONITOR monitor, PCWSTR deviceId) noexcept;
@@ -927,6 +955,7 @@ void FancyZones::MoveSizeStartInternal(HWND window, HMONITOR monitor, POINT cons
} }
else if (m_zoneWindowMoveSize) else if (m_zoneWindowMoveSize)
{ {
m_zoneWindowMoveSize->RestoreOrginalTransparency();
m_zoneWindowMoveSize = nullptr; m_zoneWindowMoveSize = nullptr;
for (auto [keyMonitor, zoneWindow] : m_zoneWindowMap) for (auto [keyMonitor, zoneWindow] : m_zoneWindowMap)
{ {
@@ -996,10 +1025,12 @@ void FancyZones::MoveSizeUpdateInternal(HMONITOR monitor, POINT const& ptScreen,
{ {
// Drag got disabled, tell it to cancel and hide all windows // Drag got disabled, tell it to cancel and hide all windows
m_zoneWindowMoveSize = nullptr; m_zoneWindowMoveSize = nullptr;
for (auto [keyMonitor, zoneWindow] : m_zoneWindowMap) for (auto [keyMonitor, zoneWindow] : m_zoneWindowMap)
{ {
if (zoneWindow) if (zoneWindow)
{ {
zoneWindow->RestoreOrginalTransparency();
zoneWindow->HideZoneWindow(); zoneWindow->HideZoneWindow();
} }
} }
@@ -1012,14 +1043,14 @@ void FancyZones::MoveSizeUpdateInternal(HMONITOR monitor, POINT const& ptScreen,
if (iter->second != m_zoneWindowMoveSize) if (iter->second != m_zoneWindowMoveSize)
{ {
// The drag has moved to a different monitor. // The drag has moved to a different monitor.
auto const isDragEnabled = m_zoneWindowMoveSize->IsDragEnabled(); m_zoneWindowMoveSize->RestoreOrginalTransparency();
// only hide if the option to show all zones is off
if (!m_settings->GetSettings()->showZonesOnAllMonitors) if (!m_settings->GetSettings()->showZonesOnAllMonitors)
{ {
m_zoneWindowMoveSize->HideZoneWindow(); m_zoneWindowMoveSize->HideZoneWindow();
} }
m_zoneWindowMoveSize = iter->second; m_zoneWindowMoveSize = iter->second;
m_zoneWindowMoveSize->MoveSizeEnter(m_windowMoveSize, isDragEnabled); m_zoneWindowMoveSize->MoveSizeEnter(m_windowMoveSize, m_zoneWindowMoveSize->IsDragEnabled());
} }
m_zoneWindowMoveSize->MoveSizeUpdate(ptScreen, m_dragEnabled); m_zoneWindowMoveSize->MoveSizeUpdate(ptScreen, m_dragEnabled);
} }

View File

@@ -89,6 +89,14 @@ interface __declspec(uuid("{5C8D99D6-34B2-4F4A-A8E5-7483F6869775}")) IZoneWindow
* Assign window to appropriate zone inside new zone layout. * Assign window to appropriate zone inside new zone layout.
*/ */
IFACEMETHOD_(void, MoveWindowsOnActiveZoneSetChange)() = 0; IFACEMETHOD_(void, MoveWindowsOnActiveZoneSetChange)() = 0;
/**
* @returns Basic zone color.
*/
IFACEMETHOD_(COLORREF, GetZoneColor)() = 0;
/**
* @returns Zone border color.
*/
IFACEMETHOD_(COLORREF, GetZoneBorderColor)() = 0;
/** /**
* @returns Color used to highlight zone while giving zone layout hints. * @returns Color used to highlight zone while giving zone layout hints.
*/ */
@@ -101,6 +109,10 @@ interface __declspec(uuid("{5C8D99D6-34B2-4F4A-A8E5-7483F6869775}")) IZoneWindow
* @returns Integer in range [0, 100] indicating opacity of highlited zone (while giving zone layout hints). * @returns Integer in range [0, 100] indicating opacity of highlited zone (while giving zone layout hints).
*/ */
IFACEMETHOD_(int, GetZoneHighlightOpacity)() = 0; IFACEMETHOD_(int, GetZoneHighlightOpacity)() = 0;
/**
* @returns Bool indicating if dragged window should be transparrent
*/
IFACEMETHOD_(bool, isMakeDraggedWindowTransparentActive) () = 0;
}; };
winrt::com_ptr<IFancyZones> MakeFancyZones(HINSTANCE hinstance, const winrt::com_ptr<IFancyZonesSettings>& settings) noexcept; winrt::com_ptr<IFancyZones> MakeFancyZones(HINSTANCE hinstance, const winrt::com_ptr<IFancyZonesSettings>& settings) noexcept;

View File

@@ -36,7 +36,7 @@ private:
PCWSTR name; PCWSTR name;
bool* value; bool* value;
int resourceId; int resourceId;
} m_configBools[9] = { } m_configBools[10] = {
{ L"fancyzones_shiftDrag", &m_settings.shiftDrag, IDS_SETTING_DESCRIPTION_SHIFTDRAG }, { L"fancyzones_shiftDrag", &m_settings.shiftDrag, IDS_SETTING_DESCRIPTION_SHIFTDRAG },
{ L"fancyzones_overrideSnapHotkeys", &m_settings.overrideSnapHotkeys, IDS_SETTING_DESCRIPTION_OVERRIDE_SNAP_HOTKEYS }, { L"fancyzones_overrideSnapHotkeys", &m_settings.overrideSnapHotkeys, IDS_SETTING_DESCRIPTION_OVERRIDE_SNAP_HOTKEYS },
{ L"fancyzones_zoneSetChange_flashZones", &m_settings.zoneSetChange_flashZones, IDS_SETTING_DESCRIPTION_ZONESETCHANGE_FLASHZONES }, { L"fancyzones_zoneSetChange_flashZones", &m_settings.zoneSetChange_flashZones, IDS_SETTING_DESCRIPTION_ZONESETCHANGE_FLASHZONES },
@@ -46,8 +46,11 @@ private:
{ L"fancyzones_appLastZone_moveWindows", &m_settings.appLastZone_moveWindows, IDS_SETTING_DESCRIPTION_APPLASTZONE_MOVEWINDOWS }, { L"fancyzones_appLastZone_moveWindows", &m_settings.appLastZone_moveWindows, IDS_SETTING_DESCRIPTION_APPLASTZONE_MOVEWINDOWS },
{ L"use_cursorpos_editor_startupscreen", &m_settings.use_cursorpos_editor_startupscreen, IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN }, { L"use_cursorpos_editor_startupscreen", &m_settings.use_cursorpos_editor_startupscreen, IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN },
{ L"fancyzones_show_on_all_monitors", &m_settings.showZonesOnAllMonitors, IDS_SETTING_DESCRIPTION_SHOW_FANCY_ZONES_ON_ALL_MONITORS}, { L"fancyzones_show_on_all_monitors", &m_settings.showZonesOnAllMonitors, IDS_SETTING_DESCRIPTION_SHOW_FANCY_ZONES_ON_ALL_MONITORS},
{ L"fancyzones_makeDraggedWindowTransparent", &m_settings.makeDraggedWindowTransparent, IDS_SETTING_DESCRIPTION_MAKE_DRAGGED_WINDOW_TRANSPARENT},
}; };
const std::wstring m_zoneColorName = L"fancyzones_zoneColor";
const std::wstring m_zoneBorderColorName = L"fancyzones_zoneBorderColor";
const std::wstring m_zoneHiglightName = L"fancyzones_zoneHighlightColor"; const std::wstring m_zoneHiglightName = L"fancyzones_zoneHighlightColor";
const std::wstring m_editorHotkeyName = L"fancyzones_editor_hotkey"; const std::wstring m_editorHotkeyName = L"fancyzones_editor_hotkey";
const std::wstring m_excludedAppsName = L"fancyzones_excluded_apps"; const std::wstring m_excludedAppsName = L"fancyzones_excluded_apps";
@@ -79,8 +82,12 @@ IFACEMETHODIMP_(bool) FancyZonesSettings::GetConfig(_Out_ PWSTR buffer, _Out_ in
settings.add_bool_toogle(setting.name, setting.resourceId, *setting.value); settings.add_bool_toogle(setting.name, setting.resourceId, *setting.value);
} }
settings.add_int_spinner(m_zoneHighlightOpacity, IDS_SETTINGS_HIGHLIGHT_OPACITY, m_settings.zoneHighlightOpacity, 0, 100, 1);
settings.add_color_picker(m_zoneHiglightName, IDS_SETTING_DESCRIPTION_ZONEHIGHLIGHTCOLOR, m_settings.zoneHightlightColor); settings.add_color_picker(m_zoneHiglightName, IDS_SETTING_DESCRIPTION_ZONEHIGHLIGHTCOLOR, m_settings.zoneHightlightColor);
settings.add_color_picker(m_zoneColorName, IDS_SETTING_DESCRIPTION_ZONECOLOR, m_settings.zoneColor);
settings.add_color_picker(m_zoneBorderColorName, IDS_SETTING_DESCRIPTION_ZONE_BORDER_COLOR, m_settings.zoneBorderColor);
settings.add_int_spinner(m_zoneHighlightOpacity, IDS_SETTINGS_HIGHLIGHT_OPACITY, m_settings.zoneHighlightOpacity, 0, 100, 1);
settings.add_multiline_string(m_excludedAppsName, IDS_SETTING_EXCLCUDED_APPS_DESCRIPTION, m_settings.excludedApps); settings.add_multiline_string(m_excludedAppsName, IDS_SETTING_EXCLCUDED_APPS_DESCRIPTION, m_settings.excludedApps);
return settings.serialize_to_buffer(buffer, buffer_size); return settings.serialize_to_buffer(buffer, buffer_size);
@@ -125,6 +132,16 @@ void FancyZonesSettings::LoadSettings(PCWSTR config, bool fromFile) noexcept try
} }
} }
if (auto val = values.get_string_value(m_zoneColorName))
{
m_settings.zoneColor = std::move(*val);
}
if (auto val = values.get_string_value(m_zoneBorderColorName))
{
m_settings.zoneBorderColor = std::move(*val);
}
if (auto val = values.get_string_value(m_zoneHiglightName)) if (auto val = values.get_string_value(m_zoneHiglightName))
{ {
m_settings.zoneHightlightColor = std::move(*val); m_settings.zoneHightlightColor = std::move(*val);
@@ -174,6 +191,8 @@ void FancyZonesSettings::SaveSettings() noexcept try
values.add_property(setting.name, *setting.value); values.add_property(setting.name, *setting.value);
} }
values.add_property(m_zoneColorName, m_settings.zoneColor);
values.add_property(m_zoneBorderColorName, m_settings.zoneBorderColor);
values.add_property(m_zoneHiglightName, m_settings.zoneHightlightColor); values.add_property(m_zoneHiglightName, m_settings.zoneHightlightColor);
values.add_property(m_zoneHighlightOpacity, m_settings.zoneHighlightOpacity); values.add_property(m_zoneHighlightOpacity, m_settings.zoneHighlightOpacity);
values.add_property(m_editorHotkeyName, m_settings.editorHotkey.get_json()); values.add_property(m_editorHotkeyName, m_settings.editorHotkey.get_json());

View File

@@ -15,8 +15,11 @@ struct Settings
bool appLastZone_moveWindows = false; bool appLastZone_moveWindows = false;
bool use_cursorpos_editor_startupscreen = true; bool use_cursorpos_editor_startupscreen = true;
bool showZonesOnAllMonitors = false; bool showZonesOnAllMonitors = false;
std::wstring zoneHightlightColor = L"#0078D7"; bool makeDraggedWindowTransparent = true;
int zoneHighlightOpacity = 90; std::wstring zoneColor = L"#F5FCFF";
std::wstring zoneBorderColor = L"#FFFFFF";
std::wstring zoneHightlightColor = L"#008CFF";
int zoneHighlightOpacity = 50;
PowerToysSettings::HotkeyObject editorHotkey = PowerToysSettings::HotkeyObject::from_settings(true, false, false, false, VK_OEM_3); PowerToysSettings::HotkeyObject editorHotkey = PowerToysSettings::HotkeyObject::from_settings(true, false, false, false, VK_OEM_3);
std::wstring excludedApps = L""; std::wstring excludedApps = L"";
std::vector<std::wstring> excludedAppsArray; std::vector<std::wstring> excludedAppsArray;

View File

@@ -10,6 +10,8 @@
#include <ShellScalingApi.h> #include <ShellScalingApi.h>
#include <mutex> #include <mutex>
#include <gdiplus.h>
namespace ZoneWindowUtils namespace ZoneWindowUtils
{ {
const std::wstring& GetActiveZoneSetTmpPath() const std::wstring& GetActiveZoneSetTmpPath()
@@ -92,146 +94,70 @@ namespace ZoneWindowDrawUtils
int thickness{}; int thickness{};
}; };
bool IsOccluded(const std::vector<winrt::com_ptr<IZone>>& zones, POINT pt, size_t index) noexcept
{
size_t i = 1;
for (auto iter = zones.begin(); iter != zones.end(); iter++)
{
if (winrt::com_ptr<IZone> zone = iter->try_as<IZone>())
{
if (i < index)
{
if (PtInRect(&zone->GetZoneRect(), pt))
{
return true;
}
}
}
i++;
}
return false;
}
void DrawBackdrop(wil::unique_hdc& hdc, RECT const& clientRect) noexcept void DrawBackdrop(wil::unique_hdc& hdc, RECT const& clientRect) noexcept
{ {
FillRectARGB(hdc, &clientRect, 0, RGB(0, 0, 0), false); FillRectARGB(hdc, &clientRect, 0, RGB(0, 0, 0), false);
} }
void DrawIndex(wil::unique_hdc& hdc, POINT offset, size_t index, int padding, int size, bool flipX, bool flipY, COLORREF colorFill) void DrawIndex(wil::unique_hdc& hdc, Rect rect, size_t index)
{ {
RECT rect = { offset.x, offset.y, offset.x + size, offset.y + size }; Gdiplus::Graphics g(hdc.get());
for (int y = 0; y < 3; y++)
{
for (int x = 0; x < 3; x++)
{
RECT useRect = rect;
if (flipX)
{
if (x == 0)
useRect.left += (size + padding + size + padding);
else if (x == 2)
useRect.left -= (size + padding + size + padding);
useRect.right = useRect.left + size;
}
if (flipY) Gdiplus::FontFamily fontFamily(L"Segoe ui");
{ Gdiplus::Font font(&fontFamily, 80, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
if (y == 0) Gdiplus::SolidBrush solidBrush(Gdiplus::Color(255, 0, 0, 0));
useRect.top += (size + padding + size + padding);
else if (y == 2)
useRect.top -= (size + padding + size + padding);
useRect.bottom = useRect.top + size;
}
FillRectARGB(hdc, &useRect, 200, RGB(50, 50, 50), true); std::wstring text = std::to_wstring(index);
RECT inside = useRect; g.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
InflateRect(&inside, -2, -2); Gdiplus::StringFormat stringFormat = new Gdiplus::StringFormat();
stringFormat.SetAlignment(Gdiplus::StringAlignmentCenter);
stringFormat.SetLineAlignment(Gdiplus::StringAlignmentCenter);
FillRectARGB(hdc, &inside, 100, colorFill, true); Gdiplus::RectF gdiRect(static_cast<Gdiplus::REAL>(rect.left()),
static_cast<Gdiplus::REAL>(rect.top()),
static_cast<Gdiplus::REAL>(rect.width()),
static_cast<Gdiplus::REAL>(rect.height()));
rect.left += (size + padding); g.DrawString(text.c_str(), -1, &font, gdiRect, &stringFormat, &solidBrush);
rect.right = rect.left + size;
if (--index == 0)
{
return;
}
}
rect.left = offset.x;
rect.right = rect.left + size;
rect.top += (size + padding);
rect.bottom = rect.top + size;
}
} }
void DrawZone(wil::unique_hdc& hdc, ColorSetting const& colorSetting, winrt::com_ptr<IZone> zone, const std::vector<winrt::com_ptr<IZone>>& zones, bool flashMode) noexcept void DrawZone(wil::unique_hdc& hdc, ColorSetting const& colorSetting, winrt::com_ptr<IZone> zone, const std::vector<winrt::com_ptr<IZone>>& zones, bool flashMode) noexcept
{ {
RECT zoneRect = zone->GetZoneRect(); RECT zoneRect = zone->GetZoneRect();
if (colorSetting.borderAlpha > 0)
{
FillRectARGB(hdc, &zoneRect, colorSetting.borderAlpha, colorSetting.border, false);
InflateRect(&zoneRect, colorSetting.thickness, colorSetting.thickness);
}
FillRectARGB(hdc, &zoneRect, colorSetting.fillAlpha, colorSetting.fill, false);
if (flashMode) Gdiplus::Graphics g(hdc.get());
{ Gdiplus::Color fillColor(colorSetting.fillAlpha, GetRValue(colorSetting.fill), GetGValue(colorSetting.fill), GetBValue(colorSetting.fill));
return; Gdiplus::Color borderColor(colorSetting.borderAlpha, GetRValue(colorSetting.border), GetGValue(colorSetting.border), GetBValue(colorSetting.border));
}
COLORREF const colorFill = RGB(255, 255, 255);
size_t const index = zone->Id(); Gdiplus::Rect rectangle(zoneRect.left, zoneRect.top, zoneRect.right - zoneRect.left, zoneRect.bottom - zoneRect.top);
int const padding = 5;
int const size = 10;
POINT offset = { zoneRect.left + padding, zoneRect.top + padding };
if (!IsOccluded(zones, offset, index))
{
DrawIndex(hdc, offset, index, padding, size, false, false, colorFill); // top left
return;
}
offset.x = zoneRect.right - ((padding + size) * 3); Gdiplus::Pen pen(borderColor, static_cast<Gdiplus::REAL>(colorSetting.thickness));
if (!IsOccluded(zones, offset, index)) g.FillRectangle(new Gdiplus::SolidBrush(fillColor), rectangle);
{ g.DrawRectangle(&pen, rectangle);
DrawIndex(hdc, offset, index, padding, size, true, false, colorFill); // top right
return;
}
offset.y = zoneRect.bottom - ((padding + size) * 3); if (!flashMode)
if (!IsOccluded(zones, offset, index))
{ {
DrawIndex(hdc, offset, index, padding, size, true, true, colorFill); // bottom right DrawIndex(hdc, zoneRect, zone->Id());
return;
} }
offset.x = zoneRect.left + padding;
DrawIndex(hdc, offset, index, padding, size, false, true, colorFill); // bottom left
} }
void DrawActiveZoneSet(wil::unique_hdc& hdc, COLORREF highlightColor, int highlightOpacity, const std::vector<winrt::com_ptr<IZone>>& zones, const winrt::com_ptr<IZone>& highlightZone, bool flashMode, bool drawHints) noexcept void DrawActiveZoneSet(wil::unique_hdc& hdc,
COLORREF zoneColor,
COLORREF zoneBorderColor,
COLORREF highlightColor,
int zoneOpacity,
const std::vector<winrt::com_ptr<IZone>>& zones,
const winrt::com_ptr<IZone>& highlightZone,
bool flashMode,
bool drawHints) noexcept
{ {
static constexpr std::array<COLORREF, 9> colors{ // { fillAlpha, fill, borderAlpha, border, thickness }
RGB(75, 75, 85), ColorSetting const colorHints{ OpacitySettingToAlpha(zoneOpacity), RGB(81, 92, 107), 255, RGB(104, 118, 138), -2 };
RGB(150, 150, 160), ColorSetting colorViewer{ OpacitySettingToAlpha(zoneOpacity), 0, 255, RGB(40, 50, 60), -2 };
RGB(100, 100, 110), ColorSetting colorHighlight{ OpacitySettingToAlpha(zoneOpacity), 0, 255, 0, -2 };
RGB(125, 125, 135), ColorSetting const colorFlash{ OpacitySettingToAlpha(zoneOpacity), RGB(81, 92, 107), 200, RGB(104, 118, 138), -2 };
RGB(225, 225, 235),
RGB(25, 25, 35),
RGB(200, 200, 210),
RGB(50, 50, 60),
RGB(175, 175, 185),
};
// ColorSetting { fillAlpha, fill, borderAlpha, border, thickness }
ColorSetting const colorHints{ 225, RGB(81, 92, 107), 255, RGB(104, 118, 138), -2 };
ColorSetting colorViewer{ OpacitySettingToAlpha(highlightOpacity), 0, 255, RGB(40, 50, 60), -2 };
ColorSetting colorHighlight{ OpacitySettingToAlpha(highlightOpacity), 0, 255, 0, -2 };
ColorSetting const colorFlash{ 200, RGB(81, 92, 107), 200, RGB(104, 118, 138), -2 };
const size_t maxColorIndex = min(size(zones) - 1, size(colors) - 1);
size_t colorIndex = maxColorIndex;
for (auto iter = zones.begin(); iter != zones.end(); iter++) for (auto iter = zones.begin(); iter != zones.end(); iter++)
{ {
winrt::com_ptr<IZone> zone = iter->try_as<IZone>(); winrt::com_ptr<IZone> zone = iter->try_as<IZone>();
@@ -251,20 +177,17 @@ namespace ZoneWindowDrawUtils
DrawZone(hdc, colorHints, zone, zones, flashMode); DrawZone(hdc, colorHints, zone, zones, flashMode);
} }
{ {
colorViewer.fill = colors[colorIndex]; colorViewer.fill = zoneColor;
colorViewer.border = zoneBorderColor;
DrawZone(hdc, colorViewer, zone, zones, flashMode); DrawZone(hdc, colorViewer, zone, zones, flashMode);
} }
} }
colorIndex = colorIndex != 0 ? colorIndex - 1 : maxColorIndex;
} }
if (highlightZone) if (highlightZone)
{ {
colorHighlight.fill = highlightColor; colorHighlight.fill = highlightColor;
colorHighlight.border = RGB( colorHighlight.border = zoneBorderColor;
max(0, GetRValue(colorHighlight.fill) - 25),
max(0, GetGValue(colorHighlight.fill) - 25),
max(0, GetBValue(colorHighlight.fill) - 25));
DrawZone(hdc, colorHighlight, highlightZone, zones, flashMode); DrawZone(hdc, colorHighlight, highlightZone, zones, flashMode);
} }
} }
@@ -274,11 +197,15 @@ struct ZoneWindow : public winrt::implements<ZoneWindow, IZoneWindow>
{ {
public: public:
ZoneWindow(HINSTANCE hinstance); ZoneWindow(HINSTANCE hinstance);
~ZoneWindow();
bool Init(IZoneWindowHost* host, HINSTANCE hinstance, HMONITOR monitor, const std::wstring& uniqueId, bool flashZones); bool Init(IZoneWindowHost* host, HINSTANCE hinstance, HMONITOR monitor, const std::wstring& uniqueId, bool flashZones);
IFACEMETHODIMP MoveSizeEnter(HWND window, bool dragEnabled) noexcept; IFACEMETHODIMP MoveSizeEnter(HWND window, bool dragEnabled) noexcept;
IFACEMETHODIMP MoveSizeUpdate(POINT const& ptScreen, bool dragEnabled) noexcept; IFACEMETHODIMP MoveSizeUpdate(POINT const& ptScreen, bool dragEnabled) noexcept;
IFACEMETHODIMP MoveSizeEnd(HWND window, POINT const& ptScreen) noexcept; IFACEMETHODIMP MoveSizeEnd(HWND window, POINT const& ptScreen) noexcept;
IFACEMETHODIMP_(void)
RestoreOrginalTransparency() noexcept;
IFACEMETHODIMP_(bool) IFACEMETHODIMP_(bool)
IsDragEnabled() noexcept { return m_dragEnabled; } IsDragEnabled() noexcept { return m_dragEnabled; }
IFACEMETHODIMP_(void) IFACEMETHODIMP_(void)
@@ -304,7 +231,6 @@ protected:
static LRESULT CALLBACK s_WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) noexcept; static LRESULT CALLBACK s_WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) noexcept;
private: private:
void LoadSettings() noexcept; void LoadSettings() noexcept;
void InitializeZoneSets(MONITORINFO const& mi) noexcept; void InitializeZoneSets(MONITORINFO const& mi) noexcept;
void CalculateZoneSet() noexcept; void CalculateZoneSet() noexcept;
@@ -332,6 +258,10 @@ private:
size_t m_keyCycle{}; size_t m_keyCycle{};
static const UINT m_showAnimationDuration = 200; // ms static const UINT m_showAnimationDuration = 200; // ms
static const UINT m_flashDuration = 700; // ms static const UINT m_flashDuration = 700; // ms
HWND draggedWindow;
BYTE draggedWindowInitialAlpha;
ULONG_PTR gdiplusToken;
}; };
ZoneWindow::ZoneWindow(HINSTANCE hinstance) ZoneWindow::ZoneWindow(HINSTANCE hinstance)
@@ -343,6 +273,16 @@ ZoneWindow::ZoneWindow(HINSTANCE hinstance)
wcex.lpszClassName = L"SuperFancyZones_ZoneWindow"; wcex.lpszClassName = L"SuperFancyZones_ZoneWindow";
wcex.hCursor = LoadCursorW(nullptr, IDC_ARROW); wcex.hCursor = LoadCursorW(nullptr, IDC_ARROW);
RegisterClassExW(&wcex); RegisterClassExW(&wcex);
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
}
ZoneWindow::~ZoneWindow()
{
RestoreOrginalTransparency();
Gdiplus::GdiplusShutdown(gdiplusToken);
} }
bool ZoneWindow::Init(IZoneWindowHost* host, HINSTANCE hinstance, HMONITOR monitor, const std::wstring& uniqueId, bool flashZones) bool ZoneWindow::Init(IZoneWindowHost* host, HINSTANCE hinstance, HMONITOR monitor, const std::wstring& uniqueId, bool flashZones)
@@ -395,6 +335,17 @@ bool ZoneWindow::Init(IZoneWindowHost* host, HINSTANCE hinstance, HMONITOR monit
IFACEMETHODIMP ZoneWindow::MoveSizeEnter(HWND window, bool dragEnabled) noexcept IFACEMETHODIMP ZoneWindow::MoveSizeEnter(HWND window, bool dragEnabled) noexcept
{ {
if (m_host->isMakeDraggedWindowTransparentActive())
{
draggedWindow = window;
SetWindowLong(window,
GWL_EXSTYLE,
GetWindowLong(window, GWL_EXSTYLE) | WS_EX_LAYERED);
GetLayeredWindowAttributes(window, 0, &draggedWindowInitialAlpha, 0);
SetLayeredWindowAttributes(window, 0, (255 * 50) / 100, LWA_ALPHA);
}
if (m_windowMoveSize) if (m_windowMoveSize)
{ {
return E_INVALIDARG; return E_INVALIDARG;
@@ -437,6 +388,8 @@ IFACEMETHODIMP ZoneWindow::MoveSizeUpdate(POINT const& ptScreen, bool dragEnable
IFACEMETHODIMP ZoneWindow::MoveSizeEnd(HWND window, POINT const& ptScreen) noexcept IFACEMETHODIMP ZoneWindow::MoveSizeEnd(HWND window, POINT const& ptScreen) noexcept
{ {
RestoreOrginalTransparency();
if (m_windowMoveSize != window) if (m_windowMoveSize != window)
{ {
return E_INVALIDARG; return E_INVALIDARG;
@@ -457,6 +410,19 @@ IFACEMETHODIMP ZoneWindow::MoveSizeEnd(HWND window, POINT const& ptScreen) noexc
return S_OK; return S_OK;
} }
IFACEMETHODIMP_(void)
ZoneWindow::RestoreOrginalTransparency() noexcept
{
if (m_host->isMakeDraggedWindowTransparentActive() && draggedWindow != nullptr)
{
SetLayeredWindowAttributes(draggedWindow,
0,
draggedWindowInitialAlpha == 0 ? 255 : draggedWindowInitialAlpha,
LWA_ALPHA);
draggedWindow = nullptr;
}
}
IFACEMETHODIMP_(void) IFACEMETHODIMP_(void)
ZoneWindow::MoveWindowIntoZoneByIndex(HWND window, int index) noexcept ZoneWindow::MoveWindowIntoZoneByIndex(HWND window, int index) noexcept
{ {
@@ -633,7 +599,8 @@ LRESULT ZoneWindow::WndProc(UINT message, WPARAM wparam, LPARAM lparam) noexcept
{ {
switch (message) switch (message)
{ {
case WM_NCDESTROY: { case WM_NCDESTROY:
{
::DefWindowProc(m_window.get(), message, wparam, lparam); ::DefWindowProc(m_window.get(), message, wparam, lparam);
SetWindowLongPtr(m_window.get(), GWLP_USERDATA, 0); SetWindowLongPtr(m_window.get(), GWLP_USERDATA, 0);
} }
@@ -643,7 +610,8 @@ LRESULT ZoneWindow::WndProc(UINT message, WPARAM wparam, LPARAM lparam) noexcept
return 1; return 1;
case WM_PRINTCLIENT: case WM_PRINTCLIENT:
case WM_PAINT: { case WM_PAINT:
{
PAINTSTRUCT ps; PAINTSTRUCT ps;
wil::unique_hdc hdc{ reinterpret_cast<HDC>(wparam) }; wil::unique_hdc hdc{ reinterpret_cast<HDC>(wparam) };
if (!hdc) if (!hdc)
@@ -680,9 +648,18 @@ void ZoneWindow::OnPaint(wil::unique_hdc& hdc) noexcept
if (bufferedPaint) if (bufferedPaint)
{ {
ZoneWindowDrawUtils::DrawBackdrop(hdcMem, clientRect); ZoneWindowDrawUtils::DrawBackdrop(hdcMem, clientRect);
if (m_activeZoneSet && m_host) if (m_activeZoneSet && m_host)
{ {
ZoneWindowDrawUtils::DrawActiveZoneSet(hdcMem, m_host->GetZoneHighlightColor(), m_host->GetZoneHighlightOpacity(), m_activeZoneSet->GetZones(), m_highlightZone, m_flashMode, m_drawHints); ZoneWindowDrawUtils::DrawActiveZoneSet(hdcMem,
m_host->GetZoneColor(),
m_host->GetZoneBorderColor(),
m_host->GetZoneHighlightColor(),
m_host->GetZoneHighlightOpacity(),
m_activeZoneSet->GetZones(),
m_highlightZone,
m_flashMode,
m_drawHints);
} }
EndBufferedPaint(bufferedPaint, TRUE); EndBufferedPaint(bufferedPaint, TRUE);

View File

@@ -70,6 +70,10 @@ interface __declspec(uuid("{7F017528-8110-4FB3-BE41-F472969C2560}")) IZoneWindow
* @param vkCode Pressed key representing layout index. * @param vkCode Pressed key representing layout index.
*/ */
IFACEMETHOD_(void, CycleActiveZoneSet)(DWORD vkCode) = 0; IFACEMETHOD_(void, CycleActiveZoneSet)(DWORD vkCode) = 0;
/**
* Restore orginal transaprency of dragged window.
*/
IFACEMETHOD_(void, RestoreOrginalTransparency) () = 0;
/** /**
* Save information about zone in which window was assigned, when closing the window. * Save information about zone in which window was assigned, when closing the window.
* Used once we open same window again to assign it to its previous zone. * Used once we open same window again to assign it to its previous zone.

View File

@@ -4,15 +4,18 @@
#define IDS_SETTING_DESCRIPTION_ZONESETCHANGE_MOVEWINDOWS 104 #define IDS_SETTING_DESCRIPTION_ZONESETCHANGE_MOVEWINDOWS 104
#define IDS_SETTING_DESCRIPTION_ZONESETCHANGE_FLASHZONES 105 #define IDS_SETTING_DESCRIPTION_ZONESETCHANGE_FLASHZONES 105
#define IDS_SETTING_DESCRIPTION_VIRTUALDESKTOPCHANGE_MOVEWINDOWS 106 #define IDS_SETTING_DESCRIPTION_VIRTUALDESKTOPCHANGE_MOVEWINDOWS 106
#define IDS_SETTING_DESCRIPTION_ZONEHIGHLIGHTCOLOR 107 #define IDS_SETTING_DESCRIPTION_SHOW_FANCY_ZONES_ON_ALL_MONITORS 107
#define IDS_SETTING_DESCRIPTION_APPLASTZONE_MOVEWINDOWS 108 #define IDS_SETTING_DESCRIPTION_MAKE_DRAGGED_WINDOW_TRANSPARENT 108
#define IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN 109 #define IDS_SETTING_DESCRIPTION_ZONECOLOR 109
#define IDS_SETTING_DESCRIPTION_SHOW_FANCY_ZONES_ON_ALL_MONITORS 110 #define IDS_SETTING_DESCRIPTION_ZONE_BORDER_COLOR 110
#define IDS_SETTING_DESCRIPTION 111 #define IDS_SETTING_DESCRIPTION_ZONEHIGHLIGHTCOLOR 111
#define IDS_SETTING_LAUNCH_EDITOR_LABEL 112 #define IDS_SETTING_DESCRIPTION_APPLASTZONE_MOVEWINDOWS 112
#define IDS_SETTING_LAUNCH_EDITOR_BUTTON 113 #define IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN 113
#define IDS_SETTING_LAUNCH_EDITOR_DESCRIPTION 114 #define IDS_SETTING_DESCRIPTION 114
#define IDS_SETTING_LAUNCH_EDITOR_HOTKEY_LABEL 115 #define IDS_SETTING_LAUNCH_EDITOR_LABEL 115
#define IDS_SETTING_EXCLCUDED_APPS_DESCRIPTION 116 #define IDS_SETTING_LAUNCH_EDITOR_BUTTON 116
#define IDS_SETTINGS_HIGHLIGHT_OPACITY 117 #define IDS_SETTING_LAUNCH_EDITOR_DESCRIPTION 117
#define IDS_FANCYZONES 118 #define IDS_SETTING_LAUNCH_EDITOR_HOTKEY_LABEL 118
#define IDS_SETTING_EXCLCUDED_APPS_DESCRIPTION 119
#define IDS_SETTINGS_HIGHLIGHT_OPACITY 120
#define IDS_FANCYZONES 121

View File

@@ -171,6 +171,9 @@ void Trace::SettingsChanged(const Settings& settings) noexcept
TraceLoggingBoolean(settings.appLastZone_moveWindows, "MoveWindowsToLastZoneOnAppOpening"), TraceLoggingBoolean(settings.appLastZone_moveWindows, "MoveWindowsToLastZoneOnAppOpening"),
TraceLoggingBoolean(settings.use_cursorpos_editor_startupscreen, "UseCursorPosOnEditorStartup"), TraceLoggingBoolean(settings.use_cursorpos_editor_startupscreen, "UseCursorPosOnEditorStartup"),
TraceLoggingBoolean(settings.showZonesOnAllMonitors, "ShowZonesOnAllMonitors"), TraceLoggingBoolean(settings.showZonesOnAllMonitors, "ShowZonesOnAllMonitors"),
TraceLoggingBoolean(settings.makeDraggedWindowTransparent, "MakeDraggedWindowTransparent"),
TraceLoggingWideString(settings.zoneColor.c_str(), "ZoneColor"),
TraceLoggingWideString(settings.zoneBorderColor.c_str(), "ZoneBorderColor"),
TraceLoggingWideString(settings.zoneHightlightColor.c_str(), "ZoneHighlightColor"), TraceLoggingWideString(settings.zoneHightlightColor.c_str(), "ZoneHighlightColor"),
TraceLoggingInt32(settings.zoneHighlightOpacity, "ZoneHighlightOpacity"), TraceLoggingInt32(settings.zoneHighlightOpacity, "ZoneHighlightOpacity"),
TraceLoggingWideString(hotkeyStr.c_str(), "Hotkey"), TraceLoggingWideString(hotkeyStr.c_str(), "Hotkey"),

View File

@@ -1,14 +1,18 @@
#pragma once #pragma once
#include "gdiplus.h"
struct Rect struct Rect
{ {
Rect() {} Rect() {}
Rect(RECT rect) : m_rect(rect) Rect(RECT rect) :
m_rect(rect)
{ {
} }
Rect(RECT rect, UINT dpi) : m_rect(rect) Rect(RECT rect, UINT dpi) :
m_rect(rect)
{ {
m_rect.right = m_rect.left + MulDiv(m_rect.right - m_rect.left, dpi, 96); m_rect.right = m_rect.left + MulDiv(m_rect.right - m_rect.left, dpi, 96);
m_rect.bottom = m_rect.top + MulDiv(m_rect.bottom - m_rect.top, dpi, 96); m_rect.bottom = m_rect.top + MulDiv(m_rect.bottom - m_rect.top, dpi, 96);
@@ -38,7 +42,7 @@ inline void MakeWindowTransparent(HWND window)
} }
} }
inline void InitRGB(_Out_ RGBQUAD *quad, BYTE alpha, COLORREF color) inline void InitRGB(_Out_ RGBQUAD* quad, BYTE alpha, COLORREF color)
{ {
ZeroMemory(quad, sizeof(*quad)); ZeroMemory(quad, sizeof(*quad));
quad->rgbReserved = alpha; quad->rgbReserved = alpha;
@@ -47,7 +51,7 @@ inline void InitRGB(_Out_ RGBQUAD *quad, BYTE alpha, COLORREF color)
quad->rgbBlue = GetBValue(color) * alpha / 255; quad->rgbBlue = GetBValue(color) * alpha / 255;
} }
inline void FillRectARGB(wil::unique_hdc& hdc, RECT const *prcFill, BYTE alpha, COLORREF color, bool blendAlpha) inline void FillRectARGB(wil::unique_hdc& hdc, RECT const* prcFill, BYTE alpha, COLORREF color, bool blendAlpha)
{ {
BITMAPINFO bi; BITMAPINFO bi;
ZeroMemory(&bi, sizeof(bi)); ZeroMemory(&bi, sizeof(bi));
@@ -60,56 +64,23 @@ inline void FillRectARGB(wil::unique_hdc& hdc, RECT const *prcFill, BYTE alpha,
RECT fillRect; RECT fillRect;
CopyRect(&fillRect, prcFill); CopyRect(&fillRect, prcFill);
if ((alpha == 255) || !blendAlpha)
{
// Opaque or the caller does not want to blend the alpha
RGBQUAD bitmapBits;
InitRGB(&bitmapBits, alpha, color);
StretchDIBits(
hdc.get(),
fillRect.left,
fillRect.top,
fillRect.right - fillRect.left,
fillRect.bottom - fillRect.top,
0, 0, 1, 1, &bitmapBits, &bi, DIB_RGB_COLORS, SRCCOPY);
}
else
{
if (wil::unique_hdc hdcSrc{ CreateCompatibleDC(hdc.get()) })
{
void* pBitmapBits;
if (wil::unique_hbitmap bitmapSource{ CreateDIBSection(hdcSrc.get(), &bi, DIB_RGB_COLORS, &pBitmapBits, nullptr, 0) })
{
InitRGB(reinterpret_cast<RGBQUAD *>(pBitmapBits), alpha, color);
wil::unique_select_object bitmapOld{ SelectObject(hdcSrc.get(), bitmapSource.get()) }; RGBQUAD bitmapBits;
BLENDFUNCTION bf = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA }; InitRGB(&bitmapBits, alpha, color);
GdiAlphaBlend( StretchDIBits(
hdc.get(), hdc.get(),
fillRect.left, fillRect.left,
fillRect.top, fillRect.top,
fillRect.right - fillRect.left, fillRect.right - fillRect.left,
fillRect.bottom - fillRect.top, fillRect.bottom - fillRect.top,
hdcSrc.get(), 0, 0, 1, 1, bf); 0,
} 0,
1,
} 1,
} &bitmapBits,
} &bi,
DIB_RGB_COLORS,
inline void FrameRectARGB(wil::unique_hdc& hdc, const RECT &rc, BYTE bAlpha, COLORREF clr, int thickness) SRCCOPY);
{
RECT sides[] = {
{ rc.left, rc.top, (rc.left + thickness), rc.bottom },
{ (rc.right - thickness), rc.top, rc.right, rc.bottom },
{ (rc.left + thickness), rc.top, (rc.right - thickness), (rc.top + thickness) },
{ (rc.left + thickness), (rc.bottom - thickness), (rc.right - thickness), rc.bottom }
};
for (UINT i = 0; i < ARRAYSIZE(sides); i++)
{
FillRectARGB(hdc, &(sides[i]), bAlpha, clr, false);
}
} }
inline void ParseDeviceId(PCWSTR deviceId, PWSTR parsedId, size_t size) inline void ParseDeviceId(PCWSTR deviceId, PWSTR parsedId, size_t size)
@@ -140,10 +111,9 @@ inline void ParseDeviceId(PCWSTR deviceId, PWSTR parsedId, size_t size)
} }
} }
inline unsigned char OpacitySettingToAlpha(int opacity) inline BYTE OpacitySettingToAlpha(int opacity)
{ {
// convert percentage to a 0-255 alpha value return static_cast<BYTE>(opacity * 2.55);
return static_cast<unsigned char>(opacity * 2.55);
} }
UINT GetDpiForMonitor(HMONITOR monitor) noexcept; UINT GetDpiForMonitor(HMONITOR monitor) noexcept;

View File

@@ -12,92 +12,92 @@ using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace FancyZonesUnitTests namespace FancyZonesUnitTests
{ {
TEST_CLASS(FancyZonesUnitTests) TEST_CLASS (FancyZonesUnitTests)
{ {
HINSTANCE m_hInst; HINSTANCE m_hInst;
winrt::com_ptr<IFancyZonesSettings> m_settings; winrt::com_ptr<IFancyZonesSettings> m_settings;
TEST_METHOD_INITIALIZE(Init) TEST_METHOD_INITIALIZE(Init)
{
m_hInst = (HINSTANCE)GetModuleHandleW(nullptr);
m_settings = MakeFancyZonesSettings(m_hInst, L"FancyZonesUnitTests");
Assert::IsTrue(m_settings != nullptr);
}
TEST_METHOD(Create)
{
auto actual = MakeFancyZones(m_hInst, m_settings);
Assert::IsNotNull(actual.get());
}
TEST_METHOD(CreateWithEmptyHinstance)
{
auto actual = MakeFancyZones({}, m_settings);
Assert::IsNotNull(actual.get());
}
TEST_METHOD(CreateWithNullHinstance)
{
auto actual = MakeFancyZones(nullptr, m_settings);
Assert::IsNotNull(actual.get());
}
TEST_METHOD(CreateWithNullSettings)
{
auto actual = MakeFancyZones(m_hInst, nullptr);
Assert::IsNull(actual.get());
}
TEST_METHOD(Run)
{
auto actual = MakeFancyZones(m_hInst, m_settings);
std::vector<std::thread> threads;
std::atomic<int> counter = 0;
const int expectedCount = 10;
auto runFunc = [&]() {
actual->Run();
counter++;
};
for (int i = 0; i < expectedCount; i++)
{ {
threads.push_back(std::thread(runFunc)); m_hInst = (HINSTANCE)GetModuleHandleW(nullptr);
m_settings = MakeFancyZonesSettings(m_hInst, L"FancyZonesUnitTests");
Assert::IsTrue(m_settings != nullptr);
} }
for (auto& thread : threads) TEST_METHOD (Create)
{ {
thread.join(); auto actual = MakeFancyZones(m_hInst, m_settings);
Assert::IsNotNull(actual.get());
}
TEST_METHOD (CreateWithEmptyHinstance)
{
auto actual = MakeFancyZones({}, m_settings);
Assert::IsNotNull(actual.get());
} }
Assert::AreEqual(expectedCount, counter.load()); TEST_METHOD (CreateWithNullHinstance)
}
TEST_METHOD(Destroy)
{
auto actual = MakeFancyZones(m_hInst, m_settings);
std::vector<std::thread> threads;
std::atomic<int> counter = 0;
const int expectedCount = 10;
auto destroyFunc = [&]() {
actual->Destroy();
counter++;
};
for (int i = 0; i < expectedCount; i++)
{ {
threads.push_back(std::thread(destroyFunc)); auto actual = MakeFancyZones(nullptr, m_settings);
Assert::IsNotNull(actual.get());
} }
for (auto& thread : threads) TEST_METHOD (CreateWithNullSettings)
{ {
thread.join(); auto actual = MakeFancyZones(m_hInst, nullptr);
Assert::IsNull(actual.get());
} }
Assert::AreEqual(expectedCount, counter.load()); TEST_METHOD (Run)
} {
auto actual = MakeFancyZones(m_hInst, m_settings);
std::vector<std::thread> threads;
std::atomic<int> counter = 0;
const int expectedCount = 10;
auto runFunc = [&]() {
actual->Run();
counter++;
};
for (int i = 0; i < expectedCount; i++)
{
threads.push_back(std::thread(runFunc));
}
for (auto& thread : threads)
{
thread.join();
}
Assert::AreEqual(expectedCount, counter.load());
}
TEST_METHOD (Destroy)
{
auto actual = MakeFancyZones(m_hInst, m_settings);
std::vector<std::thread> threads;
std::atomic<int> counter = 0;
const int expectedCount = 10;
auto destroyFunc = [&]() {
actual->Destroy();
counter++;
};
for (int i = 0; i < expectedCount; i++)
{
threads.push_back(std::thread(destroyFunc));
}
for (auto& thread : threads)
{
thread.join();
}
Assert::AreEqual(expectedCount, counter.load());
}
/* /*
TEST_METHOD(RunDestroy) TEST_METHOD(RunDestroy)
@@ -130,7 +130,7 @@ namespace FancyZonesUnitTests
*/ */
}; };
TEST_CLASS(FancyZonesIZoneWindowHostUnitTests) TEST_CLASS (FancyZonesIZoneWindowHostUnitTests)
{ {
HINSTANCE m_hInst{}; HINSTANCE m_hInst{};
std::wstring m_settingsLocation = L"FancyZonesUnitTests"; std::wstring m_settingsLocation = L"FancyZonesUnitTests";
@@ -151,7 +151,10 @@ namespace FancyZonesUnitTests
ptSettings.add_bool_toogle(L"fancyzones_appLastZone_moveWindows", IDS_SETTING_DESCRIPTION_APPLASTZONE_MOVEWINDOWS, settings.appLastZone_moveWindows); ptSettings.add_bool_toogle(L"fancyzones_appLastZone_moveWindows", IDS_SETTING_DESCRIPTION_APPLASTZONE_MOVEWINDOWS, settings.appLastZone_moveWindows);
ptSettings.add_bool_toogle(L"use_cursorpos_editor_startupscreen", IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN, settings.use_cursorpos_editor_startupscreen); ptSettings.add_bool_toogle(L"use_cursorpos_editor_startupscreen", IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN, settings.use_cursorpos_editor_startupscreen);
ptSettings.add_bool_toogle(L"fancyzones_show_on_all_monitors", IDS_SETTING_DESCRIPTION_SHOW_FANCY_ZONES_ON_ALL_MONITORS, settings.showZonesOnAllMonitors); ptSettings.add_bool_toogle(L"fancyzones_show_on_all_monitors", IDS_SETTING_DESCRIPTION_SHOW_FANCY_ZONES_ON_ALL_MONITORS, settings.showZonesOnAllMonitors);
ptSettings.add_bool_toogle(L"fancyzones_makeDraggedWindowTransparent", IDS_SETTING_DESCRIPTION_MAKE_DRAGGED_WINDOW_TRANSPARENT, settings.makeDraggedWindowTransparent);
ptSettings.add_int_spinner(L"fancyzones_highlight_opacity", IDS_SETTINGS_HIGHLIGHT_OPACITY, settings.zoneHighlightOpacity, 0, 100, 1); ptSettings.add_int_spinner(L"fancyzones_highlight_opacity", IDS_SETTINGS_HIGHLIGHT_OPACITY, settings.zoneHighlightOpacity, 0, 100, 1);
ptSettings.add_color_picker(L"fancyzones_zoneColor", IDS_SETTING_DESCRIPTION_ZONECOLOR, settings.zoneColor);
ptSettings.add_color_picker(L"fancyzones_zoneBorderColor", IDS_SETTING_DESCRIPTION_ZONE_BORDER_COLOR, settings.zoneBorderColor);
ptSettings.add_color_picker(L"fancyzones_zoneHighlightColor", IDS_SETTING_DESCRIPTION_ZONEHIGHLIGHTCOLOR, settings.zoneHightlightColor); ptSettings.add_color_picker(L"fancyzones_zoneHighlightColor", IDS_SETTING_DESCRIPTION_ZONEHIGHLIGHTCOLOR, settings.zoneHightlightColor);
ptSettings.add_multiline_string(L"fancyzones_excluded_apps", IDS_SETTING_EXCLCUDED_APPS_DESCRIPTION, settings.excludedApps); ptSettings.add_multiline_string(L"fancyzones_excluded_apps", IDS_SETTING_EXCLCUDED_APPS_DESCRIPTION, settings.excludedApps);
@@ -159,94 +162,185 @@ namespace FancyZonesUnitTests
} }
TEST_METHOD_INITIALIZE(Init) TEST_METHOD_INITIALIZE(Init)
{ {
m_hInst = (HINSTANCE)GetModuleHandleW(nullptr); m_hInst = (HINSTANCE)GetModuleHandleW(nullptr);
m_settings = MakeFancyZonesSettings(m_hInst, m_settingsLocation.c_str()); m_settings = MakeFancyZonesSettings(m_hInst, m_settingsLocation.c_str());
Assert::IsTrue(m_settings != nullptr); Assert::IsTrue(m_settings != nullptr);
auto fancyZones = MakeFancyZones(m_hInst, m_settings); auto fancyZones = MakeFancyZones(m_hInst, m_settings);
Assert::IsTrue(fancyZones != nullptr); Assert::IsTrue(fancyZones != nullptr);
m_zoneWindowHost = fancyZones.as<IZoneWindowHost>(); m_zoneWindowHost = fancyZones.as<IZoneWindowHost>();
Assert::IsTrue(m_zoneWindowHost != nullptr); Assert::IsTrue(m_zoneWindowHost != nullptr);
} }
TEST_METHOD_CLEANUP(Cleanup) TEST_METHOD_CLEANUP(Cleanup)
{ {
auto settingsFolder = PTSettingsHelper::get_module_save_folder_location(m_settingsLocation); auto settingsFolder = PTSettingsHelper::get_module_save_folder_location(m_settingsLocation);
const auto settingsFile = settingsFolder + L"\\settings.json"; const auto settingsFile = settingsFolder + L"\\settings.json";
std::filesystem::remove(settingsFile); std::filesystem::remove(settingsFile);
std::filesystem::remove(settingsFolder); std::filesystem::remove(settingsFolder);
} }
TEST_METHOD(GetZoneHighlightColor) TEST_METHOD (GetZoneColor)
{ {
const auto expected = RGB(171, 175, 238); const auto expected = RGB(171, 175, 238);
const Settings settings{ const Settings settings{
.shiftDrag = true, .shiftDrag = true,
.displayChange_moveWindows = true, .displayChange_moveWindows = true,
.virtualDesktopChange_moveWindows = true, .virtualDesktopChange_moveWindows = true,
.zoneSetChange_flashZones = false, .zoneSetChange_flashZones = false,
.zoneSetChange_moveWindows = true, .zoneSetChange_moveWindows = true,
.overrideSnapHotkeys = false, .overrideSnapHotkeys = false,
.appLastZone_moveWindows = true, .appLastZone_moveWindows = true,
.use_cursorpos_editor_startupscreen = true, .use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false, .zoneColor = L"#abafee",
.zoneHightlightColor = L"#abafee", .zoneBorderColor = L"FAFAFA",
.zoneHighlightOpacity = 45, .zoneHightlightColor = L"#FAFAFA",
.editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, false, false, false, VK_OEM_3), .zoneHighlightOpacity = 45,
.excludedApps = L"app\r\napp2", .editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, false, false, false, VK_OEM_3),
.excludedAppsArray = { L"APP", L"APP2" }, .excludedApps = L"app\r\napp2",
}; .excludedAppsArray = { L"APP", L"APP2" },
};
auto config = serializedPowerToySettings(settings); auto config = serializedPowerToySettings(settings);
m_settings->SetConfig(config.c_str()); m_settings->SetConfig(config.c_str());
const auto actual = m_zoneWindowHost->GetZoneHighlightColor(); const auto actual = m_zoneWindowHost->GetZoneColor();
Assert::AreEqual(expected, actual); Assert::AreEqual(expected, actual);
} }
TEST_METHOD(GetZoneHighlightOpacity) TEST_METHOD (GetZoneBorderColor)
{ {
const auto expected = 88; const auto expected = RGB(171, 175, 238);
const Settings settings{ const Settings settings{
.shiftDrag = true, .shiftDrag = true,
.displayChange_moveWindows = true, .displayChange_moveWindows = true,
.virtualDesktopChange_moveWindows = true, .virtualDesktopChange_moveWindows = true,
.zoneSetChange_flashZones = false, .zoneSetChange_flashZones = false,
.zoneSetChange_moveWindows = true, .zoneSetChange_moveWindows = true,
.overrideSnapHotkeys = false, .overrideSnapHotkeys = false,
.appLastZone_moveWindows = true, .appLastZone_moveWindows = true,
.use_cursorpos_editor_startupscreen = true, .use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false, .zoneColor = L"#FAFAFA",
.zoneHightlightColor = L"#abafee", .zoneBorderColor = L"#abafee",
.zoneHighlightOpacity = expected, .zoneHightlightColor = L"#FAFAFA",
.editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, false, false, false, VK_OEM_3), .zoneHighlightOpacity = 45,
.excludedApps = L"app\r\napp2", .editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, false, false, false, VK_OEM_3),
.excludedAppsArray = { L"APP", L"APP2" }, .excludedApps = L"app\r\napp2",
}; .excludedAppsArray = { L"APP", L"APP2" },
};
auto config = serializedPowerToySettings(settings); auto config = serializedPowerToySettings(settings);
m_settings->SetConfig(config.c_str()); m_settings->SetConfig(config.c_str());
const auto actual = m_zoneWindowHost->GetZoneHighlightOpacity(); const auto actual = m_zoneWindowHost->GetZoneBorderColor();
Assert::AreEqual(expected, actual); Assert::AreEqual(expected, actual);
} }
TEST_METHOD(GetCurrentMonitorZoneSetEmpty) TEST_METHOD (GetZoneHighlightColor)
{ {
const auto* actual = m_zoneWindowHost->GetParentZoneWindow(Mocks::Monitor()); const auto expected = RGB(171, 175, 238);
Assert::IsNull(actual); const Settings settings{
} .shiftDrag = true,
.displayChange_moveWindows = true,
.virtualDesktopChange_moveWindows = true,
.zoneSetChange_flashZones = false,
.zoneSetChange_moveWindows = true,
.overrideSnapHotkeys = false,
.appLastZone_moveWindows = true,
.use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false,
.makeDraggedWindowTransparent = true,
.zoneColor = L"#FAFAFA",
.zoneBorderColor = L"FAFAFA",
.zoneHightlightColor = L"#abafee",
.zoneHighlightOpacity = 45,
.editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, false, false, false, VK_OEM_3),
.excludedApps = L"app\r\napp2",
.excludedAppsArray = { L"APP", L"APP2" },
};
TEST_METHOD(GetCurrentMonitorZoneSetNullMonitor) auto config = serializedPowerToySettings(settings);
{ m_settings->SetConfig(config.c_str());
const auto* actual = m_zoneWindowHost->GetParentZoneWindow(nullptr);
Assert::IsNull(actual); const auto actual = m_zoneWindowHost->GetZoneHighlightColor();
} Assert::AreEqual(expected, actual);
}
TEST_METHOD (GetZoneHighlightOpacity)
{
const auto expected = 88;
const Settings settings{
.shiftDrag = true,
.displayChange_moveWindows = true,
.virtualDesktopChange_moveWindows = true,
.zoneSetChange_flashZones = false,
.zoneSetChange_moveWindows = true,
.overrideSnapHotkeys = false,
.appLastZone_moveWindows = true,
.use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false,
.makeDraggedWindowTransparent = true,
.zoneColor = L"#FAFAFA",
.zoneBorderColor = L"FAFAFA",
.zoneHightlightColor = L"#abafee",
.zoneHighlightOpacity = expected,
.editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, false, false, false, VK_OEM_3),
.excludedApps = L"app\r\napp2",
.excludedAppsArray = { L"APP", L"APP2" },
};
auto config = serializedPowerToySettings(settings);
m_settings->SetConfig(config.c_str());
const auto actual = m_zoneWindowHost->GetZoneHighlightOpacity();
Assert::AreEqual(expected, actual);
}
TEST_METHOD (IsMakeDraggenWindowTransparentActive)
{
const auto expected = true;
const Settings settings{
.shiftDrag = true,
.displayChange_moveWindows = true,
.virtualDesktopChange_moveWindows = true,
.zoneSetChange_flashZones = false,
.zoneSetChange_moveWindows = true,
.overrideSnapHotkeys = false,
.appLastZone_moveWindows = true,
.use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false,
.makeDraggedWindowTransparent = true,
.zoneColor = L"#FAFAFA",
.zoneBorderColor = L"FAFAFA",
.zoneHightlightColor = L"#abafee",
.zoneHighlightOpacity = expected,
.editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, false, false, false, VK_OEM_3),
.excludedApps = L"app\r\napp2",
.excludedAppsArray = { L"APP", L"APP2" },
};
auto config = serializedPowerToySettings(settings);
m_settings->SetConfig(config.c_str());
Assert::AreEqual(expected, m_zoneWindowHost->isMakeDraggedWindowTransparentActive());
}
TEST_METHOD (GetCurrentMonitorZoneSetEmpty)
{
const auto* actual = m_zoneWindowHost->GetParentZoneWindow(Mocks::Monitor());
Assert::IsNull(actual);
}
TEST_METHOD (GetCurrentMonitorZoneSetNullMonitor)
{
const auto* actual = m_zoneWindowHost->GetParentZoneWindow(nullptr);
Assert::IsNull(actual);
}
}; };
TEST_CLASS(FancyZonesIFancyZonesCallbackUnitTests) TEST_CLASS (FancyZonesIFancyZonesCallbackUnitTests)
{ {
HINSTANCE m_hInst{}; HINSTANCE m_hInst{};
std::wstring m_settingsLocation = L"FancyZonesUnitTests"; std::wstring m_settingsLocation = L"FancyZonesUnitTests";
@@ -269,7 +363,10 @@ namespace FancyZonesUnitTests
ptSettings.add_bool_toogle(L"fancyzones_appLastZone_moveWindows", IDS_SETTING_DESCRIPTION_APPLASTZONE_MOVEWINDOWS, settings.appLastZone_moveWindows); ptSettings.add_bool_toogle(L"fancyzones_appLastZone_moveWindows", IDS_SETTING_DESCRIPTION_APPLASTZONE_MOVEWINDOWS, settings.appLastZone_moveWindows);
ptSettings.add_bool_toogle(L"use_cursorpos_editor_startupscreen", IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN, settings.use_cursorpos_editor_startupscreen); ptSettings.add_bool_toogle(L"use_cursorpos_editor_startupscreen", IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN, settings.use_cursorpos_editor_startupscreen);
ptSettings.add_bool_toogle(L"fancyzones_show_on_all_monitors", IDS_SETTING_DESCRIPTION_SHOW_FANCY_ZONES_ON_ALL_MONITORS, settings.showZonesOnAllMonitors); ptSettings.add_bool_toogle(L"fancyzones_show_on_all_monitors", IDS_SETTING_DESCRIPTION_SHOW_FANCY_ZONES_ON_ALL_MONITORS, settings.showZonesOnAllMonitors);
ptSettings.add_bool_toogle(L"fancyzones_makeDraggedWindowTransparent", IDS_SETTING_DESCRIPTION_MAKE_DRAGGED_WINDOW_TRANSPARENT, settings.makeDraggedWindowTransparent);
ptSettings.add_int_spinner(L"fancyzones_highlight_opacity", IDS_SETTINGS_HIGHLIGHT_OPACITY, settings.zoneHighlightOpacity, 0, 100, 1); ptSettings.add_int_spinner(L"fancyzones_highlight_opacity", IDS_SETTINGS_HIGHLIGHT_OPACITY, settings.zoneHighlightOpacity, 0, 100, 1);
ptSettings.add_color_picker(L"fancyzones_zoneColor", IDS_SETTING_DESCRIPTION_ZONECOLOR, settings.zoneColor);
ptSettings.add_color_picker(L"fancyzones_zoneBorderColor", IDS_SETTING_DESCRIPTION_ZONE_BORDER_COLOR, settings.zoneBorderColor);
ptSettings.add_color_picker(L"fancyzones_zoneHighlightColor", IDS_SETTING_DESCRIPTION_ZONEHIGHLIGHTCOLOR, settings.zoneHightlightColor); ptSettings.add_color_picker(L"fancyzones_zoneHighlightColor", IDS_SETTING_DESCRIPTION_ZONEHIGHLIGHTCOLOR, settings.zoneHightlightColor);
ptSettings.add_multiline_string(L"fancyzones_excluded_apps", IDS_SETTING_EXCLCUDED_APPS_DESCRIPTION, settings.excludedApps); ptSettings.add_multiline_string(L"fancyzones_excluded_apps", IDS_SETTING_EXCLCUDED_APPS_DESCRIPTION, settings.excludedApps);
@@ -289,157 +386,157 @@ namespace FancyZonesUnitTests
} }
TEST_METHOD_INITIALIZE(Init) TEST_METHOD_INITIALIZE(Init)
{
m_hInst = (HINSTANCE)GetModuleHandleW(nullptr);
m_settings = MakeFancyZonesSettings(m_hInst, m_settingsLocation.c_str());
Assert::IsTrue(m_settings != nullptr);
auto fancyZones = MakeFancyZones(m_hInst, m_settings);
Assert::IsTrue(fancyZones != nullptr);
m_fzCallback = fancyZones.as<IFancyZonesCallback>();
Assert::IsTrue(m_fzCallback != nullptr);
m_fancyZonesData.clear_data();
}
TEST_METHOD_CLEANUP(Cleanup)
{
sendKeyboardInput(VK_SHIFT, true);
sendKeyboardInput(VK_LWIN, true);
sendKeyboardInput(VK_CONTROL, true);
auto settingsFolder = PTSettingsHelper::get_module_save_folder_location(m_settingsLocation);
const auto settingsFile = settingsFolder + L"\\settings.json";
std::filesystem::remove(settingsFile);
std::filesystem::remove(settingsFolder);
}
TEST_METHOD(OnKeyDownNothingPressed)
{
for (DWORD code = '0'; code <= '9'; code++)
{ {
tagKBDLLHOOKSTRUCT input{}; m_hInst = (HINSTANCE)GetModuleHandleW(nullptr);
input.vkCode = code; m_settings = MakeFancyZonesSettings(m_hInst, m_settingsLocation.c_str());
Assert::IsFalse(m_fzCallback->OnKeyDown(&input)); Assert::IsTrue(m_settings != nullptr);
auto fancyZones = MakeFancyZones(m_hInst, m_settings);
Assert::IsTrue(fancyZones != nullptr);
m_fzCallback = fancyZones.as<IFancyZonesCallback>();
Assert::IsTrue(m_fzCallback != nullptr);
m_fancyZonesData.clear_data();
} }
{ TEST_METHOD_CLEANUP(Cleanup)
tagKBDLLHOOKSTRUCT input{}; {
input.vkCode = VK_LEFT; sendKeyboardInput(VK_SHIFT, true);
Assert::IsFalse(m_fzCallback->OnKeyDown(&input)); sendKeyboardInput(VK_LWIN, true);
} sendKeyboardInput(VK_CONTROL, true);
{ auto settingsFolder = PTSettingsHelper::get_module_save_folder_location(m_settingsLocation);
tagKBDLLHOOKSTRUCT input{}; const auto settingsFile = settingsFolder + L"\\settings.json";
input.vkCode = VK_RIGHT; std::filesystem::remove(settingsFile);
Assert::IsFalse(m_fzCallback->OnKeyDown(&input)); std::filesystem::remove(settingsFolder);
} }
}
TEST_METHOD(OnKeyDownShiftPressed) TEST_METHOD (OnKeyDownNothingPressed)
{ {
sendKeyboardInput(VK_SHIFT); for (DWORD code = '0'; code <= '9'; code++)
{
tagKBDLLHOOKSTRUCT input{};
input.vkCode = code;
Assert::IsFalse(m_fzCallback->OnKeyDown(&input));
}
for (DWORD code = '0'; code <= '9'; code++) {
{ tagKBDLLHOOKSTRUCT input{};
tagKBDLLHOOKSTRUCT input{}; input.vkCode = VK_LEFT;
input.vkCode = code; Assert::IsFalse(m_fzCallback->OnKeyDown(&input));
Assert::IsFalse(m_fzCallback->OnKeyDown(&input)); }
}
{ {
tagKBDLLHOOKSTRUCT input{}; tagKBDLLHOOKSTRUCT input{};
input.vkCode = VK_LEFT; input.vkCode = VK_RIGHT;
Assert::IsFalse(m_fzCallback->OnKeyDown(&input)); Assert::IsFalse(m_fzCallback->OnKeyDown(&input));
} }
}
{ TEST_METHOD (OnKeyDownShiftPressed)
tagKBDLLHOOKSTRUCT input{}; {
input.vkCode = VK_RIGHT; sendKeyboardInput(VK_SHIFT);
Assert::IsFalse(m_fzCallback->OnKeyDown(&input));
}
}
TEST_METHOD(OnKeyDownWinPressed) for (DWORD code = '0'; code <= '9'; code++)
{ {
sendKeyboardInput(VK_LWIN); tagKBDLLHOOKSTRUCT input{};
input.vkCode = code;
Assert::IsFalse(m_fzCallback->OnKeyDown(&input));
}
for (DWORD code = '0'; code <= '9'; code++) {
{ tagKBDLLHOOKSTRUCT input{};
tagKBDLLHOOKSTRUCT input{}; input.vkCode = VK_LEFT;
input.vkCode = code; Assert::IsFalse(m_fzCallback->OnKeyDown(&input));
Assert::IsFalse(m_fzCallback->OnKeyDown(&input)); }
}
{ {
tagKBDLLHOOKSTRUCT input{}; tagKBDLLHOOKSTRUCT input{};
input.vkCode = VK_LEFT; input.vkCode = VK_RIGHT;
Assert::IsFalse(m_fzCallback->OnKeyDown(&input)); Assert::IsFalse(m_fzCallback->OnKeyDown(&input));
} }
}
{ TEST_METHOD (OnKeyDownWinPressed)
tagKBDLLHOOKSTRUCT input{}; {
input.vkCode = VK_RIGHT; sendKeyboardInput(VK_LWIN);
Assert::IsFalse(m_fzCallback->OnKeyDown(&input));
}
}
TEST_METHOD(OnKeyDownWinShiftPressed) for (DWORD code = '0'; code <= '9'; code++)
{ {
sendKeyboardInput(VK_LWIN); tagKBDLLHOOKSTRUCT input{};
sendKeyboardInput(VK_SHIFT); input.vkCode = code;
Assert::IsFalse(m_fzCallback->OnKeyDown(&input));
}
for (DWORD code = '0'; code <= '9'; code++) {
{ tagKBDLLHOOKSTRUCT input{};
tagKBDLLHOOKSTRUCT input{}; input.vkCode = VK_LEFT;
input.vkCode = code; Assert::IsFalse(m_fzCallback->OnKeyDown(&input));
Assert::IsFalse(m_fzCallback->OnKeyDown(&input)); }
}
{ {
tagKBDLLHOOKSTRUCT input{}; tagKBDLLHOOKSTRUCT input{};
input.vkCode = VK_LEFT; input.vkCode = VK_RIGHT;
Assert::IsFalse(m_fzCallback->OnKeyDown(&input)); Assert::IsFalse(m_fzCallback->OnKeyDown(&input));
} }
}
{ TEST_METHOD (OnKeyDownWinShiftPressed)
tagKBDLLHOOKSTRUCT input{}; {
input.vkCode = VK_RIGHT; sendKeyboardInput(VK_LWIN);
Assert::IsFalse(m_fzCallback->OnKeyDown(&input)); sendKeyboardInput(VK_SHIFT);
}
}
TEST_METHOD(OnKeyDownWinCtrlPressed) for (DWORD code = '0'; code <= '9'; code++)
{ {
sendKeyboardInput(VK_LWIN); tagKBDLLHOOKSTRUCT input{};
sendKeyboardInput(VK_CONTROL); input.vkCode = code;
Assert::IsFalse(m_fzCallback->OnKeyDown(&input));
}
const Settings settings{ {
.overrideSnapHotkeys = false, tagKBDLLHOOKSTRUCT input{};
}; input.vkCode = VK_LEFT;
Assert::IsFalse(m_fzCallback->OnKeyDown(&input));
}
auto config = serializedPowerToySettings(settings); {
m_settings->SetConfig(config.c_str()); tagKBDLLHOOKSTRUCT input{};
input.vkCode = VK_RIGHT;
Assert::IsFalse(m_fzCallback->OnKeyDown(&input));
}
}
for (DWORD code = '0'; code <= '9'; code++) TEST_METHOD (OnKeyDownWinCtrlPressed)
{ {
tagKBDLLHOOKSTRUCT input{}; sendKeyboardInput(VK_LWIN);
input.vkCode = code; sendKeyboardInput(VK_CONTROL);
Assert::IsTrue(m_fzCallback->OnKeyDown(&input));
}
{ const Settings settings{
tagKBDLLHOOKSTRUCT input{}; .overrideSnapHotkeys = false,
input.vkCode = VK_LEFT; };
Assert::IsFalse(m_fzCallback->OnKeyDown(&input));
}
{ auto config = serializedPowerToySettings(settings);
tagKBDLLHOOKSTRUCT input{}; m_settings->SetConfig(config.c_str());
input.vkCode = VK_RIGHT;
Assert::IsFalse(m_fzCallback->OnKeyDown(&input)); for (DWORD code = '0'; code <= '9'; code++)
} {
} tagKBDLLHOOKSTRUCT input{};
input.vkCode = code;
Assert::IsTrue(m_fzCallback->OnKeyDown(&input));
}
{
tagKBDLLHOOKSTRUCT input{};
input.vkCode = VK_LEFT;
Assert::IsFalse(m_fzCallback->OnKeyDown(&input));
}
{
tagKBDLLHOOKSTRUCT input{};
input.vkCode = VK_RIGHT;
Assert::IsFalse(m_fzCallback->OnKeyDown(&input));
}
}
}; };
} }

View File

@@ -35,6 +35,9 @@ namespace FancyZonesUnitTests
Assert::AreEqual(expected.appLastZone_moveWindows, actual.appLastZone_moveWindows); Assert::AreEqual(expected.appLastZone_moveWindows, actual.appLastZone_moveWindows);
Assert::AreEqual(expected.use_cursorpos_editor_startupscreen, actual.use_cursorpos_editor_startupscreen); Assert::AreEqual(expected.use_cursorpos_editor_startupscreen, actual.use_cursorpos_editor_startupscreen);
Assert::AreEqual(expected.showZonesOnAllMonitors, actual.showZonesOnAllMonitors); Assert::AreEqual(expected.showZonesOnAllMonitors, actual.showZonesOnAllMonitors);
Assert::AreEqual(expected.makeDraggedWindowTransparent, actual.makeDraggedWindowTransparent);
Assert::AreEqual(expected.zoneColor.c_str(), actual.zoneColor.c_str());
Assert::AreEqual(expected.zoneBorderColor.c_str(), actual.zoneBorderColor.c_str());
Assert::AreEqual(expected.zoneHightlightColor.c_str(), actual.zoneHightlightColor.c_str()); Assert::AreEqual(expected.zoneHightlightColor.c_str(), actual.zoneHightlightColor.c_str());
Assert::AreEqual(expected.zoneHighlightOpacity, actual.zoneHighlightOpacity); Assert::AreEqual(expected.zoneHighlightOpacity, actual.zoneHighlightOpacity);
Assert::AreEqual(expected.excludedApps.c_str(), actual.excludedApps.c_str()); Assert::AreEqual(expected.excludedApps.c_str(), actual.excludedApps.c_str());
@@ -61,7 +64,6 @@ namespace FancyZonesUnitTests
m_hInst = (HINSTANCE)GetModuleHandleW(nullptr); m_hInst = (HINSTANCE)GetModuleHandleW(nullptr);
m_tmpName = PTSettingsHelper::get_module_save_folder_location(m_moduleName) + L"\\settings.json"; m_tmpName = PTSettingsHelper::get_module_save_folder_location(m_moduleName) + L"\\settings.json";
} }
TEST_METHOD_CLEANUP(Cleanup) TEST_METHOD_CLEANUP(Cleanup)
{ {
std::filesystem::remove(m_tmpName); std::filesystem::remove(m_tmpName);
@@ -108,6 +110,9 @@ namespace FancyZonesUnitTests
.appLastZone_moveWindows = false, .appLastZone_moveWindows = false,
.use_cursorpos_editor_startupscreen = true, .use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false, .showZonesOnAllMonitors = false,
.makeDraggedWindowTransparent = true,
.zoneColor = L"FAFAFA",
.zoneBorderColor = L"CCDDEE",
.zoneHightlightColor = L"#00FFD7", .zoneHightlightColor = L"#00FFD7",
.zoneHighlightOpacity = 45, .zoneHighlightOpacity = 45,
.editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, true, true, false, VK_OEM_3), .editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, true, true, false, VK_OEM_3),
@@ -125,6 +130,9 @@ namespace FancyZonesUnitTests
values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows); values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows);
values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen); values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen);
values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors); values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors);
values.add_property(L"fancyzones_makeDraggedWindowTransparent", expected.makeDraggedWindowTransparent);
values.add_property(L"fancyzones_zoneColor", expected.zoneColor);
values.add_property(L"fancyzones_zoneBorderColor", expected.zoneBorderColor);
values.add_property(L"fancyzones_zoneHighlightColor", expected.zoneHightlightColor); values.add_property(L"fancyzones_zoneHighlightColor", expected.zoneHightlightColor);
values.add_property(L"fancyzones_highlight_opacity", expected.zoneHighlightOpacity); values.add_property(L"fancyzones_highlight_opacity", expected.zoneHighlightOpacity);
values.add_property(L"fancyzones_editor_hotkey", expected.editorHotkey.get_json()); values.add_property(L"fancyzones_editor_hotkey", expected.editorHotkey.get_json());
@@ -152,6 +160,9 @@ namespace FancyZonesUnitTests
.appLastZone_moveWindows = false, .appLastZone_moveWindows = false,
.use_cursorpos_editor_startupscreen = true, .use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false, .showZonesOnAllMonitors = false,
.makeDraggedWindowTransparent = true,
.zoneColor = L"FAFAFA",
.zoneBorderColor = L"CCDDEE",
.zoneHightlightColor = L"#00FFD7", .zoneHightlightColor = L"#00FFD7",
.zoneHighlightOpacity = 45, .zoneHighlightOpacity = 45,
.editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, true, true, false, VK_OEM_3), .editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, true, true, false, VK_OEM_3),
@@ -169,6 +180,9 @@ namespace FancyZonesUnitTests
values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows); values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows);
values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen); values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen);
values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors); values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors);
values.add_property(L"fancyzones_makeDraggedWindowTransparent", expected.makeDraggedWindowTransparent);
values.add_property(L"fancyzones_zoneColor", expected.zoneColor);
values.add_property(L"fancyzones_zoneBorderColor", expected.zoneBorderColor);
values.add_property(L"fancyzones_zoneHighlightColor", expected.zoneHightlightColor); values.add_property(L"fancyzones_zoneHighlightColor", expected.zoneHightlightColor);
values.add_property(L"fancyzones_highlight_opacity", expected.zoneHighlightOpacity); values.add_property(L"fancyzones_highlight_opacity", expected.zoneHighlightOpacity);
values.add_property(L"fancyzones_editor_hotkey", expected.editorHotkey.get_json()); values.add_property(L"fancyzones_editor_hotkey", expected.editorHotkey.get_json());
@@ -195,6 +209,9 @@ namespace FancyZonesUnitTests
.appLastZone_moveWindows = m_defaultSettings.appLastZone_moveWindows, .appLastZone_moveWindows = m_defaultSettings.appLastZone_moveWindows,
.use_cursorpos_editor_startupscreen = m_defaultSettings.use_cursorpos_editor_startupscreen, .use_cursorpos_editor_startupscreen = m_defaultSettings.use_cursorpos_editor_startupscreen,
.showZonesOnAllMonitors = m_defaultSettings.showZonesOnAllMonitors, .showZonesOnAllMonitors = m_defaultSettings.showZonesOnAllMonitors,
.makeDraggedWindowTransparent = m_defaultSettings.makeDraggedWindowTransparent,
.zoneColor = L"FAFAFA",
.zoneBorderColor = L"CCDDEE",
.zoneHightlightColor = L"#00FFD7", .zoneHightlightColor = L"#00FFD7",
.zoneHighlightOpacity = 45, .zoneHighlightOpacity = 45,
.editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, true, true, false, VK_OEM_3), .editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, true, true, false, VK_OEM_3),
@@ -203,6 +220,8 @@ namespace FancyZonesUnitTests
}; };
PowerToysSettings::PowerToyValues values(m_moduleName); PowerToysSettings::PowerToyValues values(m_moduleName);
values.add_property(L"fancyzones_zoneColor", expected.zoneColor);
values.add_property(L"fancyzones_zoneBorderColor", expected.zoneBorderColor);
values.add_property(L"fancyzones_zoneHighlightColor", expected.zoneHightlightColor); values.add_property(L"fancyzones_zoneHighlightColor", expected.zoneHightlightColor);
values.add_property(L"fancyzones_highlight_opacity", expected.zoneHighlightOpacity); values.add_property(L"fancyzones_highlight_opacity", expected.zoneHighlightOpacity);
values.add_property(L"fancyzones_editor_hotkey", expected.editorHotkey.get_json()); values.add_property(L"fancyzones_editor_hotkey", expected.editorHotkey.get_json());
@@ -230,6 +249,9 @@ namespace FancyZonesUnitTests
.appLastZone_moveWindows = false, .appLastZone_moveWindows = false,
.use_cursorpos_editor_startupscreen = true, .use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false, .showZonesOnAllMonitors = false,
.makeDraggedWindowTransparent = true,
.zoneColor = m_defaultSettings.zoneColor,
.zoneBorderColor = m_defaultSettings.zoneBorderColor,
.zoneHightlightColor = m_defaultSettings.zoneHightlightColor, .zoneHightlightColor = m_defaultSettings.zoneHightlightColor,
.zoneHighlightOpacity = 45, .zoneHighlightOpacity = 45,
.editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, true, true, false, VK_OEM_3), .editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, true, true, false, VK_OEM_3),
@@ -247,6 +269,7 @@ namespace FancyZonesUnitTests
values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows); values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows);
values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen); values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen);
values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors); values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors);
values.add_property(L"fancyzones_makeDraggedWindowTransparent", expected.makeDraggedWindowTransparent);
values.add_property(L"fancyzones_highlight_opacity", expected.zoneHighlightOpacity); values.add_property(L"fancyzones_highlight_opacity", expected.zoneHighlightOpacity);
values.add_property(L"fancyzones_editor_hotkey", expected.editorHotkey.get_json()); values.add_property(L"fancyzones_editor_hotkey", expected.editorHotkey.get_json());
values.add_property(L"fancyzones_excluded_apps", expected.excludedApps); values.add_property(L"fancyzones_excluded_apps", expected.excludedApps);
@@ -273,6 +296,9 @@ namespace FancyZonesUnitTests
.appLastZone_moveWindows = false, .appLastZone_moveWindows = false,
.use_cursorpos_editor_startupscreen = true, .use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false, .showZonesOnAllMonitors = false,
.makeDraggedWindowTransparent = true,
.zoneColor = L"#FAFAFA",
.zoneBorderColor = L"#4b4b55",
.zoneHightlightColor = L"#00FFD7", .zoneHightlightColor = L"#00FFD7",
.zoneHighlightOpacity = m_defaultSettings.zoneHighlightOpacity, .zoneHighlightOpacity = m_defaultSettings.zoneHighlightOpacity,
.editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, true, true, false, VK_OEM_3), .editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, true, true, false, VK_OEM_3),
@@ -290,6 +316,8 @@ namespace FancyZonesUnitTests
values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows); values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows);
values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen); values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen);
values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors); values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors);
values.add_property(L"fancyzones_makeDraggedWindowTransparent", expected.makeDraggedWindowTransparent);
values.add_property(L"fancyzones_zoneColor", expected.zoneColor);
values.add_property(L"fancyzones_zoneHighlightColor", expected.zoneHightlightColor); values.add_property(L"fancyzones_zoneHighlightColor", expected.zoneHightlightColor);
values.add_property(L"fancyzones_editor_hotkey", expected.editorHotkey.get_json()); values.add_property(L"fancyzones_editor_hotkey", expected.editorHotkey.get_json());
values.add_property(L"fancyzones_excluded_apps", expected.excludedApps); values.add_property(L"fancyzones_excluded_apps", expected.excludedApps);
@@ -316,6 +344,9 @@ namespace FancyZonesUnitTests
.appLastZone_moveWindows = false, .appLastZone_moveWindows = false,
.use_cursorpos_editor_startupscreen = true, .use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false, .showZonesOnAllMonitors = false,
.makeDraggedWindowTransparent = true,
.zoneColor = L"FAFAFA",
.zoneBorderColor = L"CCDDEE",
.zoneHightlightColor = L"#00FFD7", .zoneHightlightColor = L"#00FFD7",
.zoneHighlightOpacity = 45, .zoneHighlightOpacity = 45,
.editorHotkey = m_defaultSettings.editorHotkey, .editorHotkey = m_defaultSettings.editorHotkey,
@@ -333,6 +364,9 @@ namespace FancyZonesUnitTests
values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows); values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows);
values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen); values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen);
values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors); values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors);
values.add_property(L"fancyzones_makeDraggedWindowTransparent", expected.makeDraggedWindowTransparent);
values.add_property(L"fancyzones_zoneColor", expected.zoneColor);
values.add_property(L"fancyzones_zoneBorderColor", expected.zoneBorderColor);
values.add_property(L"fancyzones_zoneHighlightColor", expected.zoneHightlightColor); values.add_property(L"fancyzones_zoneHighlightColor", expected.zoneHightlightColor);
values.add_property(L"fancyzones_highlight_opacity", expected.zoneHighlightOpacity); values.add_property(L"fancyzones_highlight_opacity", expected.zoneHighlightOpacity);
values.add_property(L"fancyzones_excluded_apps", expected.excludedApps); values.add_property(L"fancyzones_excluded_apps", expected.excludedApps);
@@ -359,6 +393,9 @@ namespace FancyZonesUnitTests
.appLastZone_moveWindows = false, .appLastZone_moveWindows = false,
.use_cursorpos_editor_startupscreen = true, .use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false, .showZonesOnAllMonitors = false,
.makeDraggedWindowTransparent = true,
.zoneColor = L"FAFAFA",
.zoneBorderColor = L"CCDDEE",
.zoneHightlightColor = L"#00FFD7", .zoneHightlightColor = L"#00FFD7",
.zoneHighlightOpacity = 45, .zoneHighlightOpacity = 45,
.editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, true, true, false, VK_OEM_3), .editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, true, true, false, VK_OEM_3),
@@ -376,6 +413,9 @@ namespace FancyZonesUnitTests
values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows); values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows);
values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen); values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen);
values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors); values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors);
values.add_property(L"fancyzones_makeDraggedWindowTransparent", expected.makeDraggedWindowTransparent);
values.add_property(L"fancyzones_zoneColor", expected.zoneColor);
values.add_property(L"fancyzones_zoneBorderColor", expected.zoneBorderColor);
values.add_property(L"fancyzones_zoneHighlightColor", expected.zoneHightlightColor); values.add_property(L"fancyzones_zoneHighlightColor", expected.zoneHightlightColor);
values.add_property(L"fancyzones_highlight_opacity", expected.zoneHighlightOpacity); values.add_property(L"fancyzones_highlight_opacity", expected.zoneHighlightOpacity);
values.add_property(L"fancyzones_editor_hotkey", expected.editorHotkey.get_json()); values.add_property(L"fancyzones_editor_hotkey", expected.editorHotkey.get_json());
@@ -483,6 +523,9 @@ namespace FancyZonesUnitTests
.appLastZone_moveWindows = false, .appLastZone_moveWindows = false,
.use_cursorpos_editor_startupscreen = true, .use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false, .showZonesOnAllMonitors = false,
.makeDraggedWindowTransparent = true,
.zoneColor = L"FAFAFA",
.zoneBorderColor = L"CCDDEE",
.zoneHightlightColor = L"#00FFD7", .zoneHightlightColor = L"#00FFD7",
.zoneHighlightOpacity = 45, .zoneHighlightOpacity = 45,
.editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, true, true, false, VK_OEM_3), .editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, true, true, false, VK_OEM_3),
@@ -500,6 +543,9 @@ namespace FancyZonesUnitTests
values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows); values.add_property(L"fancyzones_appLastZone_moveWindows", expected.appLastZone_moveWindows);
values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen); values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen);
values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors); values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors);
values.add_property(L"fancyzones_makeDraggedWindowTransparent", expected.makeDraggedWindowTransparent);
values.add_property(L"fancyzones_zoneColor", expected.zoneColor);
values.add_property(L"fancyzones_zoneBorderColor", expected.zoneBorderColor);
values.add_property(L"fancyzones_zoneHighlightColor", expected.zoneHightlightColor); values.add_property(L"fancyzones_zoneHighlightColor", expected.zoneHightlightColor);
values.add_property(L"fancyzones_highlight_opacity", expected.zoneHighlightOpacity); values.add_property(L"fancyzones_highlight_opacity", expected.zoneHighlightOpacity);
values.add_property(L"fancyzones_editor_hotkey", expected.editorHotkey.get_json()); values.add_property(L"fancyzones_editor_hotkey", expected.editorHotkey.get_json());
@@ -613,7 +659,10 @@ namespace FancyZonesUnitTests
ptSettings.add_bool_toogle(L"fancyzones_appLastZone_moveWindows", IDS_SETTING_DESCRIPTION_APPLASTZONE_MOVEWINDOWS, settings.appLastZone_moveWindows); ptSettings.add_bool_toogle(L"fancyzones_appLastZone_moveWindows", IDS_SETTING_DESCRIPTION_APPLASTZONE_MOVEWINDOWS, settings.appLastZone_moveWindows);
ptSettings.add_bool_toogle(L"use_cursorpos_editor_startupscreen", IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN, settings.use_cursorpos_editor_startupscreen); ptSettings.add_bool_toogle(L"use_cursorpos_editor_startupscreen", IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN, settings.use_cursorpos_editor_startupscreen);
ptSettings.add_bool_toogle(L"fancyzones_show_on_all_monitors", IDS_SETTING_DESCRIPTION_SHOW_FANCY_ZONES_ON_ALL_MONITORS, settings.showZonesOnAllMonitors); ptSettings.add_bool_toogle(L"fancyzones_show_on_all_monitors", IDS_SETTING_DESCRIPTION_SHOW_FANCY_ZONES_ON_ALL_MONITORS, settings.showZonesOnAllMonitors);
ptSettings.add_bool_toogle(L"fancyzones_makeDraggedWindowTransparent", IDS_SETTING_DESCRIPTION_MAKE_DRAGGED_WINDOW_TRANSPARENT, settings.makeDraggedWindowTransparent);
ptSettings.add_int_spinner(L"fancyzones_highlight_opacity", IDS_SETTINGS_HIGHLIGHT_OPACITY, settings.zoneHighlightOpacity, 0, 100, 1); ptSettings.add_int_spinner(L"fancyzones_highlight_opacity", IDS_SETTINGS_HIGHLIGHT_OPACITY, settings.zoneHighlightOpacity, 0, 100, 1);
ptSettings.add_color_picker(L"fancyzones_zoneColor", IDS_SETTING_DESCRIPTION_ZONECOLOR, settings.zoneColor);
ptSettings.add_color_picker(L"fancyzones_zoneBorderColor", IDS_SETTING_DESCRIPTION_ZONE_BORDER_COLOR, settings.zoneBorderColor);
ptSettings.add_color_picker(L"fancyzones_zoneHighlightColor", IDS_SETTING_DESCRIPTION_ZONEHIGHLIGHTCOLOR, settings.zoneHightlightColor); ptSettings.add_color_picker(L"fancyzones_zoneHighlightColor", IDS_SETTING_DESCRIPTION_ZONEHIGHLIGHTCOLOR, settings.zoneHightlightColor);
ptSettings.add_multiline_string(L"fancyzones_excluded_apps", IDS_SETTING_EXCLCUDED_APPS_DESCRIPTION, settings.excludedApps); ptSettings.add_multiline_string(L"fancyzones_excluded_apps", IDS_SETTING_EXCLCUDED_APPS_DESCRIPTION, settings.excludedApps);
@@ -635,6 +684,9 @@ namespace FancyZonesUnitTests
.appLastZone_moveWindows = false, .appLastZone_moveWindows = false,
.use_cursorpos_editor_startupscreen = true, .use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false, .showZonesOnAllMonitors = false,
.makeDraggedWindowTransparent = true,
.zoneColor = L"FAFAFA",
.zoneBorderColor = L"CCDDEE",
.zoneHightlightColor = L"#00FFD7", .zoneHightlightColor = L"#00FFD7",
.zoneHighlightOpacity = 45, .zoneHighlightOpacity = 45,
.editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, true, true, false, VK_OEM_3), .editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, true, true, false, VK_OEM_3),
@@ -653,6 +705,8 @@ namespace FancyZonesUnitTests
values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen); values.add_property(L"use_cursorpos_editor_startupscreen", expected.use_cursorpos_editor_startupscreen);
values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors); values.add_property(L"fancyzones_show_on_all_monitors", expected.showZonesOnAllMonitors);
values.add_property(L"fancyzones_zoneHighlightColor", expected.zoneHightlightColor); values.add_property(L"fancyzones_zoneHighlightColor", expected.zoneHightlightColor);
values.add_property(L"fancyzones_zoneColor", expected.zoneColor);
values.add_property(L"fancyzones_zoneBorderColor", expected.zoneBorderColor);
values.add_property(L"fancyzones_highlight_opacity", expected.zoneHighlightOpacity); values.add_property(L"fancyzones_highlight_opacity", expected.zoneHighlightOpacity);
values.add_property(L"fancyzones_editor_hotkey", expected.editorHotkey.get_json()); values.add_property(L"fancyzones_editor_hotkey", expected.editorHotkey.get_json());
values.add_property(L"fancyzones_excluded_apps", expected.excludedApps); values.add_property(L"fancyzones_excluded_apps", expected.excludedApps);
@@ -684,8 +738,11 @@ namespace FancyZonesUnitTests
m_ptSettings->add_bool_toogle(L"fancyzones_appLastZone_moveWindows", IDS_SETTING_DESCRIPTION_APPLASTZONE_MOVEWINDOWS, expected.appLastZone_moveWindows); m_ptSettings->add_bool_toogle(L"fancyzones_appLastZone_moveWindows", IDS_SETTING_DESCRIPTION_APPLASTZONE_MOVEWINDOWS, expected.appLastZone_moveWindows);
m_ptSettings->add_bool_toogle(L"use_cursorpos_editor_startupscreen", IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN, expected.use_cursorpos_editor_startupscreen); m_ptSettings->add_bool_toogle(L"use_cursorpos_editor_startupscreen", IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN, expected.use_cursorpos_editor_startupscreen);
m_ptSettings->add_bool_toogle(L"fancyzones_show_on_all_monitors", IDS_SETTING_DESCRIPTION_SHOW_FANCY_ZONES_ON_ALL_MONITORS, expected.showZonesOnAllMonitors); m_ptSettings->add_bool_toogle(L"fancyzones_show_on_all_monitors", IDS_SETTING_DESCRIPTION_SHOW_FANCY_ZONES_ON_ALL_MONITORS, expected.showZonesOnAllMonitors);
m_ptSettings->add_int_spinner(L"fancyzones_highlight_opacity", IDS_SETTINGS_HIGHLIGHT_OPACITY, expected.zoneHighlightOpacity, 0, 100, 1); m_ptSettings->add_bool_toogle(L"fancyzones_makeDraggedWindowTransparent", IDS_SETTING_DESCRIPTION_MAKE_DRAGGED_WINDOW_TRANSPARENT, expected.makeDraggedWindowTransparent);
m_ptSettings->add_color_picker(L"fancyzones_zoneHighlightColor", IDS_SETTING_DESCRIPTION_ZONEHIGHLIGHTCOLOR, expected.zoneHightlightColor); m_ptSettings->add_color_picker(L"fancyzones_zoneHighlightColor", IDS_SETTING_DESCRIPTION_ZONEHIGHLIGHTCOLOR, expected.zoneHightlightColor);
m_ptSettings->add_color_picker(L"fancyzones_zoneColor", IDS_SETTING_DESCRIPTION_ZONECOLOR, expected.zoneColor);
m_ptSettings->add_color_picker(L"fancyzones_zoneBorderColor", IDS_SETTING_DESCRIPTION_ZONE_BORDER_COLOR, expected.zoneBorderColor);
m_ptSettings->add_int_spinner(L"fancyzones_highlight_opacity", IDS_SETTINGS_HIGHLIGHT_OPACITY, expected.zoneHighlightOpacity, 0, 100, 1);
m_ptSettings->add_multiline_string(L"fancyzones_excluded_apps", IDS_SETTING_EXCLCUDED_APPS_DESCRIPTION, expected.excludedApps); m_ptSettings->add_multiline_string(L"fancyzones_excluded_apps", IDS_SETTING_EXCLCUDED_APPS_DESCRIPTION, expected.excludedApps);
} }
@@ -749,6 +806,9 @@ namespace FancyZonesUnitTests
.appLastZone_moveWindows = true, .appLastZone_moveWindows = true,
.use_cursorpos_editor_startupscreen = true, .use_cursorpos_editor_startupscreen = true,
.showZonesOnAllMonitors = false, .showZonesOnAllMonitors = false,
.makeDraggedWindowTransparent = true,
.zoneColor = L"#FAFAFA",
.zoneBorderColor = L"CCDDEE",
.zoneHightlightColor = L"#00AABB", .zoneHightlightColor = L"#00AABB",
.zoneHighlightOpacity = 45, .zoneHighlightOpacity = 45,
.editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, false, false, false, VK_OEM_3), .editorHotkey = PowerToysSettings::HotkeyObject::from_settings(false, false, false, false, VK_OEM_3),

View File

@@ -18,6 +18,16 @@ namespace FancyZonesUnitTests
IFACEMETHODIMP_(void) IFACEMETHODIMP_(void)
MoveWindowsOnActiveZoneSetChange() noexcept {}; MoveWindowsOnActiveZoneSetChange() noexcept {};
IFACEMETHODIMP_(COLORREF) IFACEMETHODIMP_(COLORREF)
GetZoneColor() noexcept
{
return RGB(0xFF, 0xFF, 0xFF);
}
IFACEMETHODIMP_(COLORREF)
GetZoneBorderColor() noexcept
{
return RGB(0xFF, 0xFF, 0xFF);
}
IFACEMETHODIMP_(COLORREF)
GetZoneHighlightColor() noexcept GetZoneHighlightColor() noexcept
{ {
return RGB(0xFF, 0xFF, 0xFF); return RGB(0xFF, 0xFF, 0xFF);
@@ -32,6 +42,11 @@ namespace FancyZonesUnitTests
{ {
return 100; return 100;
} }
IFACEMETHODIMP_(bool)
isMakeDraggedWindowTransparentActive() noexcept
{
return true;
}
IZoneWindow* m_zoneWindow; IZoneWindow* m_zoneWindow;
}; };