mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-27 18:51:41 +02:00
Implement timers for the linux event loops
Needed for dbus integration. Also cleanup the event handling code. X11 and Wayland now share most of their event polling and dispatch logic.
This commit is contained in:
45
glfw/wl_window.c
vendored
45
glfw/wl_window.c
vendored
@@ -688,34 +688,14 @@ static GLFWbool createXdgSurface(_GLFWwindow* window)
|
||||
return GLFW_TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
dispatchPendingKeyRepeats() {
|
||||
if (_glfw.wl.keyRepeatInfo.nextRepeatAt <= 0 || _glfw.wl.keyRepeatInfo.keyboardFocus != _glfw.wl.keyboardFocus || _glfw.wl.keyboardRepeatRate == 0) return;
|
||||
double now = glfwGetTime();
|
||||
while (_glfw.wl.keyRepeatInfo.nextRepeatAt <= now) {
|
||||
glfw_xkb_handle_key_event(_glfw.wl.keyRepeatInfo.keyboardFocus, &_glfw.wl.xkb, _glfw.wl.keyRepeatInfo.key, GLFW_REPEAT);
|
||||
_glfw.wl.keyRepeatInfo.nextRepeatAt += 1.0 / _glfw.wl.keyboardRepeatRate;
|
||||
now = glfwGetTime();
|
||||
}
|
||||
}
|
||||
|
||||
static double
|
||||
adjustTimeoutForKeyRepeat(double timeout) {
|
||||
if (_glfw.wl.keyRepeatInfo.nextRepeatAt <= 0 || _glfw.wl.keyRepeatInfo.keyboardFocus != _glfw.wl.keyboardFocus || _glfw.wl.keyboardRepeatRate == 0) return timeout;
|
||||
double now = glfwGetTime();
|
||||
if (timeout < 0 || now + timeout > _glfw.wl.keyRepeatInfo.nextRepeatAt) {
|
||||
timeout = _glfw.wl.keyRepeatInfo.nextRepeatAt <= now ? 0 : ( (_glfw.wl.keyRepeatInfo.nextRepeatAt - now) + 0.001 );
|
||||
}
|
||||
return timeout;
|
||||
}
|
||||
|
||||
static void
|
||||
handleEvents(double timeout)
|
||||
{
|
||||
struct wl_display* display = _glfw.wl.display;
|
||||
|
||||
while (wl_display_prepare_read(display) != 0)
|
||||
while (wl_display_prepare_read(display) != 0) {
|
||||
wl_display_dispatch_pending(display);
|
||||
}
|
||||
|
||||
// If an error different from EAGAIN happens, we have likely been
|
||||
// disconnected from the Wayland session, try to handle that the best we
|
||||
@@ -732,24 +712,8 @@ handleEvents(double timeout)
|
||||
return;
|
||||
}
|
||||
|
||||
dispatchPendingKeyRepeats();
|
||||
timeout = adjustTimeoutForKeyRepeat(timeout);
|
||||
GLFWbool read_ok = GLFW_FALSE;
|
||||
prepareForPoll(&_glfw.wl.eventLoopData);
|
||||
|
||||
if (timeout >= 0) {
|
||||
const int result = pollWithTimeout(_glfw.wl.eventLoopData.fds, _glfw.wl.eventLoopData.fds_count, timeout);
|
||||
if (result > 0) {
|
||||
dispatchEvents(&_glfw.wl.eventLoopData);
|
||||
read_ok = _glfw.wl.eventLoopData.watches[0].ready;
|
||||
}
|
||||
} else {
|
||||
if (poll(_glfw.wl.eventLoopData.fds, _glfw.wl.eventLoopData.fds_count, -1) > 0) {
|
||||
dispatchEvents(&_glfw.wl.eventLoopData);
|
||||
read_ok = _glfw.wl.eventLoopData.watches[0].ready;
|
||||
}
|
||||
}
|
||||
if (read_ok) {
|
||||
GLFWbool display_read_ok = pollForEvents(&_glfw.wl.eventLoopData, timeout);
|
||||
if (display_read_ok) {
|
||||
wl_display_read_events(display);
|
||||
wl_display_dispatch_pending(display);
|
||||
}
|
||||
@@ -757,7 +721,6 @@ handleEvents(double timeout)
|
||||
{
|
||||
wl_display_cancel_read(display);
|
||||
}
|
||||
dispatchPendingKeyRepeats();
|
||||
}
|
||||
|
||||
// Translates a GLFW standard cursor to a theme cursor name
|
||||
|
||||
Reference in New Issue
Block a user