From 012c7d00d24ff983c135444da1c21f54eef9b48f Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 7 Aug 2019 12:44:42 +0100 Subject: [PATCH] Linux: Fix for high CPU load --- .../native/juce_linux_Messaging.cpp | 2 +- .../native/juce_linux_X11_Windowing.cpp | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/juce_events/native/juce_linux_Messaging.cpp b/modules/juce_events/native/juce_linux_Messaging.cpp index 33bfbadad4..9f20e95b45 100644 --- a/modules/juce_events/native/juce_linux_Messaging.cpp +++ b/modules/juce_events/native/juce_linux_Messaging.cpp @@ -124,7 +124,7 @@ public: const ScopedLock sl (lock); fdReadCallbacks.push_back ({ fd, std::move (cb) }); - pfds.push_back ({ fd, POLLIN | POLLOUT, 0 }); + pfds.push_back ({ fd, POLLIN, 0 }); } void unregisterFdCallback (int fd) diff --git a/modules/juce_gui_basics/native/juce_linux_X11_Windowing.cpp b/modules/juce_gui_basics/native/juce_linux_X11_Windowing.cpp index 00de9d6b89..40e5e1ccd8 100644 --- a/modules/juce_gui_basics/native/juce_linux_X11_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_linux_X11_Windowing.cpp @@ -1661,7 +1661,7 @@ public: if (XSHMHelpers::isShmAvailable (display)) { ScopedXLock xlock (display); - if (event.xany.type == XShmGetEventBase (display)) + if (event.xany.type == shmCompletionEvent) repainter->notifyPaintCompleted(); } #endif @@ -2269,6 +2269,15 @@ private: void timerCallback() override { #if JUCE_USE_XSHM + if (shmPaintsPending != 0) + { + ScopedXLock xlock (display); + + XEvent evt; + while (XCheckTypedWindowEvent (display, peer.windowH, peer.shmCompletionEvent, &evt)) + --shmPaintsPending; + } + if (shmPaintsPending != 0) return; #endif @@ -2399,6 +2408,10 @@ private: enum { KeyPressEventType = 2 }; static ::Display* display; + #if JUCE_USE_XSHM + int shmCompletionEvent = 0; + #endif + struct MotifWmHints { unsigned long flags; @@ -2728,6 +2741,11 @@ private: initialisePointerMap(); updateModifierMappings(); + + #if JUCE_USE_XSHM + if (XSHMHelpers::isShmAvailable (display)) + shmCompletionEvent = XShmGetEventBase (display) + ShmCompletion; + #endif } void destroyWindow()