/usr/include/x86_64-linux-gnu/qt5/UbuntuGestures/touchregistry.h is in libubuntugestures5-gles-dev 1.3.1918+16.04.20160404-0ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | /*
* Copyright 2015 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UNITY_TOUCHREGISTRY_H
#define UNITY_TOUCHREGISTRY_H
#include <QtQuick/QQuickItem>
#include <QObject>
#include <QPointer>
#include <QTouchEvent>
#include <QVector>
#include "ubuntugesturesglobal.h"
#include "candidateinactivitytimer.h"
#include "timer.h"
#include "pool.h"
// logging
#include <QtCore/QLoggingCategory>
namespace UbuntuGestures {
class AbstractTimerFactory;
}
/*
Where the ownership of touches is registered.
Singleton used for adding a touch point ownership model analogous to the one
described in the XInput 2.2 protocol[1] on top of the existing input dispatch logic in QQuickWindow.
It provides a much more flexible and powerful way of dealing with pointer ownership than the existing
mechanisms in Qt. Namely QQuickItem::grabTouchPoints, QuickItem::keepTouchGrab,
QQuickItem::setFiltersChildMouseEvents, QQuickItem::ungrabTouchPoints and QQuickItem::touchUngrabEvent.
Usage:
1- An item receives a a new touch point. If he's not sure whether he wants it yet, he calls:
TouchRegistry::instance()->addCandidateOwnerForTouch(touchId, this);
touchEvent->ignore();
Ignoring the event is crucial so that it can be seen by other interested parties, which will
behave similarly.
2- That item will then start receiving UnownedTouchEvents for that touch from step 1. Once he's
made a decision he calls either:
TouchRegistry::instance()->requestTouchOwnership(touchId, this);
If he wants the touch point or:
TouchRegistry::instance()->removeCandidateOwnerForTouch(touchId, this);
if he does not want it.
Candidates are put in a priority queue. The first one to call addCandidateOwnerForTouch() will
take precedence over the others for receiving ownership over the touch point (from now on called
simply top-candidate).
If the top-candidate calls requestTouchOwnership() he will immediately receive a
TouchOwnershipEvent(gained=true) for that touch point. He can then safely call
QQuickItem::grabTouchPoints to actually get the owned touch points. The other candidates
will receive TouchOwnershipEvent(gained=false) and will no longer receive UnownedTouchEvents
for that touch point. They will have to undo whatever action they were performing with that
touch point.
But if the top-candidate calls removeCandidateOwnerForTouch() instead, he's popped from the
candidacy queue and ownership is given to the new top-most candidate if he has already
made his decision, that is.
The TouchRegistry cannot enforce the results of this pointer ownership negotiation (i.e.,
who gets to grab the touch points) as that would clash with QQuickWindow's input event
dispatching logic. The candidates have to respect the decision and grab the touch points
themselves.
If an item wants ownership over touches as soon as he receives the TouchBegin for them, his step 1
would be instead:
TouchRegistry::instance()->requestTouchOwnership(touchId, this);
touchEvent->accept();
He won't get any UnownedTouchEvent for that touch as he is already the interim owner (ie, QQuickWindow
will keep sending touch updates to him already). Eventually he will be notified once ownership has
been granted to him (from TouchRegistry perspective), from which point onwards he could safely assume
other TouchRegistry users wouldn't snatch this touch away from him.
Items oblivious to TouchRegistry will lose their touch points without warning, just like in plain Qt.
[1] - http://www.x.org/releases/X11R7.7/doc/inputproto/XI2proto.txt (see multitouch-ownership)
*/
class UBUNTUGESTURES_EXPORT TouchRegistry : public QObject
{
Q_OBJECT
public:
virtual ~TouchRegistry();
// Returns a pointer to the application's TouchRegistry instance.
static TouchRegistry *instance();
void update(const QTouchEvent *event);
// Calls update() if the given event is a QTouchEvent
bool eventFilter(QObject *watched, QEvent *event) override;
// An item that might later request ownership over the given touch point.
// He will be kept informed about that touch point through UnownedTouchEvents
// All candidates must eventually decide whether they want to own the touch point
// or not. That decision is informed through requestTouchOwnership() or
// removeCandidateOwnerForTouch()
void addCandidateOwnerForTouch(int id, QQuickItem *candidate);
// The same as rejecting ownership of a touch
void removeCandidateOwnerForTouch(int id, QQuickItem *candidate);
// The candidate object wants to be the owner of the touch with the given id.
// If he's currently the oldest/top-most candidate, he will get an ownership
// event immediately. If not, he will get ownership if (or once) he becomes the
// top-most candidate.
void requestTouchOwnership(int id, QQuickItem *candidate);
// An item that has no interest (effective or potential) in owning a touch point
// but would nonetheless like to be kept up-to-date on its state.
void addTouchWatcher(int touchId, QQuickItem *watcherItem);
// Useful for tests, where you should use fake timers
void setTimerFactory(UbuntuGestures::AbstractTimerFactory *timerFactory);
private Q_SLOTS:
void rejectCandidateOwnerForTouch(int id, QQuickItem *candidate);
private:
// Only instance() can cronstruct one
TouchRegistry(QObject *parent = nullptr);
class CandidateInfo {
public:
enum {
// A candidate owner that doesn't yet know for sure whether he wants the touch point
// (gesture recognition is stilll going on)
Undecided = 0,
// A candidate owner that wants the touch but hasn't been granted it yet,
// most likely because there's an undecided candidate with higher priority
Requested = 1,
// An item that is the interim owner of the touch, receiving QTouchEvents of it
// from QQuickWindow. Ie, it's the actual touch owner from Qt's point of view.
// It wants to keep its touch ownership but hasn't been granted it by TouchRegistry
// yet because of undecided candidates higher up.
InterimOwner = 2
} state;
QPointer<QQuickItem> item;
QPointer<UbuntuGestures::CandidateInactivityTimer> inactivityTimer;
};
class TouchInfo {
public:
TouchInfo() : id(-1) {}
TouchInfo(int id);
bool isValid() const { return id >= 0; }
void reset();
void init(int id);
int id;
bool physicallyEnded;
bool isOwned() const;
bool ended() const;
void notifyCandidatesOfOwnershipResolution();
// TODO optimize storage (s/QList/Pool)
QList<CandidateInfo> candidates;
QList<QPointer<QQuickItem>> watchers;
};
void pruneNullCandidatesForTouch(int touchId);
void removeCandidateOwnerForTouchByIndex(Pool<TouchInfo>::Iterator &touchInfo, int candidateIndex);
void removeCandidateHelper(Pool<TouchInfo>::Iterator &touchInfo, int candidateIndex);
Pool<TouchInfo>::Iterator findTouchInfo(int id);
void deliverTouchUpdatesToUndecidedCandidatesAndWatchers(const QTouchEvent *event);
static void translateTouchPointFromScreenToWindowCoords(QTouchEvent::TouchPoint &touchPoint);
static void dispatchPointsToItem(const QTouchEvent *event, const QList<int> &touchIds,
QQuickItem *item);
void freeEndedTouchInfos();
Pool<TouchInfo> m_touchInfoPool;
// the singleton instance
static TouchRegistry *m_instance;
bool m_inDispatchLoop;
UbuntuGestures::AbstractTimerFactory *m_timerFactory;
friend class tst_TouchRegistry;
friend class tst_DirectionalDragArea;
};
Q_DECLARE_LOGGING_CATEGORY(ugTouchRegistry)
#endif // UNITY_TOUCHREGISTRY_H
|