6

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.

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.

  • 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 '14 at 10:33
  • Sorry, "false alarm" that it works for me, updated the comment accordingly. – user68917 May 29 '14 at 10:37
2

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.

  • excellent, thank you! Works on Ubuntu 16.04.4 – hooke May 31 '18 at 13:20
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.

  • 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 '14 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. – Aryeh Leib Taurog Jul 16 '14 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. – Dmitry Grigoryev Jan 4 '16 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.