Skip to content

Commit

Permalink
Extract toQtModifiers to place where it belongs
Browse files Browse the repository at this point in the history
`QEvdevKeyboardHandler` contains static method `toQtModifiers` which is
not operating on any of its internal fields or types. This indicates
that this method doesn't belong to this class, and in fact it should be
moved to `QEvdevKeyboardMap` where types used in it are declared.

Move this static method to `QEvdevKeyboardMap` namespace. This is a
preparatory change to extract `QEvdevKeyboardMap` to separate header.

Task-number: QTBUG-115777
Change-Id: Ibe88b40a56fb96772d903498611777b3ec19dded
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
  • Loading branch information
Michał Łoś committed Oct 16, 2024
1 parent bd475dd commit 1d0ec32
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void QEvdevKeyboardHandler::processKeyEvent(int nativecode, int unicode, int qtc
Qt::KeyboardModifiers modifiers, bool isPress, bool autoRepeat)
{
if (!autoRepeat)
QGuiApplicationPrivate::inputDeviceManager()->setKeyboardModifiers(QEvdevKeyboardHandler::toQtModifiers(m_modifiers));
QGuiApplicationPrivate::inputDeviceManager()->setKeyboardModifiers(QEvdevKeyboardMap::toQtModifiers(m_modifiers));

QWindow *window = nullptr;
#ifdef Q_OS_WEBOS
Expand Down Expand Up @@ -336,7 +336,7 @@ QEvdevKeyboardHandler::KeycodeAction QEvdevKeyboardHandler::processKeycode(quint
// so just report the plain mapping with additional modifiers.
if ((it == map_plain && it != map_withmod) ||
(map_withmod && !(map_withmod->qtcode & modmask))) {
qtcode |= QEvdevKeyboardHandler::toQtModifiers(modifiers);
qtcode |= QEvdevKeyboardMap::toQtModifiers(modifiers);
}

if (m_composing == 2 && first_press && !(it->flags & QEvdevKeyboardMap::IsModifier)) {
Expand Down
29 changes: 15 additions & 14 deletions src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ namespace QEvdevKeyboardMap {
ModCtrlR = 0x80
// ModCapsShift = 0x100, // not supported!
};

inline Qt::KeyboardModifiers toQtModifiers(quint8 mod)
{
Qt::KeyboardModifiers qtmod = Qt::NoModifier;

if (mod & (ModShift | ModShiftL | ModShiftR))
qtmod |= Qt::ShiftModifier;
if (mod & (ModControl | ModCtrlL | ModCtrlR))
qtmod |= Qt::ControlModifier;
if (mod & ModAlt)
qtmod |= Qt::AltModifier;

return qtmod;
}

}

inline QDataStream &operator>>(QDataStream &ds, QEvdevKeyboardMap::Mapping &m)
Expand Down Expand Up @@ -129,20 +144,6 @@ class QEvdevKeyboardHandler : public QObject
const QString &specification,
const QString &defaultKeymapFile = QString());

static Qt::KeyboardModifiers toQtModifiers(quint8 mod)
{
Qt::KeyboardModifiers qtmod = Qt::NoModifier;

if (mod & (QEvdevKeyboardMap::ModShift | QEvdevKeyboardMap::ModShiftL | QEvdevKeyboardMap::ModShiftR))
qtmod |= Qt::ShiftModifier;
if (mod & (QEvdevKeyboardMap::ModControl | QEvdevKeyboardMap::ModCtrlL | QEvdevKeyboardMap::ModCtrlR))
qtmod |= Qt::ControlModifier;
if (mod & QEvdevKeyboardMap::ModAlt)
qtmod |= Qt::AltModifier;

return qtmod;
}

bool loadKeymap(const QString &file);
void unloadKeymap();

Expand Down

0 comments on commit 1d0ec32

Please sign in to comment.