Always check keyboard modifiers when generating mouse events

This is basically a revert of: 634ce491e8

The cached keyboard modifier can get out of sync when switching to
another application while a modifier is pressed. In this case we get a
key press event but we might not get the key release event, which is
expected to reset the cached modifier. Switching back to the Qt
application after the modifier was released now still has the old
modifier cached.

Most prominent example is triggering alt + tab to switch to another
application and use the mouse to get back to it. In this case the alt
modifier is still cached.

Task-number: QTCREATORBUG-26581
Pick-to: 6.2
Change-Id: I9d64b7d730af089778bd1a4b3f1296bcccd5d16d
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
David Schulz 2021-11-16 06:31:37 +01:00
parent 16aa4eaa82
commit 35263fffea
2 changed files with 1 additions and 4 deletions

View File

@ -1616,7 +1616,7 @@ void QPlainTextEdit::timerEvent(QTimerEvent *e)
const QPoint globalPos = QCursor::pos();
pos = d->viewport->mapFromGlobal(globalPos);
QMouseEvent ev(QEvent::MouseMove, pos, d->viewport->mapTo(d->viewport->topLevelWidget(), pos), globalPos,
Qt::LeftButton, Qt::LeftButton, d->keyboardModifiers);
Qt::LeftButton, Qt::LeftButton, QGuiApplication::keyboardModifiers());
mouseMoveEvent(&ev);
}
int deltaY = qMax(pos.y() - visible.top(), visible.bottom() - pos.y()) - visible.height();
@ -1681,7 +1681,6 @@ void QPlainTextEdit::setPlainText(const QString &text)
void QPlainTextEdit::keyPressEvent(QKeyEvent *e)
{
Q_D(QPlainTextEdit);
d->keyboardModifiers = e->modifiers();
#ifdef QT_KEYPAD_NAVIGATION
switch (e->key()) {
@ -1832,7 +1831,6 @@ void QPlainTextEdit::keyReleaseEvent(QKeyEvent *e)
Q_D(QPlainTextEdit);
if (!isReadOnly())
d->handleSoftwareInputPanel();
d->keyboardModifiers = e->modifiers();
#ifdef QT_KEYPAD_NAVIGATION
if (QApplicationPrivate::keypadNavigationEnabled()) {

View File

@ -155,7 +155,6 @@ public:
qreal pageUpDownLastCursorY = 0;
QPlainTextEdit::LineWrapMode lineWrap = QPlainTextEdit::WidgetWidth;
QTextOption::WrapMode wordWrap = QTextOption::WrapAtWordBoundaryOrAnywhere;
Qt::KeyboardModifiers keyboardModifiers = {};
int originalOffsetY = 0;
int topLine = 0;