Logind offers this, through the LockedHint
property of sessions: an app can get the ID of the auto
session to determine the ID of its session, and then connect to the standard PropertiesChanged
signal of that session and look for changes of the LockedHint
property.
There’s no portal around this, tho; the app needs an explicit --system-talk-name=org.freedesktop.login1
finish arg in its manifest.