sergei-mironov / xkb-switch

Switch your X keyboard layouts from the command line
MIT License
345 stars 37 forks source link

Can't change to any layout #52

Closed pvonmoradi closed 3 years ago

pvonmoradi commented 3 years ago

I've built the latest master (6cd4da9e). I'm on Xubuntu 18.04 using i3. Had to sudo apt install libsigc++-2.0-dev libxkbfile-dev for a successful build.
Problem is, I can't change the layout from us to anything:

./xkb-switch -s ir
xkb-switch: /home/pooya/tools/utility/xkb-switch-i3/src/XKbSwitch.cpp:221: Condition i!=syms.end() failed. Group 'ir' is not supported by current layout. Try xkb-switch -l.
xkb-switch: layouts: [us]

de or ru also yields similar result.

./xkb-switch -l
us

Here is the script I use to change layouts:

#!/bin/bash

CURR_LANG="$(setxkbmap -query | grep layout | tr -s ' ' | cut -d ' ' -f2)"

US="us"
IR="ir"

if [[ "$CURR_LANG" == "$US" ]]
then
    setxkbmap ir
else
    setxkbmap us
fi
λ ./xkb-switch -d
[DEBUG] xkb-switch version 1.8.1
[DEBUG] layout: us
[DEBUG] variant: <empty>
us

λ ./xkb-switch -d
[DEBUG] xkb-switch version 1.8.1
[DEBUG] layout: ir
[DEBUG] variant: <empty>
ir

Am I using the program correctly?

sergei-mironov commented 3 years ago

Hi. I agree that the error message looks weird. I'll make it more human-readable. Regarding on what could caused it. The Xkb manual says that "You can use multi-layouts xkb configuration. What does it mean? Basically it allows to load up to four different keyboard layouts at a time". But Xkb could be reconfigured on the fly, so in fact users may use 2 approaches:

  1. Configure Xkb once, ask it to use several layouts. Bind some key to switch those layouts.
  2. Bind some key to switch between whole different Xkb configurations, with only one active layout each.

Now, xkb-switch is designed for the first case.. The fact that xkb-switch returns 1 layout each time makes me think that you are following the second approach instead. Could you please configure Xkb to use 2 layouts: ir and us and try once again? I think you need to call setxkbmap once with something like setxkbmap ... -layout "us,ir" ....

sergei-mironov commented 3 years ago

Had to sudo apt install libsigc++-2.0-dev libxkbfile-dev for a successful build.

libxkbfile-dev is mentioned in the Readme. Could you please check how it goes with only this package installed? Previously no one reports about libsigc++2.0-dev..

pvonmoradi commented 3 years ago

Now, xkb-switch is designed for the first case.. The fact that xkb-switch returns 1 layout each time makes me think that you are following the second approach instead. Could you please configure Xkb to use 2 layouts: ir and us and try once again? I think you need to call setxkbmap once with something like setxkbmap ... -layout "us,ir" ....

Yeah, it seems your assessment is correct. I fixed the problem by setxkbmap -layout us,ir -option 'grp:alt_shift_toggle'. (Actually, I'm using a fork of your project from this https://github.com/Zebradil/xkb-switch-i3). Anyway, it works! Thanks.

libxkbfile-dev is mentioned in the Readme. Could you please check how it goes with only this package installed? Previously no one reports about libsigc++2.0-dev..

Sorry, that dependency was for the fork I'm using (https://github.com/Zebradil/xkb-switch-i3#installation).

sergei-mironov commented 3 years ago

OK, thats good