My bad, turns out I’ve read it not as thoroughly as I remembered.
-
group_policy=2 meaning is described here:
https://github.com/zen-tools/gxkb/issues/22#issuecomment-613316444 -
After starting this forum topic I tried searching again and found next things:
https://forums.linuxmint.com/viewtopic.php?t=286032
-interesting, almost it
-mostly really it
Next, I first tried the solution from Linux Mint forum’s link: I installed xkb-switch-i3 from AUR (regular xkb-switch package works too), then tried doing the scripts posted here. Didn’t work, because it’s a distinctly different enough kind of problem they’re solving there, but I learned a bit about xkb-switch package.
Then, I read the second link. That was it! Quite a similar description of problem too, so i tried it. In the end I cobbled together this solution with some xkb-switch commands.
What do I have as the end result:
First, what I was trying to achieve:
In KDE, I use 3 layouts: [us, ru, ua]. The way the “spare layout” feature works there, as I understand it in the case of having 3 layouts, is something like this:
- I have layouts [us, ru] as main set, switching is done by alt-shift
- to switch to layout [ua] (spare) you set a different shortcut
- after pressing that shortcut, layouts 2 and 3 switch places, so in my case the main set instead of [us, ru] becomes [us, ua], now [ru] is considered “spare” for the next use of “spare layout shortcut”, so now alt-shift switches between [us, ua]
- out of any position in [us, ru] set, the “spare switching shortcut” switches to [ua]
- out of any position in [us, ua] set, the “spare switching shortcut” switches to [ru]
What I ended up with:
Here’s how I edited the script that I found in SergeM’s github post:
#!/bin/bash
current=`setxkbmap -query | grep layout|cut -d ',' -f 2`
echo $current
if [ "$current" == "ua" ]
then
notify-send -t 750 -i keyboard "EN/RU"
setxkbmap -model pc105 -layout us,ru, -option grp:alt_shift_toggle
xkb-switch -s ru
else
notify-send -t 750 -i keyboard "EN/UA"
setxkbmap -model pc105 -layout us,ua, -option grp:alt_shift_toggle
xkb-switch -s ua
fi
Notes: I added xkb-switch commands to the if statements, so they’ll result in expected behavior, current=xkb-switch or current=xkb-switch -p seems faster, but I accidentally broke all my WM’s keyboard shortcuts spamming this version of script for testing, and had to reboot so I’m not sure about that ![]()
I made a shortcut mod+shift+u in my i3 config file to execute this script and now I have on my i3wm setup this behavior: main keyboard switching shortcut is alt-shift, original set is [us, ru] if the current layout is [us] or [ru], mod+shift+u replaces [us, ru] with [us, ua] and switches to [ua], if the current layout is [ua], mod+shift+u replaces [us, ua] with [us, ru] and switches to [ru]. Which is like 95% what I wanted (only one case differs from what happens in KDE setup).
Possible ways to improve the solution:
- maybe using better logic and adding nested if statements into this bash script can recreate this behavior I described in KDE
- out of any position in [us, ru] set, the “spare switching shortcut” switches to [ua]
- out of any position in [us, ua] set, the “spare switching shortcut” switches to [ru]
Currently, if the group [us, ua] is active in [us] layout, the mod+shift+u will switch to [ua], because that’s exactly what the end result script says. Since I don’t know how to make it better, the current “95% it” version will do.
I hope this was helpful or interesting