Wayland: Clean up event pump

Adapt style to the rest of the project.
This commit is contained in:
Camilla Löwy 2021-12-26 22:01:32 +01:00
parent 855d338a65
commit 79e7e65c9d

View File

@ -708,22 +708,19 @@ static void incrementCursorImage(_GLFWwindow* window)
static void handleEvents(int timeout) static void handleEvents(int timeout)
{ {
struct wl_display* display = _glfw.wl.display; struct pollfd fds[] =
struct pollfd fds[] = { {
{ wl_display_get_fd(display), POLLIN }, { wl_display_get_fd(_glfw.wl.display), POLLIN },
{ _glfw.wl.timerfd, POLLIN }, { _glfw.wl.timerfd, POLLIN },
{ _glfw.wl.cursorTimerfd, POLLIN }, { _glfw.wl.cursorTimerfd, POLLIN },
}; };
ssize_t read_ret;
uint64_t repeats;
while (wl_display_prepare_read(display) != 0) while (wl_display_prepare_read(_glfw.wl.display) != 0)
wl_display_dispatch_pending(display); wl_display_dispatch_pending(_glfw.wl.display);
// If an error different from EAGAIN happens, we have likely been // If an error other than EAGAIN happens, we have likely been disconnected
// disconnected from the Wayland session, try to handle that the best we // from the Wayland session; try to handle that the best we can.
// can. if (wl_display_flush(_glfw.wl.display) < 0 && errno != EAGAIN)
if (wl_display_flush(display) < 0 && errno != EAGAIN)
{ {
_GLFWwindow* window = _glfw.windowListHead; _GLFWwindow* window = _glfw.windowListHead;
while (window) while (window)
@ -731,7 +728,8 @@ static void handleEvents(int timeout)
_glfwInputWindowCloseRequest(window); _glfwInputWindowCloseRequest(window);
window = window->next; window = window->next;
} }
wl_display_cancel_read(display);
wl_display_cancel_read(_glfw.wl.display);
return; return;
} }
@ -739,41 +737,42 @@ static void handleEvents(int timeout)
{ {
if (fds[0].revents & POLLIN) if (fds[0].revents & POLLIN)
{ {
wl_display_read_events(display); wl_display_read_events(_glfw.wl.display);
wl_display_dispatch_pending(display); wl_display_dispatch_pending(_glfw.wl.display);
} }
else else
{ wl_display_cancel_read(_glfw.wl.display);
wl_display_cancel_read(display);
}
if (fds[1].revents & POLLIN) if (fds[1].revents & POLLIN)
{ {
read_ret = read(_glfw.wl.timerfd, &repeats, sizeof(repeats)); uint64_t repeats;
if (read_ret == 8 && _glfw.wl.keyboardFocus)
if (read(_glfw.wl.timerfd, &repeats, sizeof(repeats)) == 8)
{ {
for (uint64_t i = 0; i < repeats; ++i) if (_glfw.wl.keyboardFocus)
{ {
_glfwInputKey(_glfw.wl.keyboardFocus, for (uint64_t i = 0; i < repeats; i++)
_glfw.wl.keyboardLastKey, {
_glfw.wl.keyboardLastScancode, _glfwInputKey(_glfw.wl.keyboardFocus,
GLFW_REPEAT, _glfw.wl.keyboardLastKey,
_glfw.wl.xkb.modifiers); _glfw.wl.keyboardLastScancode,
GLFW_REPEAT,
_glfw.wl.xkb.modifiers);
}
} }
} }
} }
if (fds[2].revents & POLLIN) if (fds[2].revents & POLLIN)
{ {
read_ret = read(_glfw.wl.cursorTimerfd, &repeats, sizeof(repeats)); uint64_t repeats;
if (read_ret == 8)
if (read(_glfw.wl.cursorTimerfd, &repeats, sizeof(repeats)) == 8)
incrementCursorImage(_glfw.wl.pointerFocus); incrementCursorImage(_glfw.wl.pointerFocus);
} }
} }
else else
{ wl_display_cancel_read(_glfw.wl.display);
wl_display_cancel_read(display);
}
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////