mirror of
https://github.com/glfw/glfw.git
synced 2026-09-23 00:59:48 +00:00
Add glfwWaitEventsTimeout
This function will put the calling thread to sleep until an event arrives or until the specified timeout has elapsed.
This commit is contained in:
@@ -1912,6 +1912,28 @@ void _glfwPlatformWaitEvents(void)
|
||||
_glfwPlatformPollEvents();
|
||||
}
|
||||
|
||||
void _glfwPlatformWaitEventsTimeout(double timeout)
|
||||
{
|
||||
const double deadline = timeout + _glfwPlatformGetTimerValue() /
|
||||
(double) _glfwPlatformGetTimerFrequency();
|
||||
|
||||
while (!XPending(_glfw.x11.display))
|
||||
{
|
||||
const double remaining = deadline - _glfwPlatformGetTimerValue() /
|
||||
(double) _glfwPlatformGetTimerFrequency();
|
||||
if (remaining <= 0.0)
|
||||
return;
|
||||
|
||||
const long seconds = (long) remaining;
|
||||
const long microseconds = (long) ((remaining - seconds) * 1e6);
|
||||
struct timeval tv = { seconds, microseconds };
|
||||
|
||||
selectDisplayConnection(&tv);
|
||||
}
|
||||
|
||||
_glfwPlatformPollEvents();
|
||||
}
|
||||
|
||||
void _glfwPlatformPostEmptyEvent(void)
|
||||
{
|
||||
XEvent event;
|
||||
|
||||
Reference in New Issue
Block a user