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:
@@ -592,6 +592,17 @@ static GLFWapplicationshouldhandlereopenfun handle_reopen_callback = NULL;
|
|||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) viewWillStartLiveResize
|
||||||
|
{
|
||||||
|
_glfwInputLiveResize(window, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)viewDidEndLiveResize
|
||||||
|
{
|
||||||
|
_glfwInputLiveResize(window, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)wantsUpdateLayer
|
- (BOOL)wantsUpdateLayer
|
||||||
{
|
{
|
||||||
return YES;
|
return YES;
|
||||||
|
|||||||
3
glfw/glfw3.h
vendored
3
glfw/glfw3.h
vendored
@@ -1474,6 +1474,8 @@ typedef void (* GLFWkeyboardfun)(GLFWwindow*, int, int, int, int, const char*, i
|
|||||||
*/
|
*/
|
||||||
typedef void (* GLFWdropfun)(GLFWwindow*,int,const char**);
|
typedef void (* GLFWdropfun)(GLFWwindow*,int,const char**);
|
||||||
|
|
||||||
|
typedef void (* GLFWliveresizefun)(GLFWwindow*, bool);
|
||||||
|
|
||||||
/*! @brief The function signature for monitor configuration callbacks.
|
/*! @brief The function signature for monitor configuration callbacks.
|
||||||
*
|
*
|
||||||
* This is the function signature for monitor configuration callback functions.
|
* This is the function signature for monitor configuration callback functions.
|
||||||
@@ -4343,6 +4345,7 @@ GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun cb
|
|||||||
* @ingroup input
|
* @ingroup input
|
||||||
*/
|
*/
|
||||||
GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun cbfun);
|
GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun cbfun);
|
||||||
|
GLFWAPI GLFWliveresizefun glfwSetLiveResizeCallback(GLFWwindow* window, GLFWliveresizefun cbfun);
|
||||||
|
|
||||||
/*! @brief Returns whether the specified joystick is present.
|
/*! @brief Returns whether the specified joystick is present.
|
||||||
*
|
*
|
||||||
|
|||||||
2
glfw/internal.h
vendored
2
glfw/internal.h
vendored
@@ -419,6 +419,7 @@ struct _GLFWwindow
|
|||||||
GLFWscrollfun scroll;
|
GLFWscrollfun scroll;
|
||||||
GLFWkeyboardfun keyboard;
|
GLFWkeyboardfun keyboard;
|
||||||
GLFWdropfun drop;
|
GLFWdropfun drop;
|
||||||
|
GLFWliveresizefun liveResize;
|
||||||
} callbacks;
|
} callbacks;
|
||||||
|
|
||||||
// This is defined in the window API's platform.h
|
// This is defined in the window API's platform.h
|
||||||
@@ -653,6 +654,7 @@ void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window,
|
|||||||
int maxwidth, int maxheight);
|
int maxwidth, int maxheight);
|
||||||
void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom);
|
void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom);
|
||||||
void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height);
|
void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height);
|
||||||
|
void _glfwInputLiveResize(_GLFWwindow* window, bool started);
|
||||||
void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
|
void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
|
||||||
int* left, int* top,
|
int* left, int* top,
|
||||||
int* right, int* bottom);
|
int* right, int* bottom);
|
||||||
|
|||||||
19
glfw/window.c
vendored
19
glfw/window.c
vendored
@@ -139,6 +139,14 @@ void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height)
|
|||||||
window->callbacks.fbsize((GLFWwindow*) window, width, 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
|
// Notifies shared code that a window content scale has changed
|
||||||
// The scale is specified as the ratio between the current and default DPI
|
// The scale is specified as the ratio between the current and default DPI
|
||||||
//
|
//
|
||||||
@@ -1122,6 +1130,17 @@ GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* handle
|
|||||||
return cbfun;
|
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,
|
GLFWAPI GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(GLFWwindow* handle,
|
||||||
GLFWwindowcontentscalefun cbfun)
|
GLFWwindowcontentscalefun cbfun)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -808,10 +808,14 @@ process_pending_resizes(double now) {
|
|||||||
for (size_t i = 0; i < global_state.num_os_windows; i++) {
|
for (size_t i = 0; i < global_state.num_os_windows; i++) {
|
||||||
OSWindow *w = global_state.os_windows + i;
|
OSWindow *w = global_state.os_windows + i;
|
||||||
if (w->has_pending_resizes) {
|
if (w->has_pending_resizes) {
|
||||||
if (now - w->last_resize_event_at >= RESIZE_DEBOUNCE_TIME) update_os_window_viewport(w, true);
|
if (w->has_live_resize_information) {
|
||||||
else {
|
if (!w->live_resize_in_progress) update_os_window_viewport(w, true);
|
||||||
global_state.has_pending_resizes = true;
|
} else {
|
||||||
set_maximum_wait(RESIZE_DEBOUNCE_TIME - now + w->last_resize_event_at);
|
if (now - w->last_resize_event_at >= RESIZE_DEBOUNCE_TIME) update_os_window_viewport(w, true);
|
||||||
|
else {
|
||||||
|
global_state.has_pending_resizes = true;
|
||||||
|
set_maximum_wait(RESIZE_DEBOUNCE_TIME - now + w->last_resize_event_at);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
3
kitty/glfw-wrapper.c
generated
3
kitty/glfw-wrapper.c
generated
@@ -290,6 +290,9 @@ load_glfw(const char* path) {
|
|||||||
*(void **) (&glfwSetDropCallback_impl) = dlsym(handle, "glfwSetDropCallback");
|
*(void **) (&glfwSetDropCallback_impl) = dlsym(handle, "glfwSetDropCallback");
|
||||||
if (glfwSetDropCallback_impl == NULL) fail("Failed to load glfw function glfwSetDropCallback with error: %s", dlerror());
|
if (glfwSetDropCallback_impl == NULL) fail("Failed to load glfw function glfwSetDropCallback with error: %s", dlerror());
|
||||||
|
|
||||||
|
*(void **) (&glfwSetLiveResizeCallback_impl) = dlsym(handle, "glfwSetLiveResizeCallback");
|
||||||
|
if (glfwSetLiveResizeCallback_impl == NULL) fail("Failed to load glfw function glfwSetLiveResizeCallback with error: %s", dlerror());
|
||||||
|
|
||||||
*(void **) (&glfwJoystickPresent_impl) = dlsym(handle, "glfwJoystickPresent");
|
*(void **) (&glfwJoystickPresent_impl) = dlsym(handle, "glfwJoystickPresent");
|
||||||
if (glfwJoystickPresent_impl == NULL) fail("Failed to load glfw function glfwJoystickPresent with error: %s", dlerror());
|
if (glfwJoystickPresent_impl == NULL) fail("Failed to load glfw function glfwJoystickPresent with error: %s", dlerror());
|
||||||
|
|
||||||
|
|||||||
6
kitty/glfw-wrapper.h
generated
6
kitty/glfw-wrapper.h
generated
@@ -1231,6 +1231,8 @@ typedef void (* GLFWkeyboardfun)(GLFWwindow*, int, int, int, int, const char*, i
|
|||||||
*/
|
*/
|
||||||
typedef void (* GLFWdropfun)(GLFWwindow*,int,const char**);
|
typedef void (* GLFWdropfun)(GLFWwindow*,int,const char**);
|
||||||
|
|
||||||
|
typedef void (* GLFWliveresizefun)(GLFWwindow*, bool);
|
||||||
|
|
||||||
/*! @brief The function signature for monitor configuration callbacks.
|
/*! @brief The function signature for monitor configuration callbacks.
|
||||||
*
|
*
|
||||||
* This is the function signature for monitor configuration callback functions.
|
* This is the function signature for monitor configuration callback functions.
|
||||||
@@ -1791,6 +1793,10 @@ typedef GLFWdropfun (*glfwSetDropCallback_func)(GLFWwindow*, GLFWdropfun);
|
|||||||
glfwSetDropCallback_func glfwSetDropCallback_impl;
|
glfwSetDropCallback_func glfwSetDropCallback_impl;
|
||||||
#define glfwSetDropCallback glfwSetDropCallback_impl
|
#define glfwSetDropCallback glfwSetDropCallback_impl
|
||||||
|
|
||||||
|
typedef GLFWliveresizefun (*glfwSetLiveResizeCallback_func)(GLFWwindow*, GLFWliveresizefun);
|
||||||
|
glfwSetLiveResizeCallback_func glfwSetLiveResizeCallback_impl;
|
||||||
|
#define glfwSetLiveResizeCallback glfwSetLiveResizeCallback_impl
|
||||||
|
|
||||||
typedef int (*glfwJoystickPresent_func)(int);
|
typedef int (*glfwJoystickPresent_func)(int);
|
||||||
glfwJoystickPresent_func glfwJoystickPresent_impl;
|
glfwJoystickPresent_func glfwJoystickPresent_impl;
|
||||||
#define glfwJoystickPresent glfwJoystickPresent_impl
|
#define glfwJoystickPresent glfwJoystickPresent_impl
|
||||||
|
|||||||
10
kitty/glfw.c
10
kitty/glfw.c
@@ -128,6 +128,15 @@ window_iconify_callback(GLFWwindow *window, int iconified UNUSED) {
|
|||||||
global_state.callback_os_window = NULL;
|
global_state.callback_os_window = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
live_resize_callback(GLFWwindow *w, bool started) {
|
||||||
|
if (!set_callback_window(w)) return;
|
||||||
|
global_state.callback_os_window->has_live_resize_information = true;
|
||||||
|
global_state.callback_os_window->live_resize_in_progress = started;
|
||||||
|
if (!started) request_tick_callback();
|
||||||
|
global_state.callback_os_window = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
framebuffer_size_callback(GLFWwindow *w, int width, int height) {
|
framebuffer_size_callback(GLFWwindow *w, int width, int height) {
|
||||||
if (!set_callback_window(w)) return;
|
if (!set_callback_window(w)) return;
|
||||||
@@ -610,6 +619,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
|
|||||||
glfwSetWindowIconifyCallback(glfw_window, window_iconify_callback);
|
glfwSetWindowIconifyCallback(glfw_window, window_iconify_callback);
|
||||||
// missing maximize/restore callback
|
// missing maximize/restore callback
|
||||||
glfwSetFramebufferSizeCallback(glfw_window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(glfw_window, framebuffer_size_callback);
|
||||||
|
glfwSetLiveResizeCallback(glfw_window, live_resize_callback);
|
||||||
glfwSetWindowContentScaleCallback(glfw_window, dpi_change_callback);
|
glfwSetWindowContentScaleCallback(glfw_window, dpi_change_callback);
|
||||||
glfwSetMouseButtonCallback(glfw_window, mouse_button_callback);
|
glfwSetMouseButtonCallback(glfw_window, mouse_button_callback);
|
||||||
glfwSetCursorPosCallback(glfw_window, cursor_pos_callback);
|
glfwSetCursorPosCallback(glfw_window, cursor_pos_callback);
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ typedef struct {
|
|||||||
bool is_key_pressed[MAX_KEY_COUNT];
|
bool is_key_pressed[MAX_KEY_COUNT];
|
||||||
bool viewport_size_dirty;
|
bool viewport_size_dirty;
|
||||||
double last_resize_event_at;
|
double last_resize_event_at;
|
||||||
|
bool has_live_resize_information, live_resize_in_progress;
|
||||||
bool has_pending_resizes, is_semi_transparent, shown_once, is_damaged;
|
bool has_pending_resizes, is_semi_transparent, shown_once, is_damaged;
|
||||||
uint32_t offscreen_texture_id;
|
uint32_t offscreen_texture_id;
|
||||||
unsigned int clear_count;
|
unsigned int clear_count;
|
||||||
|
|||||||
Reference in New Issue
Block a user