Fix double-space period, shift double-tap; settings; letters from system keymap
- Double-space replaced the space via a Backspace keysym, which clients apply after the commit: use delete_surrounding_text with the commit - Tests use a shared FakeEngine that applies ops to a simulated field - Double-tap shift locks at a sentence start; typing between taps doesn't - Organization name set: config lives in ~/.config/sloposk/ - Settings (auto-capitalization, double-space period) with a ⚙ panel - Letter rows come from the compositor's XKB keymap; other letters of the layout become long-press alternates; globe switches the system layout over org.kde.keyboard - One JSON template for non-letter layers; stretch keys even out rows Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+43
-30
@@ -1,7 +1,7 @@
|
||||
#include "engine/InputEngine.h"
|
||||
#include "FakeEngine.h"
|
||||
#include "input/KeyboardController.h"
|
||||
#include "layout/LayoutModel.h"
|
||||
#include "layout/LayoutRepository.h"
|
||||
#include "TestLayouts.h"
|
||||
|
||||
#include <QTest>
|
||||
#include <xkbcommon/xkbcommon-keysyms.h>
|
||||
@@ -10,21 +10,6 @@ using namespace Qt::StringLiterals;
|
||||
|
||||
namespace {
|
||||
|
||||
class FakeEngine : public InputEngine
|
||||
{
|
||||
public:
|
||||
void commitText(const QString &text) override { output += text; }
|
||||
void sendKeysym(quint32 keysym, Qt::KeyboardModifiers modifiers) override
|
||||
{
|
||||
keysyms.append(keysym);
|
||||
lastModifiers = modifiers;
|
||||
}
|
||||
|
||||
QString output;
|
||||
QList<quint32> keysyms;
|
||||
Qt::KeyboardModifiers lastModifiers;
|
||||
};
|
||||
|
||||
KeyDef makeKey(KeyType type, const QString &label = {})
|
||||
{
|
||||
KeyDef k;
|
||||
@@ -41,7 +26,6 @@ class TestController : public QObject
|
||||
|
||||
private:
|
||||
FakeEngine engine;
|
||||
LayoutRepository repo;
|
||||
LayoutModel model;
|
||||
std::unique_ptr<KeyboardController> controller;
|
||||
qint64 now = 0;
|
||||
@@ -57,11 +41,8 @@ private Q_SLOTS:
|
||||
void init()
|
||||
{
|
||||
engine = {};
|
||||
repo = {};
|
||||
Q_INIT_RESOURCE(layouts);
|
||||
repo.loadDirectory(u":/layouts"_s);
|
||||
repo.finalize(u"en_US"_s);
|
||||
controller = std::make_unique<KeyboardController>(engine, model, repo);
|
||||
model.setLayout(TestLayouts::build("us"));
|
||||
controller = std::make_unique<KeyboardController>(engine, model);
|
||||
}
|
||||
|
||||
void typesLowercase()
|
||||
@@ -156,11 +137,44 @@ private Q_SLOTS:
|
||||
tap(makeKey(KeyType::Character, u"a"_s));
|
||||
tap(space);
|
||||
tap(space);
|
||||
QCOMPARE(engine.output, u"a . ");
|
||||
QCOMPARE(engine.keysyms, QList<quint32>{XKB_KEY_BackSpace}); // removed the first space
|
||||
QCOMPARE(engine.output, u"a. ");
|
||||
QCOMPARE(engine.mismatchedReplacements, 0);
|
||||
// A Backspace keysym may reach the client after the commit and eat the new space.
|
||||
QVERIFY(engine.keysyms.isEmpty());
|
||||
QCOMPARE(controller->shiftMode(), KeyboardController::ShiftMode::Once);
|
||||
}
|
||||
|
||||
void doubleSpacePeriodCanBeTurnedOff()
|
||||
{
|
||||
controller->setOptions({.doubleSpacePeriod = false});
|
||||
const KeyDef space = makeKey(KeyType::Space);
|
||||
tap(makeKey(KeyType::Character, u"a"_s));
|
||||
tap(space);
|
||||
tap(space);
|
||||
QCOMPARE(engine.output, u"A ");
|
||||
}
|
||||
|
||||
void autoCapitalizationCanBeTurnedOff()
|
||||
{
|
||||
controller->resetContext();
|
||||
controller->setOptions({.autoCapitalize = false});
|
||||
QCOMPARE(controller->shiftMode(), KeyboardController::ShiftMode::Off);
|
||||
tap(makeKey(KeyType::Character, u"a"_s));
|
||||
QCOMPARE(engine.output, u"a");
|
||||
}
|
||||
|
||||
void doubleTapShiftLocksAtSentenceStart()
|
||||
{
|
||||
controller->resetContext(); // a field was focused
|
||||
QCOMPARE(controller->shiftMode(), KeyboardController::ShiftMode::Once); // auto-shift
|
||||
const KeyDef shift = makeKey(KeyType::Shift);
|
||||
controller->keyDown(shift, 5000);
|
||||
controller->keyUp(shift, KeyOutput::Primary, {}, 5050);
|
||||
controller->keyDown(shift, 5200);
|
||||
controller->keyUp(shift, KeyOutput::Primary, {}, 5250);
|
||||
QCOMPARE(controller->shiftMode(), KeyboardController::ShiftMode::Locked);
|
||||
}
|
||||
|
||||
void slideTypesSymbolAndSwitchesBack()
|
||||
{
|
||||
KeyDef layer = makeKey(KeyType::LayerSwitch);
|
||||
@@ -177,13 +191,12 @@ private Q_SLOTS:
|
||||
QCOMPARE(engine.keysyms, (QList<quint32>{XKB_KEY_Right, XKB_KEY_Right, XKB_KEY_Up}));
|
||||
}
|
||||
|
||||
void globeCyclesLayouts()
|
||||
void globeRequestsNextLayout()
|
||||
{
|
||||
QCOMPARE(model.layoutName(), u"English (US)");
|
||||
int requested = 0;
|
||||
connect(controller.get(), &KeyboardController::nextLayoutRequested, this, [&] { ++requested; });
|
||||
tap(makeKey(KeyType::Globe));
|
||||
QCOMPARE(model.layoutName(), u"Svenska");
|
||||
tap(makeKey(KeyType::Globe));
|
||||
QCOMPARE(model.layoutName(), u"English (US)");
|
||||
QCOMPARE(requested, 1);
|
||||
}
|
||||
|
||||
void dismissEmitsSignal()
|
||||
|
||||
Reference in New Issue
Block a user