mirror of
https://github.com/glfw/glfw.git
synced 2025-01-19 14:32:49 +00:00
Added select to all custom X11 event polling.
All loops waiting for specific events now use select to sleep while there is no new data.
This commit is contained in:
parent
e8f8ec027d
commit
eb7688df8f
@ -58,6 +58,22 @@ typedef struct
|
|||||||
#define MWM_HINTS_DECORATIONS (1L << 1)
|
#define MWM_HINTS_DECORATIONS (1L << 1)
|
||||||
|
|
||||||
|
|
||||||
|
// Wait for data to arrive
|
||||||
|
//
|
||||||
|
void selectDisplayConnection(struct timeval* timeout)
|
||||||
|
{
|
||||||
|
fd_set fds;
|
||||||
|
const int fd = ConnectionNumber(_glfw.x11.display);
|
||||||
|
|
||||||
|
FD_ZERO(&fds);
|
||||||
|
FD_SET(fd, &fds);
|
||||||
|
|
||||||
|
// select(1) is used instead of an X function like XNextEvent, as the
|
||||||
|
// wait inside those are guarded by the mutex protecting the display
|
||||||
|
// struct, locking out other threads from using X (including GLX)
|
||||||
|
select(fd + 1, &fds, NULL, NULL, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
// Returns whether the window is iconified
|
// Returns whether the window is iconified
|
||||||
//
|
//
|
||||||
static int getWindowState(_GLFWwindow* window)
|
static int getWindowState(_GLFWwindow* window)
|
||||||
@ -684,9 +700,8 @@ static void pushSelectionToManager(_GLFWwindow* window)
|
|||||||
{
|
{
|
||||||
XEvent event;
|
XEvent event;
|
||||||
|
|
||||||
if (!XCheckIfEvent(_glfw.x11.display, &event, isSelectionEvent, NULL))
|
while (XCheckIfEvent(_glfw.x11.display, &event, isSelectionEvent, NULL))
|
||||||
continue;
|
{
|
||||||
|
|
||||||
switch (event.type)
|
switch (event.type)
|
||||||
{
|
{
|
||||||
case SelectionRequest:
|
case SelectionRequest:
|
||||||
@ -712,6 +727,9 @@ static void pushSelectionToManager(_GLFWwindow* window)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
selectDisplayConnection(NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enter full screen mode
|
// Enter full screen mode
|
||||||
@ -1614,22 +1632,25 @@ void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
|
|||||||
// If you are affected by this and your window manager is NOT
|
// If you are affected by this and your window manager is NOT
|
||||||
// listed above, PLEASE report it to their and our issue trackers
|
// listed above, PLEASE report it to their and our issue trackers
|
||||||
base = _glfwPlatformGetTime();
|
base = _glfwPlatformGetTime();
|
||||||
for (;;)
|
while (!XCheckIfEvent(_glfw.x11.display,
|
||||||
{
|
|
||||||
if (_glfwPlatformGetTime() - base > 0.5)
|
|
||||||
{
|
|
||||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
|
||||||
"X11: The window manager has a broken _NET_REQUEST_FRAME_EXTENTS implementation; please report this issue");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (XCheckIfEvent(_glfw.x11.display,
|
|
||||||
&event,
|
&event,
|
||||||
isFrameExtentsEvent,
|
isFrameExtentsEvent,
|
||||||
(XPointer) window))
|
(XPointer) window))
|
||||||
{
|
{
|
||||||
break;
|
double remaining;
|
||||||
|
struct timeval timeout;
|
||||||
|
|
||||||
|
remaining = 0.5 + base - _glfwPlatformGetTime();
|
||||||
|
if (remaining <= 0.0)
|
||||||
|
{
|
||||||
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||||
|
"X11: The window manager has a broken _NET_REQUEST_FRAME_EXTENTS implementation; please report this issue");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timeout.tv_sec = 0;
|
||||||
|
timeout.tv_usec = (long) (remaining * 1e6);
|
||||||
|
selectDisplayConnection(&timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1743,19 +1764,7 @@ void _glfwPlatformPollEvents(void)
|
|||||||
void _glfwPlatformWaitEvents(void)
|
void _glfwPlatformWaitEvents(void)
|
||||||
{
|
{
|
||||||
if (!XPending(_glfw.x11.display))
|
if (!XPending(_glfw.x11.display))
|
||||||
{
|
selectDisplayConnection(NULL);
|
||||||
fd_set fds;
|
|
||||||
const int fd = ConnectionNumber(_glfw.x11.display);
|
|
||||||
|
|
||||||
FD_ZERO(&fds);
|
|
||||||
FD_SET(fd, &fds);
|
|
||||||
|
|
||||||
// select(1) is used instead of an X function like XNextEvent, as the
|
|
||||||
// wait inside those are guarded by the mutex protecting the display
|
|
||||||
// struct, locking out other threads from using X (including GLX)
|
|
||||||
if (select(fd + 1, &fds, NULL, NULL, NULL) < 0)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_glfwPlatformPollEvents();
|
_glfwPlatformPollEvents();
|
||||||
}
|
}
|
||||||
@ -1912,7 +1921,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
|
|||||||
// XCheckTypedEvent is used instead of XIfEvent in order not to lock
|
// XCheckTypedEvent is used instead of XIfEvent in order not to lock
|
||||||
// other threads out from the display during the entire wait period
|
// other threads out from the display during the entire wait period
|
||||||
while (!XCheckTypedEvent(_glfw.x11.display, SelectionNotify, &event))
|
while (!XCheckTypedEvent(_glfw.x11.display, SelectionNotify, &event))
|
||||||
;
|
selectDisplayConnection(NULL);
|
||||||
|
|
||||||
if (event.xselection.property == None)
|
if (event.xselection.property == None)
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user