mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 17:33:19 +01:00
feature: watch primary backlight and sync screenpad to it
This commit is contained in:
@@ -50,6 +50,22 @@ impl CtrlBacklight {
|
|||||||
device_type: &BacklightType,
|
device_type: &BacklightType,
|
||||||
level: i32,
|
level: i32,
|
||||||
) -> Result<(), FdoErr> {
|
) -> Result<(), FdoErr> {
|
||||||
|
let sync = self
|
||||||
|
.config
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.screenpad_sync_primary
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
if sync && *device_type == BacklightType::Screenpad {
|
||||||
|
if let Some(primary) = self.get_backlight(&BacklightType::Primary) {
|
||||||
|
if let Ok(primary_max) = primary.get_max_brightness() {
|
||||||
|
let primary_scaled = level * primary_max / 100;
|
||||||
|
let _ = primary.set_brightness(primary_scaled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(backlight) = self.get_backlight(device_type) {
|
if let Some(backlight) = self.get_backlight(device_type) {
|
||||||
let max = backlight.get_max_brightness().map_err(|e| {
|
let max = backlight.get_max_brightness().map_err(|e| {
|
||||||
warn!("Failed to get max brightness: {}", e);
|
warn!("Failed to get max brightness: {}", e);
|
||||||
@@ -72,13 +88,7 @@ impl CtrlBacklight {
|
|||||||
FdoErr::Failed(format!("Failed to set brightness: {}", e))
|
FdoErr::Failed(format!("Failed to set brightness: {}", e))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let sync = self
|
if sync && *device_type == BacklightType::Primary {
|
||||||
.config
|
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.screenpad_sync_primary
|
|
||||||
.unwrap_or_default();
|
|
||||||
if sync {
|
|
||||||
for other in self
|
for other in self
|
||||||
.backlights
|
.backlights
|
||||||
.iter()
|
.iter()
|
||||||
@@ -128,6 +138,55 @@ impl CtrlBacklight {
|
|||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn start_watch_primary(&self) -> Result<(), RogError> {
|
||||||
|
if self.get_backlight(&BacklightType::Screenpad).is_none() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(sync) = self.config.lock().await.screenpad_sync_primary {
|
||||||
|
if !sync {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(backlight) = self.get_backlight(&BacklightType::Primary) {
|
||||||
|
let watch = backlight.monitor_brightness()?;
|
||||||
|
|
||||||
|
let backlights = self.clone();
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let mut buffer = [0; 32];
|
||||||
|
use futures_lite::StreamExt;
|
||||||
|
if let Ok(mut stream) = watch.into_event_stream(&mut buffer) {
|
||||||
|
while (stream.next().await).is_some() {
|
||||||
|
let sync = backlights.config.lock().await.screenpad_sync_primary;
|
||||||
|
if let Some(sync) = sync {
|
||||||
|
if !sync {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if sync.is_none() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let level = backlights
|
||||||
|
.get_brightness_percent(&BacklightType::Primary)
|
||||||
|
.unwrap_or(60);
|
||||||
|
backlights
|
||||||
|
.set_brightness_with_sync(&BacklightType::Screenpad, level)
|
||||||
|
.await
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
// watch
|
||||||
|
// .into_event_stream(&mut buffer)
|
||||||
|
// .unwrap()
|
||||||
|
// .for_each(|_| async {})
|
||||||
|
// .await;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[interface(name = "xyz.ljones.Backlight")]
|
#[interface(name = "xyz.ljones.Backlight")]
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ async fn start_daemon() -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
match CtrlBacklight::new(config.clone()) {
|
match CtrlBacklight::new(config.clone()) {
|
||||||
Ok(backlight) => {
|
Ok(backlight) => {
|
||||||
|
backlight.start_watch_primary().await?;
|
||||||
backlight.add_to_server(&mut server).await;
|
backlight.add_to_server(&mut server).await;
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user