From 1d75b205cbf9affda0d6779b729f238f836d0ec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 5 Feb 2018 17:11:04 +0100 Subject: [PATCH] Cleanup Allow window creation despite video mode setting failure. Video mode setting failure is ignored the rest of the time and the desired video mode has never been a hard constraint anyway. --- src/cocoa_monitor.m | 13 ++----------- src/cocoa_platform.h | 2 +- src/cocoa_window.m | 8 +++----- src/win32_monitor.c | 13 +++++-------- src/win32_platform.h | 2 +- src/win32_window.c | 9 +++------ src/x11_monitor.c | 13 ++----------- src/x11_platform.h | 2 +- src/x11_window.c | 10 +++------- 9 files changed, 21 insertions(+), 51 deletions(-) diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index bfcf4510..a0dc69ce 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -287,7 +287,7 @@ void _glfwPollMonitorsNS(void) // Change the current video mode // -GLFWbool _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired) +void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired) { CFArrayRef modes; CFIndex count, i; @@ -299,7 +299,7 @@ GLFWbool _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired) best = _glfwChooseVideoMode(monitor, desired); _glfwPlatformGetVideoMode(monitor, ¤t); if (_glfwCompareVideoModes(¤t, best) == 0) - return GLFW_TRUE; + return; CVDisplayLinkCreateWithCGDisplay(monitor->ns.displayID, &link); @@ -332,15 +332,6 @@ GLFWbool _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired) CFRelease(modes); CVDisplayLinkRelease(link); - - if (!native) - { - _glfwInputError(GLFW_PLATFORM_ERROR, - "Cocoa: Monitor mode list changed"); - return GLFW_FALSE; - } - - return GLFW_TRUE; } // Restore the previously saved (original) video mode diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index de4bae04..cf6ca9f5 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -164,6 +164,6 @@ typedef struct _GLFWtimerNS void _glfwInitTimerNS(void); void _glfwPollMonitorsNS(void); -GLFWbool _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired); +void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired); void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor); diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 81b1acfd..9da8c0d3 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -138,9 +138,9 @@ static float transformY(float y) // Make the specified window and its video mode active on its monitor // -static GLFWbool acquireMonitor(_GLFWwindow* window) +static void acquireMonitor(_GLFWwindow* window) { - const GLFWbool status = _glfwSetVideoModeNS(window->monitor, &window->videoMode); + _glfwSetVideoModeNS(window->monitor, &window->videoMode); const CGRect bounds = CGDisplayBounds(window->monitor->ns.displayID); const NSRect frame = NSMakeRect(bounds.origin.x, transformY(bounds.origin.y + bounds.size.height), @@ -150,7 +150,6 @@ static GLFWbool acquireMonitor(_GLFWwindow* window) [window->ns.object setFrame:frame display:YES]; _glfwInputMonitorWindow(window->monitor, window); - return status; } // Remove the window and restore the original video mode @@ -1178,8 +1177,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, { _glfwPlatformShowWindow(window); _glfwPlatformFocusWindow(window); - if (!acquireMonitor(window)) - return GLFW_FALSE; + acquireMonitor(window); if (wndconfig->centerCursor) centerCursor(window); diff --git a/src/win32_monitor.c b/src/win32_monitor.c index 74dd8252..898c7f26 100644 --- a/src/win32_monitor.c +++ b/src/win32_monitor.c @@ -241,7 +241,7 @@ void _glfwPollMonitorsWin32(void) // Change the current video mode // -GLFWbool _glfwSetVideoModeWin32(_GLFWmonitor* monitor, const GLFWvidmode* desired) +void _glfwSetVideoModeWin32(_GLFWmonitor* monitor, const GLFWvidmode* desired) { GLFWvidmode current; const GLFWvidmode* best; @@ -251,7 +251,7 @@ GLFWbool _glfwSetVideoModeWin32(_GLFWmonitor* monitor, const GLFWvidmode* desire best = _glfwChooseVideoMode(monitor, desired); _glfwPlatformGetVideoMode(monitor, ¤t); if (_glfwCompareVideoModes(¤t, best) == 0) - return GLFW_TRUE; + return; ZeroMemory(&dm, sizeof(dm)); dm.dmSize = sizeof(dm); @@ -270,7 +270,9 @@ GLFWbool _glfwSetVideoModeWin32(_GLFWmonitor* monitor, const GLFWvidmode* desire NULL, CDS_FULLSCREEN, NULL); - if (result != DISP_CHANGE_SUCCESSFUL) + if (result == DISP_CHANGE_SUCCESSFUL) + monitor->win32.modeChanged = GLFW_TRUE; + else { const char* description = "Unknown error"; @@ -292,12 +294,7 @@ GLFWbool _glfwSetVideoModeWin32(_GLFWmonitor* monitor, const GLFWvidmode* desire _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to set video mode: %s", description); - - return GLFW_FALSE; } - - monitor->win32.modeChanged = GLFW_TRUE; - return GLFW_TRUE; } // Restore the previously saved (original) video mode diff --git a/src/win32_platform.h b/src/win32_platform.h index 72718ada..607ac13a 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -398,7 +398,7 @@ void _glfwUpdateKeyNamesWin32(void); void _glfwInitTimerWin32(void); void _glfwPollMonitorsWin32(void); -GLFWbool _glfwSetVideoModeWin32(_GLFWmonitor* monitor, const GLFWvidmode* desired); +void _glfwSetVideoModeWin32(_GLFWmonitor* monitor, const GLFWvidmode* desired); void _glfwRestoreVideoModeWin32(_GLFWmonitor* monitor); void _glfwGetMonitorContentScaleWin32(HMONITOR handle, float* xscale, float* yscale); diff --git a/src/win32_window.c b/src/win32_window.c index d6959d07..5ab369c4 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -473,10 +473,9 @@ static int translateKey(WPARAM wParam, LPARAM lParam) // Make the specified window and its video mode active on its monitor // -static GLFWbool acquireMonitor(_GLFWwindow* window) +static void acquireMonitor(_GLFWwindow* window) { GLFWvidmode mode; - GLFWbool status; int xpos, ypos; if (!_glfw.win32.acquiredMonitorCount) @@ -484,7 +483,7 @@ static GLFWbool acquireMonitor(_GLFWwindow* window) if (!window->monitor->window) _glfw.win32.acquiredMonitorCount++; - status = _glfwSetVideoModeWin32(window->monitor, &window->videoMode); + _glfwSetVideoModeWin32(window->monitor, &window->videoMode); _glfwPlatformGetVideoMode(window->monitor, &mode); _glfwPlatformGetMonitorPos(window->monitor, &xpos, &ypos); @@ -494,7 +493,6 @@ static GLFWbool acquireMonitor(_GLFWwindow* window) SWP_NOACTIVATE | SWP_NOCOPYBITS); _glfwInputMonitorWindow(window->monitor, window); - return status; } // Remove the window and restore the original video mode @@ -1240,8 +1238,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, { _glfwPlatformShowWindow(window); _glfwPlatformFocusWindow(window); - if (!acquireMonitor(window)) - return GLFW_FALSE; + acquireMonitor(window); if (wndconfig->centerCursor) centerCursor(window); diff --git a/src/x11_monitor.c b/src/x11_monitor.c index d9144bb4..a9bb8a23 100644 --- a/src/x11_monitor.c +++ b/src/x11_monitor.c @@ -216,7 +216,7 @@ void _glfwPollMonitorsX11(void) // Set the current video mode for the specified monitor // -GLFWbool _glfwSetVideoModeX11(_GLFWmonitor* monitor, const GLFWvidmode* desired) +void _glfwSetVideoModeX11(_GLFWmonitor* monitor, const GLFWvidmode* desired) { if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken) { @@ -231,7 +231,7 @@ GLFWbool _glfwSetVideoModeX11(_GLFWmonitor* monitor, const GLFWvidmode* desired) best = _glfwChooseVideoMode(monitor, desired); _glfwPlatformGetVideoMode(monitor, ¤t); if (_glfwCompareVideoModes(¤t, best) == 0) - return GLFW_TRUE; + return; sr = XRRGetScreenResourcesCurrent(_glfw.x11.display, _glfw.x11.root); ci = XRRGetCrtcInfo(_glfw.x11.display, sr, monitor->x11.crtc); @@ -269,16 +269,7 @@ GLFWbool _glfwSetVideoModeX11(_GLFWmonitor* monitor, const GLFWvidmode* desired) XRRFreeOutputInfo(oi); XRRFreeCrtcInfo(ci); XRRFreeScreenResources(sr); - - if (!native) - { - _glfwInputError(GLFW_PLATFORM_ERROR, - "X11: Monitor mode list changed"); - return GLFW_FALSE; - } } - - return GLFW_TRUE; } // Restore the saved (original) video mode for the specified monitor diff --git a/src/x11_platform.h b/src/x11_platform.h index c5a11cf2..c37c740e 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -425,7 +425,7 @@ typedef struct _GLFWcursorX11 void _glfwPollMonitorsX11(void); -GLFWbool _glfwSetVideoModeX11(_GLFWmonitor* monitor, const GLFWvidmode* desired); +void _glfwSetVideoModeX11(_GLFWmonitor* monitor, const GLFWvidmode* desired); void _glfwRestoreVideoModeX11(_GLFWmonitor* monitor); Cursor _glfwCreateCursorX11(const GLFWimage* image, int xhot, int yhot); diff --git a/src/x11_window.c b/src/x11_window.c index 02c49cb1..749b07f8 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1076,10 +1076,8 @@ static const char* getSelectionString(Atom selection) // Make the specified window and its video mode active on its monitor // -static GLFWbool acquireMonitor(_GLFWwindow* window) +static void acquireMonitor(_GLFWwindow* window) { - GLFWbool status; - if (_glfw.x11.saver.count == 0) { // Remember old screen saver settings @@ -1097,7 +1095,7 @@ static GLFWbool acquireMonitor(_GLFWwindow* window) if (!window->monitor->window) _glfw.x11.saver.count++; - status = _glfwSetVideoModeX11(window->monitor, &window->videoMode); + _glfwSetVideoModeX11(window->monitor, &window->videoMode); if (window->x11.overrideRedirect) { @@ -1113,7 +1111,6 @@ static GLFWbool acquireMonitor(_GLFWwindow* window) } _glfwInputMonitorWindow(window->monitor, window); - return status; } // Remove the window and restore the original video mode @@ -1977,8 +1974,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, { _glfwPlatformShowWindow(window); updateWindowMode(window); - if (!acquireMonitor(window)) - return GLFW_FALSE; + acquireMonitor(window); if (wndconfig->centerCursor) centerCursor(window);