Skip to content

Commit

Permalink
[wayland] fix crash on startup with lv3:ralt_alt XKB option
Browse files Browse the repository at this point in the history
With lv3:ralt_alt ("Right Alt never chooses 3rd level") option set, we
get more layouts from libxkbcommon than it was configured, see:
xkbcommon/libxkbcommon#262
It might be correct lib's behavior, still.

The extra layouts are redundant, so we strip them out from usual usage.

BUG: 440027
  • Loading branch information
bam80 committed Oct 8, 2021
1 parent ef06b8e commit 98dd431
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/xkb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,9 @@ QString Xkb::layoutName() const
return layoutName(m_currentLayout);
}

const QString &Xkb::layoutShortName(int index) const
const QString Xkb::layoutShortName(int index) const
{
return m_layoutList.at(index);
return m_layoutList.value(index);
}

void Xkb::updateConsumedModifiers(uint32_t key)
Expand Down Expand Up @@ -527,9 +527,7 @@ void Xkb::switchToNextLayout()
if (!m_keymap || !m_state) {
return;
}
const xkb_layout_index_t numLayouts = xkb_keymap_num_layouts(m_keymap);
const xkb_layout_index_t nextLayout = (xkb_state_serialize_layout(m_state, XKB_STATE_LAYOUT_EFFECTIVE) + 1) % numLayouts;
switchToLayout(nextLayout);
switchToLayout( (xkb_state_serialize_layout(m_state, XKB_STATE_LAYOUT_EFFECTIVE) + 1) % numberOfLayouts() );
}

void Xkb::switchToPreviousLayout()
Expand Down Expand Up @@ -560,7 +558,7 @@ quint32 Xkb::numberOfLayouts() const
if (!m_keymap) {
return 0;
}
return xkb_keymap_num_layouts(m_keymap);
return qMin( xkb_keymap_num_layouts(m_keymap), uint(m_layoutList.size()) );
}

void Xkb::setSeat(KWaylandServer::SeatInterface *seat)
Expand Down
2 changes: 1 addition & 1 deletion src/xkb.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class KWIN_EXPORT Xkb : public QObject
}
QString layoutName(xkb_layout_index_t index) const;
QString layoutName() const;
const QString &layoutShortName(int index) const;
const QString layoutShortName(int index) const;
quint32 numberOfLayouts() const;

/**
Expand Down

0 comments on commit 98dd431

Please sign in to comment.