-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FancyZones] Improve code quality (part 5: work area initialization) (#…
- Loading branch information
1 parent
c1c14b4
commit fcd05f2
Showing
12 changed files
with
469 additions
and
627 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 0 additions & 141 deletions
141
src/modules/fancyzones/FancyZonesLib/MonitorWorkAreaHandler.cpp
This file was deleted.
Oops, something went wrong.
93 changes: 0 additions & 93 deletions
93
src/modules/fancyzones/FancyZonesLib/MonitorWorkAreaHandler.h
This file was deleted.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
src/modules/fancyzones/FancyZonesLib/MonitorWorkAreaMap.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#pragma once | ||
|
||
#include "GuidUtils.h" | ||
|
||
class WorkArea; | ||
|
||
class MonitorWorkAreaMap | ||
{ | ||
public: | ||
/** | ||
* Get work area based on virtual desktop id and monitor handle. | ||
* | ||
* @param[in] monitor Monitor handle. | ||
* | ||
* @returns Object representing single work area, interface to all actions available on work area | ||
* (e.g. moving windows through zone layout specified for that work area). | ||
*/ | ||
WorkArea* const GetWorkArea(HMONITOR monitor) const; | ||
|
||
/** | ||
* Get work area based on virtual desktop id and the current cursor position. | ||
* | ||
* @returns Object representing single work area, interface to all actions available on work area | ||
* (e.g. moving windows through zone layout specified for that work area). | ||
*/ | ||
WorkArea* const GetWorkAreaFromCursor() const; | ||
|
||
/** | ||
* Get work area on which specified window is located. | ||
* | ||
* @param[in] window Window handle. | ||
* | ||
* @returns Object representing single work area, interface to all actions available on work area | ||
* (e.g. moving windows through zone layout specified for that work area). | ||
*/ | ||
WorkArea* const GetWorkAreaFromWindow(HWND window) const; | ||
|
||
/** | ||
* @returns All registered work areas. | ||
*/ | ||
const std::unordered_map<HMONITOR, std::unique_ptr<WorkArea>>& GetAllWorkAreas() const noexcept; | ||
|
||
/** | ||
* Register new work area. | ||
* | ||
* @param[in] monitor Monitor handle. | ||
* @param[in] workAra Object representing single work area. | ||
*/ | ||
void AddWorkArea(HMONITOR monitor, std::unique_ptr<WorkArea> workArea); | ||
|
||
/** | ||
* Clear all persisted work area related data. | ||
*/ | ||
void Clear() noexcept; | ||
|
||
private: | ||
std::unordered_map<HMONITOR, std::unique_ptr<WorkArea>> m_workAreaMap; | ||
}; |
Oops, something went wrong.