Fixed X11 behavior when disconnecting / connecting the last display

- Removed the one-time detection of headless display
- Removed virtual "Display" display created when no monitor is plugged
- Hardened monitor functions
This commit is contained in:
Olivier Nemoz 2017-02-13 11:58:30 +01:00
parent c3fd757b03
commit 88ac9fcb95
3 changed files with 74 additions and 103 deletions

View File

@ -499,31 +499,6 @@ static GLFWbool initExtensions(void)
if (_glfw.x11.randr.available)
{
XRRScreenResources* sr = XRRGetScreenResourcesCurrent(_glfw.x11.display,
_glfw.x11.root);
if (!sr->ncrtc || !XRRGetCrtcGammaSize(_glfw.x11.display, sr->crtcs[0]))
{
// This is either a headless system or an older Nvidia binary driver
// with broken gamma support
// Flag it as useless and fall back to Xf86VidMode gamma, if
// available
_glfwInputError(GLFW_PLATFORM_ERROR,
"X11: Detected broken RandR gamma ramp support");
_glfw.x11.randr.gammaBroken = GLFW_TRUE;
}
if (!sr->ncrtc || !sr->noutput || !sr->nmode)
{
// This is either a headless system or broken Cygwin/X RandR
// Flag it as useless and fall back to Xlib display functions
_glfwInputError(GLFW_PLATFORM_ERROR,
"X11: Detected broken RandR monitor support");
_glfw.x11.randr.monitorBroken = GLFW_TRUE;
}
XRRFreeScreenResources(sr);
XRRSelectInput(_glfw.x11.display, _glfw.x11.root,
RROutputChangeNotifyMask);
}

View File

@ -99,7 +99,7 @@ static GLFWvidmode vidmodeFromModeInfo(const XRRModeInfo* mi,
//
void _glfwPollMonitorsX11(void)
{
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)
if (_glfw.x11.randr.available)
{
int i, j, disconnectedCount, screenCount = 0;
_GLFWmonitor** disconnected;
@ -199,23 +199,6 @@ void _glfwPollMonitorsX11(void)
}
free(disconnected);
if (!_glfw.monitorCount)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"X11: RandR monitor support seems broken");
_glfw.x11.randr.monitorBroken = GLFW_TRUE;
}
}
if (!_glfw.monitorCount)
{
const int widthMM = DisplayWidthMM(_glfw.x11.display, _glfw.x11.screen);
const int heightMM = DisplayHeightMM(_glfw.x11.display, _glfw.x11.screen);
_glfwInputMonitor(_glfwAllocMonitor("Display", widthMM, heightMM),
GLFW_CONNECTED,
_GLFW_INSERT_FIRST);
}
}
@ -223,7 +206,7 @@ void _glfwPollMonitorsX11(void)
//
GLFWbool _glfwSetVideoModeX11(_GLFWmonitor* monitor, const GLFWvidmode* desired)
{
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)
if (_glfw.x11.randr.available && monitor->x11.crtc && monitor->x11.output)
{
XRRScreenResources* sr;
XRRCrtcInfo* ci;
@ -290,7 +273,7 @@ GLFWbool _glfwSetVideoModeX11(_GLFWmonitor* monitor, const GLFWvidmode* desired)
//
void _glfwRestoreVideoModeX11(_GLFWmonitor* monitor)
{
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)
if (_glfw.x11.randr.available && monitor->x11.crtc)
{
XRRScreenResources* sr;
XRRCrtcInfo* ci;
@ -324,7 +307,7 @@ void _glfwRestoreVideoModeX11(_GLFWmonitor* monitor)
void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos)
{
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)
if (_glfw.x11.randr.available && monitor->x11.crtc)
{
XRRScreenResources* sr;
XRRCrtcInfo* ci;
@ -348,7 +331,9 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
*count = 0;
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)
if (_glfw.x11.randr.available)
{
if (monitor->x11.crtc && monitor->x11.output)
{
int i, j;
XRRScreenResources* sr;
@ -387,6 +372,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
XRRFreeCrtcInfo(ci);
XRRFreeScreenResources(sr);
}
}
else
{
*count = 1;
@ -399,7 +385,9 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
{
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)
if (_glfw.x11.randr.available)
{
if (monitor->x11.crtc)
{
XRRScreenResources* sr;
XRRCrtcInfo* ci;
@ -412,6 +400,7 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
XRRFreeCrtcInfo(ci);
XRRFreeScreenResources(sr);
}
}
else
{
mode->width = DisplayWidth(_glfw.x11.display, _glfw.x11.screen);
@ -425,10 +414,14 @@ void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
{
if (_glfw.x11.randr.available && !_glfw.x11.randr.gammaBroken)
if (_glfw.x11.randr.available)
{
if (monitor->x11.crtc)
{
const size_t size = XRRGetCrtcGammaSize(_glfw.x11.display,
monitor->x11.crtc);
if (size)
{
XRRCrtcGamma* gamma = XRRGetCrtcGamma(_glfw.x11.display,
monitor->x11.crtc);
@ -440,6 +433,8 @@ void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
XRRFreeGamma(gamma);
}
}
}
else if (_glfw.x11.vidmode.available)
{
int size;
@ -455,7 +450,9 @@ void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
{
if (_glfw.x11.randr.available && !_glfw.x11.randr.gammaBroken)
if (_glfw.x11.randr.available)
{
if (monitor->x11.crtc)
{
XRRCrtcGamma* gamma = XRRAllocGamma(ramp->size);
@ -466,6 +463,7 @@ void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp)
XRRSetCrtcGamma(_glfw.x11.display, monitor->x11.crtc, gamma);
XRRFreeGamma(gamma);
}
}
else if (_glfw.x11.vidmode.available)
{
XF86VidModeSetGammaRamp(_glfw.x11.display,

View File

@ -221,8 +221,6 @@ typedef struct _GLFWlibraryX11
int errorBase;
int major;
int minor;
GLFWbool gammaBroken;
GLFWbool monitorBroken;
} randr;
struct {