40static GLFWbool modeIsGood(
const XRRModeInfo* mi)
42 return (mi->modeFlags & RR_Interlace) == 0;
47static int calculateRefreshRate(
const XRRModeInfo* mi)
49 if (mi->hTotal && mi->vTotal)
50 return (
int) round((
double) mi->dotClock / ((
double) mi->hTotal * (
double) mi->vTotal));
57static const XRRModeInfo* getModeInfo(
const XRRScreenResources* sr, RRMode
id)
59 for (
int i = 0; i < sr->nmode; i++)
61 if (sr->modes[i].id ==
id)
70static GLFWvidmode vidmodeFromModeInfo(
const XRRModeInfo* mi,
71 const XRRCrtcInfo* ci)
75 if (ci->rotation == RR_Rotate_90 || ci->rotation == RR_Rotate_270)
77 mode.
width = mi->height;
82 mode.
width = mi->width;
105 int disconnectedCount, screenCount = 0;
107 XineramaScreenInfo* screens =
NULL;
117 if (disconnectedCount)
125 for (
int i = 0; i < sr->noutput; i++)
127 int j, type, widthMM, heightMM;
130 if (oi->connection != RR_Connected || oi->crtc == None)
136 for (j = 0; j < disconnectedCount; j++)
138 if (disconnected[j] &&
139 disconnected[j]->x11.output == sr->outputs[i])
141 disconnected[j] =
NULL;
146 if (j < disconnectedCount)
153 if (ci->rotation == RR_Rotate_90 || ci->rotation == RR_Rotate_270)
155 widthMM = oi->mm_height;
156 heightMM = oi->mm_width;
160 widthMM = oi->mm_width;
161 heightMM = oi->mm_height;
164 if (widthMM <= 0 || heightMM <= 0)
170 widthMM = (int) (ci->width * 25.4f / 96.f);
171 heightMM = (int) (ci->height * 25.4f / 96.f);
175 monitor->x11.output = sr->outputs[i];
176 monitor->x11.crtc = oi->crtc;
178 for (j = 0; j < screenCount; j++)
180 if (screens[j].x_org == ci->x &&
181 screens[j].y_org == ci->y &&
182 screens[j].width == ci->width &&
183 screens[j].height == ci->height)
185 monitor->x11.index = j;
190 if (monitor->x11.output == primary)
206 for (
int i = 0; i < disconnectedCount; i++)
216 const int widthMM = DisplayWidthMM(
_glfw.x11.display,
_glfw.x11.screen);
217 const int heightMM = DisplayHeightMM(
_glfw.x11.display,
_glfw.x11.screen);
232 RRMode native = None;
239 XRRScreenResources* sr =
244 for (
int i = 0; i < oi->nmode; i++)
246 const XRRModeInfo* mi = getModeInfo(sr, oi->modes[i]);
250 const GLFWvidmode mode = vidmodeFromModeInfo(mi, ci);
260 if (monitor->x11.oldMode == None)
261 monitor->x11.oldMode = ci->mode;
264 sr, monitor->x11.crtc,
285 if (monitor->x11.oldMode == None)
288 XRRScreenResources* sr =
293 sr, monitor->x11.crtc,
296 monitor->x11.oldMode,
304 monitor->x11.oldMode = None;
321 XRRScreenResources* sr =
340 float* xscale,
float* yscale)
343 *xscale =
_glfw.x11.contentScaleX;
345 *yscale =
_glfw.x11.contentScaleY;
350 int areaX = 0, areaY = 0, areaWidth = 0, areaHeight = 0;
354 XRRScreenResources* sr =
361 const XRRModeInfo* mi = getModeInfo(sr, ci->mode);
363 if (ci->rotation == RR_Rotate_90 || ci->rotation == RR_Rotate_270)
365 areaWidth = mi->height;
366 areaHeight = mi->width;
370 areaWidth = mi->width;
371 areaHeight = mi->height;
379 areaWidth = DisplayWidth(
_glfw.x11.display,
_glfw.x11.screen);
380 areaHeight = DisplayHeight(
_glfw.x11.display,
_glfw.x11.screen);
383 if (
_glfw.x11.NET_WORKAREA &&
_glfw.x11.NET_CURRENT_DESKTOP)
385 Atom* extents =
NULL;
386 Atom* desktop =
NULL;
387 const unsigned long extentCount =
389 _glfw.x11.NET_WORKAREA,
391 (
unsigned char**) &extents);
394 _glfw.x11.NET_CURRENT_DESKTOP,
396 (
unsigned char**) &desktop) > 0)
398 if (extentCount >= 4 && *desktop < extentCount / 4)
400 const int globalX = extents[*desktop * 4 + 0];
401 const int globalY = extents[*desktop * 4 + 1];
402 const int globalWidth = extents[*desktop * 4 + 2];
403 const int globalHeight = extents[*desktop * 4 + 3];
407 areaWidth -= globalX - areaX;
413 areaHeight -= globalY - areaY;
417 if (areaX + areaWidth > globalX + globalWidth)
418 areaWidth = globalX - areaX + globalWidth;
419 if (areaY + areaHeight > globalY + globalHeight)
420 areaHeight = globalY - areaY + globalHeight;
437 *height = areaHeight;
448 XRRScreenResources* sr =
455 for (
int i = 0; i < oi->nmode; i++)
457 const XRRModeInfo* mi = getModeInfo(sr, oi->modes[i]);
461 const GLFWvidmode mode = vidmodeFromModeInfo(mi, ci);
464 for (j = 0; j < *count; j++)
475 result[*count - 1] = mode;
496 XRRScreenResources* sr =
502 const XRRModeInfo* mi = getModeInfo(sr, ci->mode);
504 *mode = vidmodeFromModeInfo(mi, ci);
533 memcpy(ramp->
red, gamma->red, size *
sizeof(
unsigned short));
534 memcpy(ramp->
green, gamma->green, size *
sizeof(
unsigned short));
535 memcpy(ramp->
blue, gamma->blue, size *
sizeof(
unsigned short));
555 "X11: Gamma ramp access not supported by server");
567 "X11: Gamma ramp size must match current ramp size");
573 memcpy(gamma->red, ramp->
red, ramp->
size *
sizeof(
unsigned short));
574 memcpy(gamma->green, ramp->
green, ramp->
size *
sizeof(
unsigned short));
575 memcpy(gamma->blue, ramp->
blue, ramp->
size *
sizeof(
unsigned short));
585 (
unsigned short*) ramp->
red,
586 (
unsigned short*) ramp->
green,
587 (
unsigned short*) ramp->
blue);
592 "X11: Gamma ramp access not supported by server");
605 return monitor->x11.crtc;
612 return monitor->x11.output;
#define GLFW_DISCONNECTED
#define GLFW_PLATFORM_ERROR
A platform-specific error occurred that does not match any of the more specific categories.
struct GLFWmonitor GLFWmonitor
Opaque monitor object.
void _glfwInputError(int code, const char *format,...)
void _glfwInputMonitor(_GLFWmonitor *monitor, int action, int placement)
void _glfwSplitBPP(int bpp, int *red, int *green, int *blue)
const GLFWvidmode * _glfwChooseVideoMode(_GLFWmonitor *monitor, const GLFWvidmode *desired)
#define _GLFW_REQUIRE_INIT_OR_RETURN(x)
#define _GLFW_INSERT_FIRST
int _glfwCompareVideoModes(const GLFWvidmode *first, const GLFWvidmode *second)
_GLFWmonitor * _glfwAllocMonitor(const char *name, int widthMM, int heightMM)
#define _GLFW_INSERT_LAST
void _glfwAllocGammaArrays(GLFWgammaramp *ramp, unsigned int size)
void _glfwPlatformFreeMonitor(_GLFWmonitor *monitor)
GLFWAPI RRCrtc glfwGetX11Adapter(GLFWmonitor *handle)
GLFWvidmode * _glfwPlatformGetVideoModes(_GLFWmonitor *monitor, int *count)
void _glfwRestoreVideoModeX11(_GLFWmonitor *monitor)
void _glfwSetVideoModeX11(_GLFWmonitor *monitor, const GLFWvidmode *desired)
void _glfwPlatformGetVideoMode(_GLFWmonitor *monitor, GLFWvidmode *mode)
void _glfwPlatformSetGammaRamp(_GLFWmonitor *monitor, const GLFWgammaramp *ramp)
void _glfwPlatformGetMonitorPos(_GLFWmonitor *monitor, int *xpos, int *ypos)
GLFWbool _glfwPlatformGetGammaRamp(_GLFWmonitor *monitor, GLFWgammaramp *ramp)
void _glfwPlatformGetMonitorContentScale(_GLFWmonitor *monitor, float *xscale, float *yscale)
void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor *monitor, int *xpos, int *ypos, int *width, int *height)
void _glfwPollMonitorsX11(void)
GLFWAPI RROutput glfwGetX11Monitor(GLFWmonitor *handle)