summaryrefslogtreecommitdiffstats
path: root/src/input
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2020-06-25 16:02:02 +0100
committerMike Krus <mike.krus@kdab.com>2020-07-01 16:59:16 +0100
commit253013fd76d1caf89d2fd7a3f6334a1eae7f75ba (patch)
tree13d5eeaf970b98e3dec1ac2f50cc17568590c7c1 /src/input
parent7d836129bc3fa502e3480c47ba04608c8e8ca708 (diff)
Input Aspect: Dispatch events directly
Rather than accumulating events during a frame, they are now directly delivered to the device handlers synchronously. This removes the need to use jobs for updating the nodes. Updating axis and logical devices remains done using jobs at every frame. Change-Id: I2853a72cfe68201d8a6eb44d37bc64c9f50efd4f Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/input')
-rw-r--r--src/input/CMakeLists.txt4
-rw-r--r--src/input/backend/backend.pri8
-rw-r--r--src/input/backend/inputhandler.cpp312
-rw-r--r--src/input/backend/inputhandler_p.h36
-rw-r--r--src/input/backend/keyboarddevice.cpp5
-rw-r--r--src/input/backend/keyboarddevice_p.h2
-rw-r--r--src/input/backend/keyboardeventfilter.cpp79
-rw-r--r--src/input/backend/keyboardeventfilter_p.h83
-rw-r--r--src/input/backend/keyeventdispatcherjob.cpp104
-rw-r--r--src/input/backend/keyeventdispatcherjob_p.h84
-rw-r--r--src/input/backend/mousedevice.cpp49
-rw-r--r--src/input/backend/mousedevice_p.h5
-rw-r--r--src/input/backend/mouseeventdispatcherjob.cpp118
-rw-r--r--src/input/backend/mouseeventdispatcherjob_p.h89
-rw-r--r--src/input/backend/mouseeventfilter.cpp101
-rw-r--r--src/input/backend/mouseeventfilter_p.h83
-rw-r--r--src/input/frontend/qinputaspect.cpp22
-rw-r--r--src/input/frontend/qinputaspect.h2
18 files changed, 221 insertions, 965 deletions
diff --git a/src/input/CMakeLists.txt b/src/input/CMakeLists.txt
index f6a605d14..ecb8a94e9 100644
--- a/src/input/CMakeLists.txt
+++ b/src/input/CMakeLists.txt
@@ -29,15 +29,11 @@ qt_add_module(3DInput
backend/inputsettings.cpp backend/inputsettings_p.h
backend/job_common_p.h
backend/keyboarddevice.cpp backend/keyboarddevice_p.h
- backend/keyboardeventfilter.cpp backend/keyboardeventfilter_p.h
backend/keyboardhandler.cpp backend/keyboardhandler_p.h
backend/keyboardmousegenericdeviceintegration.cpp backend/keyboardmousegenericdeviceintegration_p.h
- backend/keyeventdispatcherjob.cpp backend/keyeventdispatcherjob_p.h
backend/loadproxydevicejob.cpp backend/loadproxydevicejob_p.h
backend/logicaldevice.cpp backend/logicaldevice_p.h
backend/mousedevice.cpp backend/mousedevice_p.h
- backend/mouseeventdispatcherjob.cpp backend/mouseeventdispatcherjob_p.h
- backend/mouseeventfilter.cpp backend/mouseeventfilter_p.h
backend/mousehandler.cpp backend/mousehandler_p.h
backend/movingaverage.cpp backend/movingaverage_p.h
backend/physicaldeviceproxy.cpp backend/physicaldeviceproxy_p.h
diff --git a/src/input/backend/backend.pri b/src/input/backend/backend.pri
index 2330d322f..3dae8f829 100644
--- a/src/input/backend/backend.pri
+++ b/src/input/backend/backend.pri
@@ -5,13 +5,9 @@ HEADERS += \
$$PWD/inputhandler_p.h \
$$PWD/inputmanagers_p.h \
$$PWD/handle_types_p.h \
- $$PWD/keyboardeventfilter_p.h \
$$PWD/assignkeyboardfocusjob_p.h \
- $$PWD/keyeventdispatcherjob_p.h \
$$PWD/mousehandler_p.h \
$$PWD/mousedevice_p.h \
- $$PWD/mouseeventdispatcherjob_p.h \
- $$PWD/mouseeventfilter_p.h \
$$PWD/abstractactioninput_p.h \
$$PWD/abstractaxisinput_p.h \
$$PWD/actioninput_p.h \
@@ -43,13 +39,9 @@ SOURCES += \
$$PWD/keyboarddevice.cpp \
$$PWD/keyboardhandler.cpp \
$$PWD/inputhandler.cpp \
- $$PWD/keyboardeventfilter.cpp \
$$PWD/assignkeyboardfocusjob.cpp \
- $$PWD/keyeventdispatcherjob.cpp \
$$PWD/mousehandler.cpp \
$$PWD/mousedevice.cpp \
- $$PWD/mouseeventfilter.cpp \
- $$PWD/mouseeventdispatcherjob.cpp \
$$PWD/abstractactioninput.cpp \
$$PWD/abstractaxisinput.cpp \
$$PWD/actioninput.cpp \
diff --git a/src/input/backend/inputhandler.cpp b/src/input/backend/inputhandler.cpp
index 6c9b7a533..d201838d1 100644
--- a/src/input/backend/inputhandler.cpp
+++ b/src/input/backend/inputhandler.cpp
@@ -39,16 +39,18 @@
#include "inputhandler_p.h"
+#include <Qt3DCore/private/qscene_p.h>
+#include <Qt3DInput/qmousehandler.h>
+#include <Qt3DInput/qkeyboardhandler.h>
#include <Qt3DInput/private/assignkeyboardfocusjob_p.h>
#include <Qt3DInput/private/inputmanagers_p.h>
#include <Qt3DInput/private/inputsettings_p.h>
-#include <Qt3DInput/private/keyboardeventfilter_p.h>
-#include <Qt3DInput/private/keyeventdispatcherjob_p.h>
-#include <Qt3DInput/private/mouseeventdispatcherjob_p.h>
-#include <Qt3DInput/private/mouseeventfilter_p.h>
#include <Qt3DInput/private/qinputdeviceintegration_p.h>
+#include <Qt3DInput/private/qmousehandler_p.h>
+#include <Qt3DInput/private/qkeyboardhandler_p.h>
#include <Qt3DCore/private/qeventfilterservice_p.h>
+
QT_BEGIN_NAMESPACE
using namespace Qt3DCore;
@@ -56,13 +58,50 @@ using namespace Qt3DCore;
namespace Qt3DInput {
namespace Input {
+class InternalEventFilter : public QObject
+{
+public:
+ explicit InternalEventFilter(QObject *parent = nullptr) : QObject(parent), m_inputHandler(nullptr) { }
+ ~InternalEventFilter() override;
+
+ void setInputHandler(Qt3DInput::Input::InputHandler *handler) { m_inputHandler = handler; }
+ inline Qt3DInput::Input::InputHandler *inputHandler() const { return m_inputHandler; }
+
+protected:
+ bool eventFilter(QObject *obj, QEvent *e) override {
+ switch (e->type()) {
+ case QEvent::MouseMove:
+ return processMouseEvent(obj, static_cast<QT_PREPEND_NAMESPACE(QMouseEvent) *>(e));
+#if QT_CONFIG(wheelevent)
+ case QEvent::Wheel:
+ return processWheelEvent(obj, static_cast<QT_PREPEND_NAMESPACE(QWheelEvent) *>(e));
+#endif
+ case QEvent::KeyPress:
+ case QEvent::KeyRelease:
+ return processKeyEvent(obj, static_cast<QT_PREPEND_NAMESPACE(QKeyEvent) *>(e));
+ default:
+ break;
+ }
+ return false;
+ }
+
+ bool processMouseEvent(QObject *obj, QT_PREPEND_NAMESPACE(QMouseEvent) *event);
+#if QT_CONFIG(wheelevent)
+ bool processWheelEvent(QObject *obj, QT_PREPEND_NAMESPACE(QWheelEvent) *event);
+#endif
+ bool processKeyEvent(QObject *obj, QT_PREPEND_NAMESPACE(QKeyEvent) *event);
+
+private:
+ Qt3DInput::Input::InputHandler *m_inputHandler;
+};
+
+
InputHandler::InputHandler()
: m_keyboardDeviceManager(new KeyboardDeviceManager())
, m_keyboardInputManager(new KeyboardInputManager())
, m_mouseDeviceManager(new MouseDeviceManager())
, m_mouseInputManager(new MouseInputManager())
- , m_keyboardEventFilter(new KeyboardEventFilter())
- , m_mouseEventFilter(new MouseEventFilter())
+ , m_eventFilter(new InternalEventFilter())
, m_axisManager(new AxisManager())
, m_axisAccumulatorManager(new AxisAccumulatorManager())
, m_actionManager(new ActionManager())
@@ -79,8 +118,7 @@ InputHandler::InputHandler()
, m_service(nullptr)
, m_lastEventSource(nullptr)
{
- m_keyboardEventFilter->setInputHandler(this);
- m_mouseEventFilter->setInputHandler(this);
+ m_eventFilter->setInputHandler(this);
}
InputHandler::~InputHandler()
@@ -89,8 +127,7 @@ InputHandler::~InputHandler()
delete m_keyboardInputManager;
delete m_mouseDeviceManager;
delete m_mouseInputManager;
- delete m_keyboardEventFilter;
- delete m_mouseEventFilter;
+ delete m_eventFilter;
delete m_axisManager;
delete m_axisAccumulatorManager;
delete m_actionManager;
@@ -108,21 +145,14 @@ InputHandler::~InputHandler()
// Called in MainThread (by the EventSourceHelperSetter)
void InputHandler::registerEventFilters()
{
- clearPendingKeyEvents();
- clearPendingMouseEvents();
-
- if (m_service) {
- m_service->registerEventFilter(m_keyboardEventFilter, 512);
- m_service->registerEventFilter(m_mouseEventFilter, 513);
- }
+ if (m_service)
+ m_service->registerEventFilter(m_eventFilter, 512);
}
void InputHandler::unregisterEventFilters()
{
- if (m_service) {
- m_service->unregisterEventFilter(m_keyboardEventFilter);
- m_service->unregisterEventFilter(m_mouseEventFilter);
- }
+ if (m_service)
+ m_service->unregisterEventFilter(m_eventFilter);
}
void InputHandler::setInputSettings(InputSettings *settings)
@@ -158,62 +188,6 @@ void InputHandler::updateEventSource()
}
}
-// Called by the keyboardEventFilter in the main thread
-void InputHandler::appendKeyEvent(const QT_PREPEND_NAMESPACE(QKeyEvent) &event)
-{
- m_pendingKeyEvents.append(event);
-}
-
-// Called by QInputASpect::jobsToExecute (Main Thread)
-QList<QT_PREPEND_NAMESPACE(QKeyEvent)> InputHandler::pendingKeyEvents()
-{
- return std::move(m_pendingKeyEvents);
-}
-
-// Called by QInputASpect::jobsToExecute (Main Thread)
-void InputHandler::clearPendingKeyEvents()
-{
- m_pendingKeyEvents.clear();
-}
-
-// Main Thread
-void InputHandler::appendMouseEvent(const QT_PREPEND_NAMESPACE(QMouseEvent) &event)
-{
- m_pendingMouseEvents.append(event);
-}
-
-// Main Thread
-QList<QT_PREPEND_NAMESPACE(QMouseEvent)> InputHandler::pendingMouseEvents()
-{
- return std::move(m_pendingMouseEvents);
-}
-
-// Main Thread
-void InputHandler::clearPendingMouseEvents()
-{
- m_pendingMouseEvents.clear();
-}
-
-#if QT_CONFIG(wheelevent)
-// Main Thread
-void InputHandler::appendWheelEvent(const QT_PREPEND_NAMESPACE(QWheelEvent) &event)
-{
- m_pendingWheelEvents.append(event);
-}
-
-// Main Thread
-QList<QT_PREPEND_NAMESPACE (QWheelEvent)> Qt3DInput::Input::InputHandler::pendingWheelEvents()
-{
- return std::move(m_pendingWheelEvents);
-}
-
-// Main Thread
-void InputHandler::clearPendingWheelEvents()
-{
- m_pendingWheelEvents.clear();
-}
-#endif
-
void InputHandler::appendKeyboardDevice(HKeyboardDevice device)
{
m_activeKeyboardDevices.append(device);
@@ -244,81 +218,13 @@ void Qt3DInput::Input::InputHandler::removeGenericDevice(HGenericDeviceBackendNo
m_activeGenericPhysicalDevices.removeAll(device);
}
-// Return a vector of jobs to be performed for keyboard events
-// Handles all dependencies between jobs
-QVector<Qt3DCore::QAspectJobPtr> InputHandler::keyboardJobs()
+// called every frame to reset the
+void Qt3DInput::Input::InputHandler::resetMouseAxisState()
{
- // One job for Keyboard focus change event per Keyboard device
- QVector<QAspectJobPtr> jobs;
- const QList<QT_PREPEND_NAMESPACE(QKeyEvent)> events = pendingKeyEvents();
-
- for (const HKeyboardDevice &cHandle : qAsConst(m_activeKeyboardDevices)) {
- KeyboardDevice *keyboardDevice = m_keyboardDeviceManager->data(cHandle);
- if (keyboardDevice) {
- keyboardDevice->updateKeyEvents(events);
- bool haveFocusChangeJob = false;
- if (keyboardDevice->lastKeyboardInputRequester() != keyboardDevice->currentFocusItem()) {
- auto job = QSharedPointer<AssignKeyboardFocusJob>::create(keyboardDevice->peerId());
- job->setInputHandler(this);
- haveFocusChangeJob= true;
- jobs.append(std::move(job));
- // One job for Keyboard events (depends on the focus change job if there was one)
- }
- // Event dispacthing job
- if (!events.isEmpty()) {
- auto job = QSharedPointer<KeyEventDispatcherJob>::create(keyboardDevice->currentFocusItem(), events);
- job->setInputHandler(this);
- if (haveFocusChangeJob)
- job->addDependency(qAsConst(jobs).back());
- jobs.append(std::move(job));
- }
- }
- }
- return jobs;
-}
-
-QVector<Qt3DCore::QAspectJobPtr> InputHandler::mouseJobs()
-{
- QVector<QAspectJobPtr> jobs;
- const QList<QT_PREPEND_NAMESPACE(QMouseEvent)> mouseEvents = pendingMouseEvents();
-#if QT_CONFIG(wheelevent)
- const QList<QT_PREPEND_NAMESPACE(QWheelEvent)> wheelEvents = pendingWheelEvents();
-#endif
for (const HMouseDevice &cHandle : qAsConst(m_activeMouseDevices)) {
MouseDevice *controller = m_mouseDeviceManager->data(cHandle);
-
- controller->updateMouseEvents(mouseEvents);
-#if QT_CONFIG(wheelevent)
- controller->updateWheelEvents(wheelEvents);
-#endif
- // Event dispacthing job
- if (!mouseEvents.isEmpty()
-#if QT_CONFIG(wheelevent)
- || !wheelEvents.empty()
-#endif
- ) {
- // Send the events to the mouse handlers that have for sourceDevice controller
- const std::vector<HMouseHandler> &activeMouseHandlers = m_mouseInputManager->activeHandles();
- for (const HMouseHandler &mouseHandlerHandle : activeMouseHandlers) {
-
- MouseHandler *mouseHandler = m_mouseInputManager->data(mouseHandlerHandle);
- Q_ASSERT(mouseHandler);
-
- if (mouseHandler->mouseDevice() == controller->peerId()) {
- MouseEventDispatcherJob *job = new MouseEventDispatcherJob(mouseHandler->peerId(),
- mouseEvents
-#if QT_CONFIG(wheelevent)
- , wheelEvents
-#endif
- );
- job->setInputHandler(this);
- jobs.append(QAspectJobPtr(job));
- }
- }
- }
+ controller->resetMouseAxisState();
}
-
- return jobs;
}
QVector<QInputDeviceIntegration *> InputHandler::inputDeviceIntegrations() const
@@ -356,6 +262,116 @@ AbstractActionInput *InputHandler::lookupActionInput(Qt3DCore::QNodeId id) const
return inputChordManager()->lookupResource(id); // nullptr if not found
}
+InternalEventFilter::~InternalEventFilter() = default;
+
+bool InternalEventFilter::processMouseEvent(QObject *obj, QT_PREPEND_NAMESPACE(QMouseEvent) *event)
+{
+ Q_UNUSED(obj);
+ Q_ASSERT(m_inputHandler);
+ if (!m_inputHandler->m_scene)
+ return false;
+
+ for (const HMouseDevice &cHandle : qAsConst(m_inputHandler->m_activeMouseDevices)) {
+ MouseDevice *controller = m_inputHandler->m_mouseDeviceManager->data(cHandle);
+
+ controller->updateMouseEvent(event);
+
+ // Send the events to the mouse handlers that have for sourceDevice controller
+ const std::vector<HMouseHandler> &activeMouseHandlers = m_inputHandler->m_mouseInputManager->activeHandles();
+ for (const HMouseHandler &mouseHandlerHandle : activeMouseHandlers) {
+ MouseHandler *mouseHandler = m_inputHandler->m_mouseInputManager->data(mouseHandlerHandle);
+ Q_ASSERT(mouseHandler);
+
+ if (mouseHandler->mouseDevice() == controller->peerId()) {
+ QMouseHandler *node = qobject_cast<QMouseHandler *>(m_inputHandler->m_scene->lookupNode(mouseHandler->peerId()));
+ QMouseHandlerPrivate *dnode = static_cast<QMouseHandlerPrivate *>(QMouseHandlerPrivate::get(node));
+ dnode->mouseEvent(QMouseEventPtr::create(*event)); // Do we really need Qt3D specific events?
+ }
+ }
+ }
+
+ return false;
+}
+
+#if QT_CONFIG(wheelevent)
+bool InternalEventFilter::processWheelEvent(QObject *obj, QT_PREPEND_NAMESPACE(QWheelEvent) *event)
+{
+ Q_UNUSED(obj);
+ Q_ASSERT(m_inputHandler);
+ if (!m_inputHandler->m_scene)
+ return false;
+
+ for (const HMouseDevice &cHandle : qAsConst(m_inputHandler->m_activeMouseDevices)) {
+ MouseDevice *controller = m_inputHandler->m_mouseDeviceManager->data(cHandle);
+
+ controller->updateWheelEvent(event);
+
+ // Send the events to the mouse handlers that have for sourceDevice controller
+ const std::vector<HMouseHandler> &activeMouseHandlers = m_inputHandler->m_mouseInputManager->activeHandles();
+ for (const HMouseHandler &mouseHandlerHandle : activeMouseHandlers) {
+ MouseHandler *mouseHandler = m_inputHandler->m_mouseInputManager->data(mouseHandlerHandle);
+ Q_ASSERT(mouseHandler);
+
+ if (mouseHandler->mouseDevice() == controller->peerId()) {
+ QMouseHandler *node = qobject_cast<QMouseHandler *>(m_inputHandler->m_scene->lookupNode(mouseHandler->peerId()));
+ QWheelEvent we(*event);
+ node->wheel(&we); // Do we really need Qt3D specific events?
+ }
+ }
+ }
+
+ return false;
+}
+#endif
+
+bool InternalEventFilter::processKeyEvent(QObject *obj, QT_PREPEND_NAMESPACE(QKeyEvent) *event)
+{
+ Q_UNUSED(obj);
+ Q_ASSERT(m_inputHandler);
+ if (!m_inputHandler->m_scene)
+ return false;
+
+ for (const HKeyboardDevice &cHandle : qAsConst(m_inputHandler->m_activeKeyboardDevices)) {
+ KeyboardDevice *keyboardDevice = m_inputHandler->m_keyboardDeviceManager->data(cHandle);
+ if (keyboardDevice) {
+ keyboardDevice->updateKeyEvent(event);
+
+ // update the focus
+ if (keyboardDevice->lastKeyboardInputRequester() != keyboardDevice->currentFocusItem()) {
+ const auto handles = m_inputHandler->keyboardInputManager()->activeHandles();
+ for (const HKeyboardHandler &handle : handles) {
+ KeyboardHandler *input = m_inputHandler->keyboardInputManager()->data(handle);
+ Q_ASSERT(input);
+ if (input->keyboardDevice() == keyboardDevice->peerId()) {
+ bool hasFocus = input->peerId() == keyboardDevice->lastKeyboardInputRequester();
+ input->setFocus(hasFocus);
+ QKeyboardHandler *node = qobject_cast<QKeyboardHandler *>(m_inputHandler->m_scene->lookupNode(input->peerId()));
+ if (node) {
+ const bool b = node->blockNotifications(true);
+ node->setFocus(hasFocus);
+ node->blockNotifications(b);
+ }
+ if (hasFocus)
+ keyboardDevice->setCurrentFocusItem(input->peerId());
+ }
+ }
+ }
+
+ // deliver the event
+ QKeyboardHandler *node = qobject_cast<QKeyboardHandler *>(m_inputHandler->m_scene->lookupNode(keyboardDevice->currentFocusItem()));
+ if (node) {
+ QKeyboardHandlerPrivate *dnode = static_cast<QKeyboardHandlerPrivate *>(QKeyboardHandlerPrivate::get(node));
+
+ QKeyEvent ke(*event);
+ dnode->keyEvent(&ke); // Do we really need Qt3D specific events?
+ }
+ }
+ }
+
+ return false;
+}
+
+
} // namespace Input
} // namespace Qt3DInput
diff --git a/src/input/backend/inputhandler_p.h b/src/input/backend/inputhandler_p.h
index d83a77a1d..a1c82b7cf 100644
--- a/src/input/backend/inputhandler_p.h
+++ b/src/input/backend/inputhandler_p.h
@@ -63,6 +63,7 @@ QT_BEGIN_NAMESPACE
namespace Qt3DCore {
class QEventFilterService;
class QNodeId;
+class QScene;
}
namespace Qt3DInput {
@@ -75,10 +76,9 @@ namespace Input {
class AbstractActionInput;
class KeyboardInputManager;
class KeyboardDeviceManager;
-class KeyboardEventFilter;
class MouseDeviceManager;
class MouseInputManager;
-class MouseEventFilter;
+class InternalEventFilter;
class AxisManager;
class AxisAccumulatorManager;
class ActionManager;
@@ -100,6 +100,8 @@ public:
InputHandler();
~InputHandler();
+ void setScene(Qt3DCore::QScene *scene) { m_scene = scene; }
+
inline KeyboardDeviceManager *keyboardDeviceManager() const { return m_keyboardDeviceManager; }
inline KeyboardInputManager *keyboardInputManager() const { return m_keyboardInputManager; }
inline MouseDeviceManager *mouseDeviceManager() const { return m_mouseDeviceManager; }
@@ -118,20 +120,6 @@ public:
inline PhysicalDeviceProxyManager *physicalDeviceProxyManager() const { return m_physicalDeviceProxyManager; }
inline InputSettings *inputSettings() const { return m_settings; }
- void appendKeyEvent(const QT_PREPEND_NAMESPACE(QKeyEvent) &event);
- QList<QT_PREPEND_NAMESPACE(QKeyEvent)> pendingKeyEvents();
- void clearPendingKeyEvents();
-
- void appendMouseEvent(const QT_PREPEND_NAMESPACE(QMouseEvent) &event);
- QList<QT_PREPEND_NAMESPACE(QMouseEvent)> pendingMouseEvents();
- void clearPendingMouseEvents();
-
-#if QT_CONFIG(wheelevent)
- void appendWheelEvent(const QT_PREPEND_NAMESPACE(QWheelEvent) &event);
- QList<QT_PREPEND_NAMESPACE(QWheelEvent)> pendingWheelEvents();
- void clearPendingWheelEvents();
-#endif
-
void appendKeyboardDevice(HKeyboardDevice device);
void removeKeyboardDevice(HKeyboardDevice device);
@@ -141,8 +129,7 @@ public:
void appendGenericDevice(HGenericDeviceBackendNode device);
void removeGenericDevice(HGenericDeviceBackendNode device);
- QVector<Qt3DCore::QAspectJobPtr> keyboardJobs();
- QVector<Qt3DCore::QAspectJobPtr> mouseJobs();
+ void resetMouseAxisState();
QVector<Qt3DInput::QInputDeviceIntegration *> inputDeviceIntegrations() const;
void addInputDeviceIntegration(QInputDeviceIntegration *inputIntegration);
@@ -157,6 +144,9 @@ public:
AbstractActionInput *lookupActionInput(Qt3DCore::QNodeId id) const;
private:
+ friend class InternalEventFilter;
+
+ Qt3DCore::QScene *m_scene;
KeyboardDeviceManager *m_keyboardDeviceManager;
KeyboardInputManager *m_keyboardInputManager;
MouseDeviceManager *m_mouseDeviceManager;
@@ -165,15 +155,7 @@ private:
QVector<HKeyboardDevice> m_activeKeyboardDevices;
QVector<HMouseDevice> m_activeMouseDevices;
QVector<HGenericDeviceBackendNode> m_activeGenericPhysicalDevices;
- KeyboardEventFilter *m_keyboardEventFilter;
- MouseEventFilter *m_mouseEventFilter;
-
- QList<QT_PREPEND_NAMESPACE(QKeyEvent)> m_pendingKeyEvents;
- QList<QT_PREPEND_NAMESPACE(QMouseEvent)> m_pendingMouseEvents;
-#if QT_CONFIG(wheelevent)
- QList<QT_PREPEND_NAMESPACE(QWheelEvent)> m_pendingWheelEvents;
-#endif
- mutable QMutex m_mutex;
+ InternalEventFilter *m_eventFilter;
AxisManager *m_axisManager;
AxisAccumulatorManager *m_axisAccumulatorManager;
diff --git a/src/input/backend/keyboarddevice.cpp b/src/input/backend/keyboarddevice.cpp
index 0a35cefbb..3ec2802d5 100644
--- a/src/input/backend/keyboarddevice.cpp
+++ b/src/input/backend/keyboarddevice.cpp
@@ -421,10 +421,9 @@ void KeyboardDevice::setButtonValue(int key, bool value)
}
}
-void KeyboardDevice::updateKeyEvents(const QList<QT_PREPEND_NAMESPACE(QKeyEvent)> &events)
+void KeyboardDevice::updateKeyEvent(QT_PREPEND_NAMESPACE(QKeyEvent) *event)
{
- for (const QT_PREPEND_NAMESPACE(QKeyEvent) &e : events)
- setButtonValue(e.key(), e.type() == QT_PREPEND_NAMESPACE(QKeyEvent)::KeyPress ? true : false);
+ setButtonValue(event->key(), event->type() == QT_PREPEND_NAMESPACE(QKeyEvent)::KeyPress ? true : false);
}
KeyboardDeviceFunctor::KeyboardDeviceFunctor(QInputAspect *inputaspect, InputHandler *handler)
diff --git a/src/input/backend/keyboarddevice_p.h b/src/input/backend/keyboarddevice_p.h
index 76e207889..50660de61 100644
--- a/src/input/backend/keyboarddevice_p.h
+++ b/src/input/backend/keyboarddevice_p.h
@@ -81,7 +81,7 @@ public:
float axisValue(int axisIdentifier) const override;
bool isButtonPressed(int buttonIdentifier) const override;
- void updateKeyEvents(const QList<QT_PREPEND_NAMESPACE(QKeyEvent)> &events);
+ void updateKeyEvent(QT_PREPEND_NAMESPACE(QKeyEvent) *event);
inline Qt3DCore::QNodeId currentFocusItem() const { return m_currentFocusItem; }
inline Qt3DCore::QNodeId lastKeyboardInputRequester() const { return m_lastRequester; }
diff --git a/src/input/backend/keyboardeventfilter.cpp b/src/input/backend/keyboardeventfilter.cpp
deleted file mode 100644
index e4f47f08e..000000000
--- a/src/input/backend/keyboardeventfilter.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 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 "keyboardeventfilter_p.h"
-
-#include <Qt3DInput/QKeyEvent>
-#include <QtCore/QEvent>
-
-#include <Qt3DInput/private/inputhandler_p.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DInput {
-namespace Input {
-
-// The KeyboardEventFilter must be in the same thread as the view it will be monitoring
-
-KeyboardEventFilter::KeyboardEventFilter(QObject *parent)
- : QObject(parent)
- , m_inputHandler(nullptr)
-{
-}
-
-void KeyboardEventFilter::setInputHandler(InputHandler *handler)
-{
- m_inputHandler = handler;
-}
-
-// Triggered in the view thread (usually the main thread)
-bool KeyboardEventFilter::eventFilter(QObject *obj, QEvent *e)
-{
- 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)));
- }
- return false;
-}
-
-} // namespace Input
-} // namespace Qt3DInput
-
-QT_END_NAMESPACE
diff --git a/src/input/backend/keyboardeventfilter_p.h b/src/input/backend/keyboardeventfilter_p.h
deleted file mode 100644
index bcf062506..000000000
--- a/src/input/backend/keyboardeventfilter_p.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 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 QT3DINPUT_INPUT_KEYBOARDEVENTFILTER_P_H
-#define QT3DINPUT_INPUT_KEYBOARDEVENTFILTER_P_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/QObject>
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DInput {
-namespace Input {
-
-class InputHandler;
-
-class KeyboardEventFilter : public QObject
-{
- Q_OBJECT
-public:
- explicit KeyboardEventFilter(QObject *parent = 0);
- void setInputHandler(InputHandler *handler);
- inline InputHandler *inputHandler() const { return m_inputHandler; }
-
-protected:
- bool eventFilter(QObject *obj, QEvent *e) override;
-
-private:
- InputHandler *m_inputHandler;
-};
-
-} // namespace Input
-} // namespace Qt3DInput
-
-QT_END_NAMESPACE
-
-#endif // QT3DINPUT_INPUT_KEYBOARDEVENTFILTER_P_H
diff --git a/src/input/backend/keyeventdispatcherjob.cpp b/src/input/backend/keyeventdispatcherjob.cpp
deleted file mode 100644
index 26a35e885..000000000
--- a/src/input/backend/keyeventdispatcherjob.cpp
+++ /dev/null
@@ -1,104 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 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 "keyeventdispatcherjob_p.h"
-#include <Qt3DCore/private/qaspectmanager_p.h>
-#include <Qt3DInput/qkeyboardhandler.h>
-#include <Qt3DInput/private/qkeyboardhandler_p.h>
-#include <Qt3DInput/private/inputhandler_p.h>
-#include <Qt3DInput/private/inputmanagers_p.h>
-#include <Qt3DInput/private/job_common_p.h>
-#include <Qt3DInput/private/keyboardhandler_p.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DInput {
-namespace Input {
-
-class KeyEventDispatcherJobPrivate : public Qt3DCore::QAspectJobPrivate
-{
-public:
- KeyEventDispatcherJobPrivate() { }
- ~KeyEventDispatcherJobPrivate() override { }
-
- void postFrame(Qt3DCore::QAspectManager *manager) override;
-
- Qt3DCore::QNodeId m_keyboardHandler;
- QList<QT_PREPEND_NAMESPACE(QKeyEvent)> m_events;
-};
-
-KeyEventDispatcherJob::KeyEventDispatcherJob(Qt3DCore::QNodeId input, const QList<QT_PREPEND_NAMESPACE(QKeyEvent)> &events)
- : QAspectJob(*new KeyEventDispatcherJobPrivate)
- , m_inputHandler(nullptr)
-{
- Q_D(KeyEventDispatcherJob);
- d->m_keyboardHandler = input;
- d->m_events = events;
- SET_JOB_RUN_STAT_TYPE(this, JobTypes::KeyEventDispatcher, 0)
-}
-
-void KeyEventDispatcherJob::setInputHandler(InputHandler *handler)
-{
- m_inputHandler = handler;
-}
-
-void KeyEventDispatcherJob::run()
-{
- // NOP
-}
-
-void KeyEventDispatcherJobPrivate::postFrame(Qt3DCore::QAspectManager *manager)
-{
- QKeyboardHandler *node = qobject_cast<QKeyboardHandler *>(manager->lookupNode(m_keyboardHandler));
- if (!node)
- return;
-
- QKeyboardHandlerPrivate *dnode = static_cast<QKeyboardHandlerPrivate *>(QKeyboardHandlerPrivate::get(node));
- for (const auto &e: qAsConst(m_events)) {
- QKeyEvent ke(e);
- dnode->keyEvent(&ke);
- }
-
- m_events.clear();
-}
-
-} // namespace Input
-} // namespace Qt3DInput
-
-QT_END_NAMESPACE
diff --git a/src/input/backend/keyeventdispatcherjob_p.h b/src/input/backend/keyeventdispatcherjob_p.h
deleted file mode 100644
index bd0c770d4..000000000
--- a/src/input/backend/keyeventdispatcherjob_p.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 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 QT3DINPUT_INPUT_KEYEVENTDISPATCHERJOB_P_H
-#define QT3DINPUT_INPUT_KEYEVENTDISPATCHERJOB_P_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 <Qt3DInput/QKeyEvent>
-#include <Qt3DCore/qaspectjob.h>
-#include <Qt3DCore/qnodeid.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DInput {
-namespace Input {
-
-class InputHandler;
-class KeyEventDispatcherJobPrivate;
-
-class KeyEventDispatcherJob : public Qt3DCore::QAspectJob
-{
-public:
- explicit KeyEventDispatcherJob(Qt3DCore::QNodeId input, const QList<QT_PREPEND_NAMESPACE(QKeyEvent)> &events);
- void setInputHandler(InputHandler *handler);
- void run() override;
-
-private:
- Q_DECLARE_PRIVATE(KeyEventDispatcherJob)
-
- InputHandler *m_inputHandler;
-};
-
-} // namespace Input
-} // namespace Qt3DInput
-
-QT_END_NAMESPACE
-
-#endif // QT3DINPUT_INPUT_KEYEVENTDISPATCHERJOB_P_H
diff --git a/src/input/backend/mousedevice.cpp b/src/input/backend/mousedevice.cpp
index 79c7fb2fa..21a765b3f 100644
--- a/src/input/backend/mousedevice.cpp
+++ b/src/input/backend/mousedevice.cpp
@@ -133,41 +133,36 @@ bool MouseDevice::updateAxesContinuously() const
}
#if QT_CONFIG(wheelevent)
-void MouseDevice::updateWheelEvents(const QList<QT_PREPEND_NAMESPACE (QWheelEvent)> &events)
+void MouseDevice::updateWheelEvent(QT_PREPEND_NAMESPACE(QWheelEvent) *event)
{
- // Reset axis values before we accumulate new values for this frame
- m_mouseState.wXAxis = 0.0f;
- m_mouseState.wYAxis = 0.0f;
- if (!events.isEmpty()) {
- for (const QT_PREPEND_NAMESPACE(QWheelEvent) &e : events) {
- m_mouseState.wXAxis += m_sensitivity * e.angleDelta().x();
- m_mouseState.wYAxis += m_sensitivity * e.angleDelta().y();
- }
- }
+ m_mouseState.wXAxis += m_sensitivity * event->angleDelta().x();
+ m_mouseState.wYAxis += m_sensitivity * event->angleDelta().y();
}
#endif
-// Main Thread
-void MouseDevice::updateMouseEvents(const QList<QT_PREPEND_NAMESPACE(QMouseEvent)> &events)
+void MouseDevice::updateMouseEvent(QT_PREPEND_NAMESPACE(QMouseEvent) *event)
+{
+ m_mouseState.leftPressed = event->buttons() & (Qt::LeftButton);
+ m_mouseState.centerPressed = event->buttons() & (Qt::MiddleButton);
+ m_mouseState.rightPressed = event->buttons() & (Qt::RightButton);
+ const bool pressed = m_mouseState.leftPressed || m_mouseState.centerPressed || m_mouseState.rightPressed;
+ if (m_updateAxesContinuously || (m_wasPressed && pressed)) {
+ m_mouseState.xAxis += m_sensitivity * float(event->globalPosition().x() - m_previousPos.x());
+ m_mouseState.yAxis += m_sensitivity * float(m_previousPos.y() - event->globalPosition().y());
+ }
+ m_wasPressed = pressed;
+ m_previousPos = event->globalPosition();
+}
+
+void MouseDevice::resetMouseAxisState()
{
// Reset axis values before we accumulate new values for this frame
m_mouseState.xAxis = 0.0f;
m_mouseState.yAxis = 0.0f;
-
- if (!events.isEmpty()) {
- for (const QT_PREPEND_NAMESPACE(QMouseEvent) &e : events) {
- m_mouseState.leftPressed = e.buttons() & (Qt::LeftButton);
- m_mouseState.centerPressed = e.buttons() & (Qt::MiddleButton);
- m_mouseState.rightPressed = e.buttons() & (Qt::RightButton);
- const bool pressed = m_mouseState.leftPressed || m_mouseState.centerPressed || m_mouseState.rightPressed;
- if (m_updateAxesContinuously || (m_wasPressed && pressed)) {
- m_mouseState.xAxis += m_sensitivity * float(e.globalPosition().x() - m_previousPos.x());
- m_mouseState.yAxis += m_sensitivity * float(m_previousPos.y() - e.globalPosition().y());
- }
- m_wasPressed = pressed;
- m_previousPos = e.globalPosition();
- }
- }
+#if QT_CONFIG(wheelevent)
+ m_mouseState.wXAxis = 0.0f;
+ m_mouseState.wYAxis = 0.0f;
+#endif
}
void MouseDevice::syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime)
diff --git a/src/input/backend/mousedevice_p.h b/src/input/backend/mousedevice_p.h
index 41f51ba27..7ac513280 100644
--- a/src/input/backend/mousedevice_p.h
+++ b/src/input/backend/mousedevice_p.h
@@ -98,10 +98,11 @@ public:
float axisValue(int axisIdentifier) const override;
bool isButtonPressed(int buttonIdentifier) const override;
- void updateMouseEvents(const QList<QT_PREPEND_NAMESPACE(QMouseEvent)> &events);
+ void updateMouseEvent(QT_PREPEND_NAMESPACE(QMouseEvent) *events);
#if QT_CONFIG(wheelevent)
- void updateWheelEvents(const QList<QT_PREPEND_NAMESPACE(QWheelEvent)> &events);
+ void updateWheelEvent(QT_PREPEND_NAMESPACE(QWheelEvent) *events);
#endif
+ void resetMouseAxisState();
MouseState mouseState() const;
QPointF previousPos() const;
diff --git a/src/input/backend/mouseeventdispatcherjob.cpp b/src/input/backend/mouseeventdispatcherjob.cpp
deleted file mode 100644
index 0ee6862fb..000000000
--- a/src/input/backend/mouseeventdispatcherjob.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 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 "mouseeventdispatcherjob_p.h"
-#include <Qt3DCore/private/qaspectmanager_p.h>
-#include <Qt3DInput/qmousehandler.h>
-#include <Qt3DInput/private/qmousehandler_p.h>
-#include <Qt3DInput/private/inputhandler_p.h>
-#include <Qt3DInput/private/inputmanagers_p.h>
-#include <Qt3DInput/private/job_common_p.h>
-#include <Qt3DInput/private/mousehandler_p.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DInput {
-namespace Input {
-
-class MouseEventDispatcherJobPrivate : public Qt3DCore::QAspectJobPrivate
-{
-public:
- MouseEventDispatcherJobPrivate() { }
- ~MouseEventDispatcherJobPrivate() override { }
-
- void postFrame(Qt3DCore::QAspectManager *manager) override;
-
- Qt3DCore::QNodeId m_mouseInput;
- QList<QT_PREPEND_NAMESPACE(QMouseEvent)> m_mouseEvents;
-#if QT_CONFIG(wheelevent)
- QList<QT_PREPEND_NAMESPACE(QWheelEvent)> m_wheelEvents;
-#endif
-};
-
-MouseEventDispatcherJob::MouseEventDispatcherJob(Qt3DCore::QNodeId input,
- const QList<QT_PREPEND_NAMESPACE (QMouseEvent)> &mouseEvents
-#if QT_CONFIG(wheelevent)
- , const QList<QT_PREPEND_NAMESPACE (QWheelEvent)> &wheelEvents
-#endif
- )
- : QAspectJob(*new MouseEventDispatcherJobPrivate)
- , m_inputHandler(nullptr)
-{
- Q_D(MouseEventDispatcherJob);
- d->m_mouseInput = input;
- d->m_mouseEvents = mouseEvents;
-#if QT_CONFIG(wheelevent)
- d->m_wheelEvents = wheelEvents;
-#endif
- SET_JOB_RUN_STAT_TYPE(this, JobTypes::MouseEventDispatcher, 0)
-}
-
-void MouseEventDispatcherJob::setInputHandler(InputHandler *handler)
-{
- m_inputHandler = handler;
-}
-
-void MouseEventDispatcherJob::run()
-{
- // NOP
-}
-
-void MouseEventDispatcherJobPrivate::postFrame(Qt3DCore::QAspectManager *manager)
-{
- QMouseHandler *node = qobject_cast<QMouseHandler *>(manager->lookupNode(m_mouseInput));
- if (!node)
- return;
-
- QMouseHandlerPrivate *dnode = static_cast<QMouseHandlerPrivate *>(QMouseHandlerPrivate::get(node));
-
- for (const QT_PREPEND_NAMESPACE(QMouseEvent) &e : m_mouseEvents)
- dnode->mouseEvent(QMouseEventPtr::create(e));
-#if QT_CONFIG(wheelevent)
- for (const QT_PREPEND_NAMESPACE(QWheelEvent) &e : m_wheelEvents) {
- QWheelEvent we(e);
- emit node->wheel(&we);
- }
-#endif
-}
-
-} // namespace Input
-} // namespace Qt3DInput
-
-QT_END_NAMESPACE
diff --git a/src/input/backend/mouseeventdispatcherjob_p.h b/src/input/backend/mouseeventdispatcherjob_p.h
deleted file mode 100644
index 696d60da4..000000000
--- a/src/input/backend/mouseeventdispatcherjob_p.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 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 QT3DINPUT_INPUT_MOUSEEVENTDISPATCHERJOB_P_H
-#define QT3DINPUT_INPUT_MOUSEEVENTDISPATCHERJOB_P_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 <Qt3DInput/QMouseEvent>
-#include <Qt3DCore/qaspectjob.h>
-#include <Qt3DCore/qnodeid.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DInput {
-namespace Input {
-
-class InputHandler;
-class MouseEventDispatcherJobPrivate;
-
-class MouseEventDispatcherJob : public Qt3DCore::QAspectJob
-{
-public:
- explicit MouseEventDispatcherJob(Qt3DCore::QNodeId input,
- const QList<QT_PREPEND_NAMESPACE(QMouseEvent)> &mouseEvents
-#if QT_CONFIG(wheelevent)
- , const QList<QT_PREPEND_NAMESPACE(QWheelEvent)> &wheelEvents
-#endif
- );
- void setInputHandler(InputHandler *handler);
- void run() final;
-
-private:
- Q_DECLARE_PRIVATE(MouseEventDispatcherJob)
-
- InputHandler *m_inputHandler;
-};
-
-} // namespace Input
-} // namespace Qt3DInput
-
-QT_END_NAMESPACE
-
-#endif // QT3DINPUT_INPUT_MOUSEEVENTDISPATCHERJOB_P_H
diff --git a/src/input/backend/mouseeventfilter.cpp b/src/input/backend/mouseeventfilter.cpp
deleted file mode 100644
index 49fc35e2b..000000000
--- a/src/input/backend/mouseeventfilter.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 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 "mouseeventfilter_p.h"
-
-#include <Qt3DInput/QKeyEvent>
-#include <QtCore/QEvent>
-
-#include <Qt3DInput/private/inputhandler_p.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DInput {
-namespace Input {
-
-// The MouseEventFilter must be in the same thread as the view it will be monitoring
-
-MouseEventFilter::MouseEventFilter(QObject *parent)
- : QObject(parent)
- , m_inputHandler(nullptr)
-{
-}
-
-void MouseEventFilter::setInputHandler(InputHandler *handler)
-{
- m_inputHandler = handler;
-}
-
-// Triggered in the view thread (usually the main thread)
-bool MouseEventFilter::eventFilter(QObject *obj, QEvent *e)
-{
- Q_UNUSED(obj);
- switch (e->type()) {
- // When dealing with QtQuick events, there are nove MouseMove events
- // only hover events which are transmitted if hoverEnabled was set to true on the Scene3D
- case QEvent::HoverMove:
- {
- const QHoverEvent *event = static_cast<QHoverEvent *>(e);
- m_inputHandler->appendMouseEvent(QMouseEvent(QEvent::MouseMove, event->position(), Qt::NoButton, Qt::NoButton, event->modifiers()));
- break;
- }
- case QEvent::MouseButtonPress:
- case QEvent::MouseButtonRelease:
- case QEvent::MouseButtonDblClick:
- case QEvent::MouseMove:
- // Creates copy and store event to be processed later on in an InputAspect job
- m_inputHandler->appendMouseEvent(QMouseEvent(*static_cast<QMouseEvent *>(e)));
- break;
-#if QT_CONFIG(wheelevent)
- case QEvent::Wheel:
- // Creates copy and store event to be processed later on in an InputAspect job
- m_inputHandler->appendWheelEvent(QWheelEvent(*static_cast<QWheelEvent *>(e)));
- break;
-#endif
- default:
- break;
- }
-
- return false;
-}
-
-} // namespace Input
-} // namespace Qt3DInput
-
-QT_END_NAMESPACE
diff --git a/src/input/backend/mouseeventfilter_p.h b/src/input/backend/mouseeventfilter_p.h
deleted file mode 100644
index 135b1afcf..000000000
--- a/src/input/backend/mouseeventfilter_p.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 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 QT3DINPUT_INPUT_MOUSEEVENTFILTER_P_H
-#define QT3DINPUT_INPUT_MOUSEEVENTFILTER_P_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/QObject>
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DInput {
-namespace Input {
-
-class InputHandler;
-
-class MouseEventFilter : public QObject
-{
- Q_OBJECT
-public:
- explicit MouseEventFilter(QObject *parent = 0);
- void setInputHandler(InputHandler *handler);
- inline InputHandler *inputHandler() const { return m_inputHandler; }
-
-protected:
- bool eventFilter(QObject *obj, QEvent *e) override;
-
-private:
- InputHandler *m_inputHandler;
-};
-
-} // namespace Input
-} // namespace Qt3DInput
-
-QT_END_NAMESPACE
-
-#endif // QT3DINPUT_INPUT_MOUSEEVENTFILTER_P_H
diff --git a/src/input/frontend/qinputaspect.cpp b/src/input/frontend/qinputaspect.cpp
index 20e325db7..65cd35b14 100644
--- a/src/input/frontend/qinputaspect.cpp
+++ b/src/input/frontend/qinputaspect.cpp
@@ -91,6 +91,8 @@
#include <Qt3DCore/private/qeventfilterservice_p.h>
#include <Qt3DCore/private/qservicelocator_p.h>
+#include <Qt3DCore/private/qaspectmanager_p.h>
+
#ifdef HAVE_QGAMEPAD
# include <Qt3DInput/private/qgamepadinput_p.h>
#endif
@@ -223,16 +225,16 @@ QVector<QAspectJobPtr> QInputAspect::jobsToExecute(qint64 time)
{
Q_D(QInputAspect);
const qint64 deltaTime = time - d->m_time;
- const float dt = static_cast<float>(deltaTime) / 1.0e9;
+ const float dt = static_cast<float>(deltaTime) / 1.0e9f;
d->m_time = time;
QVector<QAspectJobPtr> jobs;
d->m_inputHandler->updateEventSource();
- jobs.append(d->m_inputHandler->keyboardJobs());
- jobs.append(d->m_inputHandler->mouseJobs());
-
+ // Mouse and keyboard handlers will have seen the events already.
+ // All we need now is to update the axis and the accumulators since
+ // they depend on time, and other bookkeeping.
const auto integrations = d->m_inputHandler->inputDeviceIntegrations();
for (QInputDeviceIntegration *integration : integrations)
jobs += integration->jobsToExecute(time);
@@ -303,6 +305,18 @@ void QInputAspect::onUnregistered()
d->m_inputHandler.reset(nullptr);
}
+void QInputAspect::onEngineStartup()
+{
+ Q_D(QInputAspect);
+ d->m_inputHandler->setScene(d->m_aspectManager->scene());
+}
+
+void QInputAspect::jobsDone()
+{
+ Q_D(QInputAspect);
+ d->m_inputHandler->resetMouseAxisState();
+}
+
} // namespace Qt3DInput
QT_END_NAMESPACE
diff --git a/src/input/frontend/qinputaspect.h b/src/input/frontend/qinputaspect.h
index 2e9ff76a3..eff1b9e53 100644
--- a/src/input/frontend/qinputaspect.h
+++ b/src/input/frontend/qinputaspect.h
@@ -66,6 +66,8 @@ private:
void onRegistered() override;
void onUnregistered() override;
+ void onEngineStartup() override;
+ void jobsDone() override;
Q_DECLARE_PRIVATE(QInputAspect)
explicit QInputAspect(QInputAspectPrivate &dd, QObject *parent);