From 379ec88776df0a3a4785f1d264c4b6e04234217f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 27 Apr 2019 14:40:09 +0530 Subject: [PATCH] Only use the tick callback mechanism on macOS On Linux, just call the tick callback on every loop tick. This is much simpler, and should fix the issue with screen updates sometimes getting stuck waiting for an X11 event. Note that this was what used to happen (global state being checked on every loop tick) before the refactoring to use a GLFW event loop, therefore there should be no performance regressions, though we of course end up checking global state on every group of events on Linux, instead of only when something of interest happens. I suspect, to achieve the latter is going to require implementing a mutex/lock in the main loop to avoid races, which doesn't seem worth it. --- glfw/main_loop.h | 13 ++++--------- kitty/child-monitor.c | 3 +-- kitty/glfw.c | 13 ++++++++----- kitty/state.h | 1 - 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/glfw/main_loop.h b/glfw/main_loop.h index 74bdae368..7f8bbc21e 100644 --- a/glfw/main_loop.h +++ b/glfw/main_loop.h @@ -12,10 +12,9 @@ #define GLFW_LOOP_BACKEND x11 #endif -static GLFWbool keep_going = GLFW_FALSE, tick_callback_requested = GLFW_FALSE; +static GLFWbool keep_going = GLFW_FALSE; void _glfwPlatformRequestTickCallback() { - tick_callback_requested = GLFW_TRUE; } void _glfwPlatformStopMainLoop(void) { @@ -25,16 +24,12 @@ void _glfwPlatformStopMainLoop(void) { } } -void _glfwPlatformRunMainLoop(GLFWtickcallback callback, void* data) { +void _glfwPlatformRunMainLoop(GLFWtickcallback tick_callback, void* data) { keep_going = GLFW_TRUE; - tick_callback_requested = GLFW_FALSE; while(keep_going) { - EVDBG("tick_callback_requested: %d", tick_callback_requested); - while (tick_callback_requested) { - tick_callback_requested = GLFW_FALSE; - callback(data); - } _glfwPlatformWaitEvents(); + EVDBG("loop tick"); + tick_callback(data); } } diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index 00109396c..e2046d6a6 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -940,8 +940,7 @@ process_global_state(void *data) { if (global_state.has_pending_closes) has_open_windows = process_pending_closes(self); if (has_open_windows) { if (maximum_wait >= 0) { - if (maximum_wait == 0) request_tick_callback(); - else state_check_timer_enabled = true; + state_check_timer_enabled = true; } } else { stop_main_loop(); diff --git a/kitty/glfw.c b/kitty/glfw.c index 1f2dbfa9a..f2c9b643f 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -27,6 +27,14 @@ static GLFWcursor *standard_cursor = NULL, *click_cursor = NULL, *arrow_cursor = static void set_os_window_dpi(OSWindow *w); + +static void +request_tick_callback(void) { +#ifdef __APPLE__ + glfwRequestTickCallback(); +#endif +} + void update_os_window_viewport(OSWindow *window, bool notify_boss) { int w, h, fw, fh; @@ -1128,11 +1136,6 @@ run_main_loop(tick_callback_fun cb, void* cb_data) { glfwRunMainLoop(cb, cb_data); } -void -request_tick_callback(void) { - glfwRequestTickCallback(); -} - void stop_main_loop(void) { glfwStopMainLoop(); diff --git a/kitty/state.h b/kitty/state.h index 84bcb75c2..fbdac3383 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -238,5 +238,4 @@ id_type add_main_loop_timer(double interval, bool repeats, timer_callback_fun ca void remove_main_loop_timer(id_type timer_id); void update_main_loop_timer(id_type timer_id, double interval, bool enabled); void run_main_loop(tick_callback_fun, void*); -void request_tick_callback(void); void stop_main_loop(void);