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