mirror of
https://github.com/glfw/glfw.git
synced 2025-10-04 05:36:35 +00:00
wl: Fix PostEmptyEvent not waking WaitEvents
Use an eventfd as a means to signal waitEvents to wake up as wl_display_sync does not always achieve this. This fixes GitHub Issue #1520
This commit is contained in:
parent
d834f01ca4
commit
148b683f53
@ -35,6 +35,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <unistd.h>
|
||||
@ -1152,6 +1153,8 @@ int _glfwPlatformInit(void)
|
||||
if (_glfw.wl.seatVersion >= 4)
|
||||
_glfw.wl.timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
|
||||
|
||||
_glfw.wl.eventfd = eventfd(0, 0);
|
||||
|
||||
if (!_glfw.wl.wmBase)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
@ -1288,6 +1291,8 @@ void _glfwPlatformTerminate(void)
|
||||
|
||||
if (_glfw.wl.timerfd >= 0)
|
||||
close(_glfw.wl.timerfd);
|
||||
if (_glfw.wl.eventfd >= 0)
|
||||
close(_glfw.wl.eventfd);
|
||||
if (_glfw.wl.cursorTimerfd >= 0)
|
||||
close(_glfw.wl.cursorTimerfd);
|
||||
|
||||
|
@ -259,6 +259,7 @@ typedef struct _GLFWlibraryWayland
|
||||
char* clipboardSendString;
|
||||
size_t clipboardSendSize;
|
||||
int timerfd;
|
||||
int eventfd;
|
||||
short int keycodes[256];
|
||||
short int scancodes[GLFW_KEY_LAST + 1];
|
||||
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <sys/eventfd.h>
|
||||
#include <poll.h>
|
||||
|
||||
|
||||
@ -709,6 +710,7 @@ static void handleEvents(int timeout)
|
||||
{ wl_display_get_fd(display), POLLIN },
|
||||
{ _glfw.wl.timerfd, POLLIN },
|
||||
{ _glfw.wl.cursorTimerfd, POLLIN },
|
||||
{ _glfw.wl.eventfd, POLLIN },
|
||||
};
|
||||
ssize_t read_ret;
|
||||
uint64_t repeats, i;
|
||||
@ -731,7 +733,7 @@ static void handleEvents(int timeout)
|
||||
return;
|
||||
}
|
||||
|
||||
if (poll(fds, 3, timeout) > 0)
|
||||
if (poll(fds, 4, timeout) > 0)
|
||||
{
|
||||
if (fds[0].revents & POLLIN)
|
||||
{
|
||||
@ -763,6 +765,11 @@ static void handleEvents(int timeout)
|
||||
|
||||
incrementCursorImage(_glfw.wl.pointerFocus);
|
||||
}
|
||||
|
||||
if (fds[3].revents & POLLIN)
|
||||
{
|
||||
read_ret = read(_glfw.wl.eventfd, &repeats, sizeof(repeats));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1176,7 +1183,8 @@ void _glfwPlatformWaitEventsTimeout(double timeout)
|
||||
|
||||
void _glfwPlatformPostEmptyEvent(void)
|
||||
{
|
||||
wl_display_sync(_glfw.wl.display);
|
||||
uint64_t value = 1;
|
||||
write(_glfw.wl.eventfd, &value, sizeof value);
|
||||
}
|
||||
|
||||
void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos)
|
||||
|
Loading…
Reference in New Issue
Block a user