9

xscreensaver doesn't show which is the current keyboard layout, so sometimes I can't enter my password, because I've switched to Cyrillic without knowing it. I found a discussion about the same problem at http://forum.xfce.org/viewtopic.php?id=6877, for example.

Is there a way to make it show the current keyboard layout, or always switch to English?

My system is Debian Wheezy.

4 Answers 4

4

At least on ubuntu the following worked for me:

  1. Created folder: mkdir ~/.startup
  2. And a file touch ~/.startup/xscreensaver-reset-kbd-us.pl
  3. Chmodded it chmod 755 ~/.startup/xscreensaver-reset-kbd-us.pl
  4. Edit (copy&paste the code below) gedit ~/.startup/xscreensaver-reset-kbd-us.pl

    #!/usr/bin/perl
    
    my $blanked = 0;
    open (IN, "xscreensaver-command -watch |");
    while (<IN>) {
        if (m/^(BLANK|LOCK)/) {
            if (!$blanked) {
               system "setxkbmap -layout us";
               $blanked = 1;
            }
        } elsif (m/^UNBLANK/) {
            system "setxkbmap -layout us,ru";
            $blanked = 0;
        }
    }
    
  5. Added the script to startup applications

It watches the events from xscreensaver and resets keyboard layout to english only on lock, and adds the ru layout back upon unblank.

1
  • excellent, thank you! Works on Ubuntu 16.04.4
    – hooke
    May 31, 2018 at 13:20
2

Can be done via executing a couple of setxkbmap lines before locking (in xfce, into /usr/bin/xflock4, see: http://www.reddit.com/r/xfce/comments/11yi34/reset_the_keyboard_layout_on_xscreensaver_lock/ similar to:

setxkbmap -layout us 
setxkbmap -layout us,ru

This should disable and then re-enable the international layout, supposedly switching the current layout to the US one. Seems to work fine. Just re-tested, and it doesn't. But the general solution is along those lines, just need more experimentation.

2
  • I see that you use the line setxkbmap -layout us,ru. I assume it must be manually tuned to whichever configuration I have, and when I change configurations? I set my keyboard layout from the GUI, though, do you have an idea how I could figure out how this line should look for me? Maybe print out my actual layouts or something...
    – sashoalm
    May 29, 2014 at 10:33
  • Sorry, "false alarm" that it works for me, updated the comment accordingly.
    – user68917
    May 29, 2014 at 10:37
0

Another option is installing a different screen locking utility, e.g. just now I tried "i3lock" http://i3wm.org/i3lock/ , it works without requiring any hacking around keyboard layouts whatsoever.

3
  • Yes, I had tried installing gnome-screensaver, but it seemed to want to install half of GNOME desktop with it, including Pulseaudio and what not. In the end I decided to stay with xscreensaver. Might try your suggestion, though.
    – sashoalm
    May 29, 2014 at 10:57
  • You might add that i3lock reset the keyboard layout when the user is entering a password. That "works" iff the password can be entered with the primary layout. Jul 16, 2014 at 7:47
  • i3lock doesn't work for me (Debian Jessie). The layout I have selected before locking remains effective when I enter the password. Jan 4, 2016 at 19:35
0

One option is to have a shortcut to always switch to first keyboard layout. For example, I have WIN+Space to switch to the next layout and LCTRL+LWIN to always switch to the first one.

How to pick that option depends on the program you use to pick the keyboard layouts and switching options. Here are 2 examples:

  • If it is localectl set-x11-keymap from command line, then the options for switching are passed in the OPTIONS argument (see man localectl for the syntax and "OPTIONS > Switching to another layout" section of man xkeyboard-config for the list of options). For example, on my laptop it looks as localectl set-x11-keymap "us,ru" thinkpad "" "grp:win_space_toggle,grp:lctrl_lwin_rctrl_menu". Current values for arguments of localectl set-x11-keymap can be seen in the output of setxkbmap -query. New settings work only after restart of xorg (e.g. after rebooting the OS).
  • In cinnamon GUI (which internally calls /usr/bin/python2 /usr/share/cinnamon/cinnamon-settings/cinnamon-settings.py keyboard) it is "Menu > Keyboard > Layouts > Options > Switching to another layout".

In both cases you may want to pick one of the options with the words "to first layout" in the description. Then (assuming, e.g., that the first layout is us and can be used to type in the password) you can press LCTRL+LWIN to switch to us and type the password.

2
  • xscreensaver swallows all global keyboards shortcuts AFAIK (it makes sense since it would be a secirity vulnerability otherwise)
    – sashoalm
    Jun 13, 2021 at 4:53
  • @sashoalm I'm not actually sure how exactly keyboard switching works despite xScreenSaver swallowing the keyboard shortcuts, but the first example in the answer is how it works on my computer, and it works: I can press LCTRL+LWIN and type the password, knowing that it will be typed in us keyboard layout, otherwise the layout is an unknown one (either us or ru in my case).
    – fiktor
    Jun 16, 2021 at 13:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .