Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 30 additions & 29 deletions src/controllers/keyboard/keyboardeventfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,41 +118,42 @@ bool KeyboardEventFilter::eventFilter(QObject*, QEvent* e) {
return false;
}

// static
QKeySequence KeyboardEventFilter::getKeySeq(QKeyEvent* e) {
QString modseq;
QKeySequence k;

// TODO(XXX) check if we may simply return QKeySequence(e->modifiers()+e->key())

if (e->modifiers() & Qt::ShiftModifier) {
modseq += "Shift+";
}

if (e->modifiers() & Qt::ControlModifier) {
modseq += "Ctrl+";
}

if (e->modifiers() & Qt::AltModifier) {
modseq += "Alt+";
}

if (e->modifiers() & Qt::MetaModifier) {
modseq += "Meta+";
}

if (e->key() >= 0x01000020 && e->key() <= 0x01000023) {
// Do not act on Modifier only
// avoid returning "khmer vowel sign ie (U+17C0)"
return k;
// Do not act on Modifier only, avoid returning "khmer vowel sign ie (U+17C0)"
return {};
}

QString keyseq = QKeySequence(e->key()).toString();
k = QKeySequence(modseq + keyseq);

if (CmdlineArgs::Instance().getDeveloper()) {
qDebug() << "keyboard press: " << k.toString();
QString modseq;
QKeySequence k;
if (e->modifiers() & Qt::ShiftModifier) {
modseq += "Shift+";
}
if (e->modifiers() & Qt::ControlModifier) {
modseq += "Ctrl+";
}
if (e->modifiers() & Qt::AltModifier) {
modseq += "Alt+";
}
if (e->modifiers() & Qt::MetaModifier) {
modseq += "Meta+";
}
QString keyseq = QKeySequence(e->key()).toString();
k = QKeySequence(modseq + keyseq);
if (e->type() == QEvent::KeyPress) {
qDebug() << "keyboard press: " << k.toString();
} else if (e->type() == QEvent::KeyRelease) {
qDebug() << "keyboard release: " << k.toString();
}
}
return k;

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return QKeySequence(e->modifiers() | e->key());
#else
return QKeySequence(e->modifiers() + e->key());
#endif
}

void KeyboardEventFilter::setKeyboardConfig(ConfigObject<ConfigValueKbd>* pKbdConfigObject) {
Expand Down
7 changes: 3 additions & 4 deletions src/controllers/keyboard/keyboardeventfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class KeyboardEventFilter : public QObject {
void setKeyboardConfig(ConfigObject<ConfigValueKbd> *pKbdConfigObject);
ConfigObject<ConfigValueKbd>* getKeyboardConfig();

// Returns a valid QString with modifier keys from a QKeyEvent
static QKeySequence getKeySeq(QKeyEvent* e);

private:
struct KeyDownInformation {
KeyDownInformation(int keyId, int modifiers, ControlObject* pControl)
Expand All @@ -38,9 +41,6 @@ class KeyboardEventFilter : public QObject {
ControlObject* pControl;
};

// Returns a valid QString with modifier keys from a QKeyEvent
QKeySequence getKeySeq(QKeyEvent *e);

// Run through list of active keys to see if the pressed key is already active
// and is not a control that repeats when held.
bool shouldSkipHeldKey(int keyId) {
Expand All @@ -51,7 +51,6 @@ class KeyboardEventFilter : public QObject {
return keyDownInfo.keyId == keyId && !keyDownInfo.pControl->getKbdRepeatable();
});
}

// List containing keys which is currently pressed
QList<KeyDownInformation> m_qActiveKeyList;
// Pointer to keyboard config object
Expand Down