nightlight

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 22 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 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

View Source
const (
	MinTemp  = 1000
	MaxTemp  = 20000
	MaxGamma = 200
)

The documented ranges of the module's temperature and gamma.

View Source
const MaxTransitionMinutes = 120

MaxTransitionMinutes bounds an ease: past two hours it stops reading as a transition at a solar event.

Variables

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

View Source
var ErrUnsupported = errors.New("nightlight: the compositor offers neither " + ctmIface + " nor " + gammaIface)

ErrUnsupported is a compositor that offers neither colour protocol.

Functions

func ClearOverride

func ClearOverride(dir string) error

ClearOverride drops the record (a phase change ends it); having none to drop is not a failure.

func NextEase

func NextEase(now time.Time, loc Location, transition Transition) (time.Time, bool)

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

func SaveLocation(dir string, loc Location) error

SaveLocation remembers a fix for the next start, atomically, so a restart at night tints the display at once rather than after GeoClue answers.

func SaveOverride

func SaveOverride(dir string, o Override, now time.Time) error

SaveOverride records a toggle made at now (persist.rs save), atomically.

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

func Open(changed func()) (*Filter, error)

Open connects to the compositor named by WAYLAND_DISPLAY. changed runs on the filter's goroutine whenever Refused may have changed.

func (*Filter) Apply

func (f *Filter) Apply(s Setting) error

Apply tints every output with s, binding the protocol on first use.

func (*Filter) Clear

func (f *Filter) Clear() error

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

func (f *Filter) Err() error

Err is why the connection ended, nil before it has or after Close.

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.

func (*Filter) Protocol

func (f *Filter) Protocol() string

Protocol names the protocol the filter drives.

func (*Filter) Refused

func (f *Filter) Refused() error

Refused is why the compositor turned the filter away, nil while it applies or is off.

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

func LoadLocation(dir string) (Location, error)

LoadLocation reads the remembered fix; the error wraps fs.ErrNotExist when there is none, and names the file when it is unusable.

func NewLocation

func NewLocation(latitude, longitude float64) (Location, error)

NewLocation validates the coordinates, refusing NaN, anything off the globe, and ErrNullIsland.

func QueryLocation

func QueryLocation(ctx context.Context, conn *dbus.Conn) (Location, error)

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.

func (Location) Latitude

func (l Location) Latitude() float64

Latitude is the latitude in decimal degrees, north positive.

func (Location) Longitude

func (l Location) Longitude() float64

Longitude is the longitude in decimal degrees, east positive.

type Matrix

type Matrix [9]float64

Matrix is a row-major 3×3 colour transform.

type Override

type Override struct {
	Phase   Phase
	Enabled bool
}

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

func LoadOverride

func LoadOverride(dir string, now time.Time) (Override, bool)

LoadOverride reads the record; false when absent, malformed, or stale.

type Phase

type Phase uint8

Phase is whether the sun is above civil twilight at a place and time.

const (
	PhaseDay Phase = iota + 1
	PhaseNight
)

Solar phases.

func PhaseAt

func PhaseAt(now time.Time, loc Location) Phase

PhaseAt is day from civil dawn up to civil dusk of the solar day now belongs to, night otherwise; polar day is day and polar night is night.

func (Phase) String

func (p Phase) String() string

String is the persist-record spelling.

type RefusedError

type RefusedError struct {
	Protocol string
	Output   string
}

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

func NewSetting(temp, gamma int) (Setting, error)

NewSetting validates temp against MinTemp..MaxTemp and gamma against 0..MaxGamma.

func (Setting) Gamma

func (s Setting) Gamma() int

Gamma is the brightness percentage, to the nearest whole one.

func (Setting) IsIdentity

func (s Setting) IsIdentity() bool

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

func (s Setting) Matrix() Matrix

Matrix is the colour transform that applies s: a diagonal of the channel scales.

func (Setting) Ramps

func (s Setting) Ramps(size int) []uint16

Ramps is the gamma table that applies s on an output with size entries per channel: the red, then green, then blue ramp, each the identity scaled by its channel, so the result matches Matrix.

func (Setting) Temp

func (s Setting) Temp() int

Temp is the colour temperature in Kelvin, to the nearest whole one.

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.

func TargetAt

func TargetAt(now time.Time, loc Location, transition Transition, night Setting) Target

TargetAt is the schedule at now for a place, a transition length and the full night strength. Each transition is centred on civil dawn or dusk; a polar solar day has neither, so it has no transition.

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.

func (Transition) Minutes

func (t Transition) Minutes() uint32

Minutes is the length in minutes.

Jump to

Keyboard shortcuts

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