Skip to main content

Crate tauri_brightness_core

Crate tauri_brightness_core 

Source
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:

BackendMechanismNotes
Backend::DdcDDC/CI over I2C, in processFast, no external tools
Backend::DdcutilThe ddcutil command line toolNVIDIA, docks, USB-DDC
Backend::BacklightLinux /sys/class/backlightLaptop 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.
MonitorId
A display identifier that can be round-tripped through its textual form.
MonitorInfo
A display whose brightness can be read and written.

Enums§

Backend
Which mechanism a display is driven through.
Error
Errors returned by the brightness backends.

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 to 0..=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.

Type Aliases§

Result
Alias for a Result with the error type Error.