mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-27 18:51:41 +02:00
Linux: Only process global state when something interesting happens
This matches behavior on macOS. Had initially set the code to process on every loop tick in an attmept to workaround the issue of the event loop freezing on X11 until an X event is delivered. However, in light of #1782 that workaround was incorrect anyway. Better to have similar behavior across platforms. This also has the advantage of reducing CPU consumption. Also add a simple program to test event loop wakeups.
This commit is contained in:
25
glfw/main_loop.h
vendored
25
glfw/main_loop.h
vendored
@@ -12,9 +12,11 @@
|
||||
#define GLFW_LOOP_BACKEND x11
|
||||
#endif
|
||||
|
||||
static bool keep_going = false;
|
||||
static bool keep_going = false, tick_callback_requested = false;
|
||||
|
||||
void _glfwPlatformRequestTickCallback() {
|
||||
EVDBG("tick_callback requested");
|
||||
tick_callback_requested = true;
|
||||
}
|
||||
|
||||
void _glfwPlatformStopMainLoop(void) {
|
||||
@@ -24,15 +26,26 @@ void _glfwPlatformStopMainLoop(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void _glfwPlatformRunMainLoop(GLFWtickcallback tick_callback, void* data) {
|
||||
keep_going = true;
|
||||
while(keep_going) {
|
||||
_glfwPlatformWaitEvents();
|
||||
EVDBG("loop tick");
|
||||
static inline void
|
||||
dispatch_tick_callbacks(GLFWtickcallback tick_callback, void *data) {
|
||||
while (tick_callback_requested) {
|
||||
EVDBG("Calling tick callback");
|
||||
tick_callback_requested = false;
|
||||
tick_callback(data);
|
||||
}
|
||||
}
|
||||
|
||||
void _glfwPlatformRunMainLoop(GLFWtickcallback tick_callback, void* data) {
|
||||
keep_going = true;
|
||||
tick_callback_requested = false;
|
||||
while(keep_going) {
|
||||
EVDBG("loop tick, tick_callback_requested: %d", tick_callback_requested);
|
||||
dispatch_tick_callbacks(tick_callback, data);
|
||||
_glfwPlatformWaitEvents();
|
||||
}
|
||||
EVDBG("main loop exiting");
|
||||
}
|
||||
|
||||
unsigned long long _glfwPlatformAddTimer(double interval, bool repeats, GLFWuserdatafreefun callback, void *callback_data, GLFWuserdatafreefun free_callback) {
|
||||
return addTimer(&_glfw.GLFW_LOOP_BACKEND.eventLoopData, "user timer", interval, 1, repeats, callback, callback_data, free_callback);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user