Unable to lock screen before suspend in KDE Plasma

When I suspend the session in Plasma 6 and resume it, I can see my desktop for 2-3 seconds and only then the lockscreen appears. I want the lockscreen to appear immediately after resuming, for obvious privacy reasons.

After searching through forums, I learned that this issue isn’t uncommon, but none provided solutions worked for me.

Screen Locking settings:

I have created the following systemd script in /usr/lib/systemd/system-sleep/lock_before_suspend.sh:

#!/bin/sh
case $1/$2 in
    pre/*)
        case $2 in
            suspend|hibernate)
		echo "suspending $(date)" > /home/tom/sleep_script_out
                loginctl lock-session
                sleep 1
                ;;
	esac
        ;;
esac

After every suspend/resume, I can see the sleep_script_out is correctly written. But the loginctl lock-session is ineffective.

If I enter loginctl lock-session in the terminal (zsh), the session gets locked without any errors. I also tried modifying the script to loginctl lock-sessions or even loginctl lock-session 7, where 7 is the number of my current session, but without success.

systemd log here:

tom@ideapad-16ihu6 /usr/lib/systemd/system-sleep$ LC_ALL=C sudo journalctl -b -u systemd-suspend.service
Feb 16 17:38:49 ideapad-16ihu6 systemd[1]: Starting System Suspend...
Feb 16 17:38:49 ideapad-16ihu6 systemd-sleep[4518]: Successfully froze unit 'user.slice'.
Feb 16 17:38:49 ideapad-16ihu6 systemd-sleep[4532]: INFO: Skip running /usr/lib/systemd/system-sleep/grub2.sl>
Feb 16 17:38:49 ideapad-16ihu6 loginctl[4535]: Failed to issue method call: Unknown object '/org/freedesktop/>
Feb 16 17:38:50 ideapad-16ihu6 systemd-sleep[4518]: Performing sleep operation 'suspend'...
Feb 16 17:39:01 ideapad-16ihu6 systemd-sleep[4518]: System returned from sleep operation 'suspend'.
Feb 16 17:39:01 ideapad-16ihu6 systemd-sleep[4647]: INFO: Skip running /usr/lib/systemd/system-sleep/grub2.sl>
Feb 16 17:39:01 ideapad-16ihu6 systemd-sleep[4518]: Successfully thawed unit 'user.slice'.
Feb 16 17:39:01 ideapad-16ihu6 systemd[1]: systemd-suspend.service: Deactivated successfully.
Feb 16 17:39:01 ideapad-16ihu6 systemd[1]: Finished System Suspend.

System info:

tom@ideapad-16ihu6 /usr/lib/systemd/system-sleep$ inxi -Fxpmzr                                               
System:
  Kernel: 6.13.1-1-default arch: x86_64 bits: 64 compiler: gcc v: 14.2.1
  Desktop: KDE Plasma v: 6.3.0 Distro: openSUSE Tumbleweed 20250211
Machine:
  Type: Laptop System: LENOVO product: 82L9 v: IdeaPad 5 Pro 16IHU6
    serial: <superuser required>
  Mobo: LENOVO model: LNVNB161216 v: WIN serial: <superuser required>
    UEFI: LENOVO v: GRCN30WW date: 03/29/2024
Battery:
  ID-1: BAT0 charge: 43.6 Wh (60.0%) condition: 72.7/75.0 Wh (96.9%)
    volts: 15.7 min: 15.4 model: Celxpert L20C4PE1 status: not charging
Memory:
  System RAM: total: 16 GiB available: 15.41 GiB used: 5.43 GiB (35.2%)
  Array-1: capacity: 16 GiB slots: 2 modules: 2 EC: None
    max-module-size: 8 GiB note: est.
  Device-1: Controller0-ChannelA type: DDR4 size: 8 GiB speed: 3200 MT/s
  Device-2: Controller1-ChannelA type: DDR4 size: 8 GiB speed: 3200 MT/s
CPU:
  Info: quad core model: 11th Gen Intel Core i7-11370H bits: 64 type: MT MCP
    arch: Tiger Lake rev: 1 cache: L1: 320 KiB L2: 5 MiB L3: 12 MiB
  Speed (MHz): avg: 400 min/max: 400/4800 cores: 1: 400 2: 400 3: 400 4: 400
    5: 400 6: 400 7: 400 8: 400 bogomips: 52838
  Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx
Graphics:
  Device-1: Intel TigerLake-LP GT2 [Iris Xe Graphics] vendor: Lenovo
    driver: i915 v: kernel arch: Xe bus-ID: 00:02.0
  Device-2: IMC Networks Integrated Camera driver: uvcvideo type: USB
    bus-ID: 3-7:3
  Display: x11 server: X.Org v: 21.1.15 with: Xwayland v: 24.1.5 driver: X:
    loaded: modesetting unloaded: vesa dri: iris gpu: i915
    resolution: 2560x1600~60Hz
  API: EGL v: 1.5 drivers: iris,swrast platforms:
    active: gbm,x11,surfaceless,device inactive: wayland
  API: OpenGL v: 4.6 compat-v: 4.5 vendor: intel mesa v: 24.3.4 glx-v: 1.4
    direct-render: yes renderer: Mesa Intel Iris Xe Graphics (TGL GT2)
  API: Vulkan v: 1.4.304 drivers: N/A surfaces: xcb,xlib devices: 1
  Info: Tools: api: eglinfo, glxinfo, vulkaninfo
    de: kscreen-console,kscreen-doctor wl: wayland-info
    x11: xdpyinfo, xprop, xrandr
Audio:
  Device-1: Intel Tiger Lake-LP Smart Sound Audio vendor: Lenovo
    driver: sof-audio-pci-intel-tgl bus-ID: 00:1f.3
  API: ALSA v: k6.13.1-1-default status: kernel-api
  Server-1: PipeWire v: 1.2.7 status: active
Network:
  Device-1: Intel Wi-Fi 6 AX201 driver: iwlwifi v: kernel bus-ID: 00:14.3
  IF: wlp0s20f3 state: up mac: <filter>
Bluetooth:
  Device-1: Intel AX201 Bluetooth driver: btusb v: 0.8 type: USB
    bus-ID: 3-10:4
  Report: btmgmt ID: hci0 rfk-id: 3 state: down bt-service: enabled,running
    rfk-block: hardware: no software: yes address: <filter> bt-v: 5.2 lmp-v: 11
Drives:
  Local Storage: total: 476.94 GiB used: 251.46 GiB (52.7%)
  ID-1: /dev/nvme0n1 vendor: Samsung model: MZVLB512HBJQ-000L2
    size: 476.94 GiB temp: 34.9 C
Partition:
  ID-1: / size: 180 GiB used: 62.75 GiB (34.9%) fs: btrfs dev: /dev/nvme0n1p2
  ID-2: /boot/efi size: 99.8 MiB used: 23.9 MiB (24.0%) fs: vfat
    dev: /dev/nvme0n1p1
  ID-3: /boot/grub2/i386-pc size: 180 GiB used: 62.75 GiB (34.9%) fs: btrfs
    dev: /dev/nvme0n1p2
  ID-4: /boot/grub2/x86_64-efi size: 180 GiB used: 62.75 GiB (34.9%)
    fs: btrfs dev: /dev/nvme0n1p2
  ID-5: /data size: 219.27 GiB used: 165.45 GiB (75.5%) fs: ext4
    dev: /dev/nvme0n1p5
  ID-6: /home size: 48.91 GiB used: 23.23 GiB (47.5%) fs: ext4
    dev: /dev/nvme0n1p3
  ID-7: /opt size: 180 GiB used: 62.75 GiB (34.9%) fs: btrfs
    dev: /dev/nvme0n1p2
  ID-8: /root size: 180 GiB used: 62.75 GiB (34.9%) fs: btrfs
    dev: /dev/nvme0n1p2
  ID-9: /srv size: 180 GiB used: 62.75 GiB (34.9%) fs: btrfs
    dev: /dev/nvme0n1p2
  ID-10: /usr/local size: 180 GiB used: 62.75 GiB (34.9%) fs: btrfs
    dev: /dev/nvme0n1p2
  ID-11: /var size: 180 GiB used: 62.75 GiB (34.9%) fs: btrfs
    dev: /dev/nvme0n1p2
Swap:
  ID-1: swap-1 type: partition size: 23 GiB used: 0 KiB (0.0%)
    dev: /dev/nvme0n1p4
Sensors:
  System Temperatures: cpu: 49.0 C mobo: N/A
  Fan Speeds (rpm): N/A
Repos:
  Packages: 18 note: see --rpm
  Active zypp repos in: /etc/zypp/repos.d/NVIDIA.repo
    1: NVIDIA ~ https://download.nvidia.com/opensuse/tumbleweed
  Active zypp repos in: /etc/zypp/repos.d/megasync.repo
    1: MEGAsync ~ https://mega.nz/linux/repo/openSUSE_Tumbleweed/
  Active zypp repos in: /etc/zypp/repos.d/openSUSE:repo-non-oss.repo
    1: openSUSE:repo-non-oss ~ http://cdn.opensuse.org/tumbleweed/repo/non-oss
  Active zypp repos in: /etc/zypp/repos.d/openSUSE:repo-openh264.repo
    1: openSUSE:repo-openh264 ~ http://codecs.opensuse.org/openh264/openSUSE_Tumbleweed
  No active zypp repos in: /etc/zypp/repos.d/openSUSE:repo-oss-debug.repo
  No active zypp repos in: /etc/zypp/repos.d/openSUSE:repo-oss-source.repo
  Active zypp repos in: /etc/zypp/repos.d/openSUSE:repo-oss.repo
    1: openSUSE:repo-oss ~ http://cdn.opensuse.org/tumbleweed/repo/oss
  Active zypp repos in: /etc/zypp/repos.d/openSUSE:update-tumbleweed.repo
    1: openSUSE:update-tumbleweed ~ http://cdn.opensuse.org/update/tumbleweed
  Active zypp repos in: /etc/zypp/repos.d/packman.repo
    1: packman ~ https://ftp.gwdg.de/pub/linux/misc/packman/suse/openSUSE_Tumbleweed/
  Active zypp repos in: /etc/zypp/repos.d/vscodium.repo
    1: gitlab.com_paulcarroty_vscodium_repo ~ https://download.vscodium.com/rpms/
Info:
  Processes: 316 Uptime: 1h 22m Init: systemd
  Compilers: gcc: 14.2.1 Shell: Zsh v: 5.9 inxi: 3.3.37

There is an error in the systemd log which I don’t understand. What could be the cause? Thanks!

Use loginctl lock-sessions instead. (From a multi-user POV this is better idea anyway.)

1 Like

It doesn’t happen to me, I think it’s a problem related to the Nvidia drivers or Xorg, because on my PC with intel-wayland this problem doesn’t exist.
One of the problems that has always been linked to Xorg has always been the lock screen, because on Xorg it works as a normal application. Moreover, the Xorg session is now less and less considered by developers.

I have tried it with the same result.

The NVIDIA GPU was disabled in the UEFI Setup and the proprietary driver wasn’t even installed. But switching to Wayland solved the issue. Thanks!

However, I am not sure I will be able to completely move to Wayland because of some applications that are incompatible with Wayland. Is there any way to solve it with X11? On my other PC I also have up-to-date openSUSE Tumbleweed with X11, but the AMD GPU and this issue have never occured.

I use Plasma Wayland and don’t observe this.

Using Wayland really solves this issue, but brings many new problems, which render the Wayland session basically unusable. Is there any other way how to solve my problem without switching to Wayland, which is obviously not production-ready? Thanks.

That’s a subjective view and depends on your particular graphics hardware. Take it up at https://discuss.kde.org/