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
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.
Two features of blight that standout:
- Prioritizing device detection in this order: iGPU>dGPU>ACPI>Fallback device.
- Smooth backlight change by writing in increments/decrements of 1 with a few milliseconds of delay.
IMPORTANT: You need write permission for the file
/sys/class/backlight/{your_device}/brightness
to 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.
§Usage
use blight::{BlResult, Change, Device, Direction, Delay};
fn main() -> BlResult<()> {
// 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 (important)
let new = dev.calculate_change(5, Direction::Inc);
dev.sweep_write(new, Delay::default()); // smoothly increases brightness by 5%
Ok(())
}
Re-exports§
pub use err::BlResult;
Modules§
- All blight library related errors in one place. See BlibError
Structs§
- A wrapper type for
std::time::Duration
used for specifying delay between each iteration of the loop inDevice::sweep_write
. - An abstraction of a backlight device containing a name, current and max backlight values, and some related functionality.
Enums§
- This enum is used to specify the kind of backlight change to carry out while calling the
change_bl
function. - This enum is used to specify the direction in which the backlight should be changed in the
change_bl
andDevice::calculate_change
functions. Inc -> Increase, Dec -> Decrease.
Constants§
- Linux backlight directory location. All backlight hardware devices appear here.
Functions§
- 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.