Fix resize debounce implementation

This commit is contained in:
Kovid Goyal 2018-02-02 12:21:59 +05:30
parent 9b0ffdbf5a
commit 4c53a74fa9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 8 additions and 11 deletions

View File

@ -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);
}
}
}

View File

@ -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;
}

View File

@ -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);