diff --git a/examples/list_displays_async.rs b/examples/list_displays_async.rs index 56c7568..a1c6825 100644 --- a/examples/list_displays_async.rs +++ b/examples/list_displays_async.rs @@ -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(()) diff --git a/examples/set_brightness_async.rs b/examples/set_brightness_async.rs index 84b3e1f..c410eca 100644 --- a/examples/set_brightness_async.rs +++ b/examples/set_brightness_async.rs @@ -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(()) diff --git a/examples/set_brightness_blocking.rs b/examples/set_brightness_blocking.rs index 9f9c376..f200053 100644 --- a/examples/set_brightness_blocking.rs +++ b/examples/set_brightness_blocking.rs @@ -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(()) diff --git a/src/blocking.rs b/src/blocking.rs index 3618e3f..8b29719 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -25,6 +25,10 @@ pub trait Brightness { /// Returns the device name. fn device_name(&self) -> Result; + /// 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; + /// Returns the current brightness as a percentage. fn get(&self) -> Result; @@ -37,6 +41,10 @@ impl Brightness for BrightnessDevice { self.0.device_name() } + fn friendly_device_name(&self) -> Result { + self.0.friendly_device_name() + } + fn get(&self) -> Result { self.0.get() } diff --git a/src/blocking/linux.rs b/src/blocking/linux.rs index 337173f..307fff4 100644 --- a/src/blocking/linux.rs +++ b/src/blocking/linux.rs @@ -22,6 +22,10 @@ impl crate::blocking::Brightness for BlockingDeviceImpl { Ok(self.device.clone()) } + fn friendly_device_name(&self) -> Result { + Ok(self.device.clone()) + } + fn get(&self) -> Result { let max = read_value(&self.device, Value::Max)?; let actual = read_value(&self.device, Value::Actual)?; diff --git a/src/blocking/windows.rs b/src/blocking/windows.rs index 07327ad..b51f3b2 100644 --- a/src/blocking/windows.rs +++ b/src/blocking/windows.rs @@ -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, @@ -127,6 +128,10 @@ impl crate::blocking::Brightness for BlockingDeviceImpl { Ok(self.device_name.clone()) } + fn friendly_device_name(&self) -> Result { + Ok(self.friendly_name.clone()) + } + fn get(&self) -> Result { Ok(if self.is_internal() { ioctl_query_display_brightness(self)? @@ -194,6 +199,7 @@ pub(crate) fn brightness_devices() -> impl Iterator impl Future> + 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> + Send; + /// Returns the current brightness as a percentage. fn get(&self) -> impl Future> + Send; @@ -95,6 +99,10 @@ mod r#async { self.0.device_name().await } + async fn friendly_device_name(&self) -> Result { + self.0.friendly_device_name().await + } + async fn get(&self) -> Result { self.0.get().await } diff --git a/src/linux.rs b/src/linux.rs index db0658f..2c039b4 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -22,6 +22,10 @@ impl crate::Brightness for AsyncDeviceImpl { Ok(self.device.clone()) } + async fn friendly_device_name(&self) -> Result { + Ok(self.device.clone()) + } + async fn get(&self) -> Result { let max = read_value(&self.device, Value::Max)?; let actual = read_value(&self.device, Value::Actual)?; diff --git a/src/windows.rs b/src/windows.rs index fae6c3b..96c19ef 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -25,6 +25,10 @@ impl crate::Brightness for AsyncDeviceImpl { self.0.device_name() } + async fn friendly_device_name(&self) -> Result { + self.0.friendly_device_name() + } + async fn get(&self) -> Result { let cloned = Arc::clone(&self.0); unblock(move || cloned.get()).await