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:
2026-10-14 20:28:39 +02:00
co-authored by Claude Opus 5.5
parent c6c977eb4c
commit 5277ab16ff
49 changed files with 1162 additions and 359 deletions
+16 -21
View File
@@ -3,7 +3,6 @@
#include "engine/InputEngine.h"
#include "layout/LayoutModel.h"
#include "layout/LayoutRepository.h"
#include <xkbcommon/xkbcommon-keysyms.h>
@@ -17,15 +16,11 @@ namespace {
constexpr qsizetype MaxTextBefore = 256;
}
KeyboardController::KeyboardController(InputEngine &engine, LayoutModel &model,
const LayoutRepository &layouts, QObject *parent)
KeyboardController::KeyboardController(InputEngine &engine, LayoutModel &model, QObject *parent)
: QObject(parent)
, m_engine(engine)
, m_model(model)
, m_layouts(layouts)
{
if (!m_layouts.layouts().isEmpty())
m_model.setLayout(m_layouts.layouts().first());
connect(&m_backspaceRepeater, &KeyRepeater::repeat, this, &KeyboardController::deleteBackward);
}
@@ -79,7 +74,7 @@ void KeyboardController::keyUp(const KeyDef &key, KeyOutput output, const QStrin
autoCapitalize();
break;
case KeyType::Globe:
nextLayout();
Q_EMIT nextLayoutRequested();
break;
case KeyType::Dismiss:
Q_EMIT dismissRequested();
@@ -130,26 +125,25 @@ void KeyboardController::setContext(const TextContext &context)
autoCapitalize();
}
void KeyboardController::nextLayout()
void KeyboardController::setOptions(const TypingOptions &options)
{
const auto &layouts = m_layouts.layouts();
if (layouts.size() < 2)
return;
m_layoutIndex = int((m_layoutIndex + 1) % layouts.size());
m_model.setLayout(layouts[m_layoutIndex]);
m_options = options;
autoCapitalize();
}
void KeyboardController::typeText(const QString &text)
{
if (text == u" " && m_context.isProse() && TextRules::wantsDoubleSpacePeriod(m_textBefore)) {
m_engine.sendKeysym(XKB_KEY_BackSpace);
if (text == u" " && m_options.doubleSpacePeriod && m_context.isProse()
&& TextRules::wantsDoubleSpacePeriod(m_textBefore)) {
// "word " + space → "word. ", replacing the first space in place.
m_engine.replaceBeforeCursor(QStringLiteral(" "), QStringLiteral(". "));
m_textBefore.chop(1);
typeText(QStringLiteral(". "));
return;
m_textBefore += QStringLiteral(". ");
} else {
m_engine.commitText(text);
m_textBefore += text;
}
m_engine.commitText(text);
m_textBefore = (m_textBefore + text).right(MaxTextBefore);
m_textBefore = m_textBefore.right(MaxTextBefore);
changeShift([&] { m_shift.characterTyped(); });
autoCapitalize();
}
@@ -164,7 +158,8 @@ void KeyboardController::deleteBackward(bool wholeWord)
void KeyboardController::autoCapitalize()
{
const bool capitalize = m_context.allowsAutoCapitalization() && TextRules::startsSentence(m_textBefore);
const bool capitalize = m_options.autoCapitalize && m_context.allowsAutoCapitalization()
&& TextRules::startsSentence(m_textBefore);
changeShift([&] { m_shift.setAutomatic(capitalize); });
}