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 LoadLocation(dir string) (nightschedule.Location, error)
- func NextEase(now time.Time, loc nightschedule.Location, transition nightschedule.Transition) (time.Time, bool)
- func QueryLocation(ctx context.Context, conn *dbus.Conn) (nightschedule.Location, error)
- func SaveLocation(dir string, loc nightschedule.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) EaseStep() time.Duration
- 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) HandleRegistryGlobal(ev wl.RegistryGlobalEvent)
- func (f *Filter) HandleRegistryGlobalRemove(ev wl.RegistryGlobalRemoveEvent)
- func (f *Filter) Protocol() string
- func (f *Filter) Refused() error
- type Matrix
- type Override
- type Phase
- type RefusedError
- type Setting
- type Target
Constants ¶
const ( MinTemp = 1000 MaxTemp = 20000 MaxGamma = 200 )
The documented ranges of the module's temperature and gamma.
const NeutralTemp = 6600
NeutralTemp is where the whitepoint fit is exactly the identity.
Variables ¶
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 LoadLocation ¶
func LoadLocation(dir string) (nightschedule.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 NextEase ¶
func NextEase(now time.Time, loc nightschedule.Location, transition nightschedule.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 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.
func SaveLocation ¶
func SaveLocation(dir string, loc nightschedule.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.
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) EaseStep ¶
EaseStep is how often an ease steps on the filter's protocol so that no step shows: a CTM matrix crosses wl_fixed's 1/256 steps, so it is evaluated often enough to move one of them at a time, while 16-bit gamma ramps change smoothly once a second.
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) 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 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.
func TargetAt ¶
func TargetAt(now time.Time, loc nightschedule.Location, transition nightschedule.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.