Documentation
¶
Overview ¶
Package nightlight is the night light module's service side: the colour filter it applies through the compositor's CTM or gamma protocol, the dawn/dusk schedule (NOAA sunrise equation, no network) and its easing, the GeoClue location lookup, and the records that survive restarts.
Index ¶
- Constants
- Variables
- func ClearOverride(dir string) error
- func NextEase(now time.Time, loc Location, transition Transition) (time.Time, bool)
- func SaveLocation(dir string, loc Location) error
- func SaveOverride(dir string, o Override, now time.Time) error
- type Filter
- func (f *Filter) Apply(s Setting) error
- func (f *Filter) Clear() error
- func (f *Filter) Close()
- func (f *Filter) Ended() <-chan struct{}
- func (f *Filter) Err() error
- func (f *Filter) HandleCallbackDone(wl.CallbackDoneEvent)
- func (f *Filter) HandleCtmControlManagerV1Blocked(wlr.CtmControlManagerV1BlockedEvent)
- func (f *Filter) HandleDisplayDeleteId(ev wl.DisplayDeleteIdEvent)
- func (f *Filter) HandleRegistryGlobal(ev wl.RegistryGlobalEvent)
- func (f *Filter) HandleRegistryGlobalRemove(ev wl.RegistryGlobalRemoveEvent)
- func (f *Filter) Protocol() string
- func (f *Filter) Refused() error
- type Location
- type Matrix
- type Override
- type Phase
- type RefusedError
- type Setting
- type Target
- type Transition
Constants ¶
const ( MinTemp = 1000 MaxTemp = 20000 MaxGamma = 200 )
The documented ranges of the module's temperature and gamma.
const MaxTransitionMinutes = 120
MaxTransitionMinutes bounds an ease: past two hours it stops reading as a transition at a solar event.
Variables ¶
var ErrNullIsland = errors.New("nightlight: the coordinates 0, 0 are not a position")
ErrNullIsland is the coordinates 0, 0: open water no machine sits on, and the value an unset coordinate used to default to, so it is never taken for a position.
var ErrUnsupported = errors.New("nightlight: the compositor offers neither " + ctmIface + " nor " + gammaIface)
ErrUnsupported is a compositor that offers neither colour protocol.
Functions ¶
func ClearOverride ¶
ClearOverride drops the record (a phase change ends it); having none to drop is not a failure.
func NextEase ¶
NextEase is the moment the next transition after now starts, or, with no transition length, the next civil dawn or dusk; false when polar days leave none in reach.
func SaveLocation ¶
SaveLocation remembers a fix for the next start, atomically, so a restart at night tints the display at once rather than after GeoClue answers.
Types ¶
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter applies a Setting to every output over a private Wayland connection, following outputs as they come and go. The compositor restores the identity when the filter clears or the connection ends, so a crashed shell never leaves the display tinted.
One goroutine reads the connection and alone closes it; requests go out from any goroutine under mu, which the event handlers take too.
func Open ¶
Open connects to the compositor named by WAYLAND_DISPLAY. changed runs on the filter's goroutine whenever Refused may have changed.
func (*Filter) Clear ¶
Clear lets go of the protocol, which returns every output to the identity, and forgets a refusal.
func (*Filter) Close ¶
func (f *Filter) Close()
Close clears the filter and waits for the connection to close: a final sync's reply ends the read loop, which closes it. A request that cannot be sent means the connection is already broken, and the read loop ends on that instead.
func (*Filter) Ended ¶
func (f *Filter) Ended() <-chan struct{}
Ended closes once the connection is gone; Err then says why.
func (*Filter) HandleCallbackDone ¶
func (f *Filter) HandleCallbackDone(wl.CallbackDoneEvent)
HandleCallbackDone is the final sync of Close: the read loop stops.
func (*Filter) HandleCtmControlManagerV1Blocked ¶
func (f *Filter) HandleCtmControlManagerV1Blocked(wlr.CtmControlManagerV1BlockedEvent)
HandleCtmControlManagerV1Blocked is another CTM manager owning the outputs: the compositor ignores this one's matrices.
func (*Filter) HandleDisplayDeleteId ¶
func (f *Filter) HandleDisplayDeleteId(ev wl.DisplayDeleteIdEvent)
HandleDisplayDeleteId frees a destroyed handle's id.
func (*Filter) HandleRegistryGlobal ¶
func (f *Filter) HandleRegistryGlobal(ev wl.RegistryGlobalEvent)
HandleRegistryGlobal records the colour protocols and binds outputs.
func (*Filter) HandleRegistryGlobalRemove ¶
func (f *Filter) HandleRegistryGlobalRemove(ev wl.RegistryGlobalRemoveEvent)
HandleRegistryGlobalRemove forgets an unplugged output.
type Location ¶
type Location struct {
// contains filtered or unexported fields
}
Location is a position in decimal degrees, north and east positive. NewLocation is the only way to build one, so every Location is on the globe and not 0, 0.
func LoadLocation ¶
LoadLocation reads the remembered fix; the error wraps fs.ErrNotExist when there is none, and names the file when it is unusable.
func NewLocation ¶
NewLocation validates the coordinates, refusing NaN, anything off the globe, and ErrNullIsland.
func QueryLocation ¶
QueryLocation resolves the position once over GeoClue2 on conn (the system bus in the shell): get a client, set DesktopId and the city accuracy, start it, and take the first LocationUpdated. GeoClue answers GetClient only once an agent serves this user, so with none running the lookup registers as one for as long as conn stays open; the caller closes conn when the lookup returns, which ends that. Any failure (no daemon, not allowed as an agent, denied, timeout, a fix of 0, 0) is an error, which leaves the schedule on the last location it had, or on none.
type Override ¶
Override is a manual toggle remembered across restarts: the filter state it chose and, when the auto-schedule ran, the solar phase it was made in (zero Phase for none).
type Phase ¶
type Phase uint8
Phase is whether the sun is above civil twilight at a place and time.
type RefusedError ¶
RefusedError is the compositor turning the filter away because another client already controls the display colours.
func (*RefusedError) Error ¶
func (e *RefusedError) Error() string
type Setting ¶
type Setting struct {
// contains filtered or unexported fields
}
Setting is a filter strength: the colour temperature in Kelvin and the gamma, a brightness percentage. NewSetting and the easing between two valid strengths are the only ways to build one, so every Setting is in range. Eased strengths are fractional, so no step of an ease shows.
func NewSetting ¶
NewSetting validates temp against MinTemp..MaxTemp and gamma against 0..MaxGamma.
func (Setting) IsIdentity ¶
IsIdentity reports whether s leaves the display's colours alone, so the filter can let go of the protocol instead of applying it.
func (Setting) Matrix ¶
Matrix is the colour transform that applies s: a diagonal of the channel scales.
type Target ¶
type Target struct {
// Phase is the phase in force: an ease counts as the phase it heads
// for from its first moment, though it is centred on the solar
// event, so a manual toggle made during one outlasts it.
Phase Phase
// Setting is the strength to show; the identity means no filter.
Setting Setting
// Easing is whether the moment is inside a transition, when Setting
// keeps changing.
Easing bool
}
Target is what the schedule wants at a moment.
type Transition ¶
type Transition struct {
// contains filtered or unexported fields
}
Transition is how long an ease between day and night lasts, in whole minutes, 0 for an instant switch. NewTransition is the only way to a non-zero one, so it never exceeds MaxTransitionMinutes.
func NewTransition ¶
func NewTransition(minutes int64) (Transition, error)
NewTransition validates minutes against 0..MaxTransitionMinutes.
func (Transition) Duration ¶
func (t Transition) Duration() time.Duration
Duration is the length as a duration.