9#include <private/qpointingdevice_p.h>
17Q_CONSTINIT
QPointF QCocoaTouch::_screenReferencePos;
18Q_CONSTINIT
QPointF QCocoaTouch::_trackpadReferencePos;
19int QCocoaTouch::_idAssignmentCount = 0;
20int QCocoaTouch::_touchCount = 0;
21bool QCocoaTouch::_updateInternalStateOnly =
true;
23QCocoaTouch::QCocoaTouch(NSTouch *nstouch)
25 if (_currentTouches.
size() == 0)
26 _idAssignmentCount = 0;
28 _touchPoint.
id = _idAssignmentCount++;
30 _identity =
qint64([nstouch identity]);
31 _currentTouches.
insert(_identity,
this);
32 updateTouchData(nstouch, NSTouchPhaseBegan);
35QCocoaTouch::~QCocoaTouch()
37 _currentTouches.
remove(_identity);
40void QCocoaTouch::updateTouchData(NSTouch *nstouch, NSTouchPhase phase)
42 _touchPoint.
state = toTouchPointState(phase);
47 NSPoint npos = [nstouch normalizedPosition];
51 if (_touchPoint.
id == 0 && phase == NSTouchPhaseBegan) {
52 _trackpadReferencePos = qnpos;
56 QPointF screenPos = _screenReferencePos;
58 NSSize dsize = [nstouch deviceSize];
59 float ppiX = (qnpos.
x() - _trackpadReferencePos.
x()) * dsize.width;
60 float ppiY = (qnpos.
y() - _trackpadReferencePos.
y()) * dsize.height;
62 screenPos -= relativePos;
66 screenPos.
rx() -= 0.5;
67 screenPos.
ry() -= 0.5;
71QCocoaTouch *QCocoaTouch::findQCocoaTouch(NSTouch *nstouch)
74 if (_currentTouches.
contains(identity))
75 return _currentTouches.
value(identity);
83 case NSTouchPhaseBegan:
86 case NSTouchPhaseMoved:
89 case NSTouchPhaseStationary:
92 case NSTouchPhaseEnded:
93 case NSTouchPhaseCancelled:
106 NSSet *ended = [
event touchesMatchingPhase:NSTouchPhaseEnded | NSTouchPhaseCancelled inView:nil];
107 NSSet *active = [
event
108 touchesMatchingPhase:NSTouchPhaseBegan | NSTouchPhaseMoved | NSTouchPhaseStationary
110 _touchCount = [active
count];
117 for (
int i=0;
i<int([ended
count]); ++
i) {
118 NSTouch *touch = [[ended allObjects] objectAtIndex:
i];
121 qcocoaTouch->updateTouchData(touch, [touch phase]);
122 if (!_updateInternalStateOnly)
123 touchPoints.
insert(qcocoaTouch->_touchPoint.
id, qcocoaTouch->_touchPoint);
128 bool wasUpdateInternalStateOnly = _updateInternalStateOnly;
129 _updateInternalStateOnly = !acceptSingleTouch && _touchCount < 2;
135 for (
int i=0;
i<int([active
count]); ++
i) {
136 NSTouch *touch = [[active allObjects] objectAtIndex:
i];
141 qcocoaTouch->updateTouchData(touch, wasUpdateInternalStateOnly ? NSTouchPhaseBegan : [touch phase]);
142 if (!_updateInternalStateOnly)
143 touchPoints.
insert(qcocoaTouch->_touchPoint.
id, qcocoaTouch->_touchPoint);
150 if (_touchCount != _currentTouches.
size()) {
155 const auto currentTouchesSnapshot = _currentTouches;
156 for (
QCocoaTouch *qcocoaTouch : currentTouchesSnapshot) {
157 if (!_updateInternalStateOnly) {
159 touchPoints.
insert(qcocoaTouch->_touchPoint.id, qcocoaTouch->_touchPoint);
163 _currentTouches.
clear();
164 _updateInternalStateOnly = !acceptSingleTouch;
165 return touchPoints.
values();
172 if (_updateInternalStateOnly && !wasUpdateInternalStateOnly && !_currentTouches.
isEmpty()) {
175 touchPoints.
insert(qcocoaTouch->_touchPoint.
id, qcocoaTouch->_touchPoint);
179 qcocoaTouch->_touchPoint.
id = 0;
180 _idAssignmentCount = 1;
183 return touchPoints.
values();
static QPointF mapFromNative(CGPoint pos, QCocoaScreen *screen=QCocoaScreen::primaryScreen())
static QList< QWindowSystemInterface::TouchPoint > getCurrentTouchPointList(NSEvent *event, bool acceptSingleTouch)
static QPointingDevice * getTouchDevice(QInputDevice::DeviceType type, quint64 id)
State
Specifies the state of this event point.
bool remove(const Key &key)
Removes the item that has the key from the hash.
const_iterator cbegin() const noexcept
qsizetype size() const noexcept
Returns the number of items in the hash.
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
T value(const Key &key) const noexcept
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
bool isEmpty() const noexcept
Returns true if the hash contains no items; otherwise returns false.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
iterator insert(const Key &key, const T &value)
QList< T > values() const
\inmodule QtCore\reentrant
constexpr qreal & ry() noexcept
Returns a reference to the y coordinate of this point.
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
constexpr qreal & rx() noexcept
Returns a reference to the x coordinate of this point.
The QPointingDevice class describes a device from which mouse, touch or tablet events originate.
\inmodule QtCore\reentrant
static void registerInputDevice(const QInputDevice *device)
Combined button and popup list for selecting options.
GLenum GLenum GLsizei count
unsigned long long quint64