on bionic help sign in
unity8/plugins/Utils/WindowInputMonitor.h
97 lines 3.1 kB history raw
1/*
2 * Copyright (C) 2015-2016 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#ifndef UNITY_WINDOWINPUTMONITOR_H
18#define UNITY_WINDOWINPUTMONITOR_H
20#include <QQuickItem>
21#include <QList>
22#include <QPointer>
24#include "Timer.h"
25#include "ElapsedTimer.h"
27/**
28 * Monitors input events received by the window holding this item and the Home (Win aka Super_L)
29 * key presses.
30 *
31 * Additionally, this class monitors for generic touch events on the screen, to
32 * help with hiding/revealing the mouse pointer.
33 */
34class WindowInputMonitor : public QQuickItem
36 Q_OBJECT
37public:
39 WindowInputMonitor(QQuickItem *parent = 0);
41 // for testing
42 WindowInputMonitor(UnityUtil::AbstractTimer *timer,
43 UnityUtil::AbstractElapsedTimer *elapsedTimer,
44 QQuickItem *parent = 0);
46 virtual ~WindowInputMonitor();
48 bool eventFilter(QObject *watched, QEvent *event) override;
50 void update(QEvent *event);
52 const qint64 msecsWithoutTouches = 150;
54Q_SIGNALS:
55 /**
56 * Emitted when the home key has been intentionally tapped
57 *
58 * It only says the home key has been activated if it has been tapped in isolation,
59 * that is, without being accompanied by touches on the screen. Home key taps that
60 * happen along with (or immediately after, or immediately before) touches on the
61 * screen are considered to have happened unintentionally and are thus ignored.
62 *
63 * Rationale being that it's easy to accidentally hit the home key while performing
64 * a swipe from a screen edge, for instance. That's particularly the case when the
65 * home key is a capacitive key.
66 */
67 void homeKeyActivated();
69 /**
70 * Emitted when a touch begin event is detected
71 */
72 void touchBegun();
74 /**
75 * Emitted when a touch end event is detected
76 * @param pos the position in screen coordinates
77 */
78 void touchEnded(const QPointF &pos);
80private Q_SLOTS:
81 void setupFilterOnWindow(QQuickWindow *window);
82 void emitActivatedIfNoTouchesAround();
84private:
85 QPointer<QQuickWindow> m_filteredWindow;
86 bool m_windowBeingTouched;
87 UnityUtil::AbstractElapsedTimer *m_windowLastTouchedTimer;
88 UnityUtil::AbstractTimer *m_activationTimer;
90 // Qt::Keys that are mapped to our "home" key.
91 QList<int> m_homeKeys{Qt::Key_Super_L, Qt::Key_HomePage};
92 // Which Qt::Key from m_homeKeys is currently pressed.
93 // 0 if none
94 int m_pressedHomeKey{0};
95};
97#endif // UNITY_WINDOWINPUTMONITOR_H