Commit 718c1872 authored by Andrey Butirsky's avatar Andrey Butirsky
Browse files

feat: [Keyboard Layout applet] add spare layouts support

For now, X11 only

To support spare layouts in new Keyboard Layouts applet via existing
DBus API, they are appended to the main ones and passed to the applet
alongside in a row.
When spare layout selected in applet's context menu, layout swapping
logic takes place - the spare layout activates and placed in last
position of the main layouts loop, preempting previous layout there in
current keymap.
That way the actual keymap can be dynamically modified from the menu,
without reconfiguring in KCM.
No DBus API/applet changes are needed currently.

CCBUG: 430661
parent 9f2f6cc8
......@@ -221,6 +221,17 @@ bool KeyboardDaemon::setLayout(QAction *action)
bool KeyboardDaemon::setLayout(uint index)
if (keyboardConfig.layoutLoopCount != KeyboardConfig::NO_LOOPING && index >= uint(keyboardConfig.layoutLoopCount)) {
QList<LayoutUnit> layouts = X11Helper::getLayoutsList();
if ( int(index) <= keyboardConfig.layouts.lastIndexOf(layouts.takeLast()) ) {
// got to a shifted diapason due to previously selected spare layout, so adjusting the index accordingly
// spare layout preempts last one in the loop
index = layouts.size() - 1;
return X11Helper::setGroup(index);
......@@ -233,8 +244,16 @@ QVector<LayoutNames> KeyboardDaemon::getLayoutsList() const
QVector<LayoutNames> ret;
const auto layoutsList = X11Helper::getLayoutsList();
for (auto &layoutUnit : layoutsList) {
auto layoutsList = X11Helper::getLayoutsList();
if (keyboardConfig.layoutLoopCount != KeyboardConfig::NO_LOOPING) {
// extra layouts list overlaps with the main layouts loop initially by 1 position
auto extraLayouts = keyboardConfig.layouts.mid(keyboardConfig.layoutLoopCount - 1);
// spare layout currently placed in the loop is removed from the extra layouts
// as it was already "moved" to the last loop position
for (auto &layoutUnit : std::as_const(layoutsList)) {
ret.append({layoutUnit.layout(), Flags::getShortText(layoutUnit, keyboardConfig), Flags::getLongText(layoutUnit, rules)});
return ret;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment