Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
NightLight.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <PhosphorServiceNightLight/phosphorservicenightlight_export.h>
7
8#include <QDateTime>
9#include <QObject>
10#include <QTime>
11
12#include <functional>
13#include <memory>
14
16
17class GammaBackend;
18
48class PHOSPHORSERVICENIGHTLIGHT_EXPORT NightLight : public QObject
49{
50 Q_OBJECT
51 Q_PROPERTY(bool available READ isAvailable NOTIFY availableChanged)
52 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
53 Q_PROPERTY(Mode mode READ mode WRITE setMode NOTIFY modeChanged)
56 Q_PROPERTY(QTime eveningStart READ eveningStart NOTIFY hoursChanged)
57 Q_PROPERTY(QTime morningStart READ morningStart NOTIFY hoursChanged)
58 Q_PROPERTY(
60 Q_PROPERTY(bool hasLocation READ hasLocation NOTIFY locationChanged)
61 Q_PROPERTY(double latitude READ latitude NOTIFY locationChanged)
62 Q_PROPERTY(double longitude READ longitude NOTIFY locationChanged)
63 Q_PROPERTY(int fadeDuration READ fadeDuration WRITE setFadeDuration NOTIFY fadeDurationChanged)
64 Q_PROPERTY(bool inhibited READ isInhibited NOTIFY inhibitedChanged)
65 Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
68 Q_PROPERTY(QDateTime nextTransition READ nextTransition NOTIFY nextTransitionChanged)
69
70public:
71 enum class Mode {
72 Constant,
73 Hours,
74 Location,
75 };
76 Q_ENUM(Mode)
77
78
79 static constexpr int DefaultTransitionDuration = 30 * 60;
81 static constexpr int MaximumTransitionDuration = 6 * 60 * 60;
83 static constexpr int DefaultFadeDuration = 1000;
85 static constexpr int MaximumFadeDuration = 10000;
87 static constexpr int DefaultNightTemperature = 4500;
88
91 explicit NightLight(QObject* parent = nullptr);
92
97 NightLight(std::unique_ptr<GammaBackend> backend, std::function<QDateTime()> clock, QObject* parent = nullptr);
98
99 ~NightLight() override;
100
106 [[nodiscard]] bool isAvailable() const;
107
109 [[nodiscard]] bool isEnabled() const;
110 void setEnabled(bool enabled);
111
113 [[nodiscard]] Mode mode() const;
115
119 [[nodiscard]] int dayTemperature() const;
120 void setDayTemperature(int kelvin);
121
124 [[nodiscard]] int nightTemperature() const;
125 void setNightTemperature(int kelvin);
126
129 [[nodiscard]] QTime eveningStart() const;
132 [[nodiscard]] QTime morningStart() const;
135 Q_INVOKABLE bool setHours(QTime eveningStart, QTime morningStart);
136
141 [[nodiscard]] int transitionDuration() const;
142 void setTransitionDuration(int seconds);
143
146 [[nodiscard]] bool hasLocation() const;
148 [[nodiscard]] double latitude() const;
150 [[nodiscard]] double longitude() const;
154 Q_INVOKABLE bool setLocation(double latitude, double longitude);
156 Q_INVOKABLE void clearLocation();
157
161 [[nodiscard]] int fadeDuration() const;
162 void setFadeDuration(int milliseconds);
163
166 [[nodiscard]] bool isInhibited() const;
167
171 [[nodiscard]] bool isActive() const;
172
175 [[nodiscard]] int targetTemperature() const;
176
179 [[nodiscard]] int currentTemperature() const;
180
184 [[nodiscard]] QDateTime nextTransition() const;
185
191 Q_INVOKABLE uint inhibit(bool untilNextTransition = false);
192
194 Q_INVOKABLE void uninhibit(uint cookie);
195
198 Q_INVOKABLE void refresh();
199
200Q_SIGNALS:
215
216private:
217 Q_DISABLE_COPY_MOVE(NightLight)
218
219 class Private;
220 std::unique_ptr<Private> d;
221};
222
223} // namespace PhosphorServiceNightLight
What NightLight drives: something that can tint every output.
Definition GammaBackend.h:24
bool setLocation(double latitude, double longitude)
Set the location for the Location schedule.
int fadeDuration() const
How long a user change fades, milliseconds, clamped to [0, MaximumFadeDuration].
Mode
Definition NightLight.h:71
static constexpr int MaximumTransitionDuration
The longest transition the library accepts, in seconds.
Definition NightLight.h:81
QTime eveningStart() const
The Hours schedule's evening start (the transition toward night begins).
static constexpr int DefaultNightTemperature
The night temperature used until the app sets one, in kelvin.
Definition NightLight.h:87
void setFadeDuration(int milliseconds)
void clearLocation()
Forget the location.
bool isActive() const
Whether the night temperature is at least partly in effect: available, enabled, not inhibited,...
double latitude() const
Degrees north. 0 without a location.
void refresh()
Re-read the clock and try again on outputs whose gamma control failed.
Mode mode() const
The schedule. Default Hours.
bool hasLocation() const
Whether a location is set.
int nightTemperature() const
The night temperature, kelvin, clamped like the day temperature.
bool isAvailable() const
Whether the compositor offers gamma control and at least one output accepts it.
uint inhibit(bool untilNextTransition=false)
Hold the night light off.
double longitude() const
Degrees east. 0 without a location.
void uninhibit(uint cookie)
Release the inhibition cookie. Unknown cookies are ignored.
int dayTemperature() const
The day temperature, kelvin, clamped to [ColorTemperature::Minimum, ColorTemperature::Maximum].
bool isInhibited() const
Whether at least one inhibition is held.
bool setHours(QTime eveningStart, QTime morningStart)
Set both hours.
static constexpr int DefaultTransitionDuration
The transition length used until the app sets one, in seconds.
Definition NightLight.h:79
bool isEnabled() const
The user's on/off switch. Default false.
static constexpr int MaximumFadeDuration
The longest fade the library accepts, in milliseconds.
Definition NightLight.h:85
int transitionDuration() const
The requested length of each Hours transition, seconds, clamped to [0, MaximumTransitionDuration].
static constexpr int DefaultFadeDuration
The fade length used until the app sets one, in milliseconds.
Definition NightLight.h:83
QTime morningStart() const
The Hours schedule's morning start (the transition toward day begins).
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).
NightLight(QObject *parent=nullptr)
The production night light: a wlr-gamma-control client on the session's Wayland display and the syste...
int targetTemperature() const
The temperature the screen is heading for now, kelvin.
Definition ColorTemperature.h:11