From 33e4a440084b793d4d07cba7b8ae2cf7d81a6060 Mon Sep 17 00:00:00 2001 From: Jacob Wahlgren Date: Fri, 18 Jan 2019 17:32:22 +0100 Subject: [PATCH] Unjam event loop when adding pending cocoa action Fixes the problem reported in https://github.com/kovidgoyal/kitty/issues/1312. --- kitty/child-monitor.c | 3 +++ kitty/glfw.c | 23 +++++++++++++---------- kitty/state.h | 1 + 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index d8c35199b..09f488857 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -771,6 +771,9 @@ static unsigned int cocoa_pending_actions = 0; void set_cocoa_pending_action(CocoaPendingAction action) { cocoa_pending_actions |= action; + // The main loop may be blocking on the event queue, if e.g. unfocused. + // Unjam it so the pending action is processed right now. + unjam_event_loop(); } #endif diff --git a/kitty/glfw.c b/kitty/glfw.c index 2811bb7e0..31a159466 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -57,6 +57,19 @@ update_os_window_viewport(OSWindow *window, bool notify_boss) { } } +// On Cocoa, glfwWaitEvents() can block indefinitely because of the way Cocoa +// works. See https://github.com/glfw/glfw/issues/1251. I have noticed this +// happening in particular with window resize events, when waiting with no +// timeout. See https://github.com/kovidgoyal/kitty/issues/458 +// So we use an unlovely hack to workaround that case +void +unjam_event_loop() { +#ifdef __APPLE__ + if (event_loop_blocking_with_no_timeout) + wakeup_main_loop(); +#endif +} + // callbacks {{{ @@ -98,16 +111,6 @@ show_mouse_cursor(GLFWwindow *w) { } static int min_width = 100, min_height = 100; -// On Cocoa, glfwWaitEvents() can block indefinitely because of the way Cocoa -// works. See https://github.com/glfw/glfw/issues/1251. I have noticed this -// happening in particular with window resize events, when waiting with no -// timeout. See https://github.com/kovidgoyal/kitty/issues/458 -// So we use an unlovely hack to workaround that case -#ifdef __APPLE__ -#define unjam_event_loop() { if (event_loop_blocking_with_no_timeout) wakeup_main_loop(); } -#else -#define unjam_event_loop() -#endif static void framebuffer_size_callback(GLFWwindow *w, int width, int height) { diff --git a/kitty/state.h b/kitty/state.h index 75852b097..19b648646 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -172,6 +172,7 @@ void make_os_window_context_current(OSWindow *w); void update_os_window_references(); void mark_os_window_for_close(OSWindow* w, bool yes); void update_os_window_viewport(OSWindow *window, bool); +void unjam_event_loop(); bool should_os_window_close(OSWindow* w); bool should_os_window_be_rendered(OSWindow* w); void wakeup_main_loop();