5

I'd like my Ubuntu to automatically switch my keyboard layout to English each time I lock the screen, so that I wouldn't have to do it manually each time to enter my password. How do I do that?

Also, I'd like that my keyboard layout also be English each time after I unlock the screen. Is it possible?

whyer
  • 519
  • 2
    you can make a script with below content like gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager().inputSources[1].activate()" && gnome-screensaver-command -l & and make a keyboard shortcut to run that script. change inputSources[1] with your languages list starting from 0 – PRATAP Dec 29 '19 at 12:17
  • 1
  • @HolyBlackCat in Xubuntu did you install GNOME? is your distribution Xubuntu have GNOME and GDM? if yes can you provide the gnome-shell version? – PRATAP Jun 21 '22 at 11:46
  • 1
    @UnKNOWn I'm using the stock Xubuntu 22.04 (so, lightgdm). – HolyBlackCat Jun 21 '22 at 19:11
  • 1
    Maybe this thread can help you find an answer: https://wiki.archlinux.org/title/LightDM#Wrong_locale_displayed – starkus Jun 23 '22 at 04:50
  • 1
    @starkus I don't think that's it. Locale probably defines the interface language, not the input language. – HolyBlackCat Jun 23 '22 at 21:24

3 Answers3

0

Just bumped into the same problem, use xkblayout-state tool like this (assuming 0 is the default En keyboard layout)

xkblayout-state set 0

then you can first change the keyboard layout to the default and launch screenlocker like this

 xkblayout-state set 0 && screen_locker
0

If you don't want to dive into command line, you can configure keyboard layout switcher to remember layout for each window. As the lock screen has it's own window, it will use the first keyboard layout regardless of which language you were typing before.

In KDE: System Settings -> Input devices -> Keyboard -> Layouts -> set Switching Policy to Window. You will also need to set your first layout to English.

pelya
  • 101
0

Since xkb tools do not work on Wayland, I wrote an extension that solves the problem by automatically resetting keyboard layout when screensaver activates. You can get extension here: https://github.com/galets/gnome-keyboard-reset

galets
  • 634