mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +02:00
[FancyZones] Improve code quality (part 5: work area initialization) (#23671)
This commit is contained in:
67
src/modules/fancyzones/FancyZonesLib/MonitorWorkAreaMap.cpp
Normal file
67
src/modules/fancyzones/FancyZonesLib/MonitorWorkAreaMap.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "pch.h"
|
||||
#include "MonitorWorkAreaMap.h"
|
||||
|
||||
#include <FancyZonesLib/WorkArea.h>
|
||||
|
||||
WorkArea* const MonitorWorkAreaMap::GetWorkArea(HMONITOR monitor) const
|
||||
{
|
||||
auto iter = m_workAreaMap.find(monitor);
|
||||
if (iter != m_workAreaMap.end())
|
||||
{
|
||||
return iter->second.get();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
WorkArea* const MonitorWorkAreaMap::GetWorkAreaFromCursor() const
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
WorkArea* const MonitorWorkAreaMap::GetWorkAreaFromWindow(HWND window) const
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
const std::unordered_map<HMONITOR, std::unique_ptr<WorkArea>>& MonitorWorkAreaMap::GetAllWorkAreas() const noexcept
|
||||
{
|
||||
return m_workAreaMap;
|
||||
}
|
||||
|
||||
void MonitorWorkAreaMap::AddWorkArea(HMONITOR monitor, std::unique_ptr<WorkArea> workArea)
|
||||
{
|
||||
m_workAreaMap.insert({ monitor, std::move(workArea) });
|
||||
}
|
||||
|
||||
void MonitorWorkAreaMap::Clear() noexcept
|
||||
{
|
||||
m_workAreaMap.clear();
|
||||
}
|
||||
Reference in New Issue
Block a user