A logind session manager for Phosphor-based desktop shells.
Surfaces the system session and power actions over org.freedesktop.login1 and, because we own the compositor and the session, manages the logind inhibitor locks that let the shell lock before the machine sleeps and own the power / lid keys. It is the logind edge of the shell, covering capabilities, actions, inhibitors, and the session and sleep signals. It has no UI of its own and binds no Wayland protocols. The logind D-Bus calls are private to the implementation, and the public surface is clean Qt/QML types plus an injectable QDBusConnection (the test / advanced-wiring seam).
This is more than a systemctl wrapper. A plugin shell (Quickshell / Noctalia) has no logind inhibitor integration, so it cannot lock before an externally-initiated suspend (lid, systemctl suspend, idle) and races the lock surface. Owning the session, we close that race.
| Type | Role |
|---|---|
| SessionHost | The logind session host. Exposes each capability as an Availability Q_PROPERTY (canSuspend, canPowerOff, ...); the actions as invokables (lock(), logout(), suspend(), reboot(), powerOff(), ...), each gated by its capability; allowSleep() for the lock-before-sleep handshake; and the aboutToSleep / lockRequested / unlockRequested / prepareForSleep signals. interactive selects whether actions route auth through a polkit agent. A plain instantiable QML type, not a singleton. |
| SessionHost::Availability | Yes / No / NotApplicable / Challenge / Unknown, parsed from logind's yes / no / na / challenge capability strings (Unknown when logind is unreachable or the answer is unrecognised). |
C++ shell composition root:
#include <PhosphorServiceSession/QmlRegistration.h>
int main(int argc, char** argv)
{
QGuiApplication app(argc, argv);
PhosphorServiceSession::registerQmlTypes();
// ... load shell.qml
}QML power menu, plus the lock-before-sleep handshake wired against phosphor-service-lock (the two services stay independent, and the shell wires them):
import Phosphor.Service.Lock 1.0
import Phosphor.Service.Session 1.0
SessionHost {
id: session
// Lock before the system sleeps: logind holds on our delay inhibitor until
// we release it, so lock first and release once the surface is up.
onAboutToSleep: lock.lock()
onLockRequested: lock.lock()
}
LockService {
id: lock
onLockedChanged: if (locked) session.allowSleep()
}
// power-menu buttons bind enablement to the capability and call the action
Button {
text: "Suspend"
enabled: session.canSuspend === SessionHost.Yes || session.canSuspend === SessionHost.Challenge
onClicked: session.suspend()
}The CLI doubles as the worked example and the acceptance harness:
# print the logind session capabilities
phosphor-service-session-cli status
# lock this session through logind
phosphor-service-session-cli lock
# suspend / reboot / power off (capability-gated; exits non-zero if unavailable)
phosphor-service-session-cli suspendShipped. SessionHost reads the seven logind capabilities into an Availability enum, issues the capability-gated session / power actions with the interactive flag, takes the delay-on-sleep and block-on-keys inhibitors, runs the PrepareForSleep lock-before-sleep handshake (aboutToSleep → LockService.lock() → allowSleep()), and surfaces the session Lock / Unlock signals. The examples/phosphor-service-session-cli demo drives status and the actions against a live logind. Three test binaries pin the surface: the smoke harness (registration idempotency, inert construction, the handshake and session-signal slot logic), the QML-engine facade load, and the behaviour test against an in-process fake logind Manager + Session (capability parsing, action routing with the interactive flag, capability-gated refusal, inhibitor what/mode, the PrepareForSleep handshake over the bus, and lock / terminate / signal surfacing). The shell wires the handshake to phosphor-service-lock in SessionLockCoordinator.qml. The lock surface itself is the shell's lock screen.