Struct MonitorDevice

Source
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

Source

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);
Source

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);
}
Source

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())
}
Source

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);
}
Source

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)
}
Source

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)
}
Source

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)
}
Source

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);
}
Source

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

Source§

fn clone(&self) -> MonitorDevice

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MonitorDevice

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.