pub struct MonitorDevice {
pub device: String,
pub bl_power: u32,
pub brightness: u32,
pub actual_brightness: u32,
pub max_brightness: u32,
pub bl_type: BackLightType,
}
Expand description
Monitor Device information.
Devices are extracted from the /sys/class/backlight/
directory.
Fields§
§device: String
Value taken from /sys/class/backlight/<backlight>
.
Name of the backlight device
bl_power: u32
Value taken from
/sys/class/backlight/<backlight>/bl_power
.
Controls the power of <backlight>
.
brightness: u32
Value taken from
/sys/class/backlight/<backlight>/brightness
.
Control the brightness for this <backlight>
. Values
are between 0 and max_brightness.
This file will also show the brightness level stored in the driver, which
may not be the actual brightness (see actual_brightness).
actual_brightness: u32
Value taken from
/sys/class/backlight/<backlight>/actual_brightness
.
Show the actual brightness by querying the hardware.
max_brightness: u32
Value taken from
/sys/class/backlight/<backlight>/max_brightness
.
Maximum brightness for <backlight>
.
bl_type: BackLightType
Value taken from
/sys/class/backlight/<backlight>/type
.
The type of interface controlled by <backlight>
.
Implementations§
Source§impl MonitorDevice
impl MonitorDevice
Sourcepub fn get_monitor_device(device: String) -> Result<MonitorDevice, Error>
pub fn get_monitor_device(device: String) -> Result<MonitorDevice, Error>
Get monitor by device name.
§Examples
use bulbb::monitor::MonitorDevice;
let device_name = format!("amdgpu_bl0");
let monitor = MonitorDevice::get_monitor_device(device_name.clone()).unwrap();
assert_eq!(monitor.get_device_name(), device_name);
Sourcepub fn get_all_monitor_devices() -> Result<Vec<MonitorDevice>, Error>
pub fn get_all_monitor_devices() -> Result<Vec<MonitorDevice>, Error>
Get all monitor devices.
§Examples
use bulbb::monitor::MonitorDevice;
let monitors = MonitorDevice::get_all_monitor_devices().unwrap();
for monitor in monitors {
println!("Monitor: {:?}", monitor);
}
Sourcepub fn get_device_name(&self) -> &str
pub fn get_device_name(&self) -> &str
Get device name of monitor.
§Examples
use bulbb::monitor::MonitorDevice;
let monitors = MonitorDevice::get_all_monitor_devices().unwrap();
for monitor in monitors {
let max_brightness = monitor.get_max_brightness();
let device = monitor.get_device_name();
println!("Device: {}", device);
assert!(!device.is_empty())
}
Sourcepub fn get_power(&self) -> u32
pub fn get_power(&self) -> u32
Get power of monitor.
§Examples
use bulbb::monitor::MonitorDevice;
let monitors = MonitorDevice::get_all_monitor_devices().unwrap();
for monitor in monitors {
let power = monitor.get_power();
println!("Power: {}", power);
}
Sourcepub fn get_brightness(&self) -> u32
pub fn get_brightness(&self) -> u32
Get brightness of monitor.
§Examples
use bulbb::monitor::MonitorDevice;
let monitors = MonitorDevice::get_all_monitor_devices().unwrap();
for monitor in monitors {
let max_brightness = monitor.get_max_brightness();
let brightness = monitor.get_brightness();
println!("Brightness: {}", brightness);
assert!(brightness >= 0 && brightness <= max_brightness)
}
Sourcepub fn get_actual_brightness(&self) -> u32
pub fn get_actual_brightness(&self) -> u32
Get actual brightness of monitor
§Examples
use bulbb::monitor::MonitorDevice;
let monitors = MonitorDevice::get_all_monitor_devices().unwrap();
for monitor in monitors {
let max_brightness = monitor.get_max_brightness();
let brightness = monitor.get_actual_brightness();
println!("Brightness: {}", brightness);
assert!(brightness >= 0 && brightness <= max_brightness)
}
Sourcepub fn get_max_brightness(&self) -> u32
pub fn get_max_brightness(&self) -> u32
Get the maximum brightness value of monitor.
§Examples
use bulbb::monitor::MonitorDevice;
let monitors = MonitorDevice::get_all_monitor_devices().unwrap();
for monitor in monitors {
let max_brightness = monitor.get_max_brightness();
println!("Max Brightness: {}", max_brightness);
assert!(max_brightness > 0)
}
Sourcepub fn get_type(&self) -> BackLightType
pub fn get_type(&self) -> BackLightType
Get the backlight type of monitor.
§Examples
use bulbb::monitor::MonitorDevice;
let monitors = MonitorDevice::get_all_monitor_devices().unwrap();
for monitor in monitors {
let mon_type = monitor.get_type();
println!("Type: {}", mon_type);
}
Sourcepub fn set_brightness(&self, level: u32) -> Result<(), Error>
pub fn set_brightness(&self, level: u32) -> Result<(), Error>
Set brightness of monitor.
§NOTE
This method writes to /sys/class/backlight/<backlight>/brightness
and will fail if user is not root (even when executed with sudo).
It is recommended to create a udev rule to allow user of a certain
group to write to the file. The example below will allow all users in
the video
group to change the brightness of all devices in /sys/class/backlight/
.
ACTION=="add", SUBSYSTEM=="backlight", RUN+="/bin/chgrp video /sys/class/backlight/%k/brightness"
ACTION=="add", SUBSYSTEM=="backlight", RUN+="/bin/chmod g+w /sys/class/backlight/%k/brightness"
§Examples
use bulbb::monitor::MonitorDevice;
let monitors = MonitorDevice::get_all_monitor_devices().unwrap();
monitors[0].set_brightness(20);
Trait Implementations§
Source§impl Clone for MonitorDevice
impl Clone for MonitorDevice
Source§fn clone(&self) -> MonitorDevice
fn clone(&self) -> MonitorDevice
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more