Skip to content

Commit

Permalink
Move display enumeration functionality to DisplayManager
Browse files Browse the repository at this point in the history
  • Loading branch information
malensek committed Mar 9, 2015
1 parent 19489e4 commit ac7e408
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 99 deletions.
8 changes: 4 additions & 4 deletions 3RVX/3RVX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#include <Wtsapi32.h>

#include "3RVX.h"
#include "OSD\EjectOSD.h"
#include "OSD\VolumeOSD.h"
#include "DisplayManager.h"
#include "HotkeyInfo.h"
#include "HotkeyManager.h"
#include "Logger.h"
#include "Monitor.h"
#include "OSD\EjectOSD.h"
#include "OSD\VolumeOSD.h"
#include "Settings.h"
#include "SkinManager.h"

Expand Down Expand Up @@ -117,7 +117,7 @@ void init() {
SkinManager::Instance()->LoadSkin(settings->SkinXML());

/* TODO: Detect monitor changes, update this map, and reload/reorg OSDs */
Monitor::UpdateMonitorMap();
DisplayManager::UpdateMonitorMap();

/* OSDs */
eOSD = new EjectOSD();
Expand Down
3 changes: 2 additions & 1 deletion 3RVX/3RVX.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<ClInclude Include="3RVX.h" />
<ClInclude Include="Controllers\Volume\CoreAudio.h" />
<ClInclude Include="Controllers\Volume\VolumeController.h" />
<ClInclude Include="DisplayManager.h" />
<ClInclude Include="Error.h" />
<ClInclude Include="HotkeyInfo.h" />
<ClInclude Include="MeterWnd\Meters\CallbackMeter.h" />
Expand Down Expand Up @@ -124,6 +125,7 @@
<ItemGroup>
<ClCompile Include="3RVX.cpp" />
<ClCompile Include="Controllers\Volume\CoreAudio.cpp" />
<ClCompile Include="DisplayManager.cpp" />
<ClCompile Include="HotkeyInfo.cpp" />
<ClCompile Include="MeterWnd\Meters\CallbackMeter.cpp" />
<ClCompile Include="MeterWnd\Meters\StaticImage.cpp" />
Expand All @@ -141,7 +143,6 @@
<ClCompile Include="MeterWnd\Meters\Text.cpp" />
<ClCompile Include="MeterWnd\Meters\VerticalTile.cpp" />
<ClCompile Include="MeterWnd\MeterWnd.cpp" />
<ClCompile Include="Monitor.cpp" />
<ClCompile Include="NotifyIcon.cpp" />
<ClCompile Include="OSD\OSD.cpp" />
<ClCompile Include="Settings.cpp" />
Expand Down
9 changes: 6 additions & 3 deletions 3RVX/3RVX.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@
<ClInclude Include="SkinManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DisplayManager.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Controllers\Volume\CoreAudio.cpp">
Expand Down Expand Up @@ -182,9 +185,6 @@
<ClCompile Include="MeterWnd\Meters\NumberStrip.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Monitor.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MeterWnd\Animations\FadeOut.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -245,6 +245,9 @@
<ClCompile Include="SkinManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="DisplayManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="3RVX.rc">
Expand Down
43 changes: 22 additions & 21 deletions 3RVX/Monitor.cpp → 3RVX/DisplayManager.cpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,48 @@
#include "Monitor.h"
#include "DisplayManager.h"

static std::unordered_map<std::wstring, HMONITOR> monitorMap;
static std::unordered_map<std::wstring, Monitor> monitorMap;

HMONITOR Monitor::Primary() {
std::unordered_map<std::wstring, Monitor> &DisplayManager::MonitorMap() {
return monitorMap;
}

void DisplayManager::UpdateMonitorMap() {
monitorMap.clear();
EnumDisplayMonitors(NULL, NULL, &MonitorEnumProc, NULL);
}

Monitor DisplayManager::Primary() {
/* The Primary or 'Main' monitor is at (0, 0). */
const POINT p = { 0, 0 };
HMONITOR monitor = MonitorFromPoint(p, MONITOR_DEFAULTTOPRIMARY);
return monitor;
MONITORINFO mInfo = Info(monitor);
return Monitor(L"Primary", mInfo.rcMonitor);
}

const int Monitor::Width(HMONITOR monitor) {
const int DisplayManager::Width(HMONITOR monitor) {
MONITORINFO mInfo = Info(monitor);
RECT mDims = mInfo.rcMonitor;
return mDims.right - mDims.left;
}

const int Monitor::Height(HMONITOR monitor) {
const int DisplayManager::Height(HMONITOR monitor) {
MONITORINFO mInfo = Info(monitor);
RECT mDims = mInfo.rcMonitor;
return mDims.bottom - mDims.top;
}

RECT Monitor::Rect(HMONITOR monitor) {
RECT DisplayManager::Rect(HMONITOR monitor) {
return Info(monitor).rcMonitor;
}

MONITORINFO Monitor::Info(HMONITOR monitor) {
MONITORINFO DisplayManager::Info(HMONITOR monitor) {
MONITORINFO mInfo = {};
mInfo.cbSize = sizeof(MONITORINFO);
GetMonitorInfo(monitor, &mInfo);
return mInfo;
}

std::list<DISPLAY_DEVICE> Monitor::ListAllDevices() {
std::list<DISPLAY_DEVICE> DisplayManager::ListAllDevices() {
std::list<DISPLAY_DEVICE> devs;
DISPLAY_DEVICE dev = {};
dev.cb = sizeof(DISPLAY_DEVICE);
Expand All @@ -44,25 +54,16 @@ std::list<DISPLAY_DEVICE> Monitor::ListAllDevices() {
return devs;
}

std::unordered_map<std::wstring, HMONITOR> Monitor::MonitorMap() {
return monitorMap;
}

void Monitor::UpdateMonitorMap() {
EnumDisplayMonitors(NULL, NULL, &MonitorEnumProc, NULL);
}

BOOL CALLBACK Monitor::MonitorEnumProc(
BOOL CALLBACK DisplayManager::MonitorEnumProc(
HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {

monitorMap.clear();

MONITORINFOEX mInfo = {};
mInfo.cbSize = sizeof(MONITORINFOEX);
GetMonitorInfo(hMonitor, &mInfo);

std::wstring monitorName = std::wstring(mInfo.szDevice);
monitorMap[monitorName] = hMonitor;
Monitor mon(monitorName, mInfo.rcMonitor);
monitorMap[monitorName] = mon;

return TRUE;
}
25 changes: 25 additions & 0 deletions 3RVX/DisplayManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once
#include <Windows.h>
#include <list>
#include <string>
#include <unordered_map>
#include <vector>

#include "Monitor.h"

class DisplayManager {
public:
static std::unordered_map<std::wstring, Monitor> &MonitorMap();
static void UpdateMonitorMap();
static Monitor Primary();
static std::list<DISPLAY_DEVICE> ListAllDevices();

private:
static MONITORINFO Info(HMONITOR monitor);
static const int Width(HMONITOR monitor);
static const int Height(HMONITOR monitor);
static RECT Rect(HMONITOR monitor);

static BOOL CALLBACK MonitorEnumProc(
HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData);
};
53 changes: 43 additions & 10 deletions 3RVX/Monitor.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,54 @@
#pragma once

#include <Windows.h>
#include <list>
#include <string>
#include <unordered_map>

class Monitor {
public:
static HMONITOR Primary();
static MONITORINFO Info(HMONITOR monitor);
static const int Width(HMONITOR monitor);
static const int Height(HMONITOR monitor);
static RECT Rect(HMONITOR monitor);
static std::list<DISPLAY_DEVICE> ListAllDevices();
Monitor() {

}

Monitor(std::wstring name, int x, int y, int width, int height) :
_name(name),
_x(x),
_y(y),
_width(width),
_height(height) {

}

Monitor(std::wstring name, RECT rect) :
_name(name),
_x(rect.left),
_y(rect.top),
_width(rect.right - rect.left),
_height(rect.bottom - rect.top) {

}

int X() {
return _x;
}

int Y() {
return _y;
}

int Width() {
return _width;
}

static void UpdateMonitorMap();
static std::unordered_map<std::wstring, HMONITOR> MonitorMap();
int Height() {
return _height;
}

private:
static BOOL CALLBACK MonitorEnumProc(
HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData);
std::wstring _name;
int _x;
int _y;
int _width;
int _height;
};
4 changes: 2 additions & 2 deletions 3RVX/OSD/EjectOSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ _mWnd(L"3RVX-EjectOSD", L"3RVX-EjectOSD") {
_mWnd.Update();
_mWnd.VisibleDuration(Settings::Instance()->HideDelay());

UpdateWindowPositions(MonitorHandles());
UpdateWindowPositions(ActiveMonitors());
}

EjectOSD::~EjectOSD() {
Expand All @@ -36,7 +36,7 @@ void EjectOSD::Hide() {
_mWnd.Hide(false);
}

void EjectOSD::UpdateWindowPositions(std::vector<HMONITOR> monitors) {
void EjectOSD::UpdateWindowPositions(std::vector<Monitor> monitors) {
PositionWindow(monitors[0], _mWnd);
}

Expand Down
2 changes: 1 addition & 1 deletion 3RVX/OSD/EjectOSD.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class EjectOSD : public OSD {
private:
MeterWnd _mWnd;

virtual void UpdateWindowPositions(std::vector<HMONITOR> monitors);
virtual void UpdateWindowPositions(std::vector<Monitor> monitors);

virtual LRESULT WndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam);
Expand Down
Loading

0 comments on commit ac7e408

Please sign in to comment.