Enumerates all connected monitors and their information.
Queries GLFW for the list of connected monitors and retrieves their properties such as name, dimensions, and current video mode.
94{
96 return {};
97
98 int count {};
99 GLFWmonitor** monitors = glfwGetMonitors(&count);
100
101 std::span<GLFWmonitor*> monitor_span(monitors, count);
102
103 std::vector<MonitorInfo> infos;
104 infos.reserve(count);
105
106 GLFWmonitor* primary = glfwGetPrimaryMonitor();
107
108 for (int i = 0; i < count; ++i) {
109 auto* mode = glfwGetVideoMode(monitor_span[i]);
110 int w_mm {}, h_mm {};
111 glfwGetMonitorPhysicalSize(monitor_span[i], &w_mm, &h_mm);
112
113 infos.push_back({ .id = i,
114 .name = glfwGetMonitorName(monitor_span[i]),
115 .width_mm = w_mm,
116 .height_mm = h_mm,
117 .current_mode = {
118 .width = static_cast<uint32_t>(mode->width),
119 .height = static_cast<uint32_t>(mode->height),
120 .refresh_rate = static_cast<uint32_t>(mode->refreshRate),
121 .red_bits = static_cast<uint8_t>(mode->redBits),
122 .green_bits = static_cast<uint8_t>(mode->greenBits),
123 .blue_bits = static_cast<uint8_t>(mode->blueBits) },
124 .is_primary = (monitor_span[i] == primary) });
125 }
126
127 return infos;
128}
static bool s_initialized
Tracks whether GLFW has been initialized.