Get current active keyboard layout (language) in linux

In my C / C ++ program, I want to know what language the user will type. I mean the language whose identifier is displayed in the corner of the taskbar. Like EN, RU or ZH or FR or IT.

I know how to get a list of possible layouts:

$ setxkbmap -query | grep layout

exit:

layout:     us,ru

But how do you know which one is currently selected? (for current window)

+4
source share
1 answer

setxkbmap -printnot useful in this case, which was also my first idea. I found a small tool , very easy to compile

sudo apt-get install git
mkdir -p `~/src`
cd `~/src`
git clone https://github.com/nonpop/xkblayout-state.git 
cd xkblayout-state
make

Now you can run the command ./xkblayout-stateto get the current layout, for example.

./xkblayout-state print "%n"                          
German%

or a list of all installed layouts

./xkblayout-state print "%N"
German
English
English

%. , \n.

+4

Source: https://habr.com/ru/post/1524719/


All Articles