Display and keyboard backlight brightness for Phosphor-based desktop shells.
Exposes the brightness-controllable backlights (display panels under /sys/class/backlight, keyboard backlights under /sys/class/leds) plus external monitors over DDC/CI as Qt + QML types. No UI. The shell decides how a brightness slider or OSD is rendered.
For internal panels and keyboard backlights the read path is sysfs (with a file watcher tracking external changes) and the write path is logind's org.freedesktop.login1.Session.SetBrightness, so no root or udev rule is required. Only display and keyboard backlights are surfaced. The other /sys/class/leds entries (capslock / power / RGB / trigger indicators) are not brightness controls and are skipped.
External monitors (which have no /sys/class/backlight entry) are surfaced over DDC/CI on I2C, alongside the sysfs devices, as a second source inside the same host. This is compile-time optional (see Design notes).
| Type | Role |
|---|---|
| BrightnessDevice | One backlight or external monitor. id (stable unique key: sysfs name for backlights, I2C bus like i2c-7 for external displays), name (human-readable, not unique: identical monitors share it), kind (Display / Keyboard / ExternalDisplay), brightness, maxBrightness, percentage; setBrightness(), setPercentage() (sysfs devices write fire-and-forget via logind, and external displays route to the DDC worker). |
| BrightnessHost | Enumerates the brightness devices under a sysfs root, resolves the logind session for sysfs writes, and (when built with libddcutil) enumerates external monitors over DDC/CI. deviceCount, deviceAt(), devices(); deviceAdded / deviceRemoved. |
| BrightnessDeviceModel | QAbstractListModel over the host's devices, tracking async deviceAdded / deviceRemoved (external displays arrive after enumeration). Roles: device, id, name, kind, brightness, maxBrightness, percentage. |
C++ shell composition root:
#include <PhosphorServiceBrightness/QmlRegistration.h>
int main(int argc, char** argv)
{
QGuiApplication app(argc, argv);
PhosphorServiceBrightness::registerQmlTypes();
// ... load shell.qml
}QML consumer (a brightness slider per device):
import Phosphor.Service.Brightness 1.0
BrightnessHost { id: bright }
BrightnessDeviceModel { id: devices; host: bright }
Repeater {
model: devices
delegate: Slider {
from: 0; to: maxBrightness; value: brightness
onMoved: device.setBrightness(value)
}
}Shipped. The sysfs read path with live QFileSystemWatcher updates (BrightnessDevice), the logind write path (setBrightness / setPercentage via Session.SetBrightness), enumeration of display + kbd_backlight devices with the indicator-LED exclusion (BrightnessHost), the QAbstractListModel (BrightnessDeviceModel), the optional external-monitor DDC/CI source (ExternalDisplay devices via a libddcutil worker thread), and the phosphorctl-style CLI demo (examples/phosphor-service-brightness-cli: list, get, set) covering the core capabilities (list devices, get/set brightness). The smoke harness pins enumeration, the kbd_backlight filter, percentage math, divide-by-zero safety, live watcher updates, model role names plus its async add / remove and host-destroyed reset, the logind write path for both the backlight and leds subsystems, and the ExternalDisplay route/clamp/read-back path deterministically against a fake sysfs tree, a fake logind over a session-bus loopback, and a recording setter (no I2C), no root or daemon required. The live DDC/CI worker is hardware-bound and validated through the CLI against real monitors.