Avoid using timing related hacks to detect the end of a live resize on macOS

Since cocoa provides start/end notifications for live resizing, rely on
those instead.
This commit is contained in:
Kovid Goyal
2019-02-28 15:15:31 +05:30
parent bbeb08ba08
commit 3bd1ca0ac3
9 changed files with 63 additions and 4 deletions

View File

@@ -592,6 +592,17 @@ static GLFWapplicationshouldhandlereopenfun handle_reopen_callback = NULL;
return YES;
}
- (void) viewWillStartLiveResize
{
_glfwInputLiveResize(window, true);
}
- (void)viewDidEndLiveResize
{
_glfwInputLiveResize(window, false);
}
- (BOOL)wantsUpdateLayer
{
return YES;

3
glfw/glfw3.h vendored
View File

@@ -1474,6 +1474,8 @@ typedef void (* GLFWkeyboardfun)(GLFWwindow*, int, int, int, int, const char*, i
*/
typedef void (* GLFWdropfun)(GLFWwindow*,int,const char**);
typedef void (* GLFWliveresizefun)(GLFWwindow*, bool);
/*! @brief The function signature for monitor configuration callbacks.
*
* This is the function signature for monitor configuration callback functions.
@@ -4343,6 +4345,7 @@ GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun cb
* @ingroup input
*/
GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun cbfun);
GLFWAPI GLFWliveresizefun glfwSetLiveResizeCallback(GLFWwindow* window, GLFWliveresizefun cbfun);
/*! @brief Returns whether the specified joystick is present.
*

2
glfw/internal.h vendored
View File

@@ -419,6 +419,7 @@ struct _GLFWwindow
GLFWscrollfun scroll;
GLFWkeyboardfun keyboard;
GLFWdropfun drop;
GLFWliveresizefun liveResize;
} callbacks;
// This is defined in the window API's platform.h
@@ -653,6 +654,7 @@ void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window,
int maxwidth, int maxheight);
void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom);
void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height);
void _glfwInputLiveResize(_GLFWwindow* window, bool started);
void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
int* left, int* top,
int* right, int* bottom);

19
glfw/window.c vendored
View File

@@ -139,6 +139,14 @@ void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height)
window->callbacks.fbsize((GLFWwindow*) window, width, height);
}
// Notifies shared code that a window live resize is in progress
//
void _glfwInputLiveResize(_GLFWwindow* window, bool started)
{
if (window->callbacks.liveResize)
window->callbacks.liveResize((GLFWwindow*) window, started);
}
// Notifies shared code that a window content scale has changed
// The scale is specified as the ratio between the current and default DPI
//
@@ -1122,6 +1130,17 @@ GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* handle
return cbfun;
}
GLFWAPI GLFWliveresizefun glfwSetLiveResizeCallback(GLFWwindow* handle,
GLFWliveresizefun cbfun)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
assert(window != NULL);
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
_GLFW_SWAP_POINTERS(window->callbacks.liveResize, cbfun);
return cbfun;
}
GLFWAPI GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(GLFWwindow* handle,
GLFWwindowcontentscalefun cbfun)
{