Dead keys: act on compose status at press time

- Two dead keys that compose (´´ → ´) type the result right away; a dead
  key that can't continue the sequence types the old accents and starts anew
- With Ctrl/Alt/Super, a dead key sends its dead keysym, as the physical
  key does, not the spacing accent from its label

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-15 10:13:49 +02:00
co-authored by Claude Opus 5.5
parent 9abd19e5d3
commit 536fc12d2f
5 changed files with 64 additions and 15 deletions
+31 -9
View File
@@ -37,11 +37,36 @@ DeadKeys::DeadKeys(const QString &locale)
DeadKeys::~DeadKeys() = default;
void DeadKeys::press(quint32 deadKeysym)
QString DeadKeys::press(quint32 deadKeysym)
{
m_pending += deadKeyText(deadKeysym);
if (m_state)
xkb_compose_state_feed(m_state.get(), deadKeysym);
if (!m_state) {
m_pending += deadKeyText(deadKeysym);
return {};
}
xkb_compose_state_feed(m_state.get(), deadKeysym);
switch (xkb_compose_state_get_status(m_state.get())) {
case XKB_COMPOSE_COMPOSED: {
const QString composed = composedText();
cancel();
return composed;
}
case XKB_COMPOSE_CANCELLED: {
// No sequence goes on like this: type the old accents, start anew.
const QString accents = m_pending;
cancel();
return accents + press(deadKeysym);
}
default:
m_pending += deadKeyText(deadKeysym);
return {};
}
}
QString DeadKeys::composedText() const
{
char utf8[64];
xkb_compose_state_get_utf8(m_state.get(), utf8, sizeof utf8);
return QString::fromUtf8(utf8);
}
QString DeadKeys::compose(const QString &text)
@@ -50,11 +75,8 @@ QString DeadKeys::compose(const QString &text)
if (m_state && !text.isEmpty()) {
const char32_t ucs = text.toUcs4().first();
xkb_compose_state_feed(m_state.get(), xkb_utf32_to_keysym(ucs));
if (xkb_compose_state_get_status(m_state.get()) == XKB_COMPOSE_COMPOSED) {
char utf8[64];
xkb_compose_state_get_utf8(m_state.get(), utf8, sizeof utf8);
result = QString::fromUtf8(utf8) + text.mid(QString::fromUcs4(&ucs, 1).size());
}
if (xkb_compose_state_get_status(m_state.get()) == XKB_COMPOSE_COMPOSED)
result = composedText() + text.mid(QString::fromUcs4(&ucs, 1).size());
}
cancel();
return result;