
Switch Keyboard Layout on Screen Locked in KDE Plasma
I needed my keyboard layout to switch to US English when locking screen, so different international keyboard layouts would not get in the way of typing my password. I use the latest KDE / Plasma 6 under Linux (KDE Neon), so I needed to programmatically change the layout when locking screen.
Solution to change keyboard layout on a screenlock
I have identified this solution using dbus-monitor and qdbus6 (qdbus would also work). DBus monitor watches for AboutToLock action and then runs dbus command to switch the keyboard.
Create this script and make it executable (chmod +x):
#!/bin/bash
dbus-monitor --profile --session "type='signal',interface='org.kde.screensaver',path='/ScreenSaver',member='AboutToLock'" |
while read -r line; do
qdbus6 org.kde.keyboard /Layouts setLayout 0
#echo "switching"
done
Now run this script on login, i.e. go to Settings -> Autostart and add as a Login script.
This will ensure your keyboard will be always switched to the first (default) layout. In case you require a different layout, just change the setLayout index number.
If you need to list current keyboard layout index, use this command:
qdbus6 org.kde.keyboard /Layouts getLayout
Keyboard layouts are indexed from 0 (zero), where 0 is the default layout.