Skip to content

Commit

Permalink
XWindowsEventQueueBuffer: Fix delays when waiting for new events
Browse files Browse the repository at this point in the history
QLength() may return 0 even if there are events pending because they
need to be read from the display socket in order to become visible. We
must use XPending() which will poll the socket if QLength() == 0.
  • Loading branch information
p12tic committed May 20, 2020
1 parent dbd1082 commit 7d2d395
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/platform/XWindowsEventQueueBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ XWindowsEventQueueBuffer::~XWindowsEventQueueBuffer()
close(m_pipefd[1]);
}

int XWindowsEventQueueBuffer::getPendingCountLocked()
{
Lock lock(&m_mutex);
return XPending(m_display);
}

void
XWindowsEventQueueBuffer::waitForEvent(double dtimeout)
{
Expand Down Expand Up @@ -163,7 +169,7 @@ XWindowsEventQueueBuffer::waitForEvent(double dtimeout)
// we want to give the cpu a chance s owe up this to 25ms
#define TIMEOUT_DELAY 25

while (((dtimeout < 0.0) || (remaining > 0)) && QLength(m_display)==0 && retval==0){
while (((dtimeout < 0.0) || (remaining > 0)) && getPendingCountLocked() == 0 && retval == 0) {
#if HAVE_POLL
retval = poll(pfds, 2, TIMEOUT_DELAY); //16ms = 60hz, but we make it > to play nicely with the cpu
if (pfds[1].revents & POLLIN) {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/platform/XWindowsEventQueueBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class XWindowsEventQueueBuffer : public IEventQueueBuffer {
private:
void flush();

int getPendingCountLocked();

private:
typedef std::vector<XEvent> EventList;
IXWindowsImpl* m_impl;
Expand Down

0 comments on commit 7d2d395

Please sign in to comment.