Lomiri
Loading...
Searching...
No Matches
WindowInputMonitor Class Reference

#include <plugins/Utils/WindowInputMonitor.h>

Inherits QQuickItem.

Signals

void homeKeyActivated ()
 
void touchBegun ()
 
void touchEnded (const QPointF &pos)
 

Public Member Functions

 WindowInputMonitor (QQuickItem *parent=0)
 
 WindowInputMonitor (LomiriUtil::AbstractTimer *timer, LomiriUtil::AbstractElapsedTimer *elapsedTimer, QQuickItem *parent=0)
 
bool eventFilter (QObject *watched, QEvent *event) override
 
void update (QEvent *event)
 

Public Attributes

const qint64 msecsWithoutTouches = 150
 

Detailed Description

Monitors input events received by the window holding this item and the Home (Win aka Super_L) key presses.

Additionally, this class monitors for generic touch events on the screen, to help with hiding/revealing the mouse pointer.

Definition at line 34 of file WindowInputMonitor.h.

Constructor & Destructor Documentation

◆ WindowInputMonitor() [1/2]

WindowInputMonitor::WindowInputMonitor ( QQuickItem *  parent = 0)

◆ WindowInputMonitor() [2/2]

WindowInputMonitor::WindowInputMonitor ( LomiriUtil::AbstractTimer timer,
LomiriUtil::AbstractElapsedTimer elapsedTimer,
QQuickItem *  parent = 0 
)

Definition at line 28 of file WindowInputMonitor.cpp.

31 : QQuickItem(parent)
32 , m_windowBeingTouched(false)
33 , m_windowLastTouchedTimer(elapsedTimer)
34 , m_activationTimer(timer)
35{
36 m_windowLastTouchedTimer->start();
37
38 connect(this, &QQuickItem::windowChanged,
39 this, &WindowInputMonitor::setupFilterOnWindow);
40
41 connect(m_activationTimer, &LomiriUtil::AbstractTimer::timeout,
42 this, &WindowInputMonitor::emitActivatedIfNoTouchesAround);
43 m_activationTimer->setInterval(msecsWithoutTouches);
44 m_activationTimer->setSingleShot(true);
45}

◆ ~WindowInputMonitor()

WindowInputMonitor::~WindowInputMonitor ( )
virtual

Definition at line 47 of file WindowInputMonitor.cpp.

48{
49 delete m_windowLastTouchedTimer;
50 delete m_activationTimer;
51}

Member Function Documentation

◆ eventFilter()

bool WindowInputMonitor::eventFilter ( QObject *  watched,
QEvent *  event 
)
override

Definition at line 53 of file WindowInputMonitor.cpp.

54{
55 Q_ASSERT(!m_filteredWindow.isNull());
56 Q_ASSERT(watched == static_cast<QObject*>(m_filteredWindow.data()));
57 Q_UNUSED(watched);
58
59 update(event);
60
61 // We're only monitoring, never filtering out events
62 return false;
63}

◆ homeKeyActivated

void WindowInputMonitor::homeKeyActivated ( )
signal

Emitted when the home key has been intentionally tapped

It only says the home key has been activated if it has been tapped in isolation, that is, without being accompanied by touches on the screen. Home key taps that happen along with (or immediately after, or immediately before) touches on the screen are considered to have happened unintentionally and are thus ignored.

Rationale being that it's easy to accidentally hit the home key while performing a swipe from a screen edge, for instance. That's particularly the case when the home key is a capacitive key.

◆ touchBegun

void WindowInputMonitor::touchBegun ( )
signal

Emitted when a touch begin event is detected

◆ touchEnded

void WindowInputMonitor::touchEnded ( const QPointF &  pos)
signal

Emitted when a touch end event is detected

Parameters
posthe position in screen coordinates

◆ update()

void WindowInputMonitor::update ( QEvent *  event)

Definition at line 65 of file WindowInputMonitor.cpp.

66{
67 if (event->type() == QEvent::KeyPress) {
68 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
69
70 if (m_pressedHomeKey == 0 && m_homeKeys.contains(keyEvent->key()) && !keyEvent->isAutoRepeat()
71 && !m_activationTimer->isRunning()
72 && !m_windowBeingTouched
73 && m_windowLastTouchedTimer->elapsed() >= msecsWithoutTouches) {
74 m_pressedHomeKey = keyEvent->key();
75 m_activationTimer->start();
76 } else if (m_pressedHomeKey != 0 && !m_homeKeys.contains(keyEvent->key())) {
77 // something else came in... cancel activation
78 m_activationTimer->stop();
79 }
80
81 } else if (event->type() == QEvent::KeyRelease) {
82 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
83
84 if (keyEvent->key() == m_pressedHomeKey) {
85 m_pressedHomeKey = 0;
86 }
87
88 } else if (event->type() == QEvent::TouchBegin) {
89
90 m_activationTimer->stop();
91 m_windowBeingTouched = true;
92 Q_EMIT touchBegun();
93
94 } else if (event->type() == QEvent::TouchEnd) {
95
96 m_windowBeingTouched = false;
97 m_windowLastTouchedTimer->start();
98
99 QTouchEvent * touchEv = static_cast<QTouchEvent *>(event);
100 if (touchEv && !touchEv->touchPoints().isEmpty()) {
101 const QPointF pos = touchEv->touchPoints().last().screenPos();
102 Q_EMIT touchEnded(pos);
103 }
104 }
105}
void touchEnded(const QPointF &pos)

Member Data Documentation

◆ msecsWithoutTouches

const qint64 WindowInputMonitor::msecsWithoutTouches = 150

Definition at line 52 of file WindowInputMonitor.h.


The documentation for this class was generated from the following files: