Commit 2cb9201b authored by Andrey Butirsky's avatar Andrey Butirsky
Browse files

fix: Keyboard layout shortcuts activate wrong language

Fixes spare layout's shortcuts activating wrong layout after the first
use, see the bug for the details.

When we switch to a spare layout (by the shortcuts or via applet's
menu), rearrangement of layouts happen - the spare one becomes the last
in the main loop, preempting the previous one on it's place.

Layouts-specific shortcut actions activate the layout by index which is
hold in the action's data. Thus, the indexes should be adjusted
accordingly.

BUG: 444569


(cherry picked from commit 7525b4a6)
parent cb3cbbe3
Pipeline #233291 passed with stage
in 4 minutes and 11 seconds
......@@ -190,14 +190,37 @@ 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()) ) {
const int indexOfLastMainLayoutInConfig = keyboardConfig->layouts.lastIndexOf(layouts.takeLast());
const int indexOfLastMainLayoutInXKB = layouts.size();
// Re-calculate indexes for layout switching Actions
const auto &actions = actionCollection->actions();
for (const auto &action : actions) {
// clang-format off
if (action->data().toInt() == indexOfLastMainLayoutInXKB) {
action->setData(indexOfLastMainLayoutInConfig < int(index) ?
indexOfLastMainLayoutInConfig + 1 :
indexOfLastMainLayoutInConfig);
} else if (action->data().toUInt() == index) {
action->setData(indexOfLastMainLayoutInXKB);
} else if (int(index) < indexOfLastMainLayoutInConfig
&& index < action->data().toUInt() && action->data().toInt() <= indexOfLastMainLayoutInConfig) {
action->setData(action->data().toUInt() - 1);
} else if (indexOfLastMainLayoutInConfig < int(index)
&& indexOfLastMainLayoutInConfig < action->data().toInt() && action->data().toUInt() < index) {
action->setData(action->data().toUInt() + 1);
}
// clang-format on
}
if (int(index) <= indexOfLastMainLayoutInConfig) {
// got to a shifted diapason due to previously selected spare layout, so adjusting the index accordingly
--index;
}
// spare layout preempts last one in the loop
layouts.append(keyboardConfig->layouts.at(index));
XkbHelper::initializeKeyboardLayouts(layouts);
index = layouts.size() - 1;
index = indexOfLastMainLayoutInXKB;
}
return X11Helper::setGroup(index);
}
......
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