mirror of
https://github.com/glfw/glfw.git
synced 2024-11-10 09:01:46 +00:00
wayland: Handle disconnect properly
Merge code for PollEvents and WaitEvents, and handle disconnect properly.
This commit is contained in:
parent
5268914b3f
commit
4974585d04
@ -114,6 +114,43 @@ createTmpfileCloexec(char* tmpname)
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
handleEvents(int timeout)
|
||||||
|
{
|
||||||
|
struct wl_display* display = _glfw.wl.display;
|
||||||
|
struct pollfd fds[] = {
|
||||||
|
{ wl_display_get_fd(display), POLLIN },
|
||||||
|
};
|
||||||
|
|
||||||
|
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
|
||||||
|
// can.
|
||||||
|
if (wl_display_flush(display) < 0 && errno != EAGAIN)
|
||||||
|
{
|
||||||
|
_GLFWwindow* window = _glfw.windowListHead;
|
||||||
|
while (window)
|
||||||
|
{
|
||||||
|
_glfwInputWindowCloseRequest(window);
|
||||||
|
window = window->next;
|
||||||
|
}
|
||||||
|
wl_display_cancel_read(display);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (poll(fds, 1, timeout) > 0)
|
||||||
|
{
|
||||||
|
wl_display_read_events(display);
|
||||||
|
wl_display_dispatch_pending(display);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wl_display_cancel_read(display);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a new, unique, anonymous file of the given size, and
|
* Create a new, unique, anonymous file of the given size, and
|
||||||
* return the file descriptor for it. The file descriptor is set
|
* return the file descriptor for it. The file descriptor is set
|
||||||
@ -327,44 +364,12 @@ int _glfwPlatformWindowVisible(_GLFWwindow* window)
|
|||||||
|
|
||||||
void _glfwPlatformPollEvents(void)
|
void _glfwPlatformPollEvents(void)
|
||||||
{
|
{
|
||||||
struct wl_display* display = _glfw.wl.display;
|
handleEvents(0);
|
||||||
struct pollfd fds[] = {
|
|
||||||
{ wl_display_get_fd(display), POLLIN },
|
|
||||||
};
|
|
||||||
|
|
||||||
while (wl_display_prepare_read(display) != 0)
|
|
||||||
wl_display_dispatch_pending(display);
|
|
||||||
wl_display_flush(display);
|
|
||||||
if (poll(fds, 1, 0) > 0)
|
|
||||||
{
|
|
||||||
wl_display_read_events(display);
|
|
||||||
wl_display_dispatch_pending(display);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wl_display_cancel_read(display);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glfwPlatformWaitEvents(void)
|
void _glfwPlatformWaitEvents(void)
|
||||||
{
|
{
|
||||||
struct wl_display* display = _glfw.wl.display;
|
handleEvents(-1);
|
||||||
struct pollfd fds[] = {
|
|
||||||
{ wl_display_get_fd(display), POLLIN },
|
|
||||||
};
|
|
||||||
|
|
||||||
while (wl_display_prepare_read(display) != 0)
|
|
||||||
wl_display_dispatch_pending(display);
|
|
||||||
wl_display_flush(display);
|
|
||||||
if (poll(fds, 1, -1) > 0)
|
|
||||||
{
|
|
||||||
wl_display_read_events(display);
|
|
||||||
wl_display_dispatch_pending(display);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wl_display_cancel_read(display);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _glfwPlatformPostEmptyEvent(void)
|
void _glfwPlatformPostEmptyEvent(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user