A compositor-neutral night light. More...
#include <PhosphorServiceNightLight/NightLight.h>
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. | |
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:
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.
|
strong |
|
explicit |
The production night light: a wlr-gamma-control client on the session's Wayland display and the system clock.
| 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.
|
override |
|
signal |
|
signal |
| void PhosphorServiceNightLight::NightLight::clearLocation | ( | ) |
Forget the location.
|
nodiscard |
The temperature on the screen now, kelvin.
Differs from the target during a fade.
|
signal |
|
nodiscard |
The day temperature, kelvin, clamped to [ColorTemperature::Minimum, ColorTemperature::Maximum].
Default ColorTemperature::Neutral (6500 K, the screen unchanged).
|
signal |
|
signal |
|
nodiscard |
The Hours schedule's evening start (the transition toward night begins).
Default 18:00.
|
nodiscard |
How long a user change fades, milliseconds, clamped to [0, MaximumFadeDuration].
0 applies changes at once. Default DefaultFadeDuration.
|
signal |
|
nodiscard |
Whether a location is set.
Without one the Location schedule is permanent day.
|
signal |
| 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().
|
signal |
|
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.
|
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().
|
nodiscard |
The user's on/off switch. Default false.
|
nodiscard |
Whether at least one inhibition is held.
While inhibited the screen fades to neutral; enabled keeps the user's choice.
|
nodiscard |
Degrees north. 0 without a location.
|
signal |
|
nodiscard |
Degrees east. 0 without a location.
|
nodiscard |
The schedule. Default Hours.
|
signal |
|
nodiscard |
The Hours schedule's morning start (the transition toward day begins).
Default 06:00.
|
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.
|
signal |
|
nodiscard |
The night temperature, kelvin, clamped like the day temperature.
Default DefaultNightTemperature.
|
signal |
| 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.
| void PhosphorServiceNightLight::NightLight::setDayTemperature | ( | int | kelvin | ) |
| void PhosphorServiceNightLight::NightLight::setEnabled | ( | bool | enabled | ) |
| void PhosphorServiceNightLight::NightLight::setFadeDuration | ( | int | milliseconds | ) |
| 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.
| 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).
| void PhosphorServiceNightLight::NightLight::setMode | ( | Mode | mode | ) |
| void PhosphorServiceNightLight::NightLight::setNightTemperature | ( | int | kelvin | ) |
| void PhosphorServiceNightLight::NightLight::setTransitionDuration | ( | int | seconds | ) |
|
nodiscard |
The temperature the screen is heading for now, kelvin.
Neutral while disabled or inhibited.
|
signal |
|
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.
|
signal |
| void PhosphorServiceNightLight::NightLight::uninhibit | ( | uint | cookie | ) |
Release the inhibition cookie. Unknown cookies are ignored.
|
staticconstexpr |
The fade length used until the app sets one, in milliseconds.
|
staticconstexpr |
The night temperature used until the app sets one, in kelvin.
|
staticconstexpr |
The transition length used until the app sets one, in seconds.
|
staticconstexpr |
The longest fade the library accepts, in milliseconds.
|
staticconstexpr |
The longest transition the library accepts, in seconds.