Xfce Forum

Sub domains
 

You are not logged in.

#1 2022-09-25 10:23:20

jt1122
Member
Registered: 2021-03-26
Posts: 172

Query/change keyboard layout from the command-line

Hi,

Is there a way to query & change the keyboard layout from the command-line?

Something analogus to the mouse theme:
xfconf-query -c xsettings -p /Gtk/CursorThemeName -s "CURSOR_THEME_NAME"

Thanks

Offline

#2 2022-09-25 10:37:21

KBar
Moderator
Registered: 2021-11-05
Posts: 643

Re: Query/change keyboard layout from the command-line

# to query:
xfconf-query -c keyboard-layout -p /Default/XkbLayout
# to set:
xfconf-query -c keyboard-layout -p /Default/XkbLayout -s us,ru,tr

Remember to edit the subject of your topic to include the [SOLVED] tag once you're satisfied with the answers or have found a solution (in which case, don't forget to share it as well), so that other members of the community can quickly refer to it and save their time. Pretty please! tongue

Offline

#3 2022-09-25 10:39:51

jt1122
Member
Registered: 2021-03-26
Posts: 172

Re: Query/change keyboard layout from the command-line

Thanks cool

I have 2 layouts defined &
xfconf-query -c keyboard-layout -p /Default/XkbLayout

shows both regardless of the active layout .

How do I check which layout is active?.

Last edited by jt1122 (2022-09-25 11:34:54)

Offline

#4 2022-09-26 07:25:24

jt1122
Member
Registered: 2021-03-26
Posts: 172

Re: Query/change keyboard layout from the command-line

Bump.

Any suggestions?.

Offline

#5 2022-09-26 14:31:21

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 9,524

Re: Query/change keyboard layout from the command-line

setxkbmap LAYOUT

...and replace LAYOUT with the layout code you want to use.

And to query the current layout:

setxkbmap -query | grep layout | awk '{print $2}'

Last edited by ToZ (2022-09-26 14:33:40)

Offline

#6 2022-09-26 14:57:13

jt1122
Member
Registered: 2021-03-26
Posts: 172

Re: Query/change keyboard layout from the command-line

Thanks but

setxkbmap -query | grep layout | awk '{print $2}'

returns both layouts defined, not the one which is active.

Offline

#7 2022-09-26 17:37:33

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 9,524

Re: Query/change keyboard layout from the command-line

For me, I get:

$ setxkbmap hr
$ setxkbmap -query | grep layout | awk '{print $2}'
hr
$ setxkbmap us
$ setxkbmap -query | grep layout | awk '{print $2}'
us

The flag on the Keyboard Layouts plugin changes as I use setxkbmap.

Offline

#8 2022-09-26 17:41:34

jt1122
Member
Registered: 2021-03-26
Posts: 172

Re: Query/change keyboard layout from the command-line

Thanks, but you have only 1 layout defined at each point.

What happens if you define 2 layouts in settings->keyboard->layout ?

Offline

#9 2022-09-26 18:05:17

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 9,524

Re: Query/change keyboard layout from the command-line

Perhaps I'm misunderstanding, but I do have 2 layouts defined.

$ xfconf-query -c keyboard-layout -p /Default/XkbLayout
us,hr

kybd.png

Offline

#10 2022-09-26 18:15:04

jt1122
Member
Registered: 2021-03-26
Posts: 172

Re: Query/change keyboard layout from the command-line

OK, it seems like there's an issue:
- If the layout is switched with a keyboard shortcut (settings->keyboard->layout->change layout option) or with the layout panel app but w/o calling setxkbmap then both layouts are shown.

- Once the layout has been set with setxkbmap the keyboard shortcut and the panel layout plugin stop working & the query returns only the layout by setxkbmap.

Can u try this on your machine to confirm?. Thanks

Last edited by jt1122 (2022-09-26 18:21:24)

Offline

#11 2022-09-26 18:21:01

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 9,524

Re: Query/change keyboard layout from the command-line

And yes, I do see the same when I use that approach.. Good catch. It appears to be a bug.

Edit:

$ setxkbmap hr,us
$ setxkbmap us,hr

also works for me, and keeps in sync with the panel plugin.

Last edited by ToZ (2022-09-26 18:28:42)

Offline

#12 2022-09-28 13:00:21

jt1122
Member
Registered: 2021-03-26
Posts: 172

Re: Query/change keyboard layout from the command-line

great, thanks.

Offline

Board footer

Powered by FluxBB