1# Monitor guide {#monitor_guide} 2 3[TOC] 4 5This guide introduces the monitor related functions of GLFW. For details on 6a specific function in this category, see the @ref monitor. There are also 7guides for the other areas of GLFW. 8 9 - @ref intro_guide 10 - @ref window_guide 11 - @ref context_guide 12 - @ref vulkan_guide 13 - @ref input_guide 14 15 16## Monitor objects {#monitor_object} 17 18A monitor object represents a currently connected monitor and is represented as 19a pointer to the [opaque](https://en.wikipedia.org/wiki/Opaque_data_type) type 20@ref GLFWmonitor. Monitor objects cannot be created or destroyed by the 21application and retain their addresses until the monitors they represent are 22disconnected or until the library is [terminated](@ref intro_init_terminate). 23 24Each monitor has a current video mode, a list of supported video modes, 25a virtual position, a human-readable name, an estimated physical size and 26a gamma ramp. One of the monitors is the primary monitor. 27 28The virtual position of a monitor is in 29[screen coordinates](@ref coordinate_systems) and, together with the current 30video mode, describes the viewports that the connected monitors provide into the 31virtual desktop that spans them. 32 33To see how GLFW views your monitor setup and its available video modes, run the 34`monitors` test program. 35 36 37### Retrieving monitors {#monitor_monitors} 38 39The primary monitor is returned by @ref glfwGetPrimaryMonitor. It is the user's 40preferred monitor and is usually the one with global UI elements like task bar 41or menu bar. 42 43```c 44GLFWmonitor* primary = glfwGetPrimaryMonitor(); 45``` 46 47You can retrieve all currently connected monitors with @ref glfwGetMonitors. 48See the reference documentation for the lifetime of the returned array. 49 50```c 51int count; 52GLFWmonitor** monitors = glfwGetMonitors(&count); 53``` 54 55The primary monitor is always the first monitor in the returned array, but other 56monitors may be moved to a different index when a monitor is connected or 57disconnected. 58 59 60### Monitor configuration changes {#monitor_event} 61 62If you wish to be notified when a monitor is connected or disconnected, set 63a monitor callback. 64 65```c 66glfwSetMonitorCallback(monitor_callback); 67``` 68 69The callback function receives the handle for the monitor that has been 70connected or disconnected and the event that occurred. 71 72```c 73void monitor_callback(GLFWmonitor* monitor, int event) 74{ 75 if (event == GLFW_CONNECTED) 76 { 77 // The monitor was connected 78 } 79 else if (event == GLFW_DISCONNECTED) 80 { 81 // The monitor was disconnected 82 } 83} 84``` 85 86If a monitor is disconnected, all windows that are full screen on it will be 87switched to windowed mode before the callback is called. Only @ref 88glfwGetMonitorName and @ref glfwGetMonitorUserPointer will return useful values 89for a disconnected monitor and only before the monitor callback returns. 90 91 92## Monitor properties {#monitor_properties} 93 94Each monitor has a current video mode, a list of supported video modes, 95a virtual position, a content scale, a human-readable name, a user pointer, an 96estimated physical size and a gamma ramp. 97 98 99### Video modes {#monitor_modes} 100 101GLFW generally does a good job selecting a suitable video mode when you create 102a full screen window, change its video mode or make a windowed one full 103screen, but it is sometimes useful to know exactly which video modes are 104supported. 105 106Video modes are represented as @ref GLFWvidmode structures. You can get an 107array of the video modes supported by a monitor with @ref glfwGetVideoModes. 108See the reference documentation for the lifetime of the returned array. 109 110```c 111int count; 112GLFWvidmode* modes = glfwGetVideoModes(monitor, &count); 113``` 114 115To get the current video mode of a monitor call @ref glfwGetVideoMode. See the 116reference documentation for the lifetime of the returned pointer. 117 118```c 119const GLFWvidmode* mode = glfwGetVideoMode(monitor); 120``` 121 122The resolution of a video mode is specified in 123[screen coordinates](@ref coordinate_systems), not pixels. 124 125 126### Physical size {#monitor_size} 127 128The physical size of a monitor in millimetres, or an estimation of it, can be 129retrieved with @ref glfwGetMonitorPhysicalSize. This has no relation to its 130current _resolution_, i.e. the width and height of its current 131[video mode](@ref monitor_modes). 132 133```c 134int width_mm, height_mm; 135glfwGetMonitorPhysicalSize(monitor, &width_mm, &height_mm); 136``` 137 138While this can be used to calculate the raw DPI of a monitor, this is often not 139useful. Instead, use the [monitor content scale](@ref monitor_scale) and 140[window content scale](@ref window_scale) to scale your content. 141 142 143### Content scale {#monitor_scale} 144 145The content scale for a monitor can be retrieved with @ref 146glfwGetMonitorContentScale. 147 148```c 149float xscale, yscale; 150glfwGetMonitorContentScale(monitor, &xscale, &yscale); 151``` 152 153For more information on what the content scale is and how to use it, see 154[window content scale](@ref window_scale). 155 156 157### Virtual position {#monitor_pos} 158 159The position of the monitor on the virtual desktop, in 160[screen coordinates](@ref coordinate_systems), can be retrieved with @ref 161glfwGetMonitorPos. 162 163```c 164int xpos, ypos; 165glfwGetMonitorPos(monitor, &xpos, &ypos); 166``` 167 168 169### Work area {#monitor_workarea} 170 171The area of a monitor not occupied by global task bars or menu bars is the work 172area. This is specified in [screen coordinates](@ref coordinate_systems) and 173can be retrieved with @ref glfwGetMonitorWorkarea. 174 175```c 176int xpos, ypos, width, height; 177glfwGetMonitorWorkarea(monitor, &xpos, &ypos, &width, &height); 178``` 179 180 181### Human-readable name {#monitor_name} 182 183The human-readable, UTF-8 encoded name of a monitor is returned by @ref 184glfwGetMonitorName. See the reference documentation for the lifetime of the 185returned string. 186 187```c 188const char* name = glfwGetMonitorName(monitor); 189``` 190 191Monitor names are not guaranteed to be unique. Two monitors of the same model 192and make may have the same name. Only the monitor handle is guaranteed to be 193unique, and only until that monitor is disconnected. 194 195 196### User pointer {#monitor_userptr} 197 198Each monitor has a user pointer that can be set with @ref 199glfwSetMonitorUserPointer and queried with @ref glfwGetMonitorUserPointer. This 200can be used for any purpose you need and will not be modified by GLFW. The 201value will be kept until the monitor is disconnected or until the library is 202terminated. 203 204The initial value of the pointer is `NULL`. 205 206 207### Gamma ramp {#monitor_gamma} 208 209The gamma ramp of a monitor can be set with @ref glfwSetGammaRamp, which accepts 210a monitor handle and a pointer to a @ref GLFWgammaramp structure. 211 212```c 213GLFWgammaramp ramp; 214unsigned short red[256], green[256], blue[256]; 215 216ramp.size = 256; 217ramp.red = red; 218ramp.green = green; 219ramp.blue = blue; 220 221for (i = 0; i < ramp.size; i++) 222{ 223 // Fill out gamma ramp arrays as desired 224} 225 226glfwSetGammaRamp(monitor, &ramp); 227``` 228 229The gamma ramp data is copied before the function returns, so there is no need 230to keep it around once the ramp has been set. 231 232It is recommended that your gamma ramp have the same size as the current gamma 233ramp for that monitor. 234 235The current gamma ramp for a monitor is returned by @ref glfwGetGammaRamp. See 236the reference documentation for the lifetime of the returned structure. 237 238```c 239const GLFWgammaramp* ramp = glfwGetGammaRamp(monitor); 240``` 241 242If you wish to set a regular gamma ramp, you can have GLFW calculate it for you 243from the desired exponent with @ref glfwSetGamma, which in turn calls @ref 244glfwSetGammaRamp with the resulting ramp. 245 246```c 247glfwSetGamma(monitor, 1.0); 248``` 249 250To experiment with gamma correction via the @ref glfwSetGamma function, run the 251`gamma` test program. 252 253@note The software controlled gamma ramp is applied _in addition_ to the 254hardware gamma correction, which today is typically an approximation of sRGB 255gamma. This means that setting a perfectly linear ramp, or gamma 1.0, will 256produce the default (usually sRGB-like) behavior. 257 258