diff --git a/src/xkb.cpp b/src/xkb.cpp index e82de0a6c16..e1556cec5c9 100644 --- a/src/xkb.cpp +++ b/src/xkb.cpp @@ -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) @@ -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() @@ -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) diff --git a/src/xkb.h b/src/xkb.h index e610d37ae69..b087d3c31f1 100644 --- a/src/xkb.h +++ b/src/xkb.h @@ -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; /**