mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-11 20:23:07 +08:00
[FancyZones] Improve code quality (part 2: WorkArea init) (#23030)
* init WorkArea with a rectangle * keep the highlighted zones state in a separate class
This commit is contained in:
parent
cc5633db30
commit
6f0b16de49
@ -733,7 +733,17 @@ void FancyZones::AddWorkArea(HMONITOR monitor, const FancyZonesDataTypes::WorkAr
|
|||||||
parentId = parentArea->UniqueId();
|
parentId = parentArea->UniqueId();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto workArea = MakeWorkArea(m_hinstance, monitor, id, parentId);
|
FancyZonesUtils::Rect rect{};
|
||||||
|
if (monitor)
|
||||||
|
{
|
||||||
|
rect = MonitorUtils::GetWorkAreaRect(monitor);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rect = FancyZonesUtils::GetAllMonitorsCombinedRect<&MONITORINFO::rcWork>();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto workArea = MakeWorkArea(m_hinstance, id, parentId, rect);
|
||||||
if (workArea)
|
if (workArea)
|
||||||
{
|
{
|
||||||
m_workAreaHandler.AddWorkArea(VirtualDesktop::instance().GetCurrentVirtualDesktopId(), monitor, workArea);
|
m_workAreaHandler.AddWorkArea(VirtualDesktop::instance().GetCurrentVirtualDesktopId(), monitor, workArea);
|
||||||
|
@ -75,6 +75,7 @@
|
|||||||
<ClInclude Include="WindowUtils.h" />
|
<ClInclude Include="WindowUtils.h" />
|
||||||
<ClInclude Include="Zone.h" />
|
<ClInclude Include="Zone.h" />
|
||||||
<ClInclude Include="Colors.h" />
|
<ClInclude Include="Colors.h" />
|
||||||
|
<ClInclude Include="HighlightedZones.h" />
|
||||||
<ClInclude Include="ZoneIndexSetBitmask.h" />
|
<ClInclude Include="ZoneIndexSetBitmask.h" />
|
||||||
<ClInclude Include="WorkArea.h" />
|
<ClInclude Include="WorkArea.h" />
|
||||||
<ClInclude Include="ZonesOverlay.h" />
|
<ClInclude Include="ZonesOverlay.h" />
|
||||||
@ -124,6 +125,7 @@
|
|||||||
<ClCompile Include="WindowUtils.cpp" />
|
<ClCompile Include="WindowUtils.cpp" />
|
||||||
<ClCompile Include="Zone.cpp" />
|
<ClCompile Include="Zone.cpp" />
|
||||||
<ClCompile Include="WorkArea.cpp" />
|
<ClCompile Include="WorkArea.cpp" />
|
||||||
|
<ClCompile Include="HighlightedZones.cpp" />
|
||||||
<ClCompile Include="ZonesOverlay.cpp" />
|
<ClCompile Include="ZonesOverlay.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -153,6 +153,9 @@
|
|||||||
<ClInclude Include="FancyZonesData\LayoutData.h">
|
<ClInclude Include="FancyZonesData\LayoutData.h">
|
||||||
<Filter>Header Files\FancyZonesData</Filter>
|
<Filter>Header Files\FancyZonesData</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="HighlightedZones.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="NotificationUtil.h">
|
<ClInclude Include="NotificationUtil.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@ -251,6 +254,9 @@
|
|||||||
<ClCompile Include="LayoutAssignedWindows.cpp">
|
<ClCompile Include="LayoutAssignedWindows.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="HighlightedZones.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
|
55
src/modules/fancyzones/FancyZonesLib/HighlightedZones.cpp
Normal file
55
src/modules/fancyzones/FancyZonesLib/HighlightedZones.cpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#include "pch.h"
|
||||||
|
#include "HighlightedZones.h"
|
||||||
|
|
||||||
|
#include <FancyZonesLib/Layout.h>
|
||||||
|
|
||||||
|
HighlightedZones::HighlightedZones()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const ZoneIndexSet& HighlightedZones::Zones() const noexcept
|
||||||
|
{
|
||||||
|
return m_highlightZone;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HighlightedZones::Empty() const noexcept
|
||||||
|
{
|
||||||
|
return m_highlightZone.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HighlightedZones::Update(const Layout* layout, POINT const& point, bool selectManyZones) noexcept
|
||||||
|
{
|
||||||
|
if (!layout)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto highlightZone = layout->ZonesFromPoint(point);
|
||||||
|
|
||||||
|
if (selectManyZones)
|
||||||
|
{
|
||||||
|
if (m_initialHighlightZone.empty())
|
||||||
|
{
|
||||||
|
// first time
|
||||||
|
m_initialHighlightZone = highlightZone;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
highlightZone = layout->GetCombinedZoneRange(m_initialHighlightZone, highlightZone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_initialHighlightZone = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool updated = (highlightZone != m_highlightZone);
|
||||||
|
m_highlightZone = std::move(highlightZone);
|
||||||
|
return updated;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HighlightedZones::Reset() noexcept
|
||||||
|
{
|
||||||
|
m_highlightZone = {};
|
||||||
|
m_initialHighlightZone = {};
|
||||||
|
}
|
22
src/modules/fancyzones/FancyZonesLib/HighlightedZones.h
Normal file
22
src/modules/fancyzones/FancyZonesLib/HighlightedZones.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <FancyZonesLib/Zone.h>
|
||||||
|
|
||||||
|
class Layout;
|
||||||
|
|
||||||
|
class HighlightedZones
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
HighlightedZones();
|
||||||
|
~HighlightedZones() = default;
|
||||||
|
|
||||||
|
const ZoneIndexSet& Zones() const noexcept;
|
||||||
|
bool Empty() const noexcept;
|
||||||
|
|
||||||
|
bool Update(const Layout* layout, POINT const& point, bool selectManyZones) noexcept;
|
||||||
|
void Reset() noexcept;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ZoneIndexSet m_initialHighlightZone;
|
||||||
|
ZoneIndexSet m_highlightZone;
|
||||||
|
};
|
@ -383,4 +383,19 @@ namespace MonitorUtils
|
|||||||
|
|
||||||
return displays;
|
return displays;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FancyZonesUtils::Rect GetWorkAreaRect(HMONITOR monitor)
|
||||||
|
{
|
||||||
|
if (monitor)
|
||||||
|
{
|
||||||
|
MONITORINFO mi{};
|
||||||
|
mi.cbSize = sizeof(mi);
|
||||||
|
if (GetMonitorInfoW(monitor, &mi))
|
||||||
|
{
|
||||||
|
return FancyZonesUtils::Rect(mi.rcWork);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FancyZonesUtils::Rect{};
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <FancyZonesLib/FancyZonesDataTypes.h>
|
#include <FancyZonesLib/FancyZonesDataTypes.h>
|
||||||
|
#include <FancyZonesLib/util.h>
|
||||||
|
|
||||||
namespace MonitorUtils
|
namespace MonitorUtils
|
||||||
{
|
{
|
||||||
@ -19,4 +20,6 @@ namespace MonitorUtils
|
|||||||
|
|
||||||
std::vector<FancyZonesDataTypes::MonitorId> IdentifyMonitors() noexcept;
|
std::vector<FancyZonesDataTypes::MonitorId> IdentifyMonitors() noexcept;
|
||||||
void OpenWindowOnActiveMonitor(HWND window, HMONITOR monitor) noexcept;
|
void OpenWindowOnActiveMonitor(HWND window, HMONITOR monitor) noexcept;
|
||||||
|
|
||||||
|
FancyZonesUtils::Rect GetWorkAreaRect(HMONITOR monitor);
|
||||||
};
|
};
|
||||||
|
@ -109,8 +109,9 @@ namespace
|
|||||||
WindowPool windowPool;
|
WindowPool windowPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkArea::WorkArea(HINSTANCE hinstance, const FancyZonesDataTypes::WorkAreaId& uniqueId) :
|
WorkArea::WorkArea(HINSTANCE hinstance, const FancyZonesDataTypes::WorkAreaId& uniqueId, const FancyZonesUtils::Rect& workAreaRect) :
|
||||||
m_uniqueId(uniqueId)
|
m_uniqueId(uniqueId),
|
||||||
|
m_workAreaRect(workAreaRect)
|
||||||
{
|
{
|
||||||
WNDCLASSEXW wcex{};
|
WNDCLASSEXW wcex{};
|
||||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||||
@ -129,8 +130,7 @@ WorkArea::~WorkArea()
|
|||||||
HRESULT WorkArea::MoveSizeEnter(HWND window) noexcept
|
HRESULT WorkArea::MoveSizeEnter(HWND window) noexcept
|
||||||
{
|
{
|
||||||
m_windowMoveSize = window;
|
m_windowMoveSize = window;
|
||||||
m_highlightZone = {};
|
m_highlightedZones.Reset();
|
||||||
m_initialHighlightZone = {};
|
|
||||||
ShowZonesOverlay();
|
ShowZonesOverlay();
|
||||||
Trace::WorkArea::MoveOrResizeStarted(m_layout.get(), m_layoutWindows.get());
|
Trace::WorkArea::MoveOrResizeStarted(m_layout.get(), m_layoutWindows.get());
|
||||||
return S_OK;
|
return S_OK;
|
||||||
@ -144,42 +144,23 @@ HRESULT WorkArea::MoveSizeUpdate(POINT const& ptScreen, bool dragEnabled, bool s
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool redraw = false;
|
bool redraw = false;
|
||||||
POINT ptClient = ptScreen;
|
|
||||||
MapWindowPoints(nullptr, m_window, &ptClient, 1);
|
|
||||||
|
|
||||||
if (dragEnabled)
|
if (dragEnabled)
|
||||||
{
|
{
|
||||||
auto highlightZone = ZonesFromPoint(ptClient);
|
POINT ptClient = ptScreen;
|
||||||
|
MapWindowPoints(nullptr, m_window, &ptClient, 1);
|
||||||
|
|
||||||
if (selectManyZones)
|
redraw = m_highlightedZones.Update(m_layout.get(), ptClient, selectManyZones);
|
||||||
{
|
|
||||||
if (m_initialHighlightZone.empty())
|
|
||||||
{
|
|
||||||
// first time
|
|
||||||
m_initialHighlightZone = highlightZone;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
highlightZone = m_layout->GetCombinedZoneRange(m_initialHighlightZone, highlightZone);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_initialHighlightZone = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
redraw = (highlightZone != m_highlightZone);
|
|
||||||
m_highlightZone = std::move(highlightZone);
|
|
||||||
}
|
}
|
||||||
else if (m_highlightZone.size())
|
else if (!m_highlightedZones.Empty())
|
||||||
{
|
{
|
||||||
m_highlightZone = {};
|
m_highlightedZones.Reset();
|
||||||
redraw = true;
|
redraw = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (redraw && m_zonesOverlay)
|
if (redraw && m_zonesOverlay)
|
||||||
{
|
{
|
||||||
m_zonesOverlay->DrawActiveZoneSet(m_layout->Zones(), m_highlightZone, Colors::GetZoneColors(), FancyZonesSettings::settings().showZoneNumber);
|
m_zonesOverlay->DrawActiveZoneSet(m_layout->Zones(), m_highlightedZones.Zones(), Colors::GetZoneColors(), FancyZonesSettings::settings().showZoneNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
@ -192,7 +173,8 @@ HRESULT WorkArea::MoveSizeEnd(HWND window) noexcept
|
|||||||
return E_INVALIDARG;
|
return E_INVALIDARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
MoveWindowIntoZoneByIndexSet(window, m_highlightZone);
|
MoveWindowIntoZoneByIndexSet(window, m_highlightedZones.Zones());
|
||||||
|
m_highlightedZones.Reset();
|
||||||
|
|
||||||
Trace::WorkArea::MoveOrResizeEnd(m_layout.get(), m_layoutWindows.get());
|
Trace::WorkArea::MoveOrResizeEnd(m_layout.get(), m_layoutWindows.get());
|
||||||
|
|
||||||
@ -505,7 +487,7 @@ void WorkArea::ShowZonesOverlay() noexcept
|
|||||||
if (m_window && m_layout)
|
if (m_window && m_layout)
|
||||||
{
|
{
|
||||||
SetAsTopmostWindow();
|
SetAsTopmostWindow();
|
||||||
m_zonesOverlay->DrawActiveZoneSet(m_layout->Zones(), m_highlightZone, Colors::GetZoneColors(), FancyZonesSettings::settings().showZoneNumber);
|
m_zonesOverlay->DrawActiveZoneSet(m_layout->Zones(), m_highlightedZones.Zones(), Colors::GetZoneColors(), FancyZonesSettings::settings().showZoneNumber);
|
||||||
m_zonesOverlay->Show();
|
m_zonesOverlay->Show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -515,9 +497,7 @@ void WorkArea::HideZonesOverlay() noexcept
|
|||||||
if (m_window)
|
if (m_window)
|
||||||
{
|
{
|
||||||
m_zonesOverlay->Hide();
|
m_zonesOverlay->Hide();
|
||||||
m_keyLast = 0;
|
|
||||||
m_windowMoveSize = nullptr;
|
m_windowMoveSize = nullptr;
|
||||||
m_highlightZone = {};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -532,8 +512,7 @@ void WorkArea::UpdateActiveZoneSet() noexcept
|
|||||||
CalculateZoneSet();
|
CalculateZoneSet();
|
||||||
if (m_window && m_layout)
|
if (m_window && m_layout)
|
||||||
{
|
{
|
||||||
m_highlightZone.clear();
|
m_zonesOverlay->DrawActiveZoneSet(m_layout->Zones(), {}, Colors::GetZoneColors(), FancyZonesSettings::settings().showZoneNumber);
|
||||||
m_zonesOverlay->DrawActiveZoneSet(m_layout->Zones(), m_highlightZone, Colors::GetZoneColors(), FancyZonesSettings::settings().showZoneNumber);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -547,10 +526,10 @@ void WorkArea::CycleWindows(HWND window, bool reverse) noexcept
|
|||||||
|
|
||||||
void WorkArea::ClearSelectedZones() noexcept
|
void WorkArea::ClearSelectedZones() noexcept
|
||||||
{
|
{
|
||||||
if (m_highlightZone.size() && m_layout)
|
if (!m_highlightedZones.Empty() && m_layout)
|
||||||
{
|
{
|
||||||
m_highlightZone.clear();
|
m_highlightedZones.Reset();
|
||||||
m_zonesOverlay->DrawActiveZoneSet(m_layout->Zones(), m_highlightZone, Colors::GetZoneColors(), FancyZonesSettings::settings().showZoneNumber);
|
m_zonesOverlay->DrawActiveZoneSet(m_layout->Zones(), {}, Colors::GetZoneColors(), FancyZonesSettings::settings().showZoneNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -609,7 +588,7 @@ void WorkArea::CalculateZoneSet() noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_layout = std::make_unique<Layout>(appliedLayout.value());
|
m_layout = std::make_unique<Layout>(appliedLayout.value());
|
||||||
m_layout->Init(m_workAreaRect, m_monitor);
|
m_layout->Init(m_workAreaRect, m_uniqueId.monitorId.monitor);
|
||||||
|
|
||||||
if (!m_layoutWindows)
|
if (!m_layoutWindows)
|
||||||
{
|
{
|
||||||
@ -639,16 +618,6 @@ LRESULT WorkArea::WndProc(UINT message, WPARAM wparam, LPARAM lparam) noexcept
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZoneIndexSet WorkArea::ZonesFromPoint(POINT pt) noexcept
|
|
||||||
{
|
|
||||||
if (m_layout)
|
|
||||||
{
|
|
||||||
return m_layout->ZonesFromPoint(pt);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
void WorkArea::SetAsTopmostWindow() noexcept
|
void WorkArea::SetAsTopmostWindow() noexcept
|
||||||
{
|
{
|
||||||
if (!m_window)
|
if (!m_window)
|
||||||
@ -667,11 +636,6 @@ void WorkArea::SetAsTopmostWindow() noexcept
|
|||||||
SetWindowPos(m_window, windowInsertAfter, 0, 0, 0, 0, flags);
|
SetWindowPos(m_window, windowInsertAfter, 0, 0, 0, 0, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorkArea::LogInitializationError()
|
|
||||||
{
|
|
||||||
Logger::error(L"Unable to get monitor info, {}", get_last_error_or_default(GetLastError()));
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
LRESULT CALLBACK WorkArea::s_WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) noexcept
|
LRESULT CALLBACK WorkArea::s_WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) noexcept
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <FancyZonesLib/FancyZonesDataTypes.h>
|
#include <FancyZonesLib/FancyZonesDataTypes.h>
|
||||||
|
#include <FancyZonesLib/HighlightedZones.h>
|
||||||
#include <FancyZonesLib/Layout.h>
|
#include <FancyZonesLib/Layout.h>
|
||||||
#include <FancyZonesLib/LayoutAssignedWindows.h>
|
#include <FancyZonesLib/LayoutAssignedWindows.h>
|
||||||
#include <FancyZonesLib/util.h>
|
#include <FancyZonesLib/util.h>
|
||||||
@ -10,7 +11,7 @@ class ZonesOverlay;
|
|||||||
class WorkArea
|
class WorkArea
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WorkArea(HINSTANCE hinstance, const FancyZonesDataTypes::WorkAreaId& uniqueId);
|
WorkArea(HINSTANCE hinstance, const FancyZonesDataTypes::WorkAreaId& uniqueId, const FancyZonesUtils::Rect& workAreaRect);
|
||||||
~WorkArea();
|
~WorkArea();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -26,34 +27,6 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool InitWorkAreaRect(HMONITOR monitor)
|
|
||||||
{
|
|
||||||
m_monitor = monitor;
|
|
||||||
|
|
||||||
#if defined(UNIT_TESTS)
|
|
||||||
m_workAreaRect = FancyZonesUtils::Rect({ 0, 0, 1920, 1080 });
|
|
||||||
#else
|
|
||||||
|
|
||||||
if (monitor)
|
|
||||||
{
|
|
||||||
MONITORINFO mi{};
|
|
||||||
mi.cbSize = sizeof(mi);
|
|
||||||
if (!GetMonitorInfoW(monitor, &mi))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_workAreaRect = FancyZonesUtils::Rect(mi.rcWork);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_workAreaRect = FancyZonesUtils::GetAllMonitorsCombinedRect<&MONITORINFO::rcWork>();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
FancyZonesDataTypes::WorkAreaId UniqueId() const noexcept { return { m_uniqueId }; }
|
FancyZonesDataTypes::WorkAreaId UniqueId() const noexcept { return { m_uniqueId }; }
|
||||||
const std::unique_ptr<Layout>& GetLayout() const noexcept { return m_layout; }
|
const std::unique_ptr<Layout>& GetLayout() const noexcept { return m_layout; }
|
||||||
const std::unique_ptr<LayoutAssignedWindows>& GetLayoutWindows() const noexcept { return m_layoutWindows; }
|
const std::unique_ptr<LayoutAssignedWindows>& GetLayoutWindows() const noexcept { return m_layoutWindows; }
|
||||||
@ -79,8 +52,6 @@ public:
|
|||||||
void ClearSelectedZones() noexcept;
|
void ClearSelectedZones() noexcept;
|
||||||
|
|
||||||
void CycleWindows(HWND window, bool reverse) noexcept;
|
void CycleWindows(HWND window, bool reverse) noexcept;
|
||||||
|
|
||||||
void LogInitializationError();
|
|
||||||
|
|
||||||
protected:
|
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;
|
||||||
@ -90,32 +61,22 @@ private:
|
|||||||
void InitLayout(const FancyZonesDataTypes::WorkAreaId& parentUniqueId) noexcept;
|
void InitLayout(const FancyZonesDataTypes::WorkAreaId& parentUniqueId) noexcept;
|
||||||
void CalculateZoneSet() noexcept;
|
void CalculateZoneSet() noexcept;
|
||||||
LRESULT WndProc(UINT message, WPARAM wparam, LPARAM lparam) noexcept;
|
LRESULT WndProc(UINT message, WPARAM wparam, LPARAM lparam) noexcept;
|
||||||
ZoneIndexSet ZonesFromPoint(POINT pt) noexcept;
|
|
||||||
void SetAsTopmostWindow() noexcept;
|
void SetAsTopmostWindow() noexcept;
|
||||||
|
|
||||||
HMONITOR m_monitor{};
|
const FancyZonesUtils::Rect m_workAreaRect{};
|
||||||
FancyZonesUtils::Rect m_workAreaRect{};
|
|
||||||
const FancyZonesDataTypes::WorkAreaId m_uniqueId;
|
const FancyZonesDataTypes::WorkAreaId m_uniqueId;
|
||||||
HWND m_window{}; // Hidden tool window used to represent current monitor desktop work area.
|
HWND m_window{}; // Hidden tool window used to represent current monitor desktop work area.
|
||||||
HWND m_windowMoveSize{};
|
|
||||||
std::unique_ptr<Layout> m_layout;
|
std::unique_ptr<Layout> m_layout;
|
||||||
std::unique_ptr<LayoutAssignedWindows> m_layoutWindows;
|
std::unique_ptr<LayoutAssignedWindows> m_layoutWindows;
|
||||||
ZoneIndexSet m_initialHighlightZone;
|
|
||||||
ZoneIndexSet m_highlightZone;
|
|
||||||
WPARAM m_keyLast{};
|
|
||||||
size_t m_keyCycle{};
|
|
||||||
std::unique_ptr<ZonesOverlay> m_zonesOverlay;
|
std::unique_ptr<ZonesOverlay> m_zonesOverlay;
|
||||||
|
HighlightedZones m_highlightedZones;
|
||||||
|
|
||||||
|
HWND m_windowMoveSize{};
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::shared_ptr<WorkArea> MakeWorkArea(HINSTANCE hinstance, HMONITOR monitor, const FancyZonesDataTypes::WorkAreaId& uniqueId, const FancyZonesDataTypes::WorkAreaId& parentUniqueId) noexcept
|
inline std::shared_ptr<WorkArea> MakeWorkArea(HINSTANCE hinstance, const FancyZonesDataTypes::WorkAreaId& uniqueId, const FancyZonesDataTypes::WorkAreaId& parentUniqueId, const FancyZonesUtils::Rect& workAreaRect)
|
||||||
{
|
{
|
||||||
auto self = std::make_shared<WorkArea>(hinstance, uniqueId);
|
auto self = std::make_shared<WorkArea>(hinstance, uniqueId, workAreaRect);
|
||||||
if (!self->InitWorkAreaRect(monitor))
|
|
||||||
{
|
|
||||||
self->LogInitializationError();
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!self->Init(hinstance, parentUniqueId))
|
if (!self->Init(hinstance, parentUniqueId))
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -22,11 +22,12 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
FancyZonesDataTypes::WorkAreaId m_uniqueId;
|
FancyZonesDataTypes::WorkAreaId m_uniqueId;
|
||||||
FancyZonesDataTypes::WorkAreaId m_emptyUniqueId;
|
FancyZonesDataTypes::WorkAreaId m_emptyUniqueId;
|
||||||
|
FancyZonesUtils::Rect m_workAreaRect{ RECT(0,0,1920,1080) };
|
||||||
|
|
||||||
HINSTANCE m_hInst{};
|
HINSTANCE m_hInst{};
|
||||||
HMONITOR m_monitor{};
|
HMONITOR m_monitor{};
|
||||||
|
|
||||||
TEST_METHOD_INITIALIZE(Init)
|
TEST_METHOD_INITIALIZE(Init) noexcept
|
||||||
{
|
{
|
||||||
m_uniqueId.monitorId.deviceId.id = L"DELA026";
|
m_uniqueId.monitorId.deviceId.id = L"DELA026";
|
||||||
m_uniqueId.monitorId.deviceId.instanceId = L"5&10a58c63&0&UID16777488";
|
m_uniqueId.monitorId.deviceId.instanceId = L"5&10a58c63&0&UID16777488";
|
||||||
@ -38,7 +39,7 @@ namespace FancyZonesUnitTests
|
|||||||
DefaultLayouts::instance().LoadData();
|
DefaultLayouts::instance().LoadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD_CLEANUP(CleanUp)
|
TEST_METHOD_CLEANUP(CleanUp) noexcept
|
||||||
{
|
{
|
||||||
std::filesystem::remove(AppliedLayouts::AppliedLayoutsFileName());
|
std::filesystem::remove(AppliedLayouts::AppliedLayoutsFileName());
|
||||||
std::filesystem::remove(AppZoneHistory::AppZoneHistoryFileName());
|
std::filesystem::remove(AppZoneHistory::AppZoneHistoryFileName());
|
||||||
@ -50,7 +51,7 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
const auto defaultLayout = DefaultLayouts::instance().GetDefaultLayout();
|
const auto defaultLayout = DefaultLayouts::instance().GetDefaultLayout();
|
||||||
|
|
||||||
auto workArea = MakeWorkArea({}, Mocks::Monitor(), m_uniqueId, m_emptyUniqueId);
|
auto workArea = MakeWorkArea({}, m_uniqueId, m_emptyUniqueId, m_workAreaRect);
|
||||||
Assert::IsFalse(workArea == nullptr);
|
Assert::IsFalse(workArea == nullptr);
|
||||||
Assert::IsTrue(m_uniqueId == workArea->UniqueId());
|
Assert::IsTrue(m_uniqueId == workArea->UniqueId());
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
const auto defaultLayout = DefaultLayouts::instance().GetDefaultLayout();
|
const auto defaultLayout = DefaultLayouts::instance().GetDefaultLayout();
|
||||||
|
|
||||||
auto workArea = MakeWorkArea({}, {}, m_uniqueId, m_emptyUniqueId);
|
auto workArea = MakeWorkArea({}, m_uniqueId, m_emptyUniqueId, m_workAreaRect);
|
||||||
Assert::IsFalse(workArea == nullptr);
|
Assert::IsFalse(workArea == nullptr);
|
||||||
Assert::IsTrue(m_uniqueId == workArea->UniqueId());
|
Assert::IsTrue(m_uniqueId == workArea->UniqueId());
|
||||||
|
|
||||||
@ -95,10 +96,10 @@ namespace FancyZonesUnitTests
|
|||||||
.sensitivityRadius = 20,
|
.sensitivityRadius = 20,
|
||||||
};
|
};
|
||||||
|
|
||||||
auto parentWorkArea = MakeWorkArea(m_hInst, m_monitor, parentUniqueId, m_emptyUniqueId);
|
auto parentWorkArea = MakeWorkArea(m_hInst, parentUniqueId, m_emptyUniqueId, m_workAreaRect);
|
||||||
AppliedLayouts::instance().ApplyLayout(parentUniqueId, layout);
|
AppliedLayouts::instance().ApplyLayout(parentUniqueId, layout);
|
||||||
|
|
||||||
auto actualWorkArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, parentUniqueId);
|
auto actualWorkArea = MakeWorkArea(m_hInst, m_uniqueId, parentUniqueId, m_workAreaRect);
|
||||||
Assert::IsNotNull(actualWorkArea->GetLayout().get());
|
Assert::IsNotNull(actualWorkArea->GetLayout().get());
|
||||||
Assert::IsNotNull(actualWorkArea->GetLayoutWindows().get());
|
Assert::IsNotNull(actualWorkArea->GetLayoutWindows().get());
|
||||||
|
|
||||||
@ -131,7 +132,7 @@ namespace FancyZonesUnitTests
|
|||||||
DefaultLayouts::instance().LoadData();
|
DefaultLayouts::instance().LoadData();
|
||||||
|
|
||||||
// test
|
// test
|
||||||
auto workArea = MakeWorkArea({}, Mocks::Monitor(), m_uniqueId, m_emptyUniqueId);
|
auto workArea = MakeWorkArea({}, m_uniqueId, m_emptyUniqueId, m_workAreaRect);
|
||||||
Assert::IsFalse(workArea == nullptr);
|
Assert::IsFalse(workArea == nullptr);
|
||||||
Assert::IsTrue(m_uniqueId == workArea->UniqueId());
|
Assert::IsTrue(m_uniqueId == workArea->UniqueId());
|
||||||
|
|
||||||
@ -164,7 +165,7 @@ namespace FancyZonesUnitTests
|
|||||||
DefaultLayouts::instance().LoadData();
|
DefaultLayouts::instance().LoadData();
|
||||||
|
|
||||||
// test
|
// test
|
||||||
auto workArea = MakeWorkArea({}, Mocks::Monitor(), m_uniqueId, m_emptyUniqueId);
|
auto workArea = MakeWorkArea({}, m_uniqueId, m_emptyUniqueId, m_workAreaRect);
|
||||||
Assert::IsFalse(workArea == nullptr);
|
Assert::IsFalse(workArea == nullptr);
|
||||||
Assert::IsTrue(m_uniqueId == workArea->UniqueId());
|
Assert::IsTrue(m_uniqueId == workArea->UniqueId());
|
||||||
|
|
||||||
@ -181,11 +182,11 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
FancyZonesDataTypes::WorkAreaId m_uniqueId;
|
FancyZonesDataTypes::WorkAreaId m_uniqueId;
|
||||||
FancyZonesDataTypes::WorkAreaId m_parentUniqueId; // default empty
|
FancyZonesDataTypes::WorkAreaId m_parentUniqueId; // default empty
|
||||||
|
FancyZonesUtils::Rect m_workAreaRect{ RECT(0, 0, 1920, 1080) };
|
||||||
|
|
||||||
HINSTANCE m_hInst{};
|
HINSTANCE m_hInst{};
|
||||||
HMONITOR m_monitor{};
|
|
||||||
|
|
||||||
TEST_METHOD_INITIALIZE(Init)
|
TEST_METHOD_INITIALIZE(Init) noexcept
|
||||||
{
|
{
|
||||||
m_uniqueId.monitorId.deviceId.id = L"DELA026";
|
m_uniqueId.monitorId.deviceId.id = L"DELA026";
|
||||||
m_uniqueId.monitorId.deviceId.instanceId = L"5&10a58c63&0&UID16777488";
|
m_uniqueId.monitorId.deviceId.instanceId = L"5&10a58c63&0&UID16777488";
|
||||||
@ -196,7 +197,7 @@ namespace FancyZonesUnitTests
|
|||||||
AppliedLayouts::instance().LoadData();
|
AppliedLayouts::instance().LoadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD_CLEANUP(CleanUp)
|
TEST_METHOD_CLEANUP(CleanUp) noexcept
|
||||||
{
|
{
|
||||||
std::filesystem::remove(AppZoneHistory::AppZoneHistoryFileName());
|
std::filesystem::remove(AppZoneHistory::AppZoneHistoryFileName());
|
||||||
std::filesystem::remove(AppliedLayouts::AppliedLayoutsFileName());
|
std::filesystem::remove(AppliedLayouts::AppliedLayoutsFileName());
|
||||||
@ -205,9 +206,9 @@ namespace FancyZonesUnitTests
|
|||||||
public:
|
public:
|
||||||
TEST_METHOD (MoveSizeEnter)
|
TEST_METHOD (MoveSizeEnter)
|
||||||
{
|
{
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
|
|
||||||
const auto expected = S_OK;
|
constexpr auto expected = S_OK;
|
||||||
const auto actual = workArea->MoveSizeEnter(Mocks::Window());
|
const auto actual = workArea->MoveSizeEnter(Mocks::Window());
|
||||||
|
|
||||||
Assert::AreEqual(expected, actual);
|
Assert::AreEqual(expected, actual);
|
||||||
@ -215,9 +216,9 @@ namespace FancyZonesUnitTests
|
|||||||
|
|
||||||
TEST_METHOD (MoveSizeEnterTwice)
|
TEST_METHOD (MoveSizeEnterTwice)
|
||||||
{
|
{
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
|
|
||||||
const auto expected = S_OK;
|
constexpr auto expected = S_OK;
|
||||||
|
|
||||||
workArea->MoveSizeEnter(Mocks::Window());
|
workArea->MoveSizeEnter(Mocks::Window());
|
||||||
const auto actual = workArea->MoveSizeEnter(Mocks::Window());
|
const auto actual = workArea->MoveSizeEnter(Mocks::Window());
|
||||||
@ -227,9 +228,9 @@ namespace FancyZonesUnitTests
|
|||||||
|
|
||||||
TEST_METHOD (MoveSizeUpdate)
|
TEST_METHOD (MoveSizeUpdate)
|
||||||
{
|
{
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
|
|
||||||
const auto expected = S_OK;
|
constexpr auto expected = S_OK;
|
||||||
const auto actual = workArea->MoveSizeUpdate(POINT{ 0, 0 }, true, false);
|
const auto actual = workArea->MoveSizeUpdate(POINT{ 0, 0 }, true, false);
|
||||||
|
|
||||||
Assert::AreEqual(expected, actual);
|
Assert::AreEqual(expected, actual);
|
||||||
@ -237,9 +238,9 @@ namespace FancyZonesUnitTests
|
|||||||
|
|
||||||
TEST_METHOD (MoveSizeUpdatePointNegativeCoordinates)
|
TEST_METHOD (MoveSizeUpdatePointNegativeCoordinates)
|
||||||
{
|
{
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
|
|
||||||
const auto expected = S_OK;
|
constexpr auto expected = S_OK;
|
||||||
const auto actual = workArea->MoveSizeUpdate(POINT{ -10, -10 }, true, false);
|
const auto actual = workArea->MoveSizeUpdate(POINT{ -10, -10 }, true, false);
|
||||||
|
|
||||||
Assert::AreEqual(expected, actual);
|
Assert::AreEqual(expected, actual);
|
||||||
@ -247,9 +248,9 @@ namespace FancyZonesUnitTests
|
|||||||
|
|
||||||
TEST_METHOD (MoveSizeUpdatePointBigCoordinates)
|
TEST_METHOD (MoveSizeUpdatePointBigCoordinates)
|
||||||
{
|
{
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
|
|
||||||
const auto expected = S_OK;
|
constexpr auto expected = S_OK;
|
||||||
const auto actual = workArea->MoveSizeUpdate(POINT{ LONG_MAX, LONG_MAX }, true, false);
|
const auto actual = workArea->MoveSizeUpdate(POINT{ LONG_MAX, LONG_MAX }, true, false);
|
||||||
|
|
||||||
Assert::AreEqual(expected, actual);
|
Assert::AreEqual(expected, actual);
|
||||||
@ -257,13 +258,13 @@ namespace FancyZonesUnitTests
|
|||||||
|
|
||||||
TEST_METHOD (MoveSizeEnd)
|
TEST_METHOD (MoveSizeEnd)
|
||||||
{
|
{
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
|
|
||||||
const auto window = Mocks::Window();
|
const auto window = Mocks::Window();
|
||||||
workArea->MoveSizeEnter(window);
|
workArea->MoveSizeEnter(window);
|
||||||
workArea->MoveSizeUpdate({ 20, 20 }, true, true);
|
workArea->MoveSizeUpdate({ 20, 20 }, true, true);
|
||||||
|
|
||||||
const auto expected = S_OK;
|
constexpr auto expected = S_OK;
|
||||||
const auto actual = workArea->MoveSizeEnd(window);
|
const auto actual = workArea->MoveSizeEnd(window);
|
||||||
Assert::AreEqual(expected, actual);
|
Assert::AreEqual(expected, actual);
|
||||||
|
|
||||||
@ -274,12 +275,12 @@ namespace FancyZonesUnitTests
|
|||||||
|
|
||||||
TEST_METHOD (MoveSizeEndDifferentWindows)
|
TEST_METHOD (MoveSizeEndDifferentWindows)
|
||||||
{
|
{
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
|
|
||||||
const auto window = Mocks::Window();
|
const auto window = Mocks::Window();
|
||||||
workArea->MoveSizeEnter(window);
|
workArea->MoveSizeEnter(window);
|
||||||
|
|
||||||
const auto expected = E_INVALIDARG;
|
constexpr auto expected = E_INVALIDARG;
|
||||||
const auto actual = workArea->MoveSizeEnd(Mocks::Window());
|
const auto actual = workArea->MoveSizeEnd(Mocks::Window());
|
||||||
|
|
||||||
Assert::AreEqual(expected, actual);
|
Assert::AreEqual(expected, actual);
|
||||||
@ -287,9 +288,9 @@ namespace FancyZonesUnitTests
|
|||||||
|
|
||||||
TEST_METHOD (MoveSizeEndWindowNotSet)
|
TEST_METHOD (MoveSizeEndWindowNotSet)
|
||||||
{
|
{
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
|
|
||||||
const auto expected = E_INVALIDARG;
|
constexpr auto expected = E_INVALIDARG;
|
||||||
const auto actual = workArea->MoveSizeEnd(Mocks::Window());
|
const auto actual = workArea->MoveSizeEnd(Mocks::Window());
|
||||||
|
|
||||||
Assert::AreEqual(expected, actual);
|
Assert::AreEqual(expected, actual);
|
||||||
@ -297,7 +298,7 @@ namespace FancyZonesUnitTests
|
|||||||
|
|
||||||
TEST_METHOD (SaveWindowProcessToZoneIndexNullptrWindow)
|
TEST_METHOD (SaveWindowProcessToZoneIndexNullptrWindow)
|
||||||
{
|
{
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
|
|
||||||
workArea->SaveWindowProcessToZoneIndex(nullptr);
|
workArea->SaveWindowProcessToZoneIndex(nullptr);
|
||||||
|
|
||||||
@ -307,7 +308,7 @@ namespace FancyZonesUnitTests
|
|||||||
|
|
||||||
TEST_METHOD (SaveWindowProcessToZoneIndexNoWindowAdded)
|
TEST_METHOD (SaveWindowProcessToZoneIndexNoWindowAdded)
|
||||||
{
|
{
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
|
|
||||||
auto window = Mocks::WindowCreate(m_hInst);
|
auto window = Mocks::WindowCreate(m_hInst);
|
||||||
workArea->GetLayout()->Init(RECT{ 0, 0, 1920, 1080 }, Mocks::Monitor());
|
workArea->GetLayout()->Init(RECT{ 0, 0, 1920, 1080 }, Mocks::Monitor());
|
||||||
@ -320,7 +321,7 @@ namespace FancyZonesUnitTests
|
|||||||
|
|
||||||
TEST_METHOD (SaveWindowProcessToZoneIndexNoWindowAddedWithFilledAppZoneHistory)
|
TEST_METHOD (SaveWindowProcessToZoneIndexNoWindowAddedWithFilledAppZoneHistory)
|
||||||
{
|
{
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
|
|
||||||
const auto window = Mocks::WindowCreate(m_hInst);
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
const auto processPath = get_process_path(window);
|
const auto processPath = get_process_path(window);
|
||||||
@ -332,7 +333,7 @@ namespace FancyZonesUnitTests
|
|||||||
Assert::AreEqual((size_t)1, AppZoneHistory::instance().GetFullAppZoneHistory().size());
|
Assert::AreEqual((size_t)1, AppZoneHistory::instance().GetFullAppZoneHistory().size());
|
||||||
const auto& appHistoryArray1 = AppZoneHistory::instance().GetFullAppZoneHistory().at(processPath);
|
const auto& appHistoryArray1 = AppZoneHistory::instance().GetFullAppZoneHistory().at(processPath);
|
||||||
Assert::AreEqual((size_t)1, appHistoryArray1.size());
|
Assert::AreEqual((size_t)1, appHistoryArray1.size());
|
||||||
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == appHistoryArray1[0].zoneIndexSet);
|
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == appHistoryArray1.at(0).zoneIndexSet);
|
||||||
|
|
||||||
// add zone without window
|
// add zone without window
|
||||||
workArea->GetLayout()->Init(RECT{ 0, 0, 1920, 1080 }, Mocks::Monitor());
|
workArea->GetLayout()->Init(RECT{ 0, 0, 1920, 1080 }, Mocks::Monitor());
|
||||||
@ -341,12 +342,12 @@ namespace FancyZonesUnitTests
|
|||||||
Assert::AreEqual((size_t)1, AppZoneHistory::instance().GetFullAppZoneHistory().size());
|
Assert::AreEqual((size_t)1, AppZoneHistory::instance().GetFullAppZoneHistory().size());
|
||||||
const auto& appHistoryArray2 = AppZoneHistory::instance().GetFullAppZoneHistory().at(processPath);
|
const auto& appHistoryArray2 = AppZoneHistory::instance().GetFullAppZoneHistory().at(processPath);
|
||||||
Assert::AreEqual((size_t)1, appHistoryArray2.size());
|
Assert::AreEqual((size_t)1, appHistoryArray2.size());
|
||||||
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == appHistoryArray2[0].zoneIndexSet);
|
Assert::IsTrue(std::vector<ZoneIndex>{ 0 } == appHistoryArray2.at(0).zoneIndexSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD (SaveWindowProcessToZoneIndexWindowAdded)
|
TEST_METHOD (SaveWindowProcessToZoneIndexWindowAdded)
|
||||||
{
|
{
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
|
|
||||||
auto window = Mocks::WindowCreate(m_hInst);
|
auto window = Mocks::WindowCreate(m_hInst);
|
||||||
const auto processPath = get_process_path(window);
|
const auto processPath = get_process_path(window);
|
||||||
@ -360,25 +361,25 @@ namespace FancyZonesUnitTests
|
|||||||
Assert::AreEqual((size_t)1, AppZoneHistory::instance().GetFullAppZoneHistory().size());
|
Assert::AreEqual((size_t)1, AppZoneHistory::instance().GetFullAppZoneHistory().size());
|
||||||
const auto& appHistoryArray = AppZoneHistory::instance().GetFullAppZoneHistory().at(processPath);
|
const auto& appHistoryArray = AppZoneHistory::instance().GetFullAppZoneHistory().at(processPath);
|
||||||
Assert::AreEqual((size_t)1, appHistoryArray.size());
|
Assert::AreEqual((size_t)1, appHistoryArray.size());
|
||||||
Assert::IsTrue(std::vector<ZoneIndex>{ 2 } == appHistoryArray[0].zoneIndexSet);
|
Assert::IsTrue(std::vector<ZoneIndex>{ 2 } == appHistoryArray.at(0).zoneIndexSet);
|
||||||
|
|
||||||
workArea->SaveWindowProcessToZoneIndex(window);
|
workArea->SaveWindowProcessToZoneIndex(window);
|
||||||
|
|
||||||
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
const auto& actualAppZoneHistory = AppZoneHistory::instance().GetFullAppZoneHistory();
|
||||||
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
||||||
const auto& expected = workArea->GetLayoutWindows()->GetZoneIndexSetFromWindow(window);
|
const auto& expected = workArea->GetLayoutWindows()->GetZoneIndexSetFromWindow(window);
|
||||||
const auto& actual = appHistoryArray[0].zoneIndexSet;
|
const auto& actual = appHistoryArray.at(0).zoneIndexSet;
|
||||||
Assert::IsTrue(expected == actual);
|
Assert::IsTrue(expected == actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD (WhenWindowIsNotResizablePlacingItIntoTheZoneShouldNotResizeIt)
|
TEST_METHOD (WhenWindowIsNotResizablePlacingItIntoTheZoneShouldNotResizeIt)
|
||||||
{
|
{
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
|
|
||||||
auto window = Mocks::WindowCreate(m_hInst);
|
auto window = Mocks::WindowCreate(m_hInst);
|
||||||
|
|
||||||
int originalWidth = 450;
|
const int originalWidth = 450;
|
||||||
int originalHeight = 550;
|
const int originalHeight = 550;
|
||||||
|
|
||||||
SetWindowPos(window, nullptr, 150, 150, originalWidth, originalHeight, SWP_SHOWWINDOW);
|
SetWindowPos(window, nullptr, 150, 150, originalWidth, originalHeight, SWP_SHOWWINDOW);
|
||||||
SetWindowLong(window, GWL_STYLE, GetWindowLong(window, GWL_STYLE) & ~WS_SIZEBOX);
|
SetWindowLong(window, GWL_STYLE, GetWindowLong(window, GWL_STYLE) & ~WS_SIZEBOX);
|
||||||
@ -412,7 +413,7 @@ namespace FancyZonesUnitTests
|
|||||||
FancyZonesDataTypes::WorkAreaId m_parentUniqueId; // default empty
|
FancyZonesDataTypes::WorkAreaId m_parentUniqueId; // default empty
|
||||||
|
|
||||||
HINSTANCE m_hInst{};
|
HINSTANCE m_hInst{};
|
||||||
HMONITOR m_monitor{};
|
FancyZonesUtils::Rect m_workAreaRect{ RECT(0, 0, 1920, 1080) };
|
||||||
|
|
||||||
void PrepareEmptyLayout()
|
void PrepareEmptyLayout()
|
||||||
{
|
{
|
||||||
@ -482,13 +483,13 @@ namespace FancyZonesUnitTests
|
|||||||
AppliedLayouts::instance().LoadData();
|
AppliedLayouts::instance().LoadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD_INITIALIZE(Init)
|
TEST_METHOD_INITIALIZE(Init) noexcept
|
||||||
{
|
{
|
||||||
AppZoneHistory::instance().LoadData();
|
AppZoneHistory::instance().LoadData();
|
||||||
AppliedLayouts::instance().LoadData();
|
AppliedLayouts::instance().LoadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD_CLEANUP(CleanUp)
|
TEST_METHOD_CLEANUP(CleanUp) noexcept
|
||||||
{
|
{
|
||||||
std::filesystem::remove(AppZoneHistory::AppZoneHistoryFileName());
|
std::filesystem::remove(AppZoneHistory::AppZoneHistoryFileName());
|
||||||
std::filesystem::remove(AppliedLayouts::AppliedLayoutsFileName());
|
std::filesystem::remove(AppliedLayouts::AppliedLayoutsFileName());
|
||||||
@ -498,7 +499,7 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
// prepare
|
// prepare
|
||||||
PrepareEmptyLayout();
|
PrepareEmptyLayout();
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
const auto window = Mocks::WindowCreate(m_hInst);
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
|
|
||||||
// test
|
// test
|
||||||
@ -515,7 +516,7 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
// prepare
|
// prepare
|
||||||
PrepareEmptyLayout();
|
PrepareEmptyLayout();
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
const auto window = Mocks::WindowCreate(m_hInst);
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
|
|
||||||
// test
|
// test
|
||||||
@ -532,7 +533,7 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
// prepare
|
// prepare
|
||||||
PrepareGridLayout();
|
PrepareGridLayout();
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
const auto window = Mocks::WindowCreate(m_hInst);
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
|
|
||||||
// test
|
// test
|
||||||
@ -549,7 +550,7 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
// prepare
|
// prepare
|
||||||
PrepareGridLayout();
|
PrepareGridLayout();
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
const auto window = Mocks::WindowCreate(m_hInst);
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
|
|
||||||
// test
|
// test
|
||||||
@ -566,7 +567,7 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
// prepare
|
// prepare
|
||||||
PrepareGridLayout();
|
PrepareGridLayout();
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
const auto window = Mocks::WindowCreate(m_hInst);
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||||
|
|
||||||
@ -585,7 +586,7 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
// prepare
|
// prepare
|
||||||
PrepareGridLayout();
|
PrepareGridLayout();
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
const auto window = Mocks::WindowCreate(m_hInst);
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
||||||
|
|
||||||
@ -596,14 +597,14 @@ namespace FancyZonesUnitTests
|
|||||||
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
Assert::AreEqual((size_t)1, actualAppZoneHistory.size());
|
||||||
|
|
||||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||||
Assert::IsTrue(ZoneIndexSet{ (ZoneIndex)workArea->GetLayout()->Zones().size() - 1 } == layoutWindows->GetZoneIndexSetFromWindow(window));
|
Assert::IsTrue(ZoneIndexSet{ static_cast<ZoneIndex>(workArea->GetLayout()->Zones().size()) - 1 } == layoutWindows->GetZoneIndexSetFromWindow(window));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD (MoveAppliedWindowByIndexNoCycle)
|
TEST_METHOD (MoveAppliedWindowByIndexNoCycle)
|
||||||
{
|
{
|
||||||
// prepare
|
// prepare
|
||||||
PrepareGridLayout();
|
PrepareGridLayout();
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
const auto window = Mocks::WindowCreate(m_hInst);
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
||||||
|
|
||||||
@ -621,7 +622,7 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
// prepare
|
// prepare
|
||||||
PrepareEmptyLayout();
|
PrepareEmptyLayout();
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
const auto window = Mocks::WindowCreate(m_hInst);
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
|
|
||||||
// test
|
// test
|
||||||
@ -638,7 +639,7 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
// prepare
|
// prepare
|
||||||
PrepareGridLayout();
|
PrepareGridLayout();
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
const auto window = Mocks::WindowCreate(m_hInst);
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
|
|
||||||
// test
|
// test
|
||||||
@ -655,7 +656,7 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
// prepare
|
// prepare
|
||||||
PrepareGridLayout();
|
PrepareGridLayout();
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
const auto window = Mocks::WindowCreate(m_hInst);
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
|
|
||||||
// test
|
// test
|
||||||
@ -672,7 +673,7 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
// prepare
|
// prepare
|
||||||
PrepareGridLayout();
|
PrepareGridLayout();
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
const auto window = Mocks::WindowCreate(m_hInst);
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
||||||
|
|
||||||
@ -690,7 +691,7 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
// prepare
|
// prepare
|
||||||
PrepareGridLayout();
|
PrepareGridLayout();
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
const auto window = Mocks::WindowCreate(m_hInst);
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
||||||
|
|
||||||
@ -708,7 +709,7 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
// prepare
|
// prepare
|
||||||
PrepareGridLayout();
|
PrepareGridLayout();
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
const auto window = Mocks::WindowCreate(m_hInst);
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
||||||
|
|
||||||
@ -726,7 +727,7 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
// prepare
|
// prepare
|
||||||
PrepareGridLayout();
|
PrepareGridLayout();
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
const auto window = Mocks::WindowCreate(m_hInst);
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
||||||
|
|
||||||
@ -744,7 +745,7 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
// prepare
|
// prepare
|
||||||
PrepareGridLayout();
|
PrepareGridLayout();
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
const auto window = Mocks::WindowCreate(m_hInst);
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
const auto& layoutWindows = workArea->GetLayoutWindows();
|
const auto& layoutWindows = workArea->GetLayoutWindows();
|
||||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
||||||
@ -763,7 +764,7 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
// prepare
|
// prepare
|
||||||
PrepareGridLayout();
|
PrepareGridLayout();
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
const auto window = Mocks::WindowCreate(m_hInst);
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
||||||
|
|
||||||
@ -781,7 +782,7 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
// prepare
|
// prepare
|
||||||
PrepareGridLayout();
|
PrepareGridLayout();
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
const auto window = Mocks::WindowCreate(m_hInst);
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
||||||
|
|
||||||
@ -799,7 +800,7 @@ namespace FancyZonesUnitTests
|
|||||||
{
|
{
|
||||||
// prepare
|
// prepare
|
||||||
PrepareGridLayout();
|
PrepareGridLayout();
|
||||||
auto workArea = MakeWorkArea(m_hInst, m_uniqueId.monitorId.monitor, m_uniqueId, m_parentUniqueId);
|
auto workArea = MakeWorkArea(m_hInst, m_uniqueId, m_parentUniqueId, m_workAreaRect);
|
||||||
const auto window = Mocks::WindowCreate(m_hInst);
|
const auto window = Mocks::WindowCreate(m_hInst);
|
||||||
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
workArea->MoveWindowIntoZoneByDirectionAndIndex(window, VK_RIGHT, true); // apply to 1st zone
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user