From 8841bd96605122340c9ea2e743b44463998eb16d Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 16 Aug 2022 12:25:18 +1000 Subject: GHOST/Wayland: Add NDOF support Logic for NDOF devices is shared with X11, process events using GHOST_NDOFManagerUnix when WITH_INPUT_NDOF is enabled. --- intern/ghost/intern/GHOST_SystemWayland.cpp | 39 +++++++++++++++++++++++++++-- intern/ghost/intern/GHOST_SystemWayland.h | 2 ++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp index 6a90cf5c71e..df9f2a899e0 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cpp +++ b/intern/ghost/intern/GHOST_SystemWayland.cpp @@ -19,6 +19,10 @@ #include "GHOST_ContextEGL.h" +#ifdef WITH_INPUT_NDOF +# include "GHOST_NDOFManagerUnix.h" +#endif + #ifdef WITH_GHOST_WAYLAND_DYNLOAD # include /* For `ghost_wl_dynload_libraries`. */ #endif @@ -2987,9 +2991,36 @@ GHOST_SystemWayland::~GHOST_SystemWayland() display_destroy(d); } +GHOST_TSuccess GHOST_SystemWayland::init() +{ + GHOST_TSuccess success = GHOST_System::init(); + + if (success) { +#ifdef WITH_INPUT_NDOF + m_ndofManager = new GHOST_NDOFManagerUnix(*this); +#endif + return GHOST_kSuccess; + } + + return GHOST_kFailure; +} + bool GHOST_SystemWayland::processEvents(bool waitForEvent) { - const bool fired = getTimerManager()->fireTimers(getMilliSeconds()); + bool any_processed = false; + + if (getTimerManager()->fireTimers(getMilliSeconds())) { + any_processed = true; + } + +#ifdef WITH_INPUT_NDOF + if (static_cast(m_ndofManager)->processEvents()) { + /* As NDOF bypasses WAYLAND event handling, + * never wait for an event when an NDOF event was found. */ + waitForEvent = false; + any_processed = true; + } +#endif /* WITH_INPUT_NDOF */ if (waitForEvent) { wl_display_dispatch(d->display); @@ -2998,7 +3029,11 @@ bool GHOST_SystemWayland::processEvents(bool waitForEvent) wl_display_roundtrip(d->display); } - return fired || (getEventManager()->getNumEvents() > 0); + if ((getEventManager()->getNumEvents() > 0)) { + any_processed = true; + } + + return any_processed; } int GHOST_SystemWayland::setConsoleWindowState(GHOST_TConsoleWindowState /*action*/) diff --git a/intern/ghost/intern/GHOST_SystemWayland.h b/intern/ghost/intern/GHOST_SystemWayland.h index bdf5f2fc273..632f4bf28d8 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.h +++ b/intern/ghost/intern/GHOST_SystemWayland.h @@ -93,6 +93,8 @@ class GHOST_SystemWayland : public GHOST_System { ~GHOST_SystemWayland() override; + GHOST_TSuccess init(); + bool processEvents(bool waitForEvent) override; int setConsoleWindowState(GHOST_TConsoleWindowState action) override; -- cgit v1.2.3