diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ed215ee..16886e94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- Gnome 45 plugin - Support for G513RW LED modes - Support Rog Ally LED modes (basic) - Add on_lid_closed and on_external_power_changed events for running certain tasks @@ -14,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - SetOffWhenUnplugged, also add asusctl CLI option - SetOffWhenSuspended, also add asusctl CLI option - SetOffWhenLidClosed, also add asusctl CLI option +- Anime: add brightness_on_battery config option ### Changed - asusd: remove set_image_brightness for anime @@ -22,6 +24,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - rog-control-center: ensure brightness slider works correctly - Update `smithay-client-toolkit` for fix to issue #407 - Remove the "sleep" animations from Anime to stop preventing the display-off +- Anime: + - Ensure display is off when lid is closed and option is set + - Ensure display is off when on battery and option is set + - Ensure builtin animations run instead of custom animations if option is set ## [v4.7.2] ### Added diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index 856cb48b..68ab2cfa 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -746,7 +746,7 @@ fn handle_fan_curve( fn handle_bios_option( dbus: &RogDbusClientBlocking<'_>, - supported: &RogBiosSupportedFunctions, + supported: &PlatformSupportedFunctions, cmd: &BiosCommand, ) -> Result<(), Box> { { diff --git a/asusd/src/ctrl_anime/config.rs b/asusd/src/ctrl_anime/config.rs index dda52997..507f1d21 100644 --- a/asusd/src/ctrl_anime/config.rs +++ b/asusd/src/ctrl_anime/config.rs @@ -120,6 +120,7 @@ pub struct AnimeConfig { pub off_when_unplugged: bool, pub off_when_suspended: bool, pub off_when_lid_closed: bool, + pub brightness_on_battery: Brightness, pub builtin_anims: Animations, } @@ -138,6 +139,7 @@ impl Default for AnimeConfig { off_when_unplugged: true, off_when_suspended: true, off_when_lid_closed: true, + brightness_on_battery: Brightness::Low, builtin_anims: Animations::default(), } } @@ -169,6 +171,7 @@ impl From<&AnimeConfig> for DeviceState { off_when_unplugged: config.off_when_unplugged, off_when_suspended: config.off_when_suspended, off_when_lid_closed: config.off_when_lid_closed, + brightness_on_battery: config.brightness_on_battery, } } } diff --git a/asusd/src/ctrl_anime/trait_impls.rs b/asusd/src/ctrl_anime/trait_impls.rs index 08739dab..eea7c5e9 100644 --- a/asusd/src/ctrl_anime/trait_impls.rs +++ b/asusd/src/ctrl_anime/trait_impls.rs @@ -4,19 +4,32 @@ use std::sync::Arc; use async_trait::async_trait; use config_traits::StdConfig; use log::warn; +use logind_zbus::manager::ManagerProxy; use rog_anime::usb::{ pkt_set_brightness, pkt_set_builtin_animations, pkt_set_enable_display, pkt_set_enable_powersave_anim, AnimAwake, AnimBooting, AnimShutdown, AnimSleeping, Brightness, }; use rog_anime::{AnimeDataBuffer, DeviceState}; use zbus::export::futures_util::lock::Mutex; -use zbus::{dbus_interface, Connection, SignalContext}; +use zbus::{dbus_interface, CacheProperties, Connection, SignalContext}; use super::CtrlAnime; use crate::error::RogError; pub(super) const ZBUS_PATH: &str = "/org/asuslinux/Anime"; +async fn get_logind_manager<'a>() -> ManagerProxy<'a> { + let connection = Connection::system() + .await + .expect("Controller could not create dbus connection"); + + ManagerProxy::builder(&connection) + .cache_properties(CacheProperties::No) + .build() + .await + .expect("Controller could not create ManagerProxy") +} + #[derive(Clone)] pub struct CtrlAnimeZbus(pub Arc>); @@ -176,6 +189,16 @@ impl CtrlAnimeZbus { enabled: bool, ) { let mut lock = self.0.lock().await; + let manager = get_logind_manager().await; + let pow = manager.on_external_power().await.unwrap_or_default(); + + lock.node + .write_bytes(&pkt_set_enable_display(!pow && !enabled)) + .map_err(|err| { + warn!("create_sys_event_tasks::off_when_lid_closed {}", err); + }) + .ok(); + lock.config.off_when_unplugged = enabled; lock.config.write(); Self::notify_device_state(&ctxt, DeviceState::from(&lock.config)) @@ -204,6 +227,16 @@ impl CtrlAnimeZbus { enabled: bool, ) { let mut lock = self.0.lock().await; + let manager = get_logind_manager().await; + let lid = manager.lid_closed().await.unwrap_or_default(); + + lock.node + .write_bytes(&pkt_set_enable_display(lid && !enabled)) + .map_err(|err| { + warn!("create_sys_event_tasks::off_when_lid_closed {}", err); + }) + .ok(); + lock.config.off_when_lid_closed = enabled; lock.config.write(); Self::notify_device_state(&ctxt, DeviceState::from(&lock.config)) @@ -225,15 +258,7 @@ impl CtrlAnimeZbus { // #[dbus_interface(property)] async fn device_state(&self) -> DeviceState { let lock = self.0.lock().await; - DeviceState { - display_enabled: lock.config.display_enabled, - display_brightness: lock.config.display_brightness, - builtin_anims_enabled: lock.config.builtin_anims_enabled, - builtin_anims: lock.config.builtin_anims, - off_when_unplugged: lock.config.off_when_unplugged, - off_when_suspended: lock.config.off_when_suspended, - off_when_lid_closed: lock.config.off_when_lid_closed, - } + DeviceState::from(&lock.config) } /// Notify listeners of the status of AniMe LED power and factory @@ -320,6 +345,13 @@ impl crate::CtrlTask for CtrlAnimeZbus { warn!("create_sys_event_tasks::off_when_unplugged {}", err); }) .ok(); + } else { + lock.node + .write_bytes(&pkt_set_brightness(lock.config.brightness_on_battery)) + .map_err(|err| { + warn!("create_sys_event_tasks::off_when_unplugged {}", err); + }) + .ok(); } } }, diff --git a/asusd/src/ctrl_platform.rs b/asusd/src/ctrl_platform.rs index 3f80bd24..513ed16c 100644 --- a/asusd/src/ctrl_platform.rs +++ b/asusd/src/ctrl_platform.rs @@ -8,7 +8,7 @@ use async_trait::async_trait; use config_traits::StdConfig; use log::{info, warn}; use rog_platform::platform::{AsusPlatform, GpuMode}; -use rog_platform::supported::RogBiosSupportedFunctions; +use rog_platform::supported::PlatformSupportedFunctions; use zbus::export::futures_util::lock::Mutex; use zbus::{dbus_interface, Connection, SignalContext}; @@ -27,31 +27,11 @@ pub struct CtrlPlatform { } impl GetSupported for CtrlPlatform { - type A = RogBiosSupportedFunctions; + type A = PlatformSupportedFunctions; fn get_supported() -> Self::A { - let mut panel_overdrive = false; - let mut mini_led_mode = false; - let mut dgpu_disable = false; - let mut egpu_enable = false; - let mut gpu_mux = false; - - if let Ok(platform) = AsusPlatform::new() { - panel_overdrive = platform.has_panel_od(); - mini_led_mode = platform.has_mini_led_mode(); - dgpu_disable = platform.has_dgpu_disable(); - egpu_enable = platform.has_egpu_enable(); - gpu_mux = platform.has_gpu_mux_mode(); - } - - RogBiosSupportedFunctions { - post_sound: Path::new(ASUS_POST_LOGO_SOUND).exists(), - gpu_mux, - panel_overdrive, - mini_led_mode, - dgpu_disable, - egpu_enable, - } + let platform = AsusPlatform::new().unwrap_or_default(); + platform.into() } } diff --git a/desktop-extensions/gnome-45/src/modules/dbus/animatrix.ts b/desktop-extensions/gnome-45/src/modules/dbus/animatrix.ts index 15d41ed8..e9bdff4e 100644 --- a/desktop-extensions/gnome-45/src/modules/dbus/animatrix.ts +++ b/desktop-extensions/gnome-45/src/modules/dbus/animatrix.ts @@ -50,7 +50,7 @@ export class AnimeDbus extends DbusBase { if (this.deviceState.builtin_anims_enabled !== state) { this.deviceState.builtin_anims_enabled = state; } - return this.dbus_proxy.SetEnableBuiltinsSync(state); + return this.dbus_proxy.SetBuiltinsEnabledSync(state); } catch (e) { //@ts-ignore log("AniMe DBus set builtins failed!", e); diff --git a/rog-anime/src/data.rs b/rog-anime/src/data.rs index d80aa83c..638aebb1 100644 --- a/rog-anime/src/data.rs +++ b/rog-anime/src/data.rs @@ -39,6 +39,7 @@ pub struct Animations { pub shutdown: AnimShutdown, } +// TODO: move this out #[typeshare] #[cfg_attr(feature = "dbus", derive(Type))] #[typeshare] @@ -51,6 +52,7 @@ pub struct DeviceState { pub off_when_unplugged: bool, pub off_when_suspended: bool, pub off_when_lid_closed: bool, + pub brightness_on_battery: Brightness, } #[typeshare] diff --git a/rog-platform/src/macros.rs b/rog-platform/src/macros.rs index f5f12f5b..5198e865 100644 --- a/rog-platform/src/macros.rs +++ b/rog-platform/src/macros.rs @@ -1,8 +1,8 @@ #[macro_export] macro_rules! has_attr { - ($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => { + ($(#[$attr:meta])* $attr_name:literal $item:ident) => { concat_idents::concat_idents!(fn_name = has_, $attr_name { - $(#[$doc_comment])* + $(#[$attr])* pub fn fn_name(&self) -> bool { match to_device(&self.$item) { Ok(p) => $crate::has_attr(&p, $attr_name), @@ -15,9 +15,9 @@ macro_rules! has_attr { #[macro_export] macro_rules! watch_attr { - ($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => { + ($(#[$attr:meta])* $attr_name:literal $item:ident) => { concat_idents::concat_idents!(fn_name = monitor_, $attr_name { - $(#[$doc_comment])* + $(#[$attr])* pub fn fn_name(&self) -> Result { let mut path = self.$item.clone(); path.push($attr_name); @@ -41,9 +41,9 @@ macro_rules! watch_attr { #[macro_export] macro_rules! get_attr_bool { - ($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => { + ($(#[$attr:meta])* $attr_name:literal $item:ident) => { concat_idents::concat_idents!(fn_name = get_, $attr_name { - $(#[$doc_comment])* + $(#[$attr])* pub fn fn_name(&self) -> Result { $crate::read_attr_bool(&to_device(&self.$item)?, $attr_name) } @@ -53,9 +53,9 @@ macro_rules! get_attr_bool { #[macro_export] macro_rules! set_attr_bool { - ($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => { + ($(#[$attr:meta])* $attr_name:literal $item:ident) => { concat_idents::concat_idents!(fn_name = set_, $attr_name { - $(#[$doc_comment])* + $(#[$attr])* pub fn fn_name(&self, value: bool) -> Result<()> { $crate::write_attr_bool(&mut to_device(&self.$item)?, $attr_name, value) } @@ -65,7 +65,7 @@ macro_rules! set_attr_bool { #[macro_export] macro_rules! attr_bool { - ($attr_name:literal, $item:ident) => { + ($(#[$attr:meta])* $attr_name:literal, $item:ident) => { $crate::has_attr!($attr_name $item); $crate::get_attr_bool!( $attr_name $item); $crate::set_attr_bool!($attr_name $item); @@ -75,9 +75,9 @@ macro_rules! attr_bool { #[macro_export] macro_rules! get_attr_u8 { - ($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => { + ($(#[$attr:meta])* $attr_name:literal $item:ident) => { concat_idents::concat_idents!(fn_name = get_, $attr_name { - $(#[$doc_comment])* + $(#[$attr])* pub fn fn_name(&self) -> Result { $crate::read_attr_u8(&to_device(&self.$item)?, $attr_name) } @@ -88,9 +88,9 @@ macro_rules! get_attr_u8 { /// Most attributes expect `u8` as a char, so `1` should be written as `b'1'`. #[macro_export] macro_rules! set_attr_u8 { - ($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => { + ($(#[$attr:meta])* $attr_name:literal $item:ident) => { concat_idents::concat_idents!(fn_name = set_, $attr_name { - $(#[$doc_comment])* + $(#[$attr])* pub fn fn_name(&self, value: u8) -> Result<()> { $crate::write_attr_u8(&mut to_device(&self.$item)?, $attr_name, value) } @@ -100,19 +100,19 @@ macro_rules! set_attr_u8 { #[macro_export] macro_rules! attr_u8 { - ($attr_name:literal, $item:ident) => { - $crate::has_attr!($attr_name $item); - $crate::get_attr_u8!($attr_name $item); - $crate::set_attr_u8!($attr_name $item); - $crate::watch_attr!($attr_name $item); + ($(#[$attr:meta])* $attr_name:literal, $item:ident) => { + $crate::has_attr!($(#[$attr])* $attr_name $item); + $crate::get_attr_u8!($(#[$attr])* $attr_name $item); + $crate::set_attr_u8!($(#[$attr])* $attr_name $item); + $crate::watch_attr!($(#[$attr])* $attr_name $item); }; } #[macro_export] macro_rules! get_attr_u8_array { - ($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => { + ($(#[$attr:meta])* $attr_name:literal $item:ident) => { concat_idents::concat_idents!(fn_name = get_, $attr_name { - $(#[$doc_comment])* + $(#[$attr])* pub fn fn_name(&self) -> Result> { $crate::read_attr_u8_array(&to_device(&self.$item)?, $attr_name) } @@ -122,9 +122,9 @@ macro_rules! get_attr_u8_array { #[macro_export] macro_rules! set_attr_u8_array { - ($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => { + ($(#[$attr:meta])* $attr_name:literal $item:ident) => { concat_idents::concat_idents!(fn_name = set_, $attr_name { - $(#[$doc_comment])* + $(#[$attr])* pub fn fn_name(&self, values: &[u8]) -> Result<()> { $crate::write_attr_u8_array(&mut to_device(&self.$item)?, $attr_name, values) } @@ -134,7 +134,7 @@ macro_rules! set_attr_u8_array { #[macro_export] macro_rules! attr_u8_array { - ($attr_name:literal, $item:ident) => { + ($(#[$attr:meta])* $attr_name:literal, $item:ident) => { $crate::has_attr!($attr_name $item); $crate::get_attr_u8_array!($attr_name $item); $crate::set_attr_u8_array!($attr_name $item); @@ -144,9 +144,9 @@ macro_rules! attr_u8_array { #[macro_export] macro_rules! get_attr_string { - ($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => { + ($(#[$attr:meta])* $attr_name:literal $item:ident) => { concat_idents::concat_idents!(fn_name = get_, $attr_name { - $(#[$doc_comment])* + $(#[$attr])* pub fn fn_name(&self) -> Result { $crate::read_attr_string(&to_device(&self.$item)?, $attr_name) } @@ -156,9 +156,9 @@ macro_rules! get_attr_string { #[macro_export] macro_rules! set_attr_string { - ($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => { + ($(#[$attr:meta])* $attr_name:literal $item:ident) => { concat_idents::concat_idents!(fn_name = set_, $attr_name { - $(#[$doc_comment])* + $(#[$attr])* pub fn fn_name(&self, values: &str) -> Result<()> { $crate::write_attr_string(&mut to_device(&self.$item)?, $attr_name, values) } @@ -168,7 +168,7 @@ macro_rules! set_attr_string { #[macro_export] macro_rules! attr_string { - ($attr_name:literal, $item:ident) => { + ($(#[$attr:meta])* $attr_name:literal, $item:ident) => { $crate::has_attr!($attr_name $item); $crate::get_attr_string!($attr_name $item); $crate::set_attr_string!($attr_name $item); diff --git a/rog-platform/src/platform.rs b/rog-platform/src/platform.rs index 170a1f34..cf525433 100644 --- a/rog-platform/src/platform.rs +++ b/rog-platform/src/platform.rs @@ -8,6 +8,7 @@ use typeshare::typeshare; use zbus::zvariant::Type; use crate::error::{PlatformError, Result}; +use crate::supported::PlatformSupportedFunctions; use crate::{attr_bool, attr_string, attr_u8, to_device}; /// The "platform" device provides access to things like: @@ -15,6 +16,7 @@ use crate::{attr_bool, attr_string, attr_u8, to_device}; /// - `egpu_enable` /// - `panel_od` /// - `gpu_mux` +/// - various CPU an GPU tunings /// - `keyboard_mode`, set keyboard RGB mode and speed /// - `keyboard_state`, set keyboard power states #[derive(Debug, PartialEq, Eq, PartialOrd, Clone)] @@ -34,12 +36,69 @@ impl AsusPlatform { attr_bool!("gpu_mux_mode", path); - // This is technically the same as `platform_profile` since both are tied - // in-kernel - attr_u8!("throttle_thermal_policy", path); + attr_u8!( + /// This is technically the same as `platform_profile` since both are + /// tied in-kernel + "throttle_thermal_policy", + path + ); - // The acpi platform_profile support - attr_string!("platform_profile", pp_path); + attr_string!( + /// The acpi platform_profile support + "platform_profile", + pp_path + ); + + attr_u8!( + /// Package Power Target total of CPU: PL1 on Intel, SPL on AMD. + /// Shown on Intel+Nvidia or AMD+Nvidia based systems: + /// * min=5, max=250 + "ppt_pl1_spl", + path + ); + + attr_u8!( + /// Slow Package Power Tracking Limit of CPU: PL2 on Intel, SPPT, + /// on AMD. Shown on Intel+Nvidia or AMD+Nvidia based systems: + /// * min=5, max=250 + "ppt_pl2_sppt", + path + ); + + attr_u8!( + /// Fast Package Power Tracking Limit of CPU. AMD+Nvidia only: + /// * min=5, max=250 + "ppt_fppt", + path + ); + + attr_u8!( + /// APU SPPT limit. Shown on full AMD systems only: + /// * min=5, max=130 + "ppt_apu_sppt", + path + ); + + attr_u8!( + /// Platform SPPT limit. Shown on full AMD systems only: + /// * min=5, max=130 + "ppt_platform_sppt", + path + ); + + attr_u8!( + /// Dynamic boost limit of the Nvidia dGPU: + /// * min=5, max=25 + "nv_dynamic_boost", + path + ); + + attr_u8!( + /// Target temperature limit of the Nvidia dGPU: + /// * min=75, max=87 + "nv_temp_target", + path + ); pub fn new() -> Result { let mut enumerator = udev::Enumerator::new().map_err(|err| { @@ -73,6 +132,37 @@ impl AsusPlatform { } } +impl Default for AsusPlatform { + fn default() -> Self { + unsafe { + Self { + path: PathBuf::from_str("/this_shouldNeVErr_exisid").unwrap_unchecked(), + pp_path: PathBuf::from_str("/this_shouldNeVErr_exisid").unwrap_unchecked(), + } + } + } +} + +impl From for PlatformSupportedFunctions { + fn from(a: AsusPlatform) -> Self { + PlatformSupportedFunctions { + post_sound: false, + gpu_mux: a.has_gpu_mux_mode(), + panel_overdrive: a.has_panel_od(), + dgpu_disable: a.has_dgpu_disable(), + egpu_enable: a.has_egpu_enable(), + mini_led_mode: a.has_mini_led_mode(), + ppt_pl1_spl: a.has_ppt_pl1_spl(), + ppt_pl2_sppt: a.has_ppt_pl2_sppt(), + ppt_fppt: a.has_ppt_fppt(), + ppt_apu_sppt: a.has_ppt_apu_sppt(), + ppt_platform_sppt: a.has_ppt_platform_sppt(), + nv_dynamic_boost: a.has_nv_dynamic_boost(), + nv_temp_target: a.has_nv_temp_target(), + } + } +} + #[typeshare] #[derive(Serialize, Deserialize, Default, Type, Debug, PartialEq, Eq, Clone, Copy)] pub enum GpuMode { diff --git a/rog-platform/src/supported.rs b/rog-platform/src/supported.rs index 9fe1d4d1..0e205de4 100644 --- a/rog-platform/src/supported.rs +++ b/rog-platform/src/supported.rs @@ -15,7 +15,7 @@ pub struct SupportedFunctions { pub charge_ctrl: ChargeSupportedFunctions, pub platform_profile: PlatformProfileFunctions, pub keyboard_led: LedSupportedFunctions, - pub rog_bios_ctrl: RogBiosSupportedFunctions, + pub rog_bios_ctrl: PlatformSupportedFunctions, } #[typeshare] @@ -68,13 +68,21 @@ pub struct LedSupportedFunctions { #[typeshare] #[derive(Serialize, Deserialize, Type, Debug, Default, Clone)] -pub struct RogBiosSupportedFunctions { +pub struct PlatformSupportedFunctions { pub post_sound: bool, pub gpu_mux: bool, pub panel_overdrive: bool, pub dgpu_disable: bool, pub egpu_enable: bool, pub mini_led_mode: bool, + + pub ppt_pl1_spl: bool, + pub ppt_pl2_sppt: bool, + pub ppt_fppt: bool, + pub ppt_apu_sppt: bool, + pub ppt_platform_sppt: bool, + pub nv_dynamic_boost: bool, + pub nv_temp_target: bool, } impl fmt::Display for SupportedFunctions { @@ -120,7 +128,8 @@ impl fmt::Display for LedSupportedFunctions { writeln!(f, "\tAdvanced modes: {:?}", self.advanced_type) } } -impl fmt::Display for RogBiosSupportedFunctions { + +impl fmt::Display for PlatformSupportedFunctions { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!(f, "ROG BIOS:")?; writeln!(f, "\tPOST sound switch: {}", self.post_sound)?; @@ -129,6 +138,13 @@ impl fmt::Display for RogBiosSupportedFunctions { writeln!(f, "\tdGPU disable switch: {}", self.dgpu_disable)?; writeln!(f, "\teGPU enable switch: {}", self.egpu_enable)?; writeln!(f, "\tGPU MUX control: {}", self.gpu_mux)?; + writeln!(f, "\tppt_pl1_spl: {}", self.ppt_pl1_spl)?; + writeln!(f, "\tppt_pl2_sppt: {}", self.ppt_pl2_sppt)?; + writeln!(f, "\tppt_fppt {}", self.ppt_fppt)?; + writeln!(f, "\tppt_apu_sppt: {}", self.ppt_apu_sppt)?; + writeln!(f, "\tppt_platform_sppt: {}", self.ppt_platform_sppt)?; + writeln!(f, "\tnv_dynamic_boost: {}", self.nv_dynamic_boost)?; + writeln!(f, "\tnv_temp_target: {}", self.nv_temp_target)?; Ok(()) } }