Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
PhosphorServiceNightLight::NightLight Class Reference

A compositor-neutral night light. More...

#include <PhosphorServiceNightLight/NightLight.h>

Inheritance diagram for PhosphorServiceNightLight::NightLight:
[legend]

Public Types

enum class  Mode { Constant , Hours , Location }

Signals

void availableChanged ()
void enabledChanged ()
void modeChanged ()
void dayTemperatureChanged ()
void nightTemperatureChanged ()
void hoursChanged ()
void transitionDurationChanged ()
void locationChanged ()
void fadeDurationChanged ()
void inhibitedChanged ()
void activeChanged ()
void targetTemperatureChanged ()
void currentTemperatureChanged ()
void nextTransitionChanged ()

Public Member Functions

 NightLight (QObject *parent=nullptr)
 The production night light: a wlr-gamma-control client on the session's Wayland display and the system clock.
 NightLight (std::unique_ptr< GammaBackend > backend, std::function< QDateTime()> clock, QObject *parent=nullptr)
 A night light driving backend, reading the time from clock (local time in production: the hours are wall-clock times in the clock's time representation).
 ~NightLight () override
bool isAvailable () const
 Whether the compositor offers gamma control and at least one output accepts it.
bool isEnabled () const
 The user's on/off switch. Default false.
void setEnabled (bool enabled)
Mode mode () const
 The schedule. Default Hours.
void setMode (Mode mode)
int dayTemperature () const
 The day temperature, kelvin, clamped to [ColorTemperature::Minimum, ColorTemperature::Maximum].
void setDayTemperature (int kelvin)
int nightTemperature () const
 The night temperature, kelvin, clamped like the day temperature.
void setNightTemperature (int kelvin)
QTime eveningStart () const
 The Hours schedule's evening start (the transition toward night begins).
QTime morningStart () const
 The Hours schedule's morning start (the transition toward day begins).
bool setHours (QTime eveningStart, QTime morningStart)
 Set both hours.
int transitionDuration () const
 The requested length of each Hours transition, seconds, clamped to [0, MaximumTransitionDuration].
void setTransitionDuration (int seconds)
bool hasLocation () const
 Whether a location is set.
double latitude () const
 Degrees north. 0 without a location.
double longitude () const
 Degrees east. 0 without a location.
bool setLocation (double latitude, double longitude)
 Set the location for the Location schedule.
void clearLocation ()
 Forget the location.
int fadeDuration () const
 How long a user change fades, milliseconds, clamped to [0, MaximumFadeDuration].
void setFadeDuration (int milliseconds)
bool isInhibited () const
 Whether at least one inhibition is held.
bool isActive () const
 Whether the night temperature is at least partly in effect: available, enabled, not inhibited, and the schedule is in its night or in a transition.
int targetTemperature () const
 The temperature the screen is heading for now, kelvin.
int currentTemperature () const
 The temperature on the screen now, kelvin.
QDateTime nextTransition () const
 When the next scheduled transition starts (the one after any transition in progress).
uint inhibit (bool untilNextTransition=false)
 Hold the night light off.
void uninhibit (uint cookie)
 Release the inhibition cookie. Unknown cookies are ignored.
void refresh ()
 Re-read the clock and try again on outputs whose gamma control failed.

Static Public Attributes

static constexpr int DefaultTransitionDuration = 30 * 60
 The transition length used until the app sets one, in seconds.
static constexpr int MaximumTransitionDuration = 6 * 60 * 60
 The longest transition the library accepts, in seconds.
static constexpr int DefaultFadeDuration = 1000
 The fade length used until the app sets one, in milliseconds.
static constexpr int MaximumFadeDuration = 10000
 The longest fade the library accepts, in milliseconds.
static constexpr int DefaultNightTemperature = 4500
 The night temperature used until the app sets one, in kelvin.

Detailed Description

A compositor-neutral night light.

Warms the screen by setting every output's gamma ramps through wlr-gamma-control-unstable-v1, so it works on any compositor that offers that protocol (wlroots-based ones, among others) and needs no compositor D-Bus API. The schedule is one of:

  • Constant: the night temperature whenever the night light is enabled.
  • Hours: night from eveningStart to morningStart every day, with a gradual transition of transitionDuration seconds starting at each.
  • Location: night from sunset to sunrise at the location set with setLocation(), the sun's position computed locally. The evening transition runs from sunset to the end of civil twilight, the morning one from the start of civil twilight to sunrise.

Changes the user makes (enabling, a new temperature, a new schedule, an inhibition) fade over fadeDuration milliseconds. Scheduled transitions follow the clock. Disabling fades back to neutral and then gives each output its original ramps back.

The library keeps no settings. The app loads its saved values, hands them over through the setters and saves what the user changes. Every property has a change signal, emitted only when the value changed.

GUI thread only. Without a Wayland session (or with a compositor that does not offer gamma control) the object constructs and works as a state model, but available is false and nothing reaches the screen.

Member Enumeration Documentation

◆ Mode

Enumerator
Constant 
Hours 
Location 

Constructor & Destructor Documentation

◆ NightLight() [1/2]

PhosphorServiceNightLight::NightLight::NightLight ( QObject * parent = nullptr)
explicit

The production night light: a wlr-gamma-control client on the session's Wayland display and the system clock.

◆ NightLight() [2/2]

PhosphorServiceNightLight::NightLight::NightLight ( std::unique_ptr< GammaBackend > backend,
std::function< QDateTime()> clock,
QObject * parent = nullptr )

A night light driving backend, reading the time from clock (local time in production: the hours are wall-clock times in the clock's time representation).

Takes ownership of backend. For another backend, and for tests.

◆ ~NightLight()

PhosphorServiceNightLight::NightLight::~NightLight ( )
override

Member Function Documentation

◆ activeChanged

void PhosphorServiceNightLight::NightLight::activeChanged ( )
signal

◆ availableChanged

void PhosphorServiceNightLight::NightLight::availableChanged ( )
signal

◆ clearLocation()

void PhosphorServiceNightLight::NightLight::clearLocation ( )

Forget the location.

◆ currentTemperature()

int PhosphorServiceNightLight::NightLight::currentTemperature ( ) const
nodiscard

The temperature on the screen now, kelvin.

Differs from the target during a fade.

◆ currentTemperatureChanged

void PhosphorServiceNightLight::NightLight::currentTemperatureChanged ( )
signal

◆ dayTemperature()

int PhosphorServiceNightLight::NightLight::dayTemperature ( ) const
nodiscard

The day temperature, kelvin, clamped to [ColorTemperature::Minimum, ColorTemperature::Maximum].

Default ColorTemperature::Neutral (6500 K, the screen unchanged).

◆ dayTemperatureChanged

void PhosphorServiceNightLight::NightLight::dayTemperatureChanged ( )
signal

◆ enabledChanged

void PhosphorServiceNightLight::NightLight::enabledChanged ( )
signal

◆ eveningStart()

QTime PhosphorServiceNightLight::NightLight::eveningStart ( ) const
nodiscard

The Hours schedule's evening start (the transition toward night begins).

Default 18:00.

◆ fadeDuration()

int PhosphorServiceNightLight::NightLight::fadeDuration ( ) const
nodiscard

How long a user change fades, milliseconds, clamped to [0, MaximumFadeDuration].

0 applies changes at once. Default DefaultFadeDuration.

◆ fadeDurationChanged

void PhosphorServiceNightLight::NightLight::fadeDurationChanged ( )
signal

◆ hasLocation()

bool PhosphorServiceNightLight::NightLight::hasLocation ( ) const
nodiscard

Whether a location is set.

Without one the Location schedule is permanent day.

◆ hoursChanged

void PhosphorServiceNightLight::NightLight::hoursChanged ( )
signal

◆ inhibit()

uint PhosphorServiceNightLight::NightLight::inhibit ( bool untilNextTransition = false)

Hold the night light off.

Returns a cookie for uninhibit(), never 0. With untilNextTransition the inhibition also ends by itself when the next scheduled transition starts (recomputed when the schedule changes), the shape of a "pause until tomorrow" action. In Constant mode there is no next transition, so it lasts until uninhibit().

◆ inhibitedChanged

void PhosphorServiceNightLight::NightLight::inhibitedChanged ( )
signal

◆ isActive()

bool PhosphorServiceNightLight::NightLight::isActive ( ) const
nodiscard

Whether the night temperature is at least partly in effect: available, enabled, not inhibited, and the schedule is in its night or in a transition.

◆ isAvailable()

bool PhosphorServiceNightLight::NightLight::isAvailable ( ) const
nodiscard

Whether the compositor offers gamma control and at least one output accepts it.

Until the night light is first enabled the outputs are not taken, so this is true when the protocol and an output are present; an output that refuses (another program holds its gamma, or it has no gamma ramps) stops counting from then on, until refresh().

◆ isEnabled()

bool PhosphorServiceNightLight::NightLight::isEnabled ( ) const
nodiscard

The user's on/off switch. Default false.

◆ isInhibited()

bool PhosphorServiceNightLight::NightLight::isInhibited ( ) const
nodiscard

Whether at least one inhibition is held.

While inhibited the screen fades to neutral; enabled keeps the user's choice.

◆ latitude()

double PhosphorServiceNightLight::NightLight::latitude ( ) const
nodiscard

Degrees north. 0 without a location.

◆ locationChanged

void PhosphorServiceNightLight::NightLight::locationChanged ( )
signal

◆ longitude()

double PhosphorServiceNightLight::NightLight::longitude ( ) const
nodiscard

Degrees east. 0 without a location.

◆ mode()

Mode PhosphorServiceNightLight::NightLight::mode ( ) const
nodiscard

The schedule. Default Hours.

◆ modeChanged

void PhosphorServiceNightLight::NightLight::modeChanged ( )
signal

◆ morningStart()

QTime PhosphorServiceNightLight::NightLight::morningStart ( ) const
nodiscard

The Hours schedule's morning start (the transition toward day begins).

Default 06:00.

◆ nextTransition()

QDateTime PhosphorServiceNightLight::NightLight::nextTransition ( ) const
nodiscard

When the next scheduled transition starts (the one after any transition in progress).

Invalid in Constant mode, in Location mode without a location, and in a polar day or night.

◆ nextTransitionChanged

void PhosphorServiceNightLight::NightLight::nextTransitionChanged ( )
signal

◆ nightTemperature()

int PhosphorServiceNightLight::NightLight::nightTemperature ( ) const
nodiscard

The night temperature, kelvin, clamped like the day temperature.

Default DefaultNightTemperature.

◆ nightTemperatureChanged

void PhosphorServiceNightLight::NightLight::nightTemperatureChanged ( )
signal

◆ refresh()

void PhosphorServiceNightLight::NightLight::refresh ( )

Re-read the clock and try again on outputs whose gamma control failed.

For a "Try again" action, and after the system resumes from suspend.

◆ setDayTemperature()

void PhosphorServiceNightLight::NightLight::setDayTemperature ( int kelvin)

◆ setEnabled()

void PhosphorServiceNightLight::NightLight::setEnabled ( bool enabled)

◆ setFadeDuration()

void PhosphorServiceNightLight::NightLight::setFadeDuration ( int milliseconds)

◆ setHours()

bool PhosphorServiceNightLight::NightLight::setHours ( QTime eveningStart,
QTime morningStart )

Set both hours.

Seconds are dropped. Returns false, changing nothing, when either time is invalid or the two are the same minute.

◆ setLocation()

bool PhosphorServiceNightLight::NightLight::setLocation ( double latitude,
double longitude )

Set the location for the Location schedule.

Returns false, changing nothing, when the latitude is outside [-90, 90] or the longitude outside [-180, 180] (or either is not a number).

◆ setMode()

void PhosphorServiceNightLight::NightLight::setMode ( Mode mode)

◆ setNightTemperature()

void PhosphorServiceNightLight::NightLight::setNightTemperature ( int kelvin)

◆ setTransitionDuration()

void PhosphorServiceNightLight::NightLight::setTransitionDuration ( int seconds)

◆ targetTemperature()

int PhosphorServiceNightLight::NightLight::targetTemperature ( ) const
nodiscard

The temperature the screen is heading for now, kelvin.

Neutral while disabled or inhibited.

◆ targetTemperatureChanged

void PhosphorServiceNightLight::NightLight::targetTemperatureChanged ( )
signal

◆ transitionDuration()

int PhosphorServiceNightLight::NightLight::transitionDuration ( ) const
nodiscard

The requested length of each Hours transition, seconds, clamped to [0, MaximumTransitionDuration].

Default DefaultTransitionDuration. When the night or the day is short the transitions run shorter, at most half of the shorter of the two, so they never overlap.

◆ transitionDurationChanged

void PhosphorServiceNightLight::NightLight::transitionDurationChanged ( )
signal

◆ uninhibit()

void PhosphorServiceNightLight::NightLight::uninhibit ( uint cookie)

Release the inhibition cookie. Unknown cookies are ignored.

Member Data Documentation

◆ DefaultFadeDuration

int PhosphorServiceNightLight::NightLight::DefaultFadeDuration = 1000
staticconstexpr

The fade length used until the app sets one, in milliseconds.

◆ DefaultNightTemperature

int PhosphorServiceNightLight::NightLight::DefaultNightTemperature = 4500
staticconstexpr

The night temperature used until the app sets one, in kelvin.

◆ DefaultTransitionDuration

int PhosphorServiceNightLight::NightLight::DefaultTransitionDuration = 30 * 60
staticconstexpr

The transition length used until the app sets one, in seconds.

◆ MaximumFadeDuration

int PhosphorServiceNightLight::NightLight::MaximumFadeDuration = 10000
staticconstexpr

The longest fade the library accepts, in milliseconds.

◆ MaximumTransitionDuration

int PhosphorServiceNightLight::NightLight::MaximumTransitionDuration = 6 * 60 * 60
staticconstexpr

The longest transition the library accepts, in seconds.


The documentation for this class was generated from the following file:
  • phosphor-service-nightlight/include/PhosphorServiceNightLight/NightLight.h