mirror of
https://github.com/gwm17/glfw.git
synced 2024-11-23 02:38:52 -05:00
Add tracking of which window 'owns' a monitor
This commit is contained in:
parent
ea888114fa
commit
99c925efd8
|
@ -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)];
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -158,6 +158,11 @@ void _glfwInputMonitorChange(void)
|
|||
_glfwFreeMonitors(monitors, monitorCount);
|
||||
}
|
||||
|
||||
void _glfwInputMonitorWindowChange(_GLFWmonitor* monitor, _GLFWwindow* window)
|
||||
{
|
||||
monitor->window = window;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW internal API //////
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user