| 1 | // Copyright (C) 2024 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QKEYBOARDMAP_P_H |
| 5 | #define QKEYBOARDMAP_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtCore/qnamespace.h> |
| 19 | #include <QtCore/qtconfigmacros.h> |
| 20 | #include <QtCore/qdatastream.h> |
| 21 | |
| 22 | QT_BEGIN_NAMESPACE |
| 23 | |
| 24 | namespace QKeyboardMap { |
| 25 | |
| 26 | const quint32 FileMagic = 0x514d4150; // 'QMAP' |
| 27 | |
| 28 | struct Mapping { |
| 29 | quint16 keycode; |
| 30 | quint16 unicode; |
| 31 | quint32 qtcode; |
| 32 | quint8 modifiers; |
| 33 | quint8 flags; |
| 34 | quint16 special; |
| 35 | |
| 36 | }; |
| 37 | |
| 38 | enum Flags { |
| 39 | IsDead = 0x01, |
| 40 | IsLetter = 0x02, |
| 41 | IsModifier = 0x04, |
| 42 | IsSystem = 0x08 |
| 43 | }; |
| 44 | |
| 45 | enum System { |
| 46 | SystemConsoleFirst = 0x0100, |
| 47 | SystemConsoleMask = 0x007f, |
| 48 | SystemConsoleLast = 0x017f, |
| 49 | SystemConsolePrevious = 0x0180, |
| 50 | SystemConsoleNext = 0x0181, |
| 51 | SystemReboot = 0x0200, |
| 52 | SystemZap = 0x0300 |
| 53 | }; |
| 54 | |
| 55 | struct Composing { |
| 56 | quint16 first; |
| 57 | quint16 second; |
| 58 | quint16 result; |
| 59 | }; |
| 60 | |
| 61 | enum Modifiers { |
| 62 | ModPlain = 0x00, |
| 63 | ModShift = 0x01, |
| 64 | ModAltGr = 0x02, |
| 65 | ModControl = 0x04, |
| 66 | ModAlt = 0x08, |
| 67 | ModShiftL = 0x10, |
| 68 | ModShiftR = 0x20, |
| 69 | ModCtrlL = 0x40, |
| 70 | ModCtrlR = 0x80 |
| 71 | // ModCapsShift = 0x100, // not supported! |
| 72 | }; |
| 73 | |
| 74 | inline Qt::KeyboardModifiers toQtModifiers(quint8 mod) |
| 75 | { |
| 76 | Qt::KeyboardModifiers qtmod = Qt::NoModifier; |
| 77 | |
| 78 | if (mod & (ModShift | ModShiftL | ModShiftR)) |
| 79 | qtmod |= Qt::ShiftModifier; |
| 80 | if (mod & (ModControl | ModCtrlL | ModCtrlR)) |
| 81 | qtmod |= Qt::ControlModifier; |
| 82 | if (mod & ModAlt) |
| 83 | qtmod |= Qt::AltModifier; |
| 84 | |
| 85 | return qtmod; |
| 86 | } |
| 87 | |
| 88 | } |
| 89 | |
| 90 | inline QDataStream &operator>>(QDataStream &ds, QKeyboardMap::Mapping &m) |
| 91 | { |
| 92 | return ds >> m.keycode >> m.unicode >> m.qtcode >> m.modifiers >> m.flags >> m.special; |
| 93 | } |
| 94 | |
| 95 | inline QDataStream &operator<<(QDataStream &ds, const QKeyboardMap::Mapping &m) |
| 96 | { |
| 97 | return ds << m.keycode << m.unicode << m.qtcode << m.modifiers << m.flags << m.special; |
| 98 | } |
| 99 | |
| 100 | inline QDataStream &operator>>(QDataStream &ds, QKeyboardMap::Composing &c) |
| 101 | { |
| 102 | return ds >> c.first >> c.second >> c.result; |
| 103 | } |
| 104 | |
| 105 | inline QDataStream &operator<<(QDataStream &ds, const QKeyboardMap::Composing &c) |
| 106 | { |
| 107 | return ds << c.first << c.second << c.result; |
| 108 | } |
| 109 | |
| 110 | QT_END_NAMESPACE |
| 111 | |
| 112 | #endif // QKEYBOARDMAP_P_H |
| 113 | |