Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/list_displays_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async fn run() {

async fn show_brightness(dev: &BrightnessDevice) -> Result<(), brightness::Error> {
println!("Display {}", dev.device_name().await?);
println!("\tFriendly name = {}", dev.friendly_device_name().await?);
println!("\tBrightness = {}%", dev.get().await?);
show_platform_specific_info(dev).await?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion examples/set_brightness_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async fn run(percentage: u32) {
async fn show_brightness(dev: &BrightnessDevice) -> Result<(), brightness::Error> {
println!(
"Brightness of device {} is {}%",
dev.device_name().await?,
dev.friendly_device_name().await?,
dev.get().await?
);
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion examples/set_brightness_blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn run(percentage: u32) {
fn show_brightness(dev: &BrightnessDevice) -> Result<(), brightness::Error> {
println!(
"Brightness of device {} is {}%",
dev.device_name()?,
dev.friendly_device_name()?,
dev.get()?
);
Ok(())
Expand Down
8 changes: 8 additions & 0 deletions src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ pub trait Brightness {
/// Returns the device name.
fn device_name(&self) -> Result<String, Error>;

/// Returns a human-readable device name suitable for display to users.
/// This may differ from the technical device identifier returned by `device_name()`.
fn friendly_device_name(&self) -> Result<String, Error>;

/// Returns the current brightness as a percentage.
fn get(&self) -> Result<u32, Error>;

Expand All @@ -37,6 +41,10 @@ impl Brightness for BrightnessDevice {
self.0.device_name()
}

fn friendly_device_name(&self) -> Result<String, Error> {
self.0.friendly_device_name()
}

fn get(&self) -> Result<u32, Error> {
self.0.get()
}
Expand Down
4 changes: 4 additions & 0 deletions src/blocking/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ impl crate::blocking::Brightness for BlockingDeviceImpl {
Ok(self.device.clone())
}

fn friendly_device_name(&self) -> Result<String, Error> {
Ok(self.device.clone())
}

fn get(&self) -> Result<u32, Error> {
let max = read_value(&self.device, Value::Max)?;
let actual = read_value(&self.device, Value::Actual)?;
Expand Down
6 changes: 6 additions & 0 deletions src/blocking/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub(crate) struct BlockingDeviceImpl {
physical_monitor: WrappedPhysicalMonitor,
file_handle: WrappedFileHandle,
device_name: String,
friendly_name: String,
/// Note: PHYSICAL_MONITOR.szPhysicalMonitorDescription == DISPLAY_DEVICEW.DeviceString
/// Description is **not** unique.
pub(crate) device_description: String,
Expand Down Expand Up @@ -127,6 +128,10 @@ impl crate::blocking::Brightness for BlockingDeviceImpl {
Ok(self.device_name.clone())
}

fn friendly_device_name(&self) -> Result<String, Error> {
Ok(self.friendly_name.clone())
}

fn get(&self) -> Result<u32, Error> {
Ok(if self.is_internal() {
ioctl_query_display_brightness(self)?
Expand Down Expand Up @@ -194,6 +199,7 @@ pub(crate) fn brightness_devices() -> impl Iterator<Item = Result<BlockingDevice
physical_monitor,
file_handle,
device_name: wchar_to_string(&display_device.DeviceName),
friendly_name: wchar_to_string(&info.monitorFriendlyDeviceName),
device_description: wchar_to_string(&display_device.DeviceString),
device_key: wchar_to_string(&display_device.DeviceKey),
device_path: wchar_to_string(&display_device.DeviceID),
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ mod r#async {
/// Returns the device name.
fn device_name(&self) -> impl Future<Output = Result<String, Error>> + Send;

/// Returns a human-readable device name suitable for display to users,
/// which may differ from the technical device identifier returned by `device_name`.
fn friendly_device_name(&self) -> impl Future<Output = Result<String, Error>> + Send;

/// Returns the current brightness as a percentage.
fn get(&self) -> impl Future<Output = Result<u32, Error>> + Send;

Expand All @@ -95,6 +99,10 @@ mod r#async {
self.0.device_name().await
}

async fn friendly_device_name(&self) -> Result<String, Error> {
self.0.friendly_device_name().await
}

async fn get(&self) -> Result<u32, Error> {
self.0.get().await
}
Expand Down
4 changes: 4 additions & 0 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ impl crate::Brightness for AsyncDeviceImpl {
Ok(self.device.clone())
}

async fn friendly_device_name(&self) -> Result<String, Error> {
Ok(self.device.clone())
}

async fn get(&self) -> Result<u32, Error> {
let max = read_value(&self.device, Value::Max)?;
let actual = read_value(&self.device, Value::Actual)?;
Expand Down
4 changes: 4 additions & 0 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ impl crate::Brightness for AsyncDeviceImpl {
self.0.device_name()
}

async fn friendly_device_name(&self) -> Result<String, Error> {
self.0.friendly_device_name()
}

async fn get(&self) -> Result<u32, Error> {
let cloned = Arc::clone(&self.0);
unblock(move || cloned.get()).await
Expand Down
Loading