diff --git a/Cargo.lock b/Cargo.lock index e02125c1..330b3acb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -225,6 +225,7 @@ dependencies = [ "config-traits", "dmi_id", "env_logger", + "futures-lite", "log", "logind-zbus", "rog_anime", diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index 958bf98d..8d98e241 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -772,10 +772,10 @@ fn handle_bios_option( } if let Some(opt) = cmd.post_sound_set { - dbus.proxies().rog_bios().set_post_boot_sound(opt)?; + dbus.proxies().rog_bios().set_post_animation_sound(opt)?; } if cmd.post_sound_get { - let res = dbus.proxies().rog_bios().post_boot_sound()? == 1; + let res = dbus.proxies().rog_bios().post_animation_sound()?; println!("Bios POST sound on: {}", res); } diff --git a/asusd/src/ctrl_platform.rs b/asusd/src/ctrl_platform.rs index a0a9fb52..15e4ef6f 100644 --- a/asusd/src/ctrl_platform.rs +++ b/asusd/src/ctrl_platform.rs @@ -240,7 +240,7 @@ impl CtrlPlatform { platform_get_value!(self, egpu_enable, "egpu_enable") } - /// *************************************************************************** + /// ************************************************************************ #[dbus_interface(property)] async fn ppt_pl1_spl(&self) -> Result { platform_get_value_if_some!(self, ppt_pl1_spl, "ppt_pl1_spl", 5) diff --git a/rog-control-center/src/system_state.rs b/rog-control-center/src/system_state.rs index 383695f8..216b7c35 100644 --- a/rog-control-center/src/system_state.rs +++ b/rog-control-center/src/system_state.rs @@ -39,13 +39,13 @@ pub struct BiosState { impl BiosState { pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking<'_>) -> Result { Ok(Self { - post_sound: if supported.rog_bios_ctrl.post_sound { - dbus.proxies().rog_bios().post_boot_sound()? != 0 + post_sound: if supported.rog_bios_ctrl.post_animation_sound { + dbus.proxies().rog_bios().post_animation_sound()? } else { false }, dedicated_gfx: if supported.rog_bios_ctrl.gpu_mux { - dbus.proxies().rog_bios().gpu_mux_mode()? + GpuMode::from(dbus.proxies().rog_bios().gpu_mux_mode()?) } else { GpuMode::NotSupported }, diff --git a/rog-control-center/src/tray.rs b/rog-control-center/src/tray.rs index 7e7bd50f..9b5cd923 100644 --- a/rog-control-center/src/tray.rs +++ b/rog-control-center/src/tray.rs @@ -325,7 +325,7 @@ impl ROGTray { let mut reboot_required = false; if let Ok(mode) = gfx_dbus.gpu_mux_mode() { - let mode = match mode { + let mode = match GpuMode::from(mode) { GpuMode::Discrete => GfxMode::AsusMuxDgpu, _ => GfxMode::Hybrid, }; diff --git a/rog-control-center/src/update_and_notify.rs b/rog-control-center/src/update_and_notify.rs index ec136aec..defc32e6 100644 --- a/rog-control-center/src/update_and_notify.rs +++ b/rog-control-center/src/update_and_notify.rs @@ -37,11 +37,11 @@ static mut POWER_BAT_CMD: Option = None; #[derive(Debug, Clone, Deserialize, Serialize)] #[serde(default)] pub struct EnabledNotifications { - pub receive_notify_post_boot_sound: bool, - pub receive_notify_panel_od: bool, - pub receive_notify_mini_led_mode: bool, - pub receive_notify_dgpu_disable: bool, - pub receive_notify_egpu_enable: bool, + pub receive_post_animation_sound_changed: bool, + pub receive_panel_od_changed: bool, + pub receive_mini_led_mode_changed: bool, + pub receive_dgpu_disable_changed: bool, + pub receive_egpu_enable_changed: bool, pub receive_notify_gpu_mux_mode: bool, pub receive_notify_charge_control_end_threshold: bool, pub receive_notify_mains_online: bool, @@ -57,11 +57,11 @@ pub struct EnabledNotifications { impl Default for EnabledNotifications { fn default() -> Self { Self { - receive_notify_post_boot_sound: false, - receive_notify_panel_od: true, - receive_notify_mini_led_mode: true, - receive_notify_dgpu_disable: true, - receive_notify_egpu_enable: true, + receive_post_animation_sound_changed: false, + receive_panel_od_changed: true, + receive_mini_led_mode_changed: true, + receive_dgpu_disable_changed: true, + receive_egpu_enable_changed: true, receive_notify_gpu_mux_mode: true, receive_notify_charge_control_end_threshold: true, receive_notify_mains_online: false, @@ -127,6 +127,49 @@ macro_rules! recv_notif { }; } +macro_rules! recv_changed { + ($proxy:ident, + $signal:ident, + $last_notif:ident, + $notif_enabled:ident, + $page_states:ident, + ($($args: tt)*), + // ($($out_arg:tt)+), + $msg:literal, + $notifier:ident) => { + + let notifs_enabled1 = $notif_enabled.clone(); + let page_states1 = $page_states.clone(); + + tokio::spawn(async move { + let conn = zbus::Connection::system().await.map_err(|e| { + log::error!("zbus signal: {}: {e}", stringify!($signal)); + e + }).unwrap(); + let proxy = $proxy::new(&conn).await.map_err(|e| { + log::error!("zbus signal: {}: {e}", stringify!($signal)); + e + }).unwrap(); + info!("Started zbus signal thread: {}", stringify!($signal)); + while let Some(e) = proxy.$signal().await.next().await { + if let Ok(out) = e.get().await { + if let Ok(config) = notifs_enabled1.lock() { + if config.all_enabled && config.$signal { + trace!("zbus signal {}", stringify!($signal)); + $notifier($msg, &out).ok(); + } + } + if let Ok(mut lock) = page_states1.lock() { + lock.$($args)+ = out; + lock.set_notified(); + } + } + sleep(Duration::from_millis(500)).await; + } + }); + }; +} + pub fn start_notifications( config: &Config, page_states: &Arc>, @@ -157,62 +200,57 @@ pub fn start_notifications( } // BIOS notif - recv_notif!( + recv_changed!( RogBiosProxy, - receive_notify_post_boot_sound, + receive_post_animation_sound_changed, last_notification, enabled_notifications, page_states, (bios.post_sound), - (on), "BIOS Post sound", do_notification ); - recv_notif!( + recv_changed!( RogBiosProxy, - receive_notify_panel_od, + receive_panel_od_changed, last_notification, enabled_notifications, page_states, (bios.panel_overdrive), - (overdrive), "Panel Overdrive enabled:", do_notification ); - recv_notif!( + recv_changed!( RogBiosProxy, - receive_notify_mini_led_mode, + receive_mini_led_mode_changed, last_notification, enabled_notifications, page_states, (bios.mini_led_mode), - (on), "MiniLED mode enabled:", do_notification ); - recv_notif!( + recv_changed!( RogBiosProxy, - receive_notify_dgpu_disable, + receive_dgpu_disable_changed, last_notification, enabled_notifications, page_states, (bios.dgpu_disable), - (disable), "BIOS dGPU disabled", do_notification ); - recv_notif!( + recv_changed!( RogBiosProxy, - receive_notify_egpu_enable, + receive_egpu_enable_changed, last_notification, enabled_notifications, page_states, (bios.egpu_enable), - (enable), "BIOS eGPU enabled", do_notification ); @@ -314,7 +352,7 @@ pub fn start_notifications( e }) .unwrap(); - if let Ok(mut p) = proxy.receive_device_state().await { + if let Ok(mut p) = proxy.receive_notify_device_state().await { info!("Started zbus signal thread: receive_device_state"); while let Some(e) = p.next().await { if let Ok(out) = e.args() { @@ -345,25 +383,23 @@ pub fn start_notifications( let mut actual_mux_mode = GpuMode::Error; if let Ok(mode) = proxy.gpu_mux_mode().await { - actual_mux_mode = mode; + actual_mux_mode = GpuMode::from(mode); } - if let Ok(mut p) = proxy.receive_notify_gpu_mux_mode().await { - info!("Started zbus signal thread: receive_notify_gpu_mux_mode"); - while let Some(e) = p.next().await { - if let Ok(out) = e.args() { - if out.mode == actual_mux_mode { - continue; - } - if let Ok(mut lock) = page_states1.lock() { - lock.bios.dedicated_gfx = out.mode; - lock.set_notified(); - } - do_mux_notification("Reboot required. BIOS GPU MUX mode set to", &out.mode) - .ok(); + info!("Started zbus signal thread: receive_notify_gpu_mux_mode"); + while let Some(e) = proxy.receive_gpu_mux_mode_changed().await.next().await { + if let Ok(out) = e.get().await { + let mode = GpuMode::from(out); + if mode == actual_mux_mode { + continue; } + if let Ok(mut lock) = page_states1.lock() { + lock.bios.dedicated_gfx = mode; + lock.set_notified(); + } + do_mux_notification("Reboot required. BIOS GPU MUX mode set to", &mode).ok(); } - }; + } }); if let Ok(lock) = page_states.try_lock() { diff --git a/rog-control-center/src/widgets/app_settings.rs b/rog-control-center/src/widgets/app_settings.rs index 7709ad6f..66babb5a 100644 --- a/rog-control-center/src/widgets/app_settings.rs +++ b/rog-control-center/src/widgets/app_settings.rs @@ -51,13 +51,13 @@ pub fn app_settings(config: &mut Config, states: &mut SystemState, ui: &mut Ui) .clicked() || ui .checkbox( - &mut enabled_notifications.receive_notify_dgpu_disable, + &mut enabled_notifications.receive_dgpu_disable_changed, "Enable dGPU disablement notification", ) .clicked() || ui .checkbox( - &mut enabled_notifications.receive_notify_egpu_enable, + &mut enabled_notifications.receive_egpu_enable_changed, "Enable eGPU enablement notification", ) .clicked() @@ -81,19 +81,19 @@ pub fn app_settings(config: &mut Config, states: &mut SystemState, ui: &mut Ui) .clicked() || ui .checkbox( - &mut enabled_notifications.receive_notify_panel_od, + &mut enabled_notifications.receive_panel_od_changed, "Enable panel overdrive notification", ) .clicked() || ui .checkbox( - &mut enabled_notifications.receive_notify_mini_led_mode, + &mut enabled_notifications.receive_mini_led_mode_changed, "Enable MiniLED mode notification", ) .clicked() || ui .checkbox( - &mut enabled_notifications.receive_notify_post_boot_sound, + &mut enabled_notifications.receive_post_animation_sound_changed, "Enable BIOS post sound notification", ) .clicked(); diff --git a/rog-control-center/src/widgets/rog_bios.rs b/rog-control-center/src/widgets/rog_bios.rs index aa82821f..80b75c4c 100644 --- a/rog-control-center/src/widgets/rog_bios.rs +++ b/rog-control-center/src/widgets/rog_bios.rs @@ -55,7 +55,7 @@ pub fn rog_bios_group(supported: &SupportedFunctions, states: &mut SystemState, .ok(); } - if supported.rog_bios_ctrl.post_sound + if supported.rog_bios_ctrl.post_animation_sound && ui .add(egui::Checkbox::new( &mut states.bios.post_sound, @@ -67,7 +67,7 @@ pub fn rog_bios_group(supported: &SupportedFunctions, states: &mut SystemState, .asus_dbus .proxies() .rog_bios() - .set_post_boot_sound(states.bios.post_sound) + .set_post_animation_sound(states.bios.post_sound) .map_err(|err| { states.error = Some(err.to_string()); }) @@ -118,7 +118,7 @@ pub fn rog_bios_group(supported: &SupportedFunctions, states: &mut SystemState, let mut reboot_required = false; if let Ok(mode) = states.asus_dbus.proxies().rog_bios().gpu_mux_mode() { - reboot_required = mode != states.bios.dedicated_gfx; + reboot_required = GpuMode::from(mode) != states.bios.dedicated_gfx; } ui.group(|ui| { diff --git a/rog-dbus/src/zbus_platform.rs b/rog-dbus/src/zbus_platform.rs index 9b485037..f2150e4f 100644 --- a/rog-dbus/src/zbus_platform.rs +++ b/rog-dbus/src/zbus_platform.rs @@ -28,64 +28,69 @@ use zbus::dbus_proxy; default_path = "/org/asuslinux/Platform" )] trait RogBios { - /// DgpuDisable method + /// SupportedProperties method + fn supported_properties(&self) -> zbus::Result>; + + /// DgpuDisable property + #[dbus_proxy(property)] fn dgpu_disable(&self) -> zbus::Result; - /// EgpuEnable method + /// EgpuEnable property + #[dbus_proxy(property)] fn egpu_enable(&self) -> zbus::Result; - /// GpuMuxMode method - fn gpu_mux_mode(&self) -> zbus::Result; + /// GpuMuxMode property + #[dbus_proxy(property)] + fn gpu_mux_mode(&self) -> zbus::Result; + fn set_gpu_mux_mode(&self, value: GpuMode) -> zbus::Result<()>; - /// PanelOd method - fn panel_od(&self) -> zbus::Result; - - /// MiniLedMode method + /// MiniLedMode property + #[dbus_proxy(property)] fn mini_led_mode(&self) -> zbus::Result; + fn set_mini_led_mode(&self, value: bool) -> zbus::Result<()>; - /// PostBootSound method - fn post_boot_sound(&self) -> zbus::Result; + /// NvDynamicBoost property + #[dbus_proxy(property)] + fn nv_dynamic_boost(&self) -> zbus::Result; + fn set_nv_dynamic_boost(&self, value: u8) -> zbus::Result<()>; - /// SetDgpuDisable method - fn set_dgpu_disable(&self, disable: bool) -> zbus::Result<()>; + /// NvTempTarget property + #[dbus_proxy(property)] + fn nv_temp_target(&self) -> zbus::Result; + fn set_nv_temp_target(&self, value: u8) -> zbus::Result<()>; - /// SetEgpuEnable method - fn set_egpu_enable(&self, enable: bool) -> zbus::Result<()>; + /// PanelOd property + #[dbus_proxy(property)] + fn panel_od(&self) -> zbus::Result; + fn set_panel_od(&self, value: bool) -> zbus::Result<()>; - /// SetGpuMuxMode method - fn set_gpu_mux_mode(&self, mode: GpuMode) -> zbus::Result<()>; + /// PostAnimationSound property + #[dbus_proxy(property)] + fn post_animation_sound(&self) -> zbus::Result; + fn set_post_animation_sound(&self, value: bool) -> zbus::Result<()>; - /// SetPanelOd method - fn set_panel_od(&self, overdrive: bool) -> zbus::Result<()>; + /// PptApuSppt property + #[dbus_proxy(property)] + fn ppt_apu_sppt(&self) -> zbus::Result; + fn set_ppt_apu_sppt(&self, value: u8) -> zbus::Result<()>; - /// SetminiLedMode - fn set_mini_led_mode(&self, on: bool) -> zbus::Result<()>; + /// PptFppt property + #[dbus_proxy(property)] + fn ppt_fppt(&self) -> zbus::Result; + fn set_ppt_fppt(&self, value: u8) -> zbus::Result<()>; - /// SetPostBootSound method - fn set_post_boot_sound(&self, on: bool) -> zbus::Result<()>; + /// PptPl1Spl property + #[dbus_proxy(property)] + fn ppt_pl1_spl(&self) -> zbus::Result; + fn set_ppt_pl1_spl(&self, value: u8) -> zbus::Result<()>; - /// NotifyDgpuDisable signal - #[dbus_proxy(signal)] - fn notify_dgpu_disable(&self, disable: bool) -> zbus::Result<()>; + /// PptPl2Sppt property + #[dbus_proxy(property)] + fn ppt_pl2_sppt(&self) -> zbus::Result; + fn set_ppt_pl2_sppt(&self, value: u8) -> zbus::Result<()>; - /// NotifyEgpuEnable signal - #[dbus_proxy(signal)] - fn notify_egpu_enable(&self, enable: bool) -> zbus::Result<()>; - - /// NotifyGpuMuxMode signal - #[dbus_proxy(signal)] - fn notify_gpu_mux_mode(&self, mode: GpuMode) -> zbus::Result<()>; - - /// NotifyPanelOd signal - #[dbus_proxy(signal)] - fn notify_panel_od(&self, overdrive: bool) -> zbus::Result<()>; - - /// NotifyMiniLedMode signal - #[dbus_proxy(signal)] - fn notify_mini_led_mode(&self, on: bool) -> zbus::Result<()>; - - /// NotifyPostBootSound signal - #[inline] - #[dbus_proxy(signal)] - fn notify_post_boot_sound(&self, on: bool) -> zbus::Result<()>; + /// PptPlatformSppt property + #[dbus_proxy(property)] + fn ppt_platform_sppt(&self) -> zbus::Result; + fn set_ppt_platform_sppt(&self, value: u8) -> zbus::Result<()>; }