diff options
author | Mike Krus <mike.krus@kdab.com> | 2020-06-19 11:33:04 +0100 |
---|---|---|
committer | Mike Krus <mike.krus@kdab.com> | 2020-06-23 13:38:14 +0100 |
commit | c2730dc176707c0b77321dd4720516a8595856af (patch) | |
tree | 39bb23583ae661868fc9d71584f6e687642e3904 /src/input | |
parent | 6698aa9d22b116aaedf820727600e44e6fcf37a7 (diff) |
Clean input event handling
- Clean up header dependencies
- Remove EventSourceSettingHelper as threading is no longer an issue
- Remove some locks which are no longer needed
Change-Id: I071173d3b4c681f5420bd7a1f4cb13f80a9c9b2f
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/input')
-rw-r--r-- | src/input/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/input/backend/backend.pri | 2 | ||||
-rw-r--r-- | src/input/backend/eventsourcesetterhelper.cpp | 90 | ||||
-rw-r--r-- | src/input/backend/eventsourcesetterhelper_p.h | 95 | ||||
-rw-r--r-- | src/input/backend/inputhandler.cpp | 82 | ||||
-rw-r--r-- | src/input/backend/inputhandler_p.h | 12 | ||||
-rw-r--r-- | src/input/backend/keyboardeventfilter.cpp | 2 | ||||
-rw-r--r-- | src/input/frontend/qinputaspect.cpp | 3 |
8 files changed, 54 insertions, 233 deletions
diff --git a/src/input/CMakeLists.txt b/src/input/CMakeLists.txt index 1b14d09b1..f6a605d14 100644 --- a/src/input/CMakeLists.txt +++ b/src/input/CMakeLists.txt @@ -19,7 +19,6 @@ qt_add_module(3DInput backend/axissetting.cpp backend/axissetting_p.h backend/backendnode.cpp backend/backendnode_p.h backend/buttonaxisinput.cpp backend/buttonaxisinput_p.h - backend/eventsourcesetterhelper.cpp backend/eventsourcesetterhelper_p.h backend/genericdevicebackendnode.cpp backend/genericdevicebackendnode_p.h backend/handle_types_p.h backend/inputbackendnodefunctor_p.h diff --git a/src/input/backend/backend.pri b/src/input/backend/backend.pri index e1ddee9c7..2330d322f 100644 --- a/src/input/backend/backend.pri +++ b/src/input/backend/backend.pri @@ -31,7 +31,6 @@ HEADERS += \ $$PWD/inputchord_p.h \ $$PWD/inputsequence_p.h \ $$PWD/inputsettings_p.h \ - $$PWD/eventsourcesetterhelper_p.h \ $$PWD/job_common_p.h \ $$PWD/physicaldeviceproxy_p.h \ $$PWD/loadproxydevicejob_p.h \ @@ -68,7 +67,6 @@ SOURCES += \ $$PWD/inputchord.cpp \ $$PWD/inputsequence.cpp \ $$PWD/inputsettings.cpp \ - $$PWD/eventsourcesetterhelper.cpp \ $$PWD/physicaldeviceproxy.cpp \ $$PWD/loadproxydevicejob.cpp \ $$PWD/axisaccumulator.cpp \ diff --git a/src/input/backend/eventsourcesetterhelper.cpp b/src/input/backend/eventsourcesetterhelper.cpp deleted file mode 100644 index fe800a1a4..000000000 --- a/src/input/backend/eventsourcesetterhelper.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "eventsourcesetterhelper_p.h" - -#include <Qt3DInput/private/inputhandler_p.h> -#include <Qt3DCore/private/qeventfilterservice_p.h> - -QT_BEGIN_NAMESPACE - -namespace Qt3DInput { - -namespace Input { - -EventSourceSetterHelper::EventSourceSetterHelper(InputHandler *inputHandler) - : QObject() - , m_service(nullptr) - , m_inputHandler(inputHandler) - , m_lastEventSource(nullptr) -{ -} - -// Main thread -void EventSourceSetterHelper::setEventFilterService(Qt3DCore::QEventFilterService *service) -{ - m_service = service; -} - -// Main thread -void EventSourceSetterHelper::setEventSource(QObject *eventSource) -{ - if (eventSource && m_lastEventSource != eventSource) { - if (m_service) { - m_service->initialize(eventSource); - m_inputHandler->registerEventFilters(m_service); - m_lastEventSource = eventSource; - } - } -} - -void EventSourceSetterHelper::unsetEventSource(QObject *eventSource) -{ - if (m_service) { - m_inputHandler->unregisterEventFilters(m_service); - if (eventSource) - m_service->shutdown(eventSource); - } -} - -} // Input - -} // Qt3DInput - -QT_END_NAMESPACE diff --git a/src/input/backend/eventsourcesetterhelper_p.h b/src/input/backend/eventsourcesetterhelper_p.h deleted file mode 100644 index b8800d8a6..000000000 --- a/src/input/backend/eventsourcesetterhelper_p.h +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef EVENTSOURCESETTERHELPER_H -#define EVENTSOURCESETTERHELPER_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtCore/QMutex> -#include <QtCore/QObject> - -QT_BEGIN_NAMESPACE - -namespace Qt3DCore { -class QEventFilterService; -} - -namespace Qt3DInput { - -namespace Input { - -class InputHandler; - -class EventSourceSetterHelper : public QObject -{ - Q_OBJECT -public: - explicit EventSourceSetterHelper(InputHandler *inputHandler); - - // Called from aspect thread - void setEventFilterService(Qt3DCore::QEventFilterService *service); - - // Called from main thread - void setEventSource(QObject *eventSource); - void unsetEventSource(QObject *eventSource); - -private: - Qt3DCore::QEventFilterService *m_service; - InputHandler *m_inputHandler; - QObject *m_lastEventSource; - QMutex m_mutex; -}; - -} // Input - -} // Qt3DInput - -QT_END_NAMESPACE - -#endif // EVENTSOURCESETTERHELPER_H diff --git a/src/input/backend/inputhandler.cpp b/src/input/backend/inputhandler.cpp index adaaebc88..6c9b7a533 100644 --- a/src/input/backend/inputhandler.cpp +++ b/src/input/backend/inputhandler.cpp @@ -40,7 +40,6 @@ #include "inputhandler_p.h" #include <Qt3DInput/private/assignkeyboardfocusjob_p.h> -#include <Qt3DInput/private/eventsourcesetterhelper_p.h> #include <Qt3DInput/private/inputmanagers_p.h> #include <Qt3DInput/private/inputsettings_p.h> #include <Qt3DInput/private/keyboardeventfilter_p.h> @@ -77,13 +76,11 @@ InputHandler::InputHandler() , m_genericPhysicalDeviceBackendNodeManager(new GenericDeviceBackendNodeManager) , m_physicalDeviceProxyManager(new PhysicalDeviceProxyManager()) , m_settings(nullptr) - , m_eventSourceSetter(new Qt3DInput::Input::EventSourceSetterHelper(this)) + , m_service(nullptr) + , m_lastEventSource(nullptr) { m_keyboardEventFilter->setInputHandler(this); m_mouseEventFilter->setInputHandler(this); - - // Created in the main thread - // m_eventSourceSetter needs to be in the main thread } InputHandler::~InputHandler() @@ -109,19 +106,56 @@ InputHandler::~InputHandler() } // Called in MainThread (by the EventSourceHelperSetter) -void InputHandler::registerEventFilters(QEventFilterService *service) +void InputHandler::registerEventFilters() { clearPendingKeyEvents(); clearPendingMouseEvents(); - service->registerEventFilter(m_keyboardEventFilter, 512); - service->registerEventFilter(m_mouseEventFilter, 513); + if (m_service) { + m_service->registerEventFilter(m_keyboardEventFilter, 512); + m_service->registerEventFilter(m_mouseEventFilter, 513); + } +} + +void InputHandler::unregisterEventFilters() +{ + if (m_service) { + m_service->unregisterEventFilter(m_keyboardEventFilter); + m_service->unregisterEventFilter(m_mouseEventFilter); + } +} + +void InputHandler::setInputSettings(InputSettings *settings) +{ + if (m_settings && settings == nullptr) { + unregisterEventFilters(); + m_lastEventSource = nullptr; + if (m_settings->eventSource() && m_service) + m_service->shutdown(m_settings->eventSource()); + } + if (m_service) { + unregisterEventFilters(); + if (m_settings && m_settings->eventSource()) + m_service->shutdown(m_settings->eventSource()); + } + m_settings = settings; } -void InputHandler::unregisterEventFilters(Qt3DCore::QEventFilterService *service) +void InputHandler::updateEventSource() { - service->unregisterEventFilter(m_keyboardEventFilter); - service->unregisterEventFilter(m_mouseEventFilter); + // Called every frame from input aspect + // Should probably just listen to changes in source property on settings object + if (!m_settings || !m_service) + return; + + // Will be updated only if eventSource is different than + // what was set last + QObject *eventSource = m_settings->eventSource(); + if (eventSource && m_lastEventSource != eventSource) { + m_service->initialize(eventSource); + registerEventFilters(); + m_lastEventSource = eventSource; + } } // Called by the keyboardEventFilter in the main thread @@ -297,23 +331,6 @@ void InputHandler::addInputDeviceIntegration(QInputDeviceIntegration *inputInteg m_inputDeviceIntegrations.push_back(inputIntegration); } -void InputHandler::setInputSettings(InputSettings *settings) -{ - if (m_settings && settings == nullptr) - m_eventSourceSetter->unsetEventSource(m_settings->eventSource()); - m_settings = settings; -} - -void InputHandler::setEventSourceHelper(EventSourceSetterHelper *helper) -{ - m_eventSourceSetter.reset(helper); -} - -EventSourceSetterHelper *InputHandler::eventSourceHelper() const -{ - return m_eventSourceSetter.data(); -} - QAbstractPhysicalDevice *Qt3DInput::Input::InputHandler::createPhysicalDevice(const QString &name) { QAbstractPhysicalDevice *device = nullptr; @@ -324,14 +341,9 @@ QAbstractPhysicalDevice *Qt3DInput::Input::InputHandler::createPhysicalDevice(co return device; } -void InputHandler::updateEventSource() +void Qt3DInput::Input::InputHandler::setEventFilterService(QEventFilterService *service) { - if (m_settings != nullptr) { - // Will be updated only if eventSource is different than - // what was set last - QObject *eventSource = m_settings->eventSource(); - m_eventSourceSetter->setEventSource(eventSource); - } + m_service = service; } AbstractActionInput *InputHandler::lookupActionInput(Qt3DCore::QNodeId id) const diff --git a/src/input/backend/inputhandler_p.h b/src/input/backend/inputhandler_p.h index a2a38262d..d83a77a1d 100644 --- a/src/input/backend/inputhandler_p.h +++ b/src/input/backend/inputhandler_p.h @@ -93,7 +93,6 @@ class GenericPhysicalDeviceManager; class GenericDeviceBackendNodeManager; class PhysicalDeviceProxyManager; class InputSettings; -class EventSourceSetterHelper; class Q_AUTOTEST_EXPORT InputHandler { @@ -149,12 +148,11 @@ public: void addInputDeviceIntegration(QInputDeviceIntegration *inputIntegration); void setInputSettings(InputSettings *settings); - void setEventSourceHelper(EventSourceSetterHelper *helper); - EventSourceSetterHelper *eventSourceHelper() const; QAbstractPhysicalDevice *createPhysicalDevice(const QString &name); void updateEventSource(); + void setEventFilterService(Qt3DCore::QEventFilterService *service); AbstractActionInput *lookupActionInput(Qt3DCore::QNodeId id) const; @@ -191,11 +189,11 @@ private: PhysicalDeviceProxyManager *m_physicalDeviceProxyManager; QVector<Qt3DInput::QInputDeviceIntegration *> m_inputDeviceIntegrations; InputSettings *m_settings; - QScopedPointer<EventSourceSetterHelper> m_eventSourceSetter; + Qt3DCore::QEventFilterService *m_service; + QObject *m_lastEventSource; - void registerEventFilters(Qt3DCore::QEventFilterService *service); - void unregisterEventFilters(Qt3DCore::QEventFilterService *service); - friend class EventSourceSetterHelper; + void registerEventFilters(); + void unregisterEventFilters(); }; } // namespace Input diff --git a/src/input/backend/keyboardeventfilter.cpp b/src/input/backend/keyboardeventfilter.cpp index e4f47f08e..53168e601 100644 --- a/src/input/backend/keyboardeventfilter.cpp +++ b/src/input/backend/keyboardeventfilter.cpp @@ -65,7 +65,7 @@ void KeyboardEventFilter::setInputHandler(InputHandler *handler) // Triggered in the view thread (usually the main thread) bool KeyboardEventFilter::eventFilter(QObject *obj, QEvent *e) { - Q_UNUSED(obj); + Q_UNUSED(obj) if (e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease) { // Store event to be processed later on in an InputAspect job m_inputHandler->appendKeyEvent(QT_PREPEND_NAMESPACE(QKeyEvent)(*static_cast<QT_PREPEND_NAMESPACE(QKeyEvent) *>(e))); diff --git a/src/input/frontend/qinputaspect.cpp b/src/input/frontend/qinputaspect.cpp index 260af5677..20e325db7 100644 --- a/src/input/frontend/qinputaspect.cpp +++ b/src/input/frontend/qinputaspect.cpp @@ -69,7 +69,6 @@ #include <Qt3DInput/private/axisaccumulatorjob_p.h> #include <Qt3DInput/private/axissetting_p.h> #include <Qt3DInput/private/buttonaxisinput_p.h> -#include <Qt3DInput/private/eventsourcesetterhelper_p.h> #include <Qt3DInput/private/genericdevicebackendnode_p.h> #include <Qt3DInput/private/inputbackendnodefunctor_p.h> #include <Qt3DInput/private/inputchord_p.h> @@ -290,7 +289,7 @@ void QInputAspect::onRegistered() Q_ASSERT(eventService); // Set it on the input handler which will also handle its lifetime - d->m_inputHandler->eventSourceHelper()->setEventFilterService(eventService); + d->m_inputHandler->setEventFilterService(eventService); } /*! |