2023-01-31 12:55:46 +03:00
|
|
|
#include "pch.h"
|
2023-09-21 13:47:56 +03:00
|
|
|
#include "WorkAreaConfiguration.h"
|
2023-01-31 12:55:46 +03:00
|
|
|
|
|
|
|
|
#include <FancyZonesLib/WorkArea.h>
|
|
|
|
|
|
2023-09-21 13:47:56 +03:00
|
|
|
WorkArea* const WorkAreaConfiguration::GetWorkArea(HMONITOR monitor) const
|
2023-01-31 12:55:46 +03:00
|
|
|
{
|
|
|
|
|
auto iter = m_workAreaMap.find(monitor);
|
|
|
|
|
if (iter != m_workAreaMap.end())
|
|
|
|
|
{
|
|
|
|
|
return iter->second.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-21 13:47:56 +03:00
|
|
|
WorkArea* const WorkAreaConfiguration::GetWorkAreaFromCursor() const
|
2023-01-31 12:55:46 +03:00
|
|
|
{
|
|
|
|
|
const auto allMonitorsWorkArea = GetWorkArea(nullptr);
|
|
|
|
|
if (allMonitorsWorkArea)
|
|
|
|
|
{
|
|
|
|
|
// First, check if there's a work area spanning all monitors (signalled by the NULL monitor handle)
|
|
|
|
|
return allMonitorsWorkArea;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Otherwise, look for the work area based on cursor position
|
|
|
|
|
POINT cursorPoint;
|
|
|
|
|
if (!GetCursorPos(&cursorPoint))
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return GetWorkArea(MonitorFromPoint(cursorPoint, MONITOR_DEFAULTTONULL));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-21 13:47:56 +03:00
|
|
|
WorkArea* const WorkAreaConfiguration::GetWorkAreaFromWindow(HWND window) const
|
2023-01-31 12:55:46 +03:00
|
|
|
{
|
|
|
|
|
const auto allMonitorsWorkArea = GetWorkArea(nullptr);
|
|
|
|
|
if (allMonitorsWorkArea)
|
|
|
|
|
{
|
|
|
|
|
// First, check if there's a work area spanning all monitors (signalled by the NULL monitor handle)
|
|
|
|
|
return allMonitorsWorkArea;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Otherwise, look for the work area based on the window's position
|
|
|
|
|
HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTONULL);
|
|
|
|
|
return GetWorkArea(monitor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-21 13:47:56 +03:00
|
|
|
const std::unordered_map<HMONITOR, std::unique_ptr<WorkArea>>& WorkAreaConfiguration::GetAllWorkAreas() const noexcept
|
2023-01-31 12:55:46 +03:00
|
|
|
{
|
|
|
|
|
return m_workAreaMap;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-21 13:47:56 +03:00
|
|
|
void WorkAreaConfiguration::AddWorkArea(HMONITOR monitor, std::unique_ptr<WorkArea> workArea)
|
2023-01-31 12:55:46 +03:00
|
|
|
{
|
|
|
|
|
m_workAreaMap.insert({ monitor, std::move(workArea) });
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-21 13:47:56 +03:00
|
|
|
void WorkAreaConfiguration::Clear() noexcept
|
2023-01-31 12:55:46 +03:00
|
|
|
{
|
|
|
|
|
m_workAreaMap.clear();
|
|
|
|
|
}
|