Documentation
¶
Overview ¶
Package idle is the shell's built-in idle policy: after the session has been idle for a stage's timeout it dims the backlights, locks, turns the outputs off and suspends, each undone (where it can be) when the user is back, with timeouts per power source; and it locks before the system sleeps. Idle is the compositor's ext-idle-notify-v1, so idle inhibitors (a playing video, the caffeine toggle, a portal or ScreenSaver hold) hold every stage, and waiting costs no timer.
Index ¶
- Variables
- func LockBeforeSleep(login Login, lockWait time.Duration) (stop func(), err error)
- type Actions
- type Backlights
- type Compositor
- func (c *Compositor) Close()
- func (c *Compositor) Ended() <-chan struct{}
- func (c *Compositor) Err() error
- func (c *Compositor) HandleCallbackDone(wl.CallbackDoneEvent)
- func (c *Compositor) HandleRegistryGlobal(ev wl.RegistryGlobalEvent)
- func (c *Compositor) HandleRegistryGlobalRemove(ev wl.RegistryGlobalRemoveEvent)
- func (c *Compositor) PowerOff() (func() error, error)
- func (c *Compositor) Watch(after time.Duration, idle, resume func()) (func(), error)
- type Login
- type Outputs
- type Service
- func (s *Service) Changes() (<-chan struct{}, func())
- func (s *Service) Close() error
- func (s *Service) Configure(p idlepolicy.Policy, enabled bool, source idlepolicy.PowerSource) error
- func (s *Service) Policy() idlepolicy.Policy
- func (s *Service) SetPowerSource(source idlepolicy.PowerSource) error
- func (s *Service) Status() Status
- type Status
- type System
- type Watcher
Constants ¶
This section is empty.
Variables ¶
var ErrNoIdleNotify = errors.New("idle: the compositor offers no " + notifierIface + " or no seat")
ErrNoIdleNotify is a compositor without ext-idle-notify-v1 or a seat: the session can never be seen idle.
var ErrNoLogind = errors.New("idle: logind is not connected")
ErrNoLogind is a lock or suspend without logind on the system bus.
var ErrNoOutputPower = errors.New("idle: the compositor offers no " + powerIface)
ErrNoOutputPower is a compositor without wlr-output-power-management: the outputs cannot be turned off.
Functions ¶
func LockBeforeSleep ¶
LockBeforeSleep holds a logind delay inhibitor on sleep, and when the system is about to sleep locks the session and lets go of the inhibitor once the lock screen has set LockedHint, so the machine wakes locked. On wake it takes the inhibitor again. lockWait bounds how long it waits for the lock screen; logind's own InhibitDelayMaxSec bounds the whole delay. It returns once the signal is watched and the inhibitor held; stop ends it and lets go of the inhibitor.
Types ¶
type Actions ¶
type Actions interface {
Dim(idlepolicy.DimPercent) (restore func() error, err error)
Lock() error
ScreenOff() (restore func() error, err error)
Suspend() error
}
Actions carry the stages out. Dim and ScreenOff return what undoes them at resume.
type Backlights ¶
type Backlights interface {
Devices(ctx context.Context) ([]brightness.Device, error)
Set(ctx context.Context, name string, percent float64) error
}
Backlights are the brightness devices the dim stage lowers.
type Compositor ¶
type Compositor struct {
// contains filtered or unexported fields
}
Compositor is the idle service's own Wayland connection: it watches the seat through ext-idle-notify-v1, which honours idle inhibitors, and turns outputs off and on through wlr-output-power-management-v1. One goroutine reads the connection; requests go out from any goroutine under mu, and no handler holds mu while it calls back.
func Connect ¶
func Connect() (*Compositor, error)
Connect connects to the compositor named by WAYLAND_DISPLAY and binds what it offers; ErrNoIdleNotify when it cannot watch idle.
func (*Compositor) Close ¶
func (c *Compositor) Close()
Close powers the outputs back on and closes the connection once a final sync comes back.
func (*Compositor) Ended ¶
func (c *Compositor) Ended() <-chan struct{}
Ended closes once the connection is gone; Err then says why.
func (*Compositor) Err ¶
func (c *Compositor) Err() error
Err is why the connection ended, nil before it has or after Close.
func (*Compositor) HandleCallbackDone ¶
func (c *Compositor) HandleCallbackDone(wl.CallbackDoneEvent)
HandleCallbackDone is Close's final sync: the read loop stops.
func (*Compositor) HandleRegistryGlobal ¶
func (c *Compositor) HandleRegistryGlobal(ev wl.RegistryGlobalEvent)
HandleRegistryGlobal binds the notifier, the first seat, the power manager and every output.
func (*Compositor) HandleRegistryGlobalRemove ¶
func (c *Compositor) HandleRegistryGlobalRemove(ev wl.RegistryGlobalRemoveEvent)
HandleRegistryGlobalRemove forgets an unplugged output.
func (*Compositor) PowerOff ¶
func (c *Compositor) PowerOff() (func() error, error)
PowerOff turns every output off, and every output that appears while off; the returned restore turns them back on.
type Login ¶ added in v0.3.23
Login is logind as the stages use it: its manager and the user's session, on one system bus connection.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service arms one idle watch per stage of the policy on the current power source, and re-arms them when either changes.
func (*Service) Changes ¶
func (s *Service) Changes() (<-chan struct{}, func())
Changes ticks after the service re-arms or a stage runs or is undone.
func (*Service) Configure ¶
func (s *Service) Configure(p idlepolicy.Policy, enabled bool, source idlepolicy.PowerSource) error
Configure arms the policy's stages on source; disabled arms none. Every stage that has run is undone first, so a new policy starts from an active session.
func (*Service) Policy ¶
func (s *Service) Policy() idlepolicy.Policy
Policy is the policy the service runs.
func (*Service) SetPowerSource ¶
func (s *Service) SetPowerSource(source idlepolicy.PowerSource) error
SetPowerSource re-arms the stages with source's timeouts.
type Status ¶
type Status struct {
Enabled bool
Source idlepolicy.PowerSource
Arms []idlepolicy.Arm
Reached []idlepolicy.Stage
}
Status is what the service has armed and which stages have run since the user was last active.
type System ¶
type System struct {
Backlights Backlights
Login *Login
Outputs Outputs
}
System carries the stages out on the session: the backlights dim, logind locks and suspends, and the compositor powers the outputs off. A nil Backlights has nothing to dim; a nil Login cannot lock or suspend, which the stage reports.
func (System) Dim ¶
func (s System) Dim(share idlepolicy.DimPercent) (func() error, error)
Dim lowers every backlight to share of its level; the restore puts back each level exactly as it was.