Skip to content

Conversation

@carsteneu
Copy link

This PR solves a problem that has been annoying me for a long time—when the load is too high when opening my laptop, you could sometimes see the content for a few seconds. The problem is apparently well known. The PR solves the problem at the JavaScript level. It works pretty well on my laptop. Details are summarized here in a more officially tone:

Add universal pre-suspend screen lock manager

Summary

This module fixes a race condition where the desktop can be briefly visible after resume when the system is under heavy CPU load. It ensures the screen is always locked before suspend completes, regardless of which screensaver is installed.

Problem

When suspending under heavy CPU load, there's a timing window where:

  1. The suspend signal arrives
  2. The screensaver hasn't finished rendering the lock screen yet
  3. The system suspends with an unlocked display
  4. On resume, the desktop is visible for a moment before the lock screen appears
  5. This is a security issue as it can expose sensitive information.

Solution

The SuspendLockManager uses systemd-logind's delay inhibitor mechanism:

  1. Hold a delay inhibitor - Prevents suspend from proceeding immediately
  2. Listen for PrepareForSleep signal - Detects when suspend is about to happen
  3. Trigger screen lock - Calls loginctl lock-session (universal, works with any screensaver)
  4. Wait for confirmation - Monitors LockedHint property via D-Bus PropertiesChanged signal
  5. Release inhibitor - Allows suspend to proceed only after lock is confirmed

Features

  • Universal compatibility - Works with cinnamon-screensaver, gnome-screensaver, light-locker, xscreensaver+xss-lock, i3lock+xss-lock, swaylock, and any other compliant screensaver
  • Non-blocking - Uses async D-Bus calls and subprocess handling to avoid freezing the UI
  • Robust session detection - Falls back to GetSessionByPID when XDG_SESSION_ID is unavailable
  • Respects user settings - Only activates when lock-on-suspend is enabled in power settings
  • Timeout protection - Releases inhibitor after 5 seconds to prevent blocking suspend forever
  • Clean shutdown - Properly disconnects all signal handlers in destroy()

Defense in Depth

This acts as a safety net alongside cinnamon-settings-daemon's existing lock-on-suspend functionality, ensuring the lock always completes before suspend regardless of system load or timing issues.

…ager

Ensures screen is locked BEFORE suspend completes, fixing a race
condition where the desktop can be briefly visible after resume.

- Add new suspendLock.js module
- Initialize SuspendLockManager in main.js
- Uses systemd inhibitor to delay suspend until lock confirmed
- Listens for LockedHint=true via D-Bus PropertiesChanged signal
- 5-second timeout prevents blocking suspend forever

Works with any screensaver: cinnamon-screensaver, gnome-screensaver,
light-locker, xscreensaver, i3lock, swaylock, etc.
…ocking

- Use GetSessionByPID as fallback when XDG_SESSION_ID is unavailable
  (fixes 5s timeout when 'auto' session ID fails on D-Bus)
- Replace synchronous lock calls with async variants (LockRemote,
  Gio.Subprocess.wait_async) to prevent UI freezes
- Properly disconnect PrepareForSleep and settings signals in destroy()
- Only hold delay inhibitor when lock-on-suspend is enabled, with
  dynamic settings listener for runtime changes
- Fix exit code handling with GLib.spawn_check_wait_status()
- Replace TextDecoder with imports.byteArray.toString() for GJS compat
- Force property sync on session proxy for reliable LockedHint caching
@carsteneu
Copy link
Author

I found the related Bug Report #4324 i think.

@carsteneu carsteneu changed the title Feature/suspend lock Feature/suspend lock - Ensure Desktop is locked after resume Jan 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant