idle

package
v0.3.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
var ErrDimPercentRange = errors.New("idle dim percentage out of range")

ErrDimPercentRange is a dim percentage outside 1-100.

View Source
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.

View Source
var ErrNoLogind = errors.New("idle: logind is not connected")

ErrNoLogind is a lock or suspend without logind on the system bus.

View Source
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.

View Source
var ErrTimeoutRange = errors.New("idle timeout out of range")

ErrTimeoutRange is a timeout outside MinTimeout-MaxTimeout.

View Source
var Never = Timeout{}

Never is the timeout of a stage that does not run.

View Source
var Stages = [stageCount]Stage{Dim, Lock, ScreenOff, Suspend}

Stages lists every stage in order.

Functions

func FormatDuration

func FormatDuration(d time.Duration) string

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 Arm

type Arm struct {
	Stage Stage
	After time.Duration
}

Arm is one stage armed on a power source: it runs after After of idle.

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.

func (*Compositor) Watch

func (c *Compositor) Watch(after time.Duration, idle, resume func()) (func(), error)

Watch implements Watcher with one ext_idle_notification_v1 that honours idle inhibitors.

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.

func (DimPercent) Percent

func (d DimPercent) Percent() uint8

Percent is the share in percent.

type Outputs

type Outputs interface {
	PowerOff() (restore func() error, err error)
}

Outputs turn the outputs off; the returned restore turns them on.

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 New

func New(w Watcher, a Actions) *Service

New is a service that has armed nothing until Configure.

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) Close

func (s *Service) Close() error

Close stops every watch and undoes what the stages did.

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) Policy

func (s *Service) Policy() Policy

Policy is the policy the service runs.

func (*Service) SetPowerSource

func (s *Service) SetPowerSource(source PowerSource) error

SetPowerSource re-arms the stages with source's timeouts.

func (*Service) Status

func (s *Service) Status() Status

Status reads what is armed and reached.

type Stage

type Stage uint8

Stage is one step of the policy, in the order a session usually reaches them.

const (
	Dim Stage = iota
	Lock
	ScreenOff
	Suspend
)

The stages.

func (Stage) String

func (s Stage) String() string

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.

func (Status) Next

func (s Status) Next() (Arm, bool)

Next is the first armed stage that has not run yet; false when every armed one has, or none is.

type System

type System struct {
	Backlights Backlights
	Session    *logind.Client
	Bus        *dbus.Conn
	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 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.

func (System) Lock

func (s System) Lock() error

Lock asks logind to lock the session.

func (System) ScreenOff

func (s System) ScreenOff() (func() error, error)

ScreenOff powers every output off.

func (System) Suspend

func (s System) Suspend() error

Suspend asks logind to suspend.

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

func NewTimeout(d time.Duration) (Timeout, error)

NewTimeout validates d, refusing one outside MinTimeout-MaxTimeout with ErrTimeoutRange.

func (Timeout) After

func (t Timeout) After() (time.Duration, bool)

After is the idle time before the stage runs; false for never.

type Timeouts

type Timeouts struct{ AC, Battery Timeout }

Timeouts are a stage's timeouts on each power source.

func (Timeouts) On

func (t Timeouts) On(source PowerSource) Timeout

On is the timeout on source.

type Watcher

type Watcher interface {
	Watch(after time.Duration, idle, resume func()) (stop func(), err error)
}

Watcher tells when the session has been idle for a while: idle runs once it has been idle for after, resume when the user is back. Both run on the watcher's own goroutine, and idle inhibitors hold the idle off.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL