Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
PhosphorServiceSession::SessionHost Class Reference

logind session manager: capability queries, session/power actions, inhibitor locks, and the sleep + session signals. More...

#include <PhosphorServiceSession/SessionHost.h>

Inheritance diagram for PhosphorServiceSession::SessionHost:
[legend]

Public Types

enum class  Availability {
  Unknown , Yes , No , NotApplicable ,
  Challenge
}
 logind capability state, parsed from the Can* query strings. More...

Signals

void capabilitiesChanged ()
 Emitted whenever any capability value actually changes (each async Can* reply that differs from the cached value fires this once).
void interactiveChanged ()
void logoutRequested ()
 Emitted by logout() so the shell / compositor can end the session gracefully (close clients, save state) rather than via a blunt logind terminate.
void prepareForSleep (bool beforeSleep)
 Raw logind PrepareForSleep passthrough: beforeSleep is true just before the system sleeps and false just after it resumes.
void aboutToSleep ()
 Emitted on PrepareForSleep(true) while the delay inhibitor is held: the shell should lock now, then call allowSleep() once the surface is up.
void lockRequested ()
 The logind session was asked to lock / unlock (e.g.
void unlockRequested ()

Public Member Functions

 SessionHost (QObject *parent=nullptr)
 Whether action calls pass logind interactive=true, routing an action that needs authorization to an in-session polkit agent (we ship one in 2.6) for a native prompt.
 SessionHost (QDBusConnection connection, QString service, QObject *parent=nullptr)
 Injectable wiring for tests / advanced consumers.
 ~SessionHost () override
Availability canPowerOff () const
Availability canReboot () const
Availability canHalt () const
Availability canSuspend () const
Availability canHibernate () const
Availability canHybridSleep () const
Availability canSuspendThenHibernate () const
void refreshCapabilities ()
 Re-read every capability from logind.
bool interactive () const
void setInteractive (bool interactive)
void lock ()
 Lock this session (resolved via XDG_SESSION_ID / GetSession, falling back to GetSessionByPID): logind emits its Lock signal, which the shell routes to the lock surface (2.9).
void logout ()
 End this session.
void terminateSession ()
void suspend ()
 Capability-gated power actions.
void hibernate ()
void hybridSleep ()
void suspendThenHibernate ()
void reboot ()
void powerOff ()
void halt ()
void allowSleep ()
 Drop the sleep delay-inhibitor so a pending suspend proceeds.

Detailed Description

logind session manager: capability queries, session/power actions, inhibitor locks, and the sleep + session signals.

Talks to org.freedesktop.login1.Manager on the system bus. The capability queries (CanSuspend and siblings) are read up front and cached; the actions are capability-gated; the inhibitor locks let the shell lock before suspend and own the power / lid keys. Inert when logind is unreachable (capabilities Unknown, actions no-op with a warning, inhibitors not taken).

The (connection, service) are injectable so the whole surface is testable against a fake logind Manager with no real system bus and no daemon.

Beyond the capability queries it issues the capability-gated session / power actions, holds the logind delay (sleep) and block (handle-keys) inhibitors, runs the PrepareForSleep lock-before-sleep handshake, and surfaces the session Lock / Unlock signals.

Member Enumeration Documentation

◆ Availability

logind capability state, parsed from the Can* query strings.

Enumerator
Unknown 

logind unreachable, or the query errored / has not returned yet.

Yes 

permitted.

No 

not permitted (hardware or configuration does not support it).

NotApplicable 

logind "na": not available (e.g. hibernate with no swap).

Challenge 

permitted but needs polkit authorization.

Constructor & Destructor Documentation

◆ SessionHost() [1/2]

PhosphorServiceSession::SessionHost::SessionHost ( QObject * parent = nullptr)
explicit

Whether action calls pass logind interactive=true, routing an action that needs authorization to an in-session polkit agent (we ship one in 2.6) for a native prompt.

Defaults true on the QML host; the CLI sets it false (no agent in a dev shell, so logind just returns an auth error). Production wiring: the system bus and org.freedesktop.login1.

◆ SessionHost() [2/2]

PhosphorServiceSession::SessionHost::SessionHost ( QDBusConnection connection,
QString service,
QObject * parent = nullptr )

Injectable wiring for tests / advanced consumers.

connection and service select the bus and the logind well-known name; the fake-logind unit tests inject a session-bus Manager so no real logind is required.

◆ ~SessionHost()

PhosphorServiceSession::SessionHost::~SessionHost ( )
override

Member Function Documentation

◆ aboutToSleep

void PhosphorServiceSession::SessionHost::aboutToSleep ( )
signal

Emitted on PrepareForSleep(true) while the delay inhibitor is held: the shell should lock now, then call allowSleep() once the surface is up.

◆ allowSleep()

void PhosphorServiceSession::SessionHost::allowSleep ( )

Drop the sleep delay-inhibitor so a pending suspend proceeds.

The shell calls this once the lock surface (2.9) is confirmed up, completing the lock-before-sleep handshake. A safety timeout drops it anyway if the shell never confirms, so a missing lock cannot wedge suspend.

◆ canHalt()

Availability PhosphorServiceSession::SessionHost::canHalt ( ) const
nodiscard

◆ canHibernate()

Availability PhosphorServiceSession::SessionHost::canHibernate ( ) const
nodiscard

◆ canHybridSleep()

Availability PhosphorServiceSession::SessionHost::canHybridSleep ( ) const
nodiscard

◆ canPowerOff()

Availability PhosphorServiceSession::SessionHost::canPowerOff ( ) const
nodiscard

◆ canReboot()

Availability PhosphorServiceSession::SessionHost::canReboot ( ) const
nodiscard

◆ canSuspend()

Availability PhosphorServiceSession::SessionHost::canSuspend ( ) const
nodiscard

◆ canSuspendThenHibernate()

Availability PhosphorServiceSession::SessionHost::canSuspendThenHibernate ( ) const
nodiscard

◆ capabilitiesChanged

void PhosphorServiceSession::SessionHost::capabilitiesChanged ( )
signal

Emitted whenever any capability value actually changes (each async Can* reply that differs from the cached value fires this once).

◆ halt()

void PhosphorServiceSession::SessionHost::halt ( )

◆ hibernate()

void PhosphorServiceSession::SessionHost::hibernate ( )

◆ hybridSleep()

void PhosphorServiceSession::SessionHost::hybridSleep ( )

◆ interactive()

bool PhosphorServiceSession::SessionHost::interactive ( ) const
nodiscard

◆ interactiveChanged

void PhosphorServiceSession::SessionHost::interactiveChanged ( )
signal

◆ lock()

void PhosphorServiceSession::SessionHost::lock ( )

Lock this session (resolved via XDG_SESSION_ID / GetSession, falling back to GetSessionByPID): logind emits its Lock signal, which the shell routes to the lock surface (2.9).

Falls back to Manager.LockSessions() when this session cannot be resolved.

◆ lockRequested

void PhosphorServiceSession::SessionHost::lockRequested ( )
signal

The logind session was asked to lock / unlock (e.g.

loginctl lock-session, a hardware lock key routed through logind, or our own lock()). The shell routes lockRequested() to 2.9's lock surface.

◆ logout()

void PhosphorServiceSession::SessionHost::logout ( )

End this session.

Emits logoutRequested() so the shell / compositor can exit gracefully; terminateSession() is the logind fallback (the resolved session's Terminate) for contexts with no graceful owner.

◆ logoutRequested

void PhosphorServiceSession::SessionHost::logoutRequested ( )
signal

Emitted by logout() so the shell / compositor can end the session gracefully (close clients, save state) rather than via a blunt logind terminate.

◆ powerOff()

void PhosphorServiceSession::SessionHost::powerOff ( )

◆ prepareForSleep

void PhosphorServiceSession::SessionHost::prepareForSleep ( bool beforeSleep)
signal

Raw logind PrepareForSleep passthrough: beforeSleep is true just before the system sleeps and false just after it resumes.

◆ reboot()

void PhosphorServiceSession::SessionHost::reboot ( )

◆ refreshCapabilities()

void PhosphorServiceSession::SessionHost::refreshCapabilities ( )

Re-read every capability from logind.

Called once at construction and exposed so the shell can refresh before opening a power menu, since the answers move with inhibitor locks, lid state, and swap availability.

◆ setInteractive()

void PhosphorServiceSession::SessionHost::setInteractive ( bool interactive)

◆ suspend()

void PhosphorServiceSession::SessionHost::suspend ( )

Capability-gated power actions.

Each is a no-op (with a warning) when its capability is not Yes or Challenge, and otherwise issues the logind Manager call with the current interactive flag.

◆ suspendThenHibernate()

void PhosphorServiceSession::SessionHost::suspendThenHibernate ( )

◆ terminateSession()

void PhosphorServiceSession::SessionHost::terminateSession ( )

◆ unlockRequested

void PhosphorServiceSession::SessionHost::unlockRequested ( )
signal

The documentation for this class was generated from the following file:
  • phosphor-service-session/include/PhosphorServiceSession/SessionHost.h