Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
BrightnessDevice.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 <PhosphorServiceBrightness/phosphorservicebrightness_export.h>
7
8#include <QObject>
9#include <QString>
10
11#include <functional>
12#include <memory>
13
14class QDBusConnection;
15
17
32class PHOSPHORSERVICEBRIGHTNESS_EXPORT BrightnessDevice : public QObject
33{
34 Q_OBJECT
35 Q_PROPERTY(QString id READ id CONSTANT)
36 Q_PROPERTY(QString name READ name CONSTANT)
37 Q_PROPERTY(Kind kind READ kind CONSTANT)
38 Q_PROPERTY(int brightness READ brightness NOTIFY brightnessChanged)
39 Q_PROPERTY(int maxBrightness READ maxBrightness CONSTANT)
40 Q_PROPERTY(qreal percentage READ percentage NOTIFY brightnessChanged)
41
42public:
48 Q_ENUM(Kind)
49
50
53 BrightnessDevice(QDBusConnection connection, QString service, QString sessionPath, Kind kind, QString name,
54 QString sysfsDir, QObject* parent = nullptr);
55
63 BrightnessDevice(QString id, QString name, int brightness, int maxBrightness, std::function<void(int)> setter,
64 QObject* parent = nullptr);
65
66 ~BrightnessDevice() override;
67
70 [[nodiscard]] QString id() const;
71 [[nodiscard]] QString name() const;
72 [[nodiscard]] Kind kind() const;
73 [[nodiscard]] int brightness() const;
74 [[nodiscard]] int maxBrightness() const;
76 [[nodiscard]] qreal percentage() const;
77
79 Q_INVOKABLE void setBrightness(int value);
81 Q_INVOKABLE void setPercentage(qreal percentage);
82
86 void refresh();
87
92
96 void setSessionPath(const QString& sessionPath);
97
98Q_SIGNALS:
100
101private:
102 Q_DISABLE_COPY_MOVE(BrightnessDevice)
103 class Private;
104 std::unique_ptr<Private> d;
105};
106
107} // namespace PhosphorServiceBrightness
BrightnessDevice(QDBusConnection connection, QString service, QString sessionPath, Kind kind, QString name, QString sysfsDir, QObject *parent=nullptr)
Sysfs-backed device (Display / Keyboard): reads sysfs, writes via logind.
Kind
Definition BrightnessDevice.h:43
@ Display
Internal panel backlight (/sys/class/backlight).
Definition BrightnessDevice.h:44
@ ExternalDisplay
External monitor over DDC/CI (libddcutil); writes do not use logind.
Definition BrightnessDevice.h:46
@ Keyboard
Keyboard backlight (*kbd_backlight under /sys/class/leds).
Definition BrightnessDevice.h:45
void setSessionPath(const QString &sessionPath)
Logind session object path used for the SetBrightness write.
void setBrightness(int value)
Set the raw brightness (clamped to [0, maxBrightness]) via logind.
void refresh()
Re-read the sysfs attributes now.
void setPercentage(qreal percentage)
Set brightness as a fraction in [0.0, 1.0] of maxBrightness, via logind.
void applyExternalValue(int brightness)
Push a DDC read-back value for an external-display device.
qreal percentage() const
brightness / maxBrightness in [0.0, 1.0]; 0.0 when maxBrightness is 0.
Definition BrightnessDevice.h:16