From 6c7e1a64677fc1d466db31fd13c56b9d09c4de41 Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Sun, 12 May 2024 11:55:34 +1200 Subject: [PATCH] Add option for enable/disable apply AC/Bat policy on change --- CHANGELOG.md | 4 + Cargo.lock | 28 +++---- Cargo.toml | 2 +- asusd/src/config.rs | 8 ++ asusd/src/ctrl_platform.rs | 91 ++++++++++------------ rog-control-center/src/ui/setup_system.rs | 26 ++++++- rog-control-center/ui/pages/system.slint | 54 +++++++++---- rog-control-center/ui/widgets/common.slint | 6 +- rog-dbus/src/zbus_platform.rs | 12 +++ 9 files changed, 150 insertions(+), 81 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7243fe54..5a71d499 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Add a config option to set if throttle policy is changed on ac/bat change (UI only) + ## [v6.0.6] ### Added diff --git a/Cargo.lock b/Cargo.lock index b7658ab8..056ca72a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -117,7 +117,7 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "asusctl" -version = "6.0.6" +version = "6.0.7" dependencies = [ "asusd", "cargo-husky", @@ -135,7 +135,7 @@ dependencies = [ [[package]] name = "asusd" -version = "6.0.6" +version = "6.0.7" dependencies = [ "cargo-husky", "concat-idents", @@ -161,7 +161,7 @@ dependencies = [ [[package]] name = "asusd-user" -version = "6.0.6" +version = "6.0.7" dependencies = [ "cargo-husky", "config-traits", @@ -828,7 +828,7 @@ dependencies = [ [[package]] name = "config-traits" -version = "6.0.6" +version = "6.0.7" dependencies = [ "cargo-husky", "log", @@ -934,7 +934,7 @@ checksum = "7704b5fdd17b18ae31c4c1da5a2e0305a2bf17b5249300a9ee9ed7b72114c636" [[package]] name = "cpuctl" -version = "6.0.6" +version = "6.0.7" [[package]] name = "cpufeatures" @@ -1134,7 +1134,7 @@ dependencies = [ [[package]] name = "dmi_id" -version = "6.0.6" +version = "6.0.7" dependencies = [ "log", "udev 0.8.0", @@ -3309,7 +3309,7 @@ dependencies = [ [[package]] name = "rog-control-center" -version = "6.0.6" +version = "6.0.7" dependencies = [ "asusd", "betrayer", @@ -3341,7 +3341,7 @@ dependencies = [ [[package]] name = "rog_anime" -version = "6.0.6" +version = "6.0.7" dependencies = [ "cargo-husky", "dmi_id", @@ -3358,7 +3358,7 @@ dependencies = [ [[package]] name = "rog_aura" -version = "6.0.6" +version = "6.0.7" dependencies = [ "cargo-husky", "dmi_id", @@ -3372,7 +3372,7 @@ dependencies = [ [[package]] name = "rog_dbus" -version = "6.0.6" +version = "6.0.7" dependencies = [ "asusd", "cargo-husky", @@ -3386,7 +3386,7 @@ dependencies = [ [[package]] name = "rog_platform" -version = "6.0.6" +version = "6.0.7" dependencies = [ "cargo-husky", "concat-idents", @@ -3401,7 +3401,7 @@ dependencies = [ [[package]] name = "rog_profiles" -version = "6.0.6" +version = "6.0.7" dependencies = [ "cargo-husky", "log", @@ -3415,7 +3415,7 @@ dependencies = [ [[package]] name = "rog_simulators" -version = "6.0.6" +version = "6.0.7" dependencies = [ "log", "rog_anime", @@ -3425,7 +3425,7 @@ dependencies = [ [[package]] name = "rog_slash" -version = "6.0.6" +version = "6.0.7" dependencies = [ "cargo-husky", "dmi_id", diff --git a/Cargo.toml b/Cargo.toml index fc7fc819..69c139d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace.package] -version = "6.0.6" +version = "6.0.7" rust-version = "1.77" license = "MPL-2.0" readme = "README.md" diff --git a/asusd/src/config.rs b/asusd/src/config.rs index e238a419..7e116277 100644 --- a/asusd/src/config.rs +++ b/asusd/src/config.rs @@ -22,8 +22,12 @@ pub struct Config { pub throttle_policy_linked_epp: bool, /// Which throttle/profile to use on battery power pub throttle_policy_on_battery: ThrottlePolicy, + /// Should the throttle policy be set on bat/ac change? + pub change_throttle_policy_on_battery: bool, /// Which throttle/profile to use on AC power pub throttle_policy_on_ac: ThrottlePolicy, + /// Should the throttle policy be set on bat/ac change? + pub change_throttle_policy_on_ac: bool, /// The energy_performance_preference for this throttle/platform profile pub throttle_quiet_epp: CPUEPP, /// The energy_performance_preference for this throttle/platform profile @@ -68,7 +72,9 @@ impl Default for Config { bat_command: Default::default(), throttle_policy_linked_epp: true, throttle_policy_on_battery: ThrottlePolicy::Quiet, + change_throttle_policy_on_battery: true, throttle_policy_on_ac: ThrottlePolicy::Performance, + change_throttle_policy_on_ac: true, throttle_quiet_epp: CPUEPP::Power, throttle_balanced_epp: CPUEPP::BalancePower, throttle_performance_epp: CPUEPP::Performance, @@ -142,7 +148,9 @@ impl From for Config { mini_led_mode: c.mini_led_mode, throttle_policy_linked_epp: true, throttle_policy_on_battery: c.platform_policy_on_battery, + change_throttle_policy_on_battery: true, throttle_policy_on_ac: c.platform_policy_on_ac, + change_throttle_policy_on_ac: true, throttle_quiet_epp: CPUEPP::Power, throttle_balanced_epp: CPUEPP::BalancePower, throttle_performance_epp: CPUEPP::Performance, diff --git a/asusd/src/ctrl_platform.rs b/asusd/src/ctrl_platform.rs index b766b940..ea6e7a9c 100644 --- a/asusd/src/ctrl_platform.rs +++ b/asusd/src/ctrl_platform.rs @@ -9,17 +9,12 @@ use rog_platform::platform::{GpuMode, Properties, RogPlatform, ThrottlePolicy}; use rog_platform::power::AsusPower; use zbus::export::futures_util::lock::Mutex; use zbus::fdo::Error as FdoErr; -use zbus::{interface, Connection, ObjectServer, SignalContext}; +use zbus::{interface, Connection, SignalContext}; use crate::config::Config; -use crate::ctrl_anime::trait_impls::{CtrlAnimeZbus, ANIME_ZBUS_NAME, ANIME_ZBUS_PATH}; -use crate::ctrl_aura::trait_impls::{CtrlAuraZbus, AURA_ZBUS_NAME, AURA_ZBUS_PATH}; -use crate::ctrl_fancurves::{CtrlFanCurveZbus, FAN_CURVE_ZBUS_NAME, FAN_CURVE_ZBUS_PATH}; -use crate::ctrl_slash::trait_impls::{CtrlSlashZbus, SLASH_ZBUS_NAME, SLASH_ZBUS_PATH}; use crate::error::RogError; use crate::{task_watch_item, task_watch_item_notify, CtrlTask, ReloadAndNotify}; -const PLATFORM_ZBUS_NAME: &str = "Platform"; const PLATFORM_ZBUS_PATH: &str = "/org/asuslinux"; macro_rules! platform_get_value { @@ -258,6 +253,21 @@ impl CtrlPlatform { } async fn update_policy_ac_or_bat(&self, power_plugged: bool, change_epp: bool) { + if power_plugged && !self.config.lock().await.change_throttle_policy_on_ac { + debug!( + "Power status changed but set_throttle_policy_on_ac set false. Not setting the \ + thing" + ); + return; + } + if !power_plugged && !self.config.lock().await.change_throttle_policy_on_battery { + debug!( + "Power status changed but set_throttle_policy_on_battery set false. Not setting \ + the thing" + ); + return; + } + let throttle = if power_plugged { self.config.lock().await.throttle_policy_on_ac } else { @@ -328,49 +338,6 @@ impl CtrlPlatform { supported } - async fn supported_interfaces( - &self, - #[zbus(object_server)] server: &ObjectServer, - ) -> Vec { - let mut interfaces = Vec::default(); - if server - .interface::<_, CtrlAnimeZbus>(ANIME_ZBUS_PATH) - .await - .is_ok() - { - interfaces.push(ANIME_ZBUS_NAME.to_owned()); - } - if server - .interface::<_, CtrlAuraZbus>(AURA_ZBUS_PATH) - .await - .is_ok() - { - interfaces.push(AURA_ZBUS_NAME.to_owned()); - } - if server - .interface::<_, CtrlFanCurveZbus>(FAN_CURVE_ZBUS_PATH) - .await - .is_ok() - { - interfaces.push(FAN_CURVE_ZBUS_NAME.to_owned()); - } - if server - .interface::<_, CtrlPlatform>(PLATFORM_ZBUS_PATH) - .await - .is_ok() - { - interfaces.push(PLATFORM_ZBUS_NAME.to_owned()); - } - if server - .interface::<_, CtrlSlashZbus>(SLASH_ZBUS_PATH) - .await - .is_ok() - { - interfaces.push(SLASH_ZBUS_NAME.to_owned()); - } - interfaces - } - #[zbus(property)] fn charge_control_end_threshold(&self) -> Result { let limit = self.power.get_charge_control_end_threshold()?; @@ -496,6 +463,18 @@ impl CtrlPlatform { Ok(()) } + #[zbus(property)] + async fn change_throttle_policy_on_battery(&self) -> Result { + Ok(self.config.lock().await.change_throttle_policy_on_battery) + } + + #[zbus(property)] + async fn set_change_throttle_policy_on_battery(&mut self, change: bool) -> Result<(), FdoErr> { + self.config.lock().await.change_throttle_policy_on_battery = change; + self.config.lock().await.write(); + Ok(()) + } + #[zbus(property)] async fn throttle_policy_on_ac(&self) -> Result { Ok(self.config.lock().await.throttle_policy_on_ac) @@ -509,6 +488,18 @@ impl CtrlPlatform { Ok(()) } + #[zbus(property)] + async fn change_throttle_policy_on_ac(&self) -> Result { + Ok(self.config.lock().await.change_throttle_policy_on_ac) + } + + #[zbus(property)] + async fn set_change_throttle_policy_on_ac(&mut self, change: bool) -> Result<(), FdoErr> { + self.config.lock().await.change_throttle_policy_on_ac = change; + self.config.lock().await.write(); + Ok(()) + } + /// The energy_performance_preference for the quiet throttle/platform /// profile #[zbus(property)] @@ -905,6 +896,8 @@ impl CtrlTask for CtrlPlatform { }) .ok(); } + // This block is commented out due to some kind of issue reported. Maybe the + // desktops used were storing a value whcih was then read here. // Don't store it on suspend, assume that the current config setting is desired // if sleeping && platform1.power.has_charge_control_end_threshold() { // platform1.config.lock().await.charge_control_end_threshold = platform1 diff --git a/rog-control-center/src/ui/setup_system.rs b/rog-control-center/src/ui/setup_system.rs index 69f92388..1697c433 100644 --- a/rog-control-center/src/ui/setup_system.rs +++ b/rog-control-center/src/ui/setup_system.rs @@ -60,7 +60,19 @@ pub fn setup_system_page_callbacks(ui: &MainWindow, _states: Arc>) set_ui_props_async!(handle, platform, SystemPageData, throttle_performance_epp); set_ui_props_async!(handle, platform, SystemPageData, throttle_quiet_epp); set_ui_props_async!(handle, platform, SystemPageData, throttle_policy_on_battery); + set_ui_props_async!( + handle, + platform, + SystemPageData, + change_throttle_policy_on_battery + ); set_ui_props_async!(handle, platform, SystemPageData, throttle_policy_on_ac); + set_ui_props_async!( + handle, + platform, + SystemPageData, + change_throttle_policy_on_ac + ); set_ui_props_async!(handle, platform, SystemPageData, panel_od); set_ui_props_async!(handle, platform, SystemPageData, boot_sound); @@ -94,6 +106,7 @@ pub fn setup_system_page_callbacks(ui: &MainWindow, _states: Arc>) throttle_thermal_policy: sys_props.contains(&Properties::ThrottlePolicy), }; + // TODO: move the fail/sucess messages to slint handle .upgrade_in_event_loop(move |handle| { handle.global::().set_available(props); @@ -163,13 +176,24 @@ pub fn setup_system_page_callbacks(ui: &MainWindow, _states: Arc>) "Throttle policy on AC set to {}", "Setting Throttle policy on AC failed" ); + set_ui_callbacks!(handle, + SystemPageData(as bool), + platform.change_throttle_policy_on_ac(.into()), + "Throttle policy on AC enabled: {}", + "Setting Throttle policy on AC failed" + ); set_ui_callbacks!(handle, SystemPageData(as i32), platform.throttle_policy_on_battery(.into()), "Throttle policy on abttery set to {}", "Setting Throttle policy on battery failed" ); - + set_ui_callbacks!(handle, + SystemPageData(as bool), + platform.change_throttle_policy_on_battery(.into()), + "Throttle policy on battery enabled: {}", + "Setting Throttle policy on AC failed" + ); set_ui_callbacks!(handle, SystemPageData(as f32), platform.ppt_pl1_spl(as u8), diff --git a/rog-control-center/ui/pages/system.slint b/rog-control-center/ui/pages/system.slint index ebcbb05a..5e3a7980 100644 --- a/rog-control-center/ui/pages/system.slint +++ b/rog-control-center/ui/pages/system.slint @@ -43,8 +43,12 @@ export global SystemPageData { callback set_throttle_policy_linked_epp(bool); in-out property throttle_policy_on_ac: 0; callback set_throttle_policy_on_ac(int); + in-out property change_throttle_policy_on_ac: true; + callback set_change_throttle_policy_on_ac(bool); in-out property throttle_policy_on_battery: 0; callback set_throttle_policy_on_battery(int); + in-out property change_throttle_policy_on_battery: true; + callback set_change_throttle_policy_on_battery(bool); in-out property panel_od; callback set_panel_od(bool); in-out property boot_sound; @@ -340,23 +344,45 @@ export component PageSystem inherits Rectangle { text: @tr("Throttle Policy for power state"); } - SystemDropdown { - text: @tr("Throttle Policy on Battery"); - current_index <=> SystemPageData.throttle_policy_on_battery; - current_value: SystemPageData.throttle_policy_choices[SystemPageData.throttle_policy_on_battery]; - model <=> SystemPageData.throttle_policy_choices; - selected => { - SystemPageData.set_throttle_policy_on_battery(SystemPageData.throttle_policy_on_battery) + HorizontalLayout { + spacing: 10px; + SystemDropdown { + text: @tr("Throttle Policy on Battery"); + current_index <=> SystemPageData.throttle_policy_on_battery; + current_value: SystemPageData.throttle_policy_choices[SystemPageData.throttle_policy_on_battery]; + model <=> SystemPageData.throttle_policy_choices; + selected => { + SystemPageData.set_throttle_policy_on_battery(SystemPageData.throttle_policy_on_battery) + } + } + + SystemToggle { + text: @tr("Enabled"); + checked <=> SystemPageData.change_throttle_policy_on_battery; + toggled => { + SystemPageData.set_change_throttle_policy_on_battery(SystemPageData.change_throttle_policy_on_battery); + } } } - SystemDropdown { - text: @tr("Throttle Policy on AC"); - current_index <=> SystemPageData.throttle_policy_on_ac; - current_value: SystemPageData.throttle_policy_choices[SystemPageData.throttle_policy_on_ac]; - model <=> SystemPageData.throttle_policy_choices; - selected => { - SystemPageData.set_throttle_policy_on_ac(SystemPageData.throttle_policy_on_ac) + HorizontalLayout { + spacing: 10px; + SystemDropdown { + text: @tr("Throttle Policy on AC"); + current_index <=> SystemPageData.throttle_policy_on_ac; + current_value: SystemPageData.throttle_policy_choices[SystemPageData.throttle_policy_on_ac]; + model <=> SystemPageData.throttle_policy_choices; + selected => { + SystemPageData.set_throttle_policy_on_ac(SystemPageData.throttle_policy_on_ac) + } + } + + SystemToggle { + text: @tr("Enabled"); + checked <=> SystemPageData.change_throttle_policy_on_ac; + toggled => { + SystemPageData.set_change_throttle_policy_on_ac(SystemPageData.change_throttle_policy_on_ac); + } } } } diff --git a/rog-control-center/ui/widgets/common.slint b/rog-control-center/ui/widgets/common.slint index 891888b9..666bd275 100644 --- a/rog-control-center/ui/widgets/common.slint +++ b/rog-control-center/ui/widgets/common.slint @@ -5,7 +5,8 @@ export component RogItem inherits Rectangle { border-color: Palette.border; border-width: 3px; border-radius: 10px; - min-height: 46px; + min-height: 48px; + max-height: 56px; } export component SystemSlider inherits RogItem { @@ -54,6 +55,7 @@ export component SystemToggle inherits RogItem { in-out property checked; callback toggled(bool); HorizontalLayout { + spacing: 6px; HorizontalLayout { alignment: LayoutAlignment.start; padding-left: 10px; @@ -195,7 +197,7 @@ export component PopupNotification { } } - public function show() { + public function show(){ _p.show(); } } diff --git a/rog-dbus/src/zbus_platform.rs b/rog-dbus/src/zbus_platform.rs index 77342151..5f433e9e 100644 --- a/rog-dbus/src/zbus_platform.rs +++ b/rog-dbus/src/zbus_platform.rs @@ -143,12 +143,24 @@ trait Platform { #[zbus(property)] fn set_throttle_policy_on_ac(&self, throttle_policy: ThrottlePolicy) -> zbus::Result<()>; + /// ChangeThrottlePolicyOnAc property + #[zbus(property)] + fn change_throttle_policy_on_ac(&self) -> zbus::Result; + #[zbus(property)] + fn set_change_throttle_policy_on_ac(&self, change: bool) -> zbus::Result<()>; + /// ThrottlePolicyOnBattery property #[zbus(property)] fn throttle_policy_on_battery(&self) -> zbus::Result; #[zbus(property)] fn set_throttle_policy_on_battery(&self, throttle_policy: ThrottlePolicy) -> zbus::Result<()>; + /// ChangeThrottlePolicyOnAc property + #[zbus(property)] + fn change_throttle_policy_on_battery(&self) -> zbus::Result; + #[zbus(property)] + fn set_change_throttle_policy_on_battery(&self, change: bool) -> zbus::Result<()>; + /// ThrottleQuietEpp property #[zbus(property)] fn throttle_quiet_epp(&self) -> zbus::Result;