From 99c925efd8a861df68e4991eecfb11d904bfdb8d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 23 Feb 2016 12:34:35 +0100 Subject: [PATCH] Add tracking of which window 'owns' a monitor --- src/cocoa_window.m | 24 +++++++++++++++--------- src/internal.h | 7 +++++++ src/monitor.c | 5 +++++ src/win32_window.c | 23 ++++++++++++++--------- src/x11_window.c | 28 +++++++++++++++++++--------- 5 files changed, 60 insertions(+), 27 deletions(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 7e7b3d50..c30c9409 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -73,9 +73,9 @@ static float transformY(float y) return CGDisplayBounds(CGMainDisplayID()).size.height - y; } -// Enter full screen mode +// Make the specified window and its video mode active on its monitor // -static GLFWbool enterFullscreenMode(_GLFWwindow* window) +static GLFWbool acquireMonitor(_GLFWwindow* window) { const GLFWbool status = _glfwSetVideoModeNS(window->monitor, &window->videoMode); const CGRect bounds = CGDisplayBounds(window->monitor->ns.displayID); @@ -85,14 +85,20 @@ static GLFWbool enterFullscreenMode(_GLFWwindow* window) bounds.size.height); [window->ns.object setFrame:frame display:YES]; + _glfwPlatformFocusWindow(window); + _glfwInputMonitorWindowChange(window->monitor, window); return status; } -// Leave full screen mode +// Remove the window and restore the original video mode // -static void leaveFullscreenMode(_GLFWwindow* window) +static void releaseMonitor(_GLFWwindow* window) { + if (window->monitor->window != window) + return; + + _glfwInputMonitorWindowChange(window->monitor, NULL); _glfwRestoreVideoModeNS(window->monitor); } @@ -219,7 +225,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; - (void)windowDidMiniaturize:(NSNotification *)notification { if (window->monitor) - leaveFullscreenMode(window); + releaseMonitor(window); _glfwInputWindowIconify(window, GLFW_TRUE); } @@ -227,7 +233,7 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; - (void)windowDidDeminiaturize:(NSNotification *)notification { if (window->monitor) - enterFullscreenMode(window); + acquireMonitor(window); _glfwInputWindowIconify(window, GLFW_FALSE); } @@ -999,7 +1005,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, if (window->monitor) { _glfwPlatformShowWindow(window); - if (!enterFullscreenMode(window)) + if (!acquireMonitor(window)) return GLFW_FALSE; } @@ -1011,7 +1017,7 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window) [window->ns.object orderOut:nil]; if (window->monitor) - leaveFullscreenMode(window); + releaseMonitor(window); if (window->context.api != GLFW_NO_API) _glfwDestroyContextNSGL(window); @@ -1070,7 +1076,7 @@ void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height) void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) { if (window->monitor) - enterFullscreenMode(window); + acquireMonitor(window); else [window->ns.object setContentSize:NSMakeSize(width, height)]; } diff --git a/src/internal.h b/src/internal.h index 01046d0d..e003ec50 100644 --- a/src/internal.h +++ b/src/internal.h @@ -381,6 +381,9 @@ struct _GLFWmonitor // Physical dimensions in millimeters. int widthMM, heightMM; + // The window whose video mode is current on this monitor + _GLFWwindow* window; + GLFWvidmode* modes; int modeCount; GLFWvidmode currentMode; @@ -911,6 +914,10 @@ void _glfwInputCursorEnter(_GLFWwindow* window, GLFWbool entered); */ void _glfwInputMonitorChange(void); +/*! @ingroup event + */ +void _glfwInputMonitorWindowChange(_GLFWmonitor* monitor, _GLFWwindow* window); + /*! @brief Notifies shared code of an error. * @param[in] error The error code most suitable for the error. * @param[in] format The `printf` style format string of the error diff --git a/src/monitor.c b/src/monitor.c index a17c1f63..d21a992b 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -158,6 +158,11 @@ void _glfwInputMonitorChange(void) _glfwFreeMonitors(monitors, monitorCount); } +void _glfwInputMonitorWindowChange(_GLFWmonitor* monitor, _GLFWwindow* window) +{ + monitor->window = window; +} + ////////////////////////////////////////////////////////////////////////// ////// GLFW internal API ////// diff --git a/src/win32_window.c b/src/win32_window.c index 7fc8c5e9..5c6cc031 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -328,9 +328,9 @@ static int translateKey(WPARAM wParam, LPARAM lParam) return _glfw.win32.publicKeys[HIWORD(lParam) & 0x1FF]; } -// Enter full screen mode +// Make the specified window and its video mode active on its monitor // -static GLFWbool enterFullscreenMode(_GLFWwindow* window) +static GLFWbool acquireMonitor(_GLFWwindow* window) { GLFWvidmode mode; GLFWbool status; @@ -344,13 +344,18 @@ static GLFWbool enterFullscreenMode(_GLFWwindow* window) SetWindowPos(window->win32.handle, HWND_TOPMOST, xpos, ypos, mode.width, mode.height, SWP_NOCOPYBITS); + _glfwInputMonitorWindowChange(window->monitor, window); return status; } -// Leave full screen mode +// Remove the window and restore the original video mode // -static void leaveFullscreenMode(_GLFWwindow* window) +static void releaseMonitor(_GLFWwindow* window) { + if (window->monitor->window != window) + return; + + _glfwInputMonitorWindowChange(window->monitor, NULL); _glfwRestoreVideoModeWin32(window->monitor); } @@ -597,7 +602,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, { window->win32.iconified = GLFW_TRUE; if (window->monitor) - leaveFullscreenMode(window); + releaseMonitor(window); _glfwInputWindowIconify(window, GLFW_TRUE); } @@ -606,7 +611,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, { window->win32.iconified = GLFW_FALSE; if (window->monitor) - enterFullscreenMode(window); + acquireMonitor(window); _glfwInputWindowIconify(window, GLFW_FALSE); } @@ -971,7 +976,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, if (window->monitor) { _glfwPlatformShowWindow(window); - if (!enterFullscreenMode(window)) + if (!acquireMonitor(window)) return GLFW_FALSE; } @@ -981,7 +986,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, void _glfwPlatformDestroyWindow(_GLFWwindow* window) { if (window->monitor) - leaveFullscreenMode(window); + releaseMonitor(window); if (window->context.api != GLFW_NO_API) { @@ -1088,7 +1093,7 @@ void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height) void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) { if (window->monitor) - enterFullscreenMode(window); + acquireMonitor(window); else { int fullWidth, fullHeight; diff --git a/src/x11_window.c b/src/x11_window.c index 0c2016b3..d1f20202 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -711,10 +711,12 @@ static void pushSelectionToManager(_GLFWwindow* window) } } -// Enter full screen mode +// Make the specified window and its video mode active on its monitor // -static void enterFullscreenMode(_GLFWwindow* window) +static GLFWbool acquireMonitor(_GLFWwindow* window) { + GLFWbool status; + if (_glfw.x11.saver.count == 0) { // Remember old screen saver settings @@ -731,7 +733,7 @@ static void enterFullscreenMode(_GLFWwindow* window) _glfw.x11.saver.count++; - _glfwSetVideoModeX11(window->monitor, &window->videoMode); + status = _glfwSetVideoModeX11(window->monitor, &window->videoMode); if (_glfw.x11.NET_WM_BYPASS_COMPOSITOR) { @@ -778,12 +780,19 @@ static void enterFullscreenMode(_GLFWwindow* window) _glfw.x11.NET_WM_STATE_FULLSCREEN, 0, 1, 0); } + + _glfwInputMonitorWindowChange(window->monitor, window); + return status; } -// Leave full screen mode +// Remove the window and restore the original video mode // -static void leaveFullscreenMode(_GLFWwindow* window) +static void releaseMonitor(_GLFWwindow* window) { + if (window->monitor->window != window) + return; + + _glfwInputMonitorWindowChange(window->monitor, NULL); _glfwRestoreVideoModeX11(window->monitor); _glfw.x11.saver.count--; @@ -1335,14 +1344,14 @@ static void processEvent(XEvent *event) if (state == IconicState) { if (window->monitor) - leaveFullscreenMode(window); + releaseMonitor(window); _glfwInputWindowIconify(window, GLFW_TRUE); } else if (state == NormalState) { if (window->monitor) - enterFullscreenMode(window); + acquireMonitor(window); _glfwInputWindowIconify(window, GLFW_FALSE); } @@ -1450,7 +1459,8 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, if (window->monitor) { _glfwPlatformShowWindow(window); - enterFullscreenMode(window); + if (!acquireMonitor(window)) + return GLFW_FALSE; } return GLFW_TRUE; @@ -1459,7 +1469,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, void _glfwPlatformDestroyWindow(_GLFWwindow* window) { if (window->monitor) - leaveFullscreenMode(window); + releaseMonitor(window); if (window->x11.ic) {