|
|
|
@ -40,140 +40,105 @@ |
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
|
// Finds the video mode closest in size to the specified desired size
|
|
|
|
|
// Set the current video mode for the specified monitor
|
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
|
|
int _glfwGetClosestVideoMode(_GLFWmonitor* monitor, int* width, int* height) |
|
|
|
|
void _glfwSetVideoMode(_GLFWmonitor* monitor, const GLFWvidmode* mode) |
|
|
|
|
{ |
|
|
|
|
int i, match, bestmatch; |
|
|
|
|
|
|
|
|
|
if (_glfw.x11.randr.available) |
|
|
|
|
{ |
|
|
|
|
int sizecount, bestsize; |
|
|
|
|
XRRScreenConfiguration* sc; |
|
|
|
|
XRRScreenSize* sizelist; |
|
|
|
|
|
|
|
|
|
sc = XRRGetScreenInfo(_glfw.x11.display, _glfw.x11.root); |
|
|
|
|
|
|
|
|
|
sizelist = XRRConfigSizes(sc, &sizecount); |
|
|
|
|
int i, j, k; |
|
|
|
|
XRRScreenResources* sr; |
|
|
|
|
XRRCrtcInfo* ci; |
|
|
|
|
RRMode bestMode = 0; |
|
|
|
|
unsigned int leastSizeDiff = UINT_MAX; |
|
|
|
|
|
|
|
|
|
// Find the best matching mode
|
|
|
|
|
bestsize = -1; |
|
|
|
|
bestmatch = INT_MAX; |
|
|
|
|
for (i = 0; i < sizecount; i++) |
|
|
|
|
{ |
|
|
|
|
match = (*width - sizelist[i].width) * |
|
|
|
|
(*width - sizelist[i].width) + |
|
|
|
|
(*height - sizelist[i].height) * |
|
|
|
|
(*height - sizelist[i].height); |
|
|
|
|
if (match < bestmatch) |
|
|
|
|
{ |
|
|
|
|
bestmatch = match; |
|
|
|
|
bestsize = i; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root); |
|
|
|
|
ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); |
|
|
|
|
|
|
|
|
|
if (bestsize != -1) |
|
|
|
|
for (i = 0; i < sr->nmode; i++) |
|
|
|
|
{ |
|
|
|
|
// Report width & height of best matching mode
|
|
|
|
|
*width = sizelist[bestsize].width; |
|
|
|
|
*height = sizelist[bestsize].height; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
XRRFreeScreenConfigInfo(sc); |
|
|
|
|
|
|
|
|
|
if (bestsize != -1) |
|
|
|
|
return bestsize; |
|
|
|
|
} |
|
|
|
|
GLboolean usable = GL_TRUE; |
|
|
|
|
XRRModeInfo* mi = sr->modes + i; |
|
|
|
|
|
|
|
|
|
// Default: Simply use the screen resolution
|
|
|
|
|
*width = DisplayWidth(_glfw.x11.display, _glfw.x11.screen); |
|
|
|
|
*height = DisplayHeight(_glfw.x11.display, _glfw.x11.screen); |
|
|
|
|
for (j = 0; j < ci->noutput; j++) |
|
|
|
|
{ |
|
|
|
|
XRROutputInfo* oi = XRRGetOutputInfo(_glfw.x11.display, |
|
|
|
|
sr, ci->outputs[j]); |
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
for (k = 0; k < oi->nmode; k++) |
|
|
|
|
{ |
|
|
|
|
if (oi->modes[k] == mi->id) |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (k == oi->nmode) |
|
|
|
|
usable = GL_FALSE; |
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
|
// Change the current video mode
|
|
|
|
|
//========================================================================
|
|
|
|
|
XRRFreeOutputInfo(oi); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void _glfwSetVideoModeMODE(_GLFWmonitor* monitor, int mode) |
|
|
|
|
{ |
|
|
|
|
if (_glfw.x11.randr.available) |
|
|
|
|
{ |
|
|
|
|
XRRScreenConfiguration* sc; |
|
|
|
|
Window root; |
|
|
|
|
if (!usable) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
root = _glfw.x11.root; |
|
|
|
|
sc = XRRGetScreenInfo(_glfw.x11.display, root); |
|
|
|
|
if (mi->modeFlags & RR_Interlace) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
// Remember old size and flag that we have changed the mode
|
|
|
|
|
if (!monitor->x11.modeChanged) |
|
|
|
|
{ |
|
|
|
|
monitor->x11.oldSizeID = XRRConfigCurrentConfiguration(sc, &monitor->x11.oldRotation); |
|
|
|
|
monitor->x11.oldWidth = DisplayWidth(_glfw.x11.display, |
|
|
|
|
_glfw.x11.screen); |
|
|
|
|
monitor->x11.oldHeight = DisplayHeight(_glfw.x11.display, |
|
|
|
|
_glfw.x11.screen); |
|
|
|
|
unsigned int sizeDiff = (mi->width - mode->width) * |
|
|
|
|
(mi->width - mode->width) + |
|
|
|
|
(mi->height - mode->height) * |
|
|
|
|
(mi->height - mode->height); |
|
|
|
|
|
|
|
|
|
monitor->x11.modeChanged = GL_TRUE; |
|
|
|
|
if (sizeDiff < leastSizeDiff) |
|
|
|
|
{ |
|
|
|
|
bestMode = mi->id; |
|
|
|
|
leastSizeDiff = sizeDiff; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
XRRSetScreenConfig(_glfw.x11.display, |
|
|
|
|
sc, |
|
|
|
|
root, |
|
|
|
|
mode, |
|
|
|
|
RR_Rotate_0, |
|
|
|
|
CurrentTime); |
|
|
|
|
|
|
|
|
|
XRRFreeScreenConfigInfo(sc); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
|
// Change the current video mode
|
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
|
|
void _glfwSetVideoMode(_GLFWmonitor* monitor, int* width, int* height) |
|
|
|
|
{ |
|
|
|
|
int bestmode; |
|
|
|
|
monitor->x11.oldMode = ci->mode; |
|
|
|
|
|
|
|
|
|
// Find a best match mode
|
|
|
|
|
bestmode = _glfwGetClosestVideoMode(monitor, width, height); |
|
|
|
|
XRRSetCrtcConfig(_glfw.x11.display, |
|
|
|
|
sr, monitor->x11.crtc, |
|
|
|
|
CurrentTime, |
|
|
|
|
ci->x, ci->y, |
|
|
|
|
bestMode, |
|
|
|
|
ci->rotation, |
|
|
|
|
ci->outputs, |
|
|
|
|
ci->noutput); |
|
|
|
|
|
|
|
|
|
// Change mode
|
|
|
|
|
_glfwSetVideoModeMODE(monitor, bestmode); |
|
|
|
|
XRRFreeCrtcInfo(ci); |
|
|
|
|
XRRFreeScreenResources(sr); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
|
// Restore the previously saved (original) video mode
|
|
|
|
|
// Restore the saved (original) video mode for the specified monitor
|
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
|
|
void _glfwRestoreVideoMode(_GLFWmonitor* monitor) |
|
|
|
|
{ |
|
|
|
|
if (!monitor->x11.modeChanged) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
if (_glfw.x11.randr.available) |
|
|
|
|
{ |
|
|
|
|
XRRScreenConfiguration* sc; |
|
|
|
|
XRRScreenResources* sr; |
|
|
|
|
XRRCrtcInfo* ci; |
|
|
|
|
|
|
|
|
|
sc = XRRGetScreenInfo(_glfw.x11.display, _glfw.x11.root); |
|
|
|
|
sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root); |
|
|
|
|
ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); |
|
|
|
|
|
|
|
|
|
XRRSetScreenConfig(_glfw.x11.display, |
|
|
|
|
sc, |
|
|
|
|
_glfw.x11.root, |
|
|
|
|
monitor->x11.oldSizeID, |
|
|
|
|
monitor->x11.oldRotation, |
|
|
|
|
CurrentTime); |
|
|
|
|
XRRSetCrtcConfig(_glfw.x11.display, |
|
|
|
|
sr, monitor->x11.crtc, |
|
|
|
|
CurrentTime, |
|
|
|
|
ci->x, ci->y, |
|
|
|
|
monitor->x11.oldMode, |
|
|
|
|
ci->rotation, |
|
|
|
|
ci->outputs, |
|
|
|
|
ci->noutput); |
|
|
|
|
|
|
|
|
|
XRRFreeScreenConfigInfo(sc); |
|
|
|
|
XRRFreeCrtcInfo(ci); |
|
|
|
|
XRRFreeScreenResources(sr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
monitor->x11.modeChanged = GL_FALSE; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -194,7 +159,6 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* found) |
|
|
|
|
XRRScreenResources* sr; |
|
|
|
|
|
|
|
|
|
sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root); |
|
|
|
|
|
|
|
|
|
primary = XRRGetOutputPrimary(_glfw.x11.display, _glfw.x11.root); |
|
|
|
|
|
|
|
|
|
monitors = (_GLFWmonitor**) calloc(sr->noutput, sizeof(_GLFWmonitor*)); |
|
|
|
@ -206,37 +170,48 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* found) |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (i = 0; i < sr->noutput; i++) |
|
|
|
|
for (i = 0; i < sr->ncrtc; i++) |
|
|
|
|
{ |
|
|
|
|
int j; |
|
|
|
|
XRROutputInfo* oi; |
|
|
|
|
XRRCrtcInfo* ci; |
|
|
|
|
RROutput output; |
|
|
|
|
|
|
|
|
|
ci = XRRGetCrtcInfo(_glfw.x11.display, sr, sr->crtcs[i]); |
|
|
|
|
output = ci->outputs[i]; |
|
|
|
|
|
|
|
|
|
for (j = 0; j < ci->noutput; j++) |
|
|
|
|
{ |
|
|
|
|
if (ci->outputs[i] == primary) |
|
|
|
|
{ |
|
|
|
|
output = primary; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
oi = XRRGetOutputInfo(_glfw.x11.display, sr, sr->outputs[i]); |
|
|
|
|
oi = XRRGetOutputInfo(_glfw.x11.display, sr, output); |
|
|
|
|
if (oi->connection != RR_Connected) |
|
|
|
|
{ |
|
|
|
|
XRRFreeOutputInfo(oi); |
|
|
|
|
XRRFreeCrtcInfo(ci); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ci = XRRGetCrtcInfo(_glfw.x11.display, sr, oi->crtc); |
|
|
|
|
|
|
|
|
|
monitors[*found] = _glfwCreateMonitor(oi->name, |
|
|
|
|
sr->outputs[i] == primary, |
|
|
|
|
output == primary, |
|
|
|
|
oi->mm_width, oi->mm_height, |
|
|
|
|
ci->x, ci->y); |
|
|
|
|
|
|
|
|
|
XRRFreeCrtcInfo(ci); |
|
|
|
|
monitors[*found]->x11.output = output; |
|
|
|
|
monitors[*found]->x11.crtc = oi->crtc; |
|
|
|
|
|
|
|
|
|
if (!monitors[*found]) |
|
|
|
|
{ |
|
|
|
|
// TODO: wat
|
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
XRRFreeOutputInfo(oi); |
|
|
|
|
XRRFreeCrtcInfo(ci); |
|
|
|
|
|
|
|
|
|
// This is retained until the monitor object is destroyed
|
|
|
|
|
monitors[*found]->x11.output = oi; |
|
|
|
|
(*found)++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
XRRFreeScreenResources(sr); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
@ -265,8 +240,6 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* found) |
|
|
|
|
|
|
|
|
|
void _glfwPlatformDestroyMonitor(_GLFWmonitor* monitor) |
|
|
|
|
{ |
|
|
|
|
if (_glfw.x11.randr.available) |
|
|
|
|
XRRFreeOutputInfo(monitor->x11.output); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) |
|
|
|
@ -283,25 +256,27 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) |
|
|
|
|
|
|
|
|
|
if (_glfw.x11.randr.available) |
|
|
|
|
{ |
|
|
|
|
int i, j; |
|
|
|
|
XRRScreenResources* sr; |
|
|
|
|
int i, j, count = monitor->x11.output->nmode; |
|
|
|
|
XRROutputInfo* oi; |
|
|
|
|
|
|
|
|
|
sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root); |
|
|
|
|
oi = XRRGetOutputInfo(_glfw.x11.display, sr, monitor->x11.output); |
|
|
|
|
|
|
|
|
|
result = (GLFWvidmode*) malloc(sizeof(GLFWvidmode) * count); |
|
|
|
|
result = (GLFWvidmode*) malloc(sizeof(GLFWvidmode) * oi->nmode); |
|
|
|
|
if (!result) |
|
|
|
|
{ |
|
|
|
|
_glfwInputError(GLFW_OUT_OF_MEMORY, NULL); |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) |
|
|
|
|
for (i = 0; i < oi->nmode; i++) |
|
|
|
|
{ |
|
|
|
|
GLFWvidmode mode; |
|
|
|
|
|
|
|
|
|
for (j = 0; j < sr->nmode; j++) |
|
|
|
|
{ |
|
|
|
|
if (sr->modes[j].id == monitor->x11.output->modes[i]) |
|
|
|
|
if (sr->modes[j].id == oi->modes[i]) |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -334,6 +309,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) |
|
|
|
|
(*found)++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
XRRFreeOutputInfo(oi); |
|
|
|
|
XRRFreeScreenResources(sr); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
@ -365,22 +341,7 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode) |
|
|
|
|
XRRCrtcInfo* ci; |
|
|
|
|
|
|
|
|
|
sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root); |
|
|
|
|
if (!sr) |
|
|
|
|
{ |
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR, |
|
|
|
|
"X11: Failed to retrieve RandR screen resources"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.output->crtc); |
|
|
|
|
if (!ci) |
|
|
|
|
{ |
|
|
|
|
XRRFreeScreenResources(sr); |
|
|
|
|
|
|
|
|
|
_glfwInputError(GLFW_PLATFORM_ERROR, |
|
|
|
|
"X11: Failed to retrieve RandR crtc info"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); |
|
|
|
|
|
|
|
|
|
mode->width = ci->width; |
|
|
|
|
mode->height = ci->height; |
|
|
|
|