From 4c53a74fa91f5dc4ba6eb93a057c2ff6f69da51c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 2 Feb 2018 12:21:59 +0530 Subject: [PATCH] Fix resize debounce implementation --- kitty/child-monitor.c | 4 ++-- kitty/glfw.c | 11 ++++------- kitty/state.h | 4 ++-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index 71d73eb32..117399110 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -692,10 +692,10 @@ process_pending_resizes(double now) { for (size_t i = 0; i < global_state.num_os_windows; i++) { OSWindow *w = global_state.os_windows + i; if (w->has_pending_resizes) { - if (now - w->last_resize_at >= RESIZE_DEBOUNCE_TIME) update_os_window_viewport(w, true); + 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_at); + set_maximum_wait(RESIZE_DEBOUNCE_TIME - now + w->last_resize_event_at); } } } diff --git a/kitty/glfw.c b/kitty/glfw.c index cc072c2e2..11416e00e 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -27,10 +27,11 @@ update_os_window_viewport(OSWindow *window, bool notify_boss) { bool dpi_changed = (xr != 0.0 && xr != window->viewport_x_ratio) || (yr != 0.0 && yr != window->viewport_y_ratio); window->viewport_size_dirty = true; window->has_pending_resizes = false; + window->viewport_width = MAX(window->viewport_width, 100); + window->viewport_height = MAX(window->viewport_height, 100); if (notify_boss) { call_boss(on_window_resize, "KiiO", window->id, window->viewport_width, window->viewport_height, dpi_changed ? Py_True : Py_False); } - window->last_resize_at = monotonic(); } @@ -77,13 +78,9 @@ static void framebuffer_size_callback(GLFWwindow *w, int width, int height) { if (!set_callback_window(w)) return; if (width > 100 && height > 100) { - double now = monotonic(); OSWindow *window = global_state.callback_os_window; - if (now - window->last_resize_at < RESIZE_DEBOUNCE_TIME) { window->has_pending_resizes = true; global_state.has_pending_resizes = true; } - else { - update_os_window_viewport(global_state.callback_os_window, is_window_ready_for_callbacks()); - glfwPostEmptyEvent(); - } + window->has_pending_resizes = true; global_state.has_pending_resizes = true; + window->last_resize_event_at = monotonic(); } else fprintf(stderr, "Ignoring resize request for tiny size: %dx%d\n", width, height); global_state.callback_os_window = NULL; } diff --git a/kitty/state.h b/kitty/state.h index 4adf4b875..4ca8a0fe6 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -107,7 +107,7 @@ typedef struct { PyObject *window_title; bool is_key_pressed[MAX_KEY_COUNT]; bool viewport_size_dirty; - double last_resize_at; + double last_resize_event_at; bool has_pending_resizes; bool is_semi_transparent; bool shown_once; @@ -141,7 +141,7 @@ extern GlobalState global_state; else Py_DECREF(cret_); \ } -#define RESIZE_DEBOUNCE_TIME 0.2 +#define RESIZE_DEBOUNCE_TIME 0.1 void gl_init(); void remove_vao(ssize_t vao_idx);