Struct bulbb::monitor::MonitorDevice [−][src]
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
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);
Get all monitor devices.
Examples
use bulbb::monitor::MonitorDevice;
let monitors = MonitorDevice::get_all_monitor_devices().unwrap();
for monitor in monitors {
println!("Monitor: {:?}", monitor);
}
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())
}
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);
}
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)
}
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)
}
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)
}
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);
}
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
Auto Trait Implementations
impl RefUnwindSafe for MonitorDevice
impl Send for MonitorDevice
impl Sync for MonitorDevice
impl Unpin for MonitorDevice
impl UnwindSafe for MonitorDevice
Blanket Implementations
Mutably borrows from an owned value. Read more