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 ¶
- Constants
- Variables
- func FormatDuration(d time.Duration) string
- func LockBeforeSleep(conn *dbus.Conn, session *logind.Client, lockWait time.Duration) (stop func(), err error)
- type Actions
- type Arm
- 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 DimPercent
- type Outputs
- type Policy
- type PowerSource
- type Service
- type Stage
- type Status
- type System
- type Timeout
- type Timeouts
- type Watcher
Constants ¶
const ( MinTimeout = time.Second MaxTimeout = time.Duration(math.MaxUint32) * time.Millisecond )
The bounds of a timeout: ext-idle-notify takes milliseconds in a uint32, and below a second a stage would fire between two keystrokes.
Variables ¶
var ErrDimPercentRange = errors.New("idle dim percentage out of range")
ErrDimPercentRange is a dim percentage outside 1-100.
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.
var ErrTimeoutRange = errors.New("idle timeout out of range")
ErrTimeoutRange is a timeout outside MinTimeout-MaxTimeout.
var Never = Timeout{}
Never is the timeout of a stage that does not run.
Stages lists every stage in order.
Functions ¶
func FormatDuration ¶
FormatDuration spells d the way the config writes it: 4m, 1h, 1h30m, 1m30s, without the zero tails time.Duration's String keeps.
func LockBeforeSleep ¶
func LockBeforeSleep(conn *dbus.Conn, session *logind.Client, lockWait time.Duration) (stop func(), err error)
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 inhibitor is held and the signal watched; stop ends it and lets go of the inhibitor.
Types ¶
type Actions ¶
type Actions interface {
Dim(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 DimPercent ¶
type DimPercent struct {
// contains filtered or unexported fields
}
DimPercent is the share of its level a dimmed backlight keeps, 1-100.
func NewDimPercent ¶
func NewDimPercent(percent int64) (DimPercent, error)
NewDimPercent validates percent, refusing one outside 1-100 with ErrDimPercentRange: at 0 a dimmed panel is a dark one, which is the screen-off stage's job.
func (DimPercent) Of ¶
func (d DimPercent) Of(level float64) float64
Of is level dimmed to this share.
type Policy ¶
type Policy struct {
Timeouts [stageCount]Timeouts
DimPercent DimPercent
LockBeforeSleep bool
}
Policy is the whole configuration of the idle service.
func (Policy) Arms ¶
func (p Policy) Arms(source PowerSource) []Arm
Arms are the stages that run on source, in stage order.
type PowerSource ¶
type PowerSource uint8
PowerSource is what the machine runs on: each has its own timeouts.
const ( AC PowerSource = iota Battery )
The power sources.
func (PowerSource) String ¶
func (p PowerSource) String() string
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 Policy, enabled bool, source 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) SetPowerSource ¶
func (s *Service) SetPowerSource(source PowerSource) error
SetPowerSource re-arms the stages with source's timeouts.
type Stage ¶
type Stage uint8
Stage is one step of the policy, in the order a session usually reaches them.
type Status ¶
type Status struct {
Enabled bool
Source PowerSource
Arms []Arm
Reached []Stage
}
Status is what the service has armed and which stages have run since the user was last active.
type System ¶
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 Session or Bus cannot lock or suspend, which the stage reports.
func (System) Dim ¶
func (s System) Dim(share DimPercent) (func() error, error)
Dim lowers every backlight to share of its level; the restore puts back each level exactly as it was.
type Timeout ¶
type Timeout struct {
// contains filtered or unexported fields
}
Timeout is how long the session idles before a stage runs; the zero value is never. NewTimeout is the only way to another.
func NewTimeout ¶
NewTimeout validates d, refusing one outside MinTimeout-MaxTimeout with ErrTimeoutRange.
type Timeouts ¶
type Timeouts struct{ AC, Battery Timeout }
Timeouts are a stage's timeouts on each power source.