fix: plus key as hotkey support
This commit is contained in:
parent
abaf233a07
commit
c6544dd4eb
7 changed files with 70 additions and 0 deletions
|
|
@ -1152,6 +1152,12 @@ bool KeyMap::parseModifiers(std::string &x, KeyModifierMask &mask)
|
|||
}
|
||||
std::string c = x.substr(tb, te - tb);
|
||||
if (c.empty()) {
|
||||
// allow '+' to be parsed as the key after modifiers (e.g. Control+Shift++)
|
||||
if (x[tb] == '+') {
|
||||
x.erase(0, tb);
|
||||
return true;
|
||||
}
|
||||
|
||||
// missing component
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ static const struct
|
|||
{Qt::Key_Launch0, "AppUser1"},
|
||||
{Qt::Key_Launch1, "AppUser2"},
|
||||
{Qt::Key_Select, "Select"},
|
||||
{Qt::Key_Plus, "Plus"},
|
||||
{Qt::Key_Comma, "Comma"},
|
||||
{Qt::Key_Semicolon, "Semicolon"},
|
||||
|
||||
|
|
|
|||
|
|
@ -183,4 +183,22 @@ void KeyMapTests::mapkey()
|
|||
QVERIFY(result == nullptr);
|
||||
}
|
||||
|
||||
void KeyMapTests::parseModifiers_plusKey_keepsPlusAsKey()
|
||||
{
|
||||
std::string keystroke = "Control+Shift++";
|
||||
KeyModifierMask mask = 0;
|
||||
|
||||
QVERIFY(KeyMap::parseModifiers(keystroke, mask));
|
||||
QCOMPARE(mask, static_cast<KeyModifierMask>(KeyModifierControl | KeyModifierShift));
|
||||
QCOMPARE(keystroke, std::string("+"));
|
||||
}
|
||||
|
||||
void KeyMapTests::parseKey_plusSymbol_parsesAsAsciiKey()
|
||||
{
|
||||
KeyID key = kKeyNone;
|
||||
|
||||
QVERIFY(KeyMap::parseKey("+", key));
|
||||
QCOMPARE(key, static_cast<KeyID>('+'));
|
||||
}
|
||||
|
||||
QTEST_MAIN(KeyMapTests)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ private Q_SLOTS:
|
|||
void findBestKey_noRequiredDown_cannotMatch();
|
||||
void isCommand();
|
||||
void mapkey();
|
||||
void parseModifiers_plusKey_keepsPlusAsKey();
|
||||
void parseKey_plusSymbol_parsesAsAsciiKey();
|
||||
|
||||
private:
|
||||
Log m_log;
|
||||
|
|
|
|||
|
|
@ -10,3 +10,10 @@ create_test(
|
|||
SOURCE LoggerTests.cpp
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/gui"
|
||||
)
|
||||
|
||||
create_test(
|
||||
NAME KeySequenceTests
|
||||
DEPENDS gui
|
||||
SOURCE KeySequenceTests.cpp
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/gui"
|
||||
)
|
||||
|
|
|
|||
22
src/unittests/gui/KeySequenceTests.cpp
Normal file
22
src/unittests/gui/KeySequenceTests.cpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2026 Deskflow Developers
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "KeySequenceTests.h"
|
||||
|
||||
#include "gui/KeySequence.h"
|
||||
|
||||
void KeySequenceTests::toString_controlShiftPlus_usesNamedPlus()
|
||||
{
|
||||
KeySequence sequence;
|
||||
|
||||
sequence.appendKey(Qt::Key_Control, Qt::ControlModifier);
|
||||
sequence.appendKey(Qt::Key_Shift, Qt::ControlModifier | Qt::ShiftModifier);
|
||||
QVERIFY(sequence.appendKey(Qt::Key_Plus, Qt::ControlModifier | Qt::ShiftModifier));
|
||||
|
||||
QCOMPARE(sequence.toString(), QStringLiteral("Control+Shift+Plus"));
|
||||
}
|
||||
|
||||
QTEST_MAIN(KeySequenceTests)
|
||||
14
src/unittests/gui/KeySequenceTests.h
Normal file
14
src/unittests/gui/KeySequenceTests.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2026 Deskflow Developers
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include <QTest>
|
||||
|
||||
class KeySequenceTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
void toString_controlShiftPlus_usesNamedPlus();
|
||||
};
|
||||
Loading…
Reference in a new issue