#!/usr/bin/perl # Yevgen Matusevych, 10.12.2018. # Tested on Scientific Linux 7.5, GNOME version 3.22.2. # This script monitors locking and unlocking events of xscreensaver. # Upon locking, the layout map is set to US-only. # Upon unlocking, the original system layout map (recorded at the script runtime) is recovered. # In case of problems upon unlocking, run the following shell command: # setxkbmap -layout $PREFERRED_LAYOUT_MAP # e.g.: # setxkbmap -layout gb,ru,us # Resources: # https://www.x.org/archive/X11R7.7/doc/man/man1/setxkbmap.1.xhtml # https://wiki.gentoo.org/wiki/Keyboard_layout_switching my $system_layout = `setxkbmap -query | grep layout | cut -f6 -d' '`; my $blanked = 0; open (IN, "xscreensaver-command -watch |"); while () { if (m/^(BLANK|LOCK)/) { if (!$blanked) { system("setxkbmap -layout us"); $blanked = 1; } } elsif (m/^UNBLANK/) { system("setxkbmap -layout $system_layout"); $blanked = 0; } }