From 6802065da8706f1fc298a56b9f66ab8a815400d3 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Fri, 23 Jul 2021 01:11:25 +0200 Subject: [PATCH] Accessibility Linux: Fix caps lock state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently in QSpiApplicationAdaptor::eventFilter, the ATSPI_MODIFIER_SHIFTLOCK flag (actually capslock modifier) only set when the capslock key is kept pressed, not when the capslock modifier is enabled. Orca however really needs to know the capslock modifier state, to be able to properly determine whether to enable/disable capslock when the user presses double-capslock. Task-number: QTBUG-84225 Pick-to: 6.2 5.15 5.12 Change-Id: I98ab8b7261c5560ebad49410b1358b2279080ec8 Reviewed-by: Liang Qi Reviewed-by: Jan Arve Sæther --- .../accessible/linux/qspiapplicationadaptor.cpp | 17 ++++++++--------- .../accessible/linux/qspiapplicationadaptor_p.h | 1 - 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/gui/accessible/linux/qspiapplicationadaptor.cpp b/src/gui/accessible/linux/qspiapplicationadaptor.cpp index 430dc13b00..af333795a4 100644 --- a/src/gui/accessible/linux/qspiapplicationadaptor.cpp +++ b/src/gui/accessible/linux/qspiapplicationadaptor.cpp @@ -48,6 +48,8 @@ #include "deviceeventcontroller_adaptor.h" #include "atspi/atspi-constants.h" +#include + //#define KEYBOARD_DEBUG QT_BEGIN_NAMESPACE @@ -62,7 +64,7 @@ QT_BEGIN_NAMESPACE */ QSpiApplicationAdaptor::QSpiApplicationAdaptor(const QDBusConnection &connection, QObject *parent) - : QObject(parent), dbusConnection(connection), inCapsLock(false) + : QObject(parent), dbusConnection(connection) { } @@ -143,13 +145,9 @@ bool QSpiApplicationAdaptor::eventFilter(QObject *target, QEvent *event) de.text = QStringLiteral("Escape"); else if (keyEvent->key() == Qt::Key_Space) de.text = QStringLiteral("space"); - else if (keyEvent->key() == Qt::Key_CapsLock) { + else if (keyEvent->key() == Qt::Key_CapsLock) de.text = QStringLiteral("Caps_Lock"); - if (event->type() == QEvent::KeyPress) - inCapsLock = true; - else - inCapsLock = false; - } else if (keyEvent->key() == Qt::Key_NumLock) + else if (keyEvent->key() == Qt::Key_NumLock) de.text = QStringLiteral("Num_Lock"); else if (keyEvent->key() == Qt::Key_Insert) de.text = QStringLiteral("Insert"); @@ -161,9 +159,10 @@ bool QSpiApplicationAdaptor::eventFilter(QObject *target, QEvent *event) de.isText = !de.text.isEmpty(); de.modifiers = 0; - if (!inCapsLock && keyEvent->modifiers() & Qt::ShiftModifier) + if ((keyEvent->modifiers() & Qt::ShiftModifier) && (keyEvent->key() != Qt::Key_Shift)) de.modifiers |= 1 << ATSPI_MODIFIER_SHIFT; - if (inCapsLock && (keyEvent->key() != Qt::Key_CapsLock)) + // TODO rather introduce Qt::CapslockModifier into KeyboardModifier + if (keyEvent->nativeModifiers() & XCB_MOD_MASK_LOCK ) de.modifiers |= 1 << ATSPI_MODIFIER_SHIFTLOCK; if ((keyEvent->modifiers() & Qt::ControlModifier) && (keyEvent->key() != Qt::Key_Control)) de.modifiers |= 1 << ATSPI_MODIFIER_CONTROL; diff --git a/src/gui/accessible/linux/qspiapplicationadaptor_p.h b/src/gui/accessible/linux/qspiapplicationadaptor_p.h index ca206edcd4..3f0ade8dde 100644 --- a/src/gui/accessible/linux/qspiapplicationadaptor_p.h +++ b/src/gui/accessible/linux/qspiapplicationadaptor_p.h @@ -91,7 +91,6 @@ private: QQueue, QKeyEvent*> > keyEvents; QDBusConnection dbusConnection; - bool inCapsLock; }; QT_END_NAMESPACE