From bf3796aea7dc5cc54db08f00c2b0a3d191b319d3 Mon Sep 17 00:00:00 2001 From: Jamie Newbon Date: Fri, 22 May 2020 14:41:04 +0100 Subject: [PATCH 1/2] Revert "#6487 Changed timeout multiplier" This reverts commit a324957e --- src/lib/platform/XWindowsEventQueueBuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/platform/XWindowsEventQueueBuffer.cpp b/src/lib/platform/XWindowsEventQueueBuffer.cpp index 079dd50bc..71e2cfba8 100644 --- a/src/lib/platform/XWindowsEventQueueBuffer.cpp +++ b/src/lib/platform/XWindowsEventQueueBuffer.cpp @@ -120,7 +120,7 @@ XWindowsEventQueueBuffer::waitForEvent(double dtimeout) pfds[1].fd = m_pipefd[0]; pfds[1].events = POLLIN; int timeout = (dtimeout < 0.0) ? -1 : - static_cast(dtimeout); + static_cast(1000.0 * dtimeout); int remaining = timeout; int retval = 0; #else From 4308b42915516ba5a19a964142697582cedacb67 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Wed, 20 May 2020 22:11:14 +0300 Subject: [PATCH 2/2] #6487 XWindowsEventQueueBuffer: Fix delays when waiting for new events 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. --- src/lib/platform/XWindowsEventQueueBuffer.cpp | 8 +++++++- src/lib/platform/XWindowsEventQueueBuffer.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib/platform/XWindowsEventQueueBuffer.cpp b/src/lib/platform/XWindowsEventQueueBuffer.cpp index 71e2cfba8..eb0ec53f1 100644 --- a/src/lib/platform/XWindowsEventQueueBuffer.cpp +++ b/src/lib/platform/XWindowsEventQueueBuffer.cpp @@ -81,6 +81,12 @@ XWindowsEventQueueBuffer::~XWindowsEventQueueBuffer() close(m_pipefd[1]); } +int XWindowsEventQueueBuffer::getPendingCountLocked() +{ + Lock lock(&m_mutex); + return XPending(m_display); +} + void XWindowsEventQueueBuffer::waitForEvent(double dtimeout) { @@ -162,7 +168,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) { diff --git a/src/lib/platform/XWindowsEventQueueBuffer.h b/src/lib/platform/XWindowsEventQueueBuffer.h index 7614deead..784ba8133 100644 --- a/src/lib/platform/XWindowsEventQueueBuffer.h +++ b/src/lib/platform/XWindowsEventQueueBuffer.h @@ -49,6 +49,8 @@ public: private: void flush(); + int getPendingCountLocked(); + private: typedef std::vector EventList;