@@ -16,36 +16,34 @@
1616 * Author: Daniel d'Andrada <daniel.dandrada@canonical.com>
1717 */
1818
19−#include "windowkeysfilter.h"
19+#include "windowinputfilter.h"
2020
2121#include <QQuickWindow>
2222
23−WindowKeysFilter::WindowKeysFilter(QQuickItem *parent)
23+WindowInputFilter::WindowInputFilter(QQuickItem *parent)
2424 : QQuickItem(parent),
25− m_currentEventTimestamp(0)
25+ m_lastInputTimestamp(0)
2626{
2727 connect(this, &QQuickItem::windowChanged,
28− this, &WindowKeysFilter::setupFilterOnWindow);
28+ this, &WindowInputFilter::setupFilterOnWindow);
2929}
3030
31−bool WindowKeysFilter::eventFilter(QObject *watched, QEvent *event)
31+bool WindowInputFilter::eventFilter(QObject *watched, QEvent *event)
3232{
3333 Q_ASSERT(!m_filteredWindow.isNull());
3434 Q_ASSERT(watched == static_cast<QObject*>(m_filteredWindow.data()));
3535 Q_UNUSED(watched);
3636
37+ QInputEvent *inputEvent = dynamic_cast<QInputEvent*>(event);
38+ if (inputEvent) {
39+ m_lastInputTimestamp = inputEvent->timestamp();
40+ Q_EMIT lastInputTimestampChanged();
41+ }
42+
3743 if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
3844 // Let QML see this event and decide if it does not want it
3945 event->accept();
40−
41− m_currentEventTimestamp = static_cast<QInputEvent*>(event)->timestamp();
42− Q_EMIT currentEventTimestampChanged();
43−
4446 QCoreApplication::sendEvent(this, event);
45−
46− m_currentEventTimestamp = 0;
47− Q_EMIT currentEventTimestampChanged();
48−
4947 return event->isAccepted();
5048 } else {
5149 // Not interested
@@ -53,7 +51,7 @@ bool WindowKeysFilter::eventFilter(QObject *watched, QEvent *event)
5351 }
5452}
5553
56−void WindowKeysFilter::setupFilterOnWindow(QQuickWindow *window)
54+void WindowInputFilter::setupFilterOnWindow(QQuickWindow *window)
5755{
5856 if (!m_filteredWindow.isNull()) {
5957 m_filteredWindow->removeEventFilter(this);
@@ -66,7 +64,7 @@ void WindowKeysFilter::setupFilterOnWindow(QQuickWindow *window)
6664 }
6765}
6866
69−ulong WindowKeysFilter::currentEventTimestamp() const
67+ulong WindowInputFilter::lastInputTimestamp() const
7068{
71− return m_currentEventTimestamp;
69+ return m_lastInputTimestamp;
7270}