Skip to content

Commit 379ec88

Browse files
committed
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.
1 parent a320e8b commit 379ec88

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

glfw/main_loop.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
#define GLFW_LOOP_BACKEND x11
1313
#endif
1414

15-
static GLFWbool keep_going = GLFW_FALSE, tick_callback_requested = GLFW_FALSE;
15+
static GLFWbool keep_going = GLFW_FALSE;
1616

1717
void _glfwPlatformRequestTickCallback() {
18-
tick_callback_requested = GLFW_TRUE;
1918
}
2019

2120
void _glfwPlatformStopMainLoop(void) {
@@ -25,16 +24,12 @@ void _glfwPlatformStopMainLoop(void) {
2524
}
2625
}
2726

28-
void _glfwPlatformRunMainLoop(GLFWtickcallback callback, void* data) {
27+
void _glfwPlatformRunMainLoop(GLFWtickcallback tick_callback, void* data) {
2928
keep_going = GLFW_TRUE;
30-
tick_callback_requested = GLFW_FALSE;
3129
while(keep_going) {
32-
EVDBG("tick_callback_requested: %d", tick_callback_requested);
33-
while (tick_callback_requested) {
34-
tick_callback_requested = GLFW_FALSE;
35-
callback(data);
36-
}
3730
_glfwPlatformWaitEvents();
31+
EVDBG("loop tick");
32+
tick_callback(data);
3833
}
3934
}
4035

kitty/child-monitor.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,8 +940,7 @@ process_global_state(void *data) {
940940
if (global_state.has_pending_closes) has_open_windows = process_pending_closes(self);
941941
if (has_open_windows) {
942942
if (maximum_wait >= 0) {
943-
if (maximum_wait == 0) request_tick_callback();
944-
else state_check_timer_enabled = true;
943+
state_check_timer_enabled = true;
945944
}
946945
} else {
947946
stop_main_loop();

kitty/glfw.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ static GLFWcursor *standard_cursor = NULL, *click_cursor = NULL, *arrow_cursor =
2727

2828
static void set_os_window_dpi(OSWindow *w);
2929

30+
31+
static void
32+
request_tick_callback(void) {
33+
#ifdef __APPLE__
34+
glfwRequestTickCallback();
35+
#endif
36+
}
37+
3038
void
3139
update_os_window_viewport(OSWindow *window, bool notify_boss) {
3240
int w, h, fw, fh;
@@ -1128,11 +1136,6 @@ run_main_loop(tick_callback_fun cb, void* cb_data) {
11281136
glfwRunMainLoop(cb, cb_data);
11291137
}
11301138

1131-
void
1132-
request_tick_callback(void) {
1133-
glfwRequestTickCallback();
1134-
}
1135-
11361139
void
11371140
stop_main_loop(void) {
11381141
glfwStopMainLoop();

kitty/state.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,5 +238,4 @@ id_type add_main_loop_timer(double interval, bool repeats, timer_callback_fun ca
238238
void remove_main_loop_timer(id_type timer_id);
239239
void update_main_loop_timer(id_type timer_id, double interval, bool enabled);
240240
void run_main_loop(tick_callback_fun, void*);
241-
void request_tick_callback(void);
242241
void stop_main_loop(void);

0 commit comments

Comments
 (0)