Expand description
Cross-platform display brightness control.
This crate is the engine behind the
tauri-plugin-brightness
plugin, and it has no dependency on Tauri, so it can be used from any Rust
program.
Three backends are supported and are selected automatically:
| Backend | Mechanism | Notes |
|---|---|---|
Backend::Ddc | DDC/CI over I2C, in process | Fast, no external tools |
Backend::Ddcutil | The ddcutil command line tool | NVIDIA, docks, USB-DDC |
Backend::Backlight | Linux /sys/class/backlight | Laptop internal panels |
A display is addressed by a MonitorId, whose textual form is stable for
the lifetime of a boot, for example ddc-0 or backlight-intel_backlight.
§Example
use tauri_brightness_core::{list_monitors, set_brightness};
for monitor in list_monitors() {
println!("{} is at {}%", monitor.name, monitor.brightness_percent());
set_brightness(&monitor.id, 50)?;
}§Permissions
On Linux, external monitors reach DDC/CI through /dev/i2c-*, which requires
the i2c-dev kernel module and usually membership of the i2c group.
Internal panels are controlled without privileges through the logind D-Bus
interface. When nothing is detected, diagnose reports which of these is
missing.
Structs§
- Diagnostics
- Result of probing the system for brightness capabilities.
- Monitor
Id - A display identifier that can be round-tripped through its textual form.
- Monitor
Info - A display whose brightness can be read and written.
Enums§
Functions§
- diagnose
- Probes the system and explains why a display may not have been detected.
- get_
brightness - Reads the brightness of the display identified by
id. - list_
monitors - Enumerates every display whose brightness can be controlled.
- percent
- Converts a raw brightness value to a percentage of
max, clamped to0..=100. - raw_
from_ percent - Converts a percentage into a raw brightness value for a display whose
maximum is
max. - set_
brightness - Sets the brightness of the display identified by
id.