on bc2da59 help sign in
unity8/plugins/Utils/WindowInputMonitor.h
91 lines 2.8 kB history raw
1/*
2 * Copyright (C) 2015 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 <QPointer>
23#include "Timer.h"
24#include "ElapsedTimer.h"
26/**
27 * Monitors input events received by the window holding this item and the Home (Win aka Super_L)
28 * key presses.
29 *
30 * Additionally, this class monitors for generic touch events on the screen, to
31 * help with hiding/revealing the mouse pointer.
32 */
33class WindowInputMonitor : public QQuickItem
35 Q_OBJECT
36public:
38 WindowInputMonitor(QQuickItem *parent = 0);
40 // for testing
41 WindowInputMonitor(UnityUtil::AbstractTimer *timer,
42 UnityUtil::AbstractElapsedTimer *elapsedTimer,
43 QQuickItem *parent = 0);
45 virtual ~WindowInputMonitor();
47 bool eventFilter(QObject *watched, QEvent *event) override;
49 void update(QEvent *event);
51 const qint64 msecsWithoutTouches = 150;
53Q_SIGNALS:
54 /**
55 * Emitted when the home key has been intentionally tapped
56 *
57 * It only says the home key has been activated if it has been tapped in isolation,
58 * that is, without being accompanied by touches on the screen. Home key taps that
59 * happen along with (or immediately after, or immediately before) touches on the
60 * screen are considered to have happened unintentionally and are thus ignored.
61 *
62 * Rationale being that it's easy to accidentally hit the home key while performing
63 * a swipe from a screen edge, for instance. That's particularly the case when the
64 * home key is a capacitive key.
65 */
66 void homeKeyActivated();
68 /**
69 * Emitted when a touch begin event is detected
70 */
71 void touchBegun();
73 /**
74 * Emitted when a touch end event is detected
75 * @param pos the position in screen coordinates
76 */
77 void touchEnded(const QPointF &pos);
79private Q_SLOTS:
80 void setupFilterOnWindow(QQuickWindow *window);
81 void emitActivatedIfNoTouchesAround();
83private:
84 QPointer<QQuickWindow> m_filteredWindow;
85 bool m_windowBeingTouched;
86 bool m_homeKeyPressed;
87 UnityUtil::AbstractElapsedTimer *m_windowLastTouchedTimer;
88 UnityUtil::AbstractTimer *m_activationTimer;
89};
91#endif // UNITY_WINDOWINPUTMONITOR_H