Expand description
§About
blight is primarily a CLI backlight utility for Linux which is focused on providing hassle-free backlight control.
However, the parts which blight relies on to make backlight changes, are also exposed through the library aspect of this crate, which can be used like any other Rust library
by using the command cargo add blight --no-default-features in your Rust project. The CLI utility, on the other hand, can be installed by running cargo install blight.
This documentation only covers the library aspect, for CLI related docs, visit the project’s Github repo.
The latest version of the libary now supports controlling LEDs using the /sys/class/leds interface.
Three features of blight that standout:
- Prioritizing backlight device detection in this order: iGPU>dGPU>ACPI>Fallback device.
- Smooth dimming by writing in increments/decrements of 1 with a few milliseconds of delay (sweep write).
- The library has zero external dependencies.
IMPORTANT: You need write permission for the file
/sys/class/backlight/{your_device}/brightnessto change brightness. The CLI utility comes with a helper script that let’s you gain access to the brightness file (which may not always work), which you can run by using the commandsudo blight setup. If you’re only using blight as a dependency, you can read about gaining file permissions here.
For LED specific documentation and usage, see led module.
§Usage
use blight::{Change, Device, Direction, Delay, Light};
fn main() -> blight::Result<()> {
// Using the helper functions
blight::change_bl(5, Change::Regular, Direction::Inc, None)?; // Increases brightness by 5%
blight::set_bl(50, Some("nvidia_0".into()))?; // Sets brightness value (not percentage) to 50
// Doing it manually
let mut dev = Device::new(None)?;
let new = dev.calculate_change(5, Direction::Dec); // safely calculate value to write
dev.write_value(new)?; // decreases brightness by 5%
dev.reload(); // reloads current brightness value from the brightness file (optional)
let new = dev.calculate_change(5, Direction::Inc);
dev.sweep_write(new, Delay::default()); // smoothly increases brightness by 5%
Ok(())
}Re-exports§
Modules§
- err
- All blight library related errors in one place. See
ErrorandErrorKind - led
- Abstractions and functions for controlling LEDs using the
/sys/class/ledsLinux interface
Structs§
- Delay
- A wrapper type for
std::time::Durationused for specifying delay between each iteration of the loop inDevice::sweep_write. - Device
- An abstraction of a backlight device containing a name, current and max backlight values, and some related functionality.
Enums§
- Change
- This enum is used to specify the kind of backlight change to carry out while calling the
change_blfunction. \ - Direction
- This enum is used to specify the direction in which the backlight should be changed in the
change_blandDevice::calculate_changefunctions. Inc -> Increase, Dec -> Decrease.
Constants§
- BLDIR
- Linux backlight directory location. All backlight hardware devices appear here.
Traits§
- Dimmable
- Marker trait to signify that a backlight device or an LED is dimmable
- Light
- The interface for controlling both backlight and LED devices
- Toggleable
- Marker trait to signify that an LED can only be toggled on/off
Functions§
- change_
bl - A helper function to change backlight based on step-size (percentage), Change type and Direction.
- set_bl
- A helper function which takes a brightness value and writes the value to the brightness file as long as the given value falls under the min and max bounds of the detected backlight device and is different from the current value.