I would like it to always switch to US English independent of whatever is set in the user session under X / Wayland before. Once it goes to a lock (screensaver) or login screen, switch back to US English.
Assuming that, your system is using systemd for the system initialisation and, that systemd is using SDDM as the default Display Manager then,
- The default (system) keyboard layout is defined by the system configuration file ‘/etc/vconsole.conf’.
Depending on which Linux distribution you’re using, there may or, may not, be system tools available to assist with the setup o the default system keyboard layout.
I’m definitely not an expert on keyboard layouts, but just one other note here - the lock screen runs within the user session, and is separate from the login screen. The former is part of Plasma (kscreenlocker
), while the latter is part of SDDM.
There would probably be different steps required to force a different keyboard layout within a user’s session if the lock screen is active, than trying to force a different layout just for SDDM.
OK, let’s just talk about Lock screen, Login screen always defaults to the first keyboard language setting anyway.
I need something like this:
if lock_screen==true then
keyboard_layout=US
end
In other words, the system has a default physical keyboard layout which, a KDE Plasma session user can change to whatever that user wants – for that particular session and, subsequent sessions when that user logs out and then logs back in again.
And, when that user locks their session, the keyboard layout is that layout the user chose while the session was active.
What happens if a new session is started for another user?
-
AFAICS, it’s not possible to start a new session instance for a user who is already has an active KDE Plasma session executing – at least that’s what this Plasma 5 session is indicating – attempting to start a new session instance simply drops me back into the already running session ….
-
But, I wasn’t able to determine if, the attempt to start a new Plasma session uses the user’s keyboard layout or, the system’s keyboard layout.
That is fine:
XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
BACKSPACE="guess"
however that does not change anything on lockscreen. I need a way to programatically switch to that layout on a Plasma 6 lockscreen.
Single-user computer, so no need for complicated setups.
I’ll have to investigate this script:
dbus-monitor --session "type='signal',interface='org.kde.screensaver'"
signal time=1744212016.289974 sender=org.freedesktop.DBus -> destination=:1.812 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired
string ":1.812"
signal time=1744212016.290021 sender=org.freedesktop.DBus -> destination=:1.812 serial=4 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameLost
string ":1.812"
signal time=1744212017.756886 sender=:1.20 -> destination=(null destination) serial=37304 path=/ScreenSaver; interface=org.kde.screensaver; member=AboutToLock
signal time=1744212017.756911 sender=:1.20 -> destination=(null destination) serial=37305 path=/org/freedesktop/ScreenSaver; interface=org.kde.screensaver; member=AboutToLock
So I guess I’ll have to create a script to run on “AboutToLock” or on locked
:
Also:
Yeah, this works well for monitoring:
dbus-monitor --session "type='signal',interface='org.kde.screensaver',path='/ScreenSaver',member='AboutToLock'" |grep -i abouttolock
signal time=1744213665.803183 sender=:1.20 -> destination=(null destination) serial=45292 path=/ScreenSaver; interface=org.kde.screensaver; member=AboutToLock
and this for changing the layout:
qdbus6 org.kde.keyboard /Layouts setLayout 0
Now I just have to put it together
So running this seems to be working:
#!/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
Although I am not sure why dbus-monitor ignores the member
requirement and displays also information such as (that nobody asked for):
sig 1744216116.433048 2 org.freedesktop.DBus :1.5147 /org/freedesktop/DBus org.freedesktop.DBus NameAcquired
sig 1744216116.433285 4 org.freedesktop.DBus :1.5147 /org/freedesktop/DBus org.freedesktop.DBus NameLost
I have also documented the solution with further explanation here: