17 #include "WindowInputMonitor.h" 19 #include <QQuickWindow> 23 WindowInputMonitor::WindowInputMonitor(QQuickItem *parent)
32 , m_windowBeingTouched(false)
33 , m_homeKeyPressed(false)
34 , m_windowLastTouchedTimer(elapsedTimer)
35 , m_activationTimer(timer)
37 m_windowLastTouchedTimer->start();
39 connect(
this, &QQuickItem::windowChanged,
40 this, &WindowInputMonitor::setupFilterOnWindow);
42 connect(m_activationTimer, &UnityUtil::AbstractTimer::timeout,
43 this, &WindowInputMonitor::emitActivatedIfNoTouchesAround);
44 m_activationTimer->setInterval(msecsWithoutTouches);
47 WindowInputMonitor::~WindowInputMonitor()
49 delete m_windowLastTouchedTimer;
50 delete m_activationTimer;
53 bool WindowInputMonitor::eventFilter(QObject *watched, QEvent *event)
55 Q_ASSERT(!m_filteredWindow.isNull());
56 Q_ASSERT(watched == static_cast<QObject*>(m_filteredWindow.data()));
65 void WindowInputMonitor::update(QEvent *event)
67 if (event->type() == QEvent::KeyPress) {
68 QKeyEvent *keyEvent =
static_cast<QKeyEvent*
>(event);
70 m_homeKeyPressed =
true;
72 if (keyEvent->key() == Qt::Key_Super_L && !keyEvent->isAutoRepeat()
73 && !m_windowBeingTouched
74 && m_windowLastTouchedTimer->elapsed() >= msecsWithoutTouches) {
75 m_activationTimer->start();
78 }
else if (event->type() == QEvent::KeyRelease) {
79 QKeyEvent *keyEvent =
static_cast<QKeyEvent*
>(event);
81 if (keyEvent->key() == Qt::Key_Super_L) {
82 m_homeKeyPressed =
false;
85 }
else if (event->type() == QEvent::TouchBegin) {
87 m_activationTimer->stop();
88 m_windowBeingTouched =
true;
91 }
else if (event->type() == QEvent::TouchEnd) {
93 m_windowBeingTouched =
false;
94 m_windowLastTouchedTimer->start();
96 QTouchEvent * touchEv =
static_cast<QTouchEvent *
>(event);
97 if (touchEv && !touchEv->touchPoints().isEmpty()) {
98 const QPointF pos = touchEv->touchPoints().last().screenPos();
99 Q_EMIT touchEnded(pos);
104 void WindowInputMonitor::setupFilterOnWindow(QQuickWindow *window)
106 if (!m_filteredWindow.isNull()) {
107 m_filteredWindow->removeEventFilter(
this);
108 m_filteredWindow.clear();
112 window->installEventFilter(
this);
113 m_filteredWindow = window;
117 void WindowInputMonitor::emitActivatedIfNoTouchesAround()
119 if (!m_homeKeyPressed && !m_windowBeingTouched &&
120 (m_windowLastTouchedTimer->elapsed() > msecsWithoutTouches)) {
121 Q_EMIT homeKeyActivated();