1 /**
2 Copyright: Copyright (c) 2017-2018 Andrey Penechko.
3 License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0).
4 Authors: Andrey Penechko.
5 */
6 
7 module voxelman.platform.monitorman;
8 
9 import derelict.glfw3.glfw3;
10 import voxelman.log;
11 import voxelman.math;
12 
13 struct MonitorManager
14 {
15 	private void printMode(const ref GLFWvidmode mode) {
16 		int colorBits = mode.redBits + mode.greenBits + mode.blueBits;
17 		infof("%sx%sp, %sbit (%s%s%s), %sHz",
18 			mode.width, mode.height, colorBits,
19 			mode.redBits, mode.greenBits, mode.blueBits,
20 			mode.refreshRate);
21 	}
22 
23 	private void printMonitor(GLFWmonitor* monitor, size_t index)
24 	{
25 		ivec2 monPos;
26 		glfwGetMonitorPos(monitor, &monPos.x, &monPos.y);
27 
28 		ivec2 physSize;
29 		glfwGetMonitorPhysicalSize(monitor, &physSize.x, &physSize.y);
30 
31 		const char* name = glfwGetMonitorName(monitor);
32 
33 		import std..string : fromStringz;
34 		infof("Monitor[%s] %s '%s' pos %s phys size %s", index, monitor, cast(string)fromStringz(name), monPos, physSize);
35 
36 		int count;
37 		const GLFWvidmode* modes = glfwGetVideoModes(monitor, &count);
38 
39 		infof("Got %s modes", count);
40 		foreach(ref mode; modes[0..count])
41 		{
42 			printMode(mode);
43 		}
44 	}
45 
46 	private void printMonitors()
47 	{
48 		GLFWmonitor* primaryMonitor = glfwGetPrimaryMonitor();
49 		infof("Primary monitor %s", primaryMonitor);
50 
51 		int monCount;
52 		GLFWmonitor** monitors = glfwGetMonitors(&monCount);
53 		foreach(i, monitor; monitors[0..monCount])
54 		{
55 			printMonitor(monitor, i);
56 		}
57 	}
58 }