Created
January 6, 2020 01:01
-
-
Save shinyquagsire23/b2ee629c9e361338329744971afaf900 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void QGuiApplicationPrivate::processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e) | |
{ | |
#if QT_CONFIG(tabletevent) | |
TabletPointData &pointData = tabletDevicePoint(e->uid); | |
QEvent::Type type = QEvent::TabletMove; | |
if (e->buttons != pointData.state) | |
type = (e->buttons > pointData.state) ? QEvent::TabletPress : QEvent::TabletRelease; | |
QPointF local = e->local; | |
QWindow *window = e->window.data(); | |
modifier_buttons = e->modifiers; | |
if (true) { | |
window = QGuiApplication::topLevelAt(e->global.toPoint()); | |
QPointF delta = e->global - e->global.toPoint(); | |
local = window->mapFromGlobal(e->global.toPoint()) + delta; | |
} | |
// If window is null, pick one based on the global position and make sure all | |
// subsequent events up to the release are delivered to that same window. | |
// If window is given, just send to that. | |
if (type == QEvent::TabletPress) { | |
if (!window) | |
return; | |
pointData.target = window; | |
} else { | |
if (type == QEvent::TabletRelease) | |
pointData.target = nullptr; | |
if (!window) | |
return; | |
} | |
Qt::MouseButtons stateChange = e->buttons ^ pointData.state; | |
Qt::MouseButton button = Qt::NoButton; | |
for (int check = Qt::LeftButton; check <= int(Qt::MaxMouseButton); check = check << 1) { | |
if (check & stateChange) { | |
button = Qt::MouseButton(check); | |
break; | |
} | |
} | |
QTabletEvent tabletEvent(type, local, e->global, | |
e->device, e->pointerType, e->pressure, e->xTilt, e->yTilt, | |
e->tangentialPressure, e->rotation, e->z, | |
e->modifiers, e->uid, button, e->buttons); | |
tabletEvent.setAccepted(false); | |
tabletEvent.setTimestamp(e->timestamp); | |
QGuiApplication::sendSpontaneousEvent(window, &tabletEvent); | |
pointData.state = e->buttons; | |
if (!tabletEvent.isAccepted() | |
&& !QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse | |
&& qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTabletEvents)) { | |
const QEvent::Type mouseType = [&]() { | |
switch (type) { | |
case QEvent::TabletPress: return QEvent::MouseButtonPress; | |
case QEvent::TabletMove: return QEvent::MouseMove; | |
case QEvent::TabletRelease: return QEvent::MouseButtonRelease; | |
default: Q_UNREACHABLE(); | |
} | |
}(); | |
QWindowSystemInterfacePrivate::MouseEvent mouseEvent(window, e->timestamp, local, | |
e->global, e->buttons, e->modifiers, button, mouseType, Qt::MouseEventSynthesizedByQt); | |
mouseEvent.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic; | |
processMouseEvent(&mouseEvent); | |
} | |
#else | |
Q_UNUSED(e) | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment