diff --git a/CHANGELOG.md b/CHANGELOG.md index d4d82996..5a620b51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [v4.5.1- RC2] +- Share pagestates with tray process in ROGCC + ## [v4.5.1- RC1] ### Added - Support for FA506IE LED modes (Author: Herohtar) @@ -12,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add a basic system tray with dGPU status and gpu mode switch actions - Fixup some notifications in ROGCC - Add config options for notifications for ROGCC +- Share pagestates with tray process in ROGCC ## [v4.5.0] ### Added diff --git a/Cargo.lock b/Cargo.lock index dbf5d7a7..04426c0c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -83,7 +83,7 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "asusctl" -version = "4.5.1-RC1" +version = "4.5.1-RC2" dependencies = [ "daemon", "gif", @@ -662,7 +662,7 @@ checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" [[package]] name = "daemon" -version = "4.5.1-RC1" +version = "4.5.1-RC2" dependencies = [ "async-trait", "concat-idents", @@ -686,7 +686,7 @@ dependencies = [ [[package]] name = "daemon-user" -version = "4.5.1-RC1" +version = "4.5.1-RC2" dependencies = [ "dirs", "rog_anime", @@ -2398,7 +2398,7 @@ dependencies = [ [[package]] name = "rog-control-center" -version = "4.5.1-RC1" +version = "4.5.1-RC2" dependencies = [ "daemon", "dirs", @@ -2428,7 +2428,7 @@ dependencies = [ [[package]] name = "rog_anime" -version = "4.5.1-RC1" +version = "4.5.1-RC2" dependencies = [ "gif", "glam", @@ -2444,7 +2444,7 @@ dependencies = [ [[package]] name = "rog_aura" -version = "4.5.1-RC1" +version = "4.5.1-RC2" dependencies = [ "serde", "serde_derive", @@ -2455,7 +2455,7 @@ dependencies = [ [[package]] name = "rog_dbus" -version = "4.5.1-RC1" +version = "4.5.1-RC2" dependencies = [ "rog_anime", "rog_aura", @@ -2468,7 +2468,7 @@ dependencies = [ [[package]] name = "rog_platform" -version = "4.5.1-RC1" +version = "4.5.1-RC2" dependencies = [ "concat-idents", "inotify", @@ -2485,7 +2485,7 @@ dependencies = [ [[package]] name = "rog_profiles" -version = "4.5.1-RC1" +version = "4.5.1-RC2" dependencies = [ "serde", "serde_derive", diff --git a/Cargo.toml b/Cargo.toml index aca9999c..99a39dcb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ members = ["asusctl", "daemon", "daemon-user", "rog-platform", "rog-dbus", "rog-anime", "rog-aura", "rog-profiles", "rog-control-center"] [workspace.package] -version = "4.5.1-RC1" +version = "4.5.1-RC2" [workspace.dependencies] async-trait = "^0.1" diff --git a/rog-aura/src/builtin_modes.rs b/rog-aura/src/builtin_modes.rs index ee56c222..22f2da98 100644 --- a/rog-aura/src/builtin_modes.rs +++ b/rog-aura/src/builtin_modes.rs @@ -5,7 +5,7 @@ pub const LED_INIT4: &str = "^ASUS Tech.Inc."; // ^ == 0x5e pub const LED_INIT5: [u8; 6] = [0x5e, 0x05, 0x20, 0x31, 0, 0x08]; use serde_derive::{Deserialize, Serialize}; -use std::str::FromStr; +use std::{fmt::Display, str::FromStr}; #[cfg(feature = "dbus")] use zvariant::Type; @@ -171,6 +171,12 @@ pub enum AuraModeNum { Flash = 12, } +impl Display for AuraModeNum { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", <&str>::from(self)) + } +} + impl From for String { fn from(mode: AuraModeNum) -> Self { match mode { diff --git a/rog-control-center/src/app.rs b/rog-control-center/src/app.rs index 2845236b..8302ded3 100644 --- a/rog-control-center/src/app.rs +++ b/rog-control-center/src/app.rs @@ -55,8 +55,6 @@ impl RogApp { let oscillator_toggle = Arc::new(AtomicBool::new(false)); let oscillator_toggle1 = oscillator_toggle.clone(); - let states1 = states.clone(); - let supported1 = supported.clone(); std::thread::spawn(move || { let started = Instant::now(); let mut toggled = false; @@ -86,13 +84,6 @@ impl RogApp { oscillator1_2.store(tmp2, Ordering::SeqCst); oscillator1_3.store(tmp3, Ordering::SeqCst); - if let Ok(mut states) = states1.try_lock() { - states - .refresh_if_notfied(&supported1) - .map_err(|e| states.error = Some(e.to_string())) - .ok(); - } - std::thread::sleep(Duration::from_millis(33)); } }); diff --git a/rog-control-center/src/main.rs b/rog-control-center/src/main.rs index 2706b190..ceaa9b94 100644 --- a/rog-control-center/src/main.rs +++ b/rog-control-center/src/main.rs @@ -118,9 +118,7 @@ fn main() -> Result<()> { Err(_) => on_tmp_dir_exists().unwrap(), }; - let states = Arc::new(Mutex::new( - setup_page_state_and_notifs(layout, enabled_notifications, &supported).unwrap(), - )); + let states = setup_page_state_and_notifs(layout, enabled_notifications, &supported).unwrap(); init_tray(supported, states.clone()); @@ -156,11 +154,14 @@ fn setup_page_state_and_notifs( keyboard_layout: KeyLayout, enabled_notifications: Arc>, supported: &SupportedFunctions, -) -> Result { - let page_states = - PageDataStates::new(keyboard_layout, enabled_notifications.clone(), supported)?; +) -> Result>> { + let page_states = Arc::new(Mutex::new(PageDataStates::new( + keyboard_layout, + enabled_notifications.clone(), + supported, + )?)); - start_notifications(page_states.was_notified.clone(), enabled_notifications)?; + start_notifications(page_states.clone(), enabled_notifications)?; Ok(page_states) } diff --git a/rog-control-center/src/notify.rs b/rog-control-center/src/notify.rs index b5a29f79..817bd478 100644 --- a/rog-control-center/src/notify.rs +++ b/rog-control-center/src/notify.rs @@ -1,4 +1,4 @@ -use crate::{config::Config, error::Result}; +use crate::{config::Config, error::Result, page_states::PageDataStates}; use notify_rust::{Hint, Notification, NotificationHandle, Urgency}; use rog_dbus::{ zbus_anime::AnimeProxy, zbus_led::LedProxy, zbus_platform::RogBiosProxy, @@ -10,10 +10,7 @@ use serde::{Deserialize, Serialize}; use std::{ fmt::Display, process::Command, - sync::{ - atomic::{AtomicBool, Ordering}, - Arc, Mutex, - }, + sync::{Arc, Mutex}, }; use supergfxctl::{pci_device::GfxPower, zbus_proxy::DaemonProxy as SuperProxy}; use zbus::export::futures_util::{future, StreamExt}; @@ -65,18 +62,6 @@ impl EnabledNotifications { } } -/// Intended as a help to determine if daemon controllers notified state -#[derive(Debug, Default, Clone)] -pub struct WasNotified { - pub charge: Arc, - pub bios: Arc, - pub aura: Arc, - pub anime: Arc, - pub profiles: Arc, - pub fans: Arc, - pub gfx: Arc, -} - macro_rules! notify { ($notifier:expr, $last_notif:ident) => { if let Some(notif) = $last_notif.take() { @@ -92,16 +77,18 @@ macro_rules! notify { macro_rules! recv_notif { ($proxy:ident, $signal:ident, - $was_notified:ident, $last_notif:ident, $notif_enabled:ident, - [$($out_arg:ident)+], + $page_states:ident, + ($($args: tt)*), + ($($out_arg:tt)+), $msg:literal, $notifier:ident) => { + let last_notif = $last_notif.clone(); let notifs_enabled1 = $notif_enabled.clone(); - let notified = $was_notified.clone(); - // TODO: make a macro or generic function or something... + let page_states1 = $page_states.clone(); + tokio::spawn(async move { let conn = zbus::Connection::system().await.unwrap(); let proxy = $proxy::new(&conn).await.unwrap(); @@ -110,12 +97,15 @@ macro_rules! recv_notif { if let Ok(out) = e.args() { if let Ok(config) = notifs_enabled1.lock() { if config.all_enabled && config.$signal { - if let Ok(ref mut lock) = last_notif.try_lock() { - notify!($notifier($msg, &out$(.$out_arg)+()), lock); + if let Ok(ref mut lock) = last_notif.lock() { + notify!($notifier($msg, &out.$($out_arg)+()), lock); } } } - notified.store(true, Ordering::SeqCst); + if let Ok(mut lock) = page_states1.lock() { + lock.$($args)+ = *out.$($out_arg)+(); + lock.set_notified(); + } } } }; @@ -126,29 +116,20 @@ macro_rules! recv_notif { type SharedHandle = Arc>>; pub fn start_notifications( - was_notified: WasNotified, + page_states: Arc>, enabled_notifications: Arc>, ) -> Result<()> { let last_notification: SharedHandle = Arc::new(Mutex::new(None)); - let WasNotified { - bios: bios_notified, - charge: charge_notified, - profiles: profiles_notified, - aura: aura_notified, - anime: anime_notified, - gfx: gfx_notified, - .. - } = was_notified; - // BIOS notif recv_notif!( RogBiosProxy, receive_notify_post_boot_sound, - bios_notified, last_notification, enabled_notifications, - [on], + page_states, + (bios.post_sound), + (on), "BIOS Post sound", do_notification ); @@ -156,10 +137,11 @@ pub fn start_notifications( recv_notif!( RogBiosProxy, receive_notify_panel_od, - bios_notified, last_notification, enabled_notifications, - [overdrive], + page_states, + (bios.panel_overdrive), + (overdrive), "Panel Overdrive enabled:", do_notification ); @@ -167,10 +149,11 @@ pub fn start_notifications( recv_notif!( RogBiosProxy, receive_notify_dgpu_disable, - bios_notified, last_notification, enabled_notifications, - [disable], + page_states, + (bios.dgpu_disable), + (disable), "BIOS dGPU disabled", do_notification ); @@ -178,10 +161,11 @@ pub fn start_notifications( recv_notif!( RogBiosProxy, receive_notify_egpu_enable, - bios_notified, last_notification, enabled_notifications, - [enable], + page_states, + (bios.egpu_enable), + (enable), "BIOS eGPU enabled", do_notification ); @@ -189,10 +173,11 @@ pub fn start_notifications( recv_notif!( RogBiosProxy, receive_notify_gpu_mux_mode, - bios_notified, last_notification, enabled_notifications, - [mode], + page_states, + (bios.dedicated_gfx), + (mode), "Reboot required. BIOS GPU MUX mode set to", do_mux_notification ); @@ -201,10 +186,11 @@ pub fn start_notifications( recv_notif!( PowerProxy, receive_notify_charge_control_end_threshold, - charge_notified, last_notification, enabled_notifications, - [limit], + page_states, + (power_state.charge_limit), + (limit), "Battery charge limit changed to", do_notification ); @@ -212,10 +198,11 @@ pub fn start_notifications( recv_notif!( PowerProxy, receive_notify_mains_online, - bios_notified, last_notification, enabled_notifications, - [on], + page_states, + (power_state.ac_power), + (on), "AC Power power is", ac_power_notification ); @@ -224,10 +211,11 @@ pub fn start_notifications( recv_notif!( ProfileProxy, receive_notify_profile, - profiles_notified, last_notification, enabled_notifications, - [profile], + page_states, + (profiles.current), + (profile), "Profile changed to", do_thermal_notif ); @@ -237,32 +225,24 @@ pub fn start_notifications( recv_notif!( LedProxy, receive_notify_led, - aura_notified, last_notification, enabled_notifications, - [data mode_name], + page_states, + (aura.current_mode), + (data.mode), "Keyboard LED mode changed to", do_notification ); - tokio::spawn(async move { - let conn = zbus::Connection::system().await.unwrap(); - let proxy = LedProxy::new(&conn).await.unwrap(); - if let Ok(p) = proxy.receive_all_signals().await { - p.for_each(|_| { - aura_notified.store(true, Ordering::SeqCst); - future::ready(()) - }) - .await; - }; - }); - + let page_states1 = page_states.clone(); tokio::spawn(async move { let conn = zbus::Connection::system().await.unwrap(); let proxy = AnimeProxy::new(&conn).await.unwrap(); if let Ok(p) = proxy.receive_power_states().await { p.for_each(|_| { - anime_notified.store(true, Ordering::SeqCst); + if let Ok(_lock) = page_states1.lock() { + // TODO: lock.anime. + } future::ready(()) }) .await; @@ -272,10 +252,11 @@ pub fn start_notifications( recv_notif!( SuperProxy, receive_notify_gfx, - bios_notified, last_notification, enabled_notifications, - [mode], + page_states, + (gfx_state.mode), + (mode), "Gfx mode changed to", do_notification ); @@ -300,7 +281,6 @@ pub fn start_notifications( let action = out.action(); do_gfx_action_notif("Gfx mode change requires", &format!("{action:?}",)) .unwrap(); - bios_notified.store(true, Ordering::SeqCst); } } }; @@ -314,20 +294,23 @@ pub fn start_notifications( if let Ok(mut p) = proxy.receive_notify_gfx_status().await { while let Some(e) = p.next().await { if let Ok(out) = e.args() { - let status = out.status(); - if *status != GfxPower::Unknown { + let status = out.status; + if status != GfxPower::Unknown { if let Ok(config) = notifs_enabled1.lock() { if config.all_enabled && config.receive_notify_gfx_status { // Required check because status cycles through active/unknown/suspended - if let Ok(ref mut lock) = last_notif.try_lock() { + if let Ok(ref mut lock) = last_notif.lock() { notify!( - do_gpu_status_notif("dGPU status changed:", status), + do_gpu_status_notif("dGPU status changed:", &status), lock ); } } } - gfx_notified.store(true, Ordering::SeqCst); + if let Ok(mut lock) = page_states.lock() { + lock.gfx_state.power_status = status; + lock.set_notified(); + } } } } diff --git a/rog-control-center/src/page_states.rs b/rog-control-center/src/page_states.rs index 081fa2ff..1ad21f4c 100644 --- a/rog-control-center/src/page_states.rs +++ b/rog-control-center/src/page_states.rs @@ -1,6 +1,6 @@ use std::{ collections::{BTreeMap, HashSet}, - sync::{atomic::Ordering, Arc, Mutex}, + sync::{Arc, Mutex}, }; use egui::Vec2; @@ -12,11 +12,7 @@ use supergfxctl::{ zbus_proxy::DaemonProxyBlocking as GfxProxyBlocking, }; -use crate::{ - error::Result, - notify::{EnabledNotifications, WasNotified}, - RogDbusClientBlocking, -}; +use crate::{error::Result, notify::EnabledNotifications, RogDbusClientBlocking}; #[derive(Clone, Debug)] pub struct BiosState { @@ -236,10 +232,24 @@ impl GfxState { } } +#[derive(Clone, Debug)] +pub struct PowerState { + pub charge_limit: u8, + pub ac_power: bool, +} + +impl PowerState { + pub fn new(_supported: &SupportedFunctions, dbus: &RogDbusClientBlocking) -> Result { + Ok(Self { + charge_limit: dbus.proxies().charge().charge_control_end_threshold()?, + ac_power: dbus.proxies().charge().mains_online()?, + }) + } +} + pub struct PageDataStates { pub keyboard_layout: KeyLayout, pub enabled_notifications: Arc>, - pub was_notified: WasNotified, /// Because much of the app state here is the same as `RogBiosSupportedFunctions` /// we can re-use that structure. pub bios: BiosState, @@ -248,7 +258,7 @@ pub struct PageDataStates { pub profiles: ProfilesState, pub fan_curves: FanCurvesState, pub gfx_state: GfxState, - pub charge_limit: u8, + pub power_state: PowerState, pub error: Option, /// Specific field for the tray only so that we can know when it does need update. /// The tray should set this to false when done. @@ -270,11 +280,7 @@ impl PageDataStates { Ok(Self { keyboard_layout, enabled_notifications, - was_notified: WasNotified::default(), - charge_limit: asus_dbus - .proxies() - .charge() - .charge_control_end_threshold()?, + power_state: PowerState::new(supported, &asus_dbus)?, bios: BiosState::new(supported, &asus_dbus)?, aura: AuraState::new(supported, &asus_dbus)?, anime: AnimeState::new(supported, &asus_dbus)?, @@ -289,61 +295,9 @@ impl PageDataStates { }) } - pub fn refresh_if_notfied(&mut self, supported: &SupportedFunctions) -> Result { - let mut notified = false; - if self.was_notified.charge.load(Ordering::SeqCst) { - self.charge_limit = self - .asus_dbus - .proxies() - .charge() - .charge_control_end_threshold()?; - self.was_notified.charge.store(false, Ordering::SeqCst); - notified = true; - self.tray_should_update = true; - self.app_should_update = true; - } - - if self.was_notified.aura.load(Ordering::SeqCst) { - self.aura = AuraState::new(supported, &self.asus_dbus)?; - self.was_notified.aura.store(false, Ordering::SeqCst); - notified = true; - self.tray_should_update = true; - self.app_should_update = true; - } - - if self.was_notified.bios.load(Ordering::SeqCst) { - self.bios = BiosState::new(supported, &self.asus_dbus)?; - self.was_notified.bios.store(false, Ordering::SeqCst); - notified = true; - self.tray_should_update = true; - self.app_should_update = true; - } - - if self.was_notified.profiles.load(Ordering::SeqCst) { - self.profiles = ProfilesState::new(supported, &self.asus_dbus)?; - self.was_notified.profiles.store(false, Ordering::SeqCst); - notified = true; - self.tray_should_update = true; - self.app_should_update = true; - } - - if self.was_notified.fans.load(Ordering::SeqCst) { - self.fan_curves = FanCurvesState::new(supported, &self.asus_dbus)?; - self.was_notified.fans.store(false, Ordering::SeqCst); - notified = true; - self.tray_should_update = true; - self.app_should_update = true; - } - - if self.was_notified.gfx.load(Ordering::SeqCst) { - self.gfx_state = GfxState::new(supported, &self.gfx_dbus)?; - self.was_notified.gfx.store(false, Ordering::SeqCst); - notified = true; - self.tray_should_update = true; - self.app_should_update = true; - } - - Ok(notified) + pub fn set_notified(&mut self) { + self.tray_should_update = true; + self.app_should_update = true; } } @@ -355,7 +309,6 @@ impl Default for PageDataStates { Self { keyboard_layout: KeyLayout::ga401_layout(), enabled_notifications: Default::default(), - was_notified: WasNotified::default(), bios: BiosState { post_sound: Default::default(), dedicated_gfx: GpuMode::NotSupported, @@ -397,7 +350,10 @@ impl Default for PageDataStates { mode: GfxMode::None, power_status: GfxPower::Unknown, }, - charge_limit: Default::default(), + power_state: PowerState { + charge_limit: 99, + ac_power: false, + }, error: Default::default(), tray_should_update: true, app_should_update: true, diff --git a/rog-control-center/src/tray.rs b/rog-control-center/src/tray.rs index d3db30d9..b3947848 100644 --- a/rog-control-center/src/tray.rs +++ b/rog-control-center/src/tray.rs @@ -299,7 +299,7 @@ pub fn init_tray( tray.rebuild_and_update( &supported, lock.gfx_state.mode, - lock.charge_limit, + lock.power_state.charge_limit, lock.bios.panel_overdrive, ); lock.tray_should_update = false; diff --git a/rog-control-center/src/widgets/rog_bios.rs b/rog-control-center/src/widgets/rog_bios.rs index 66e1ef8d..584a3d94 100644 --- a/rog-control-center/src/widgets/rog_bios.rs +++ b/rog-control-center/src/widgets/rog_bios.rs @@ -38,7 +38,7 @@ pub fn platform_profile(states: &mut PageDataStates, ui: &mut Ui) { pub fn rog_bios_group(supported: &SupportedFunctions, states: &mut PageDataStates, ui: &mut Ui) { ui.heading("Bios options"); - let slider = egui::Slider::new(&mut states.charge_limit, 20..=100) + let slider = egui::Slider::new(&mut states.power_state.charge_limit, 20..=100) .text("Charging limit") .step_by(1.0); if ui.add(slider).drag_released() { @@ -46,7 +46,7 @@ pub fn rog_bios_group(supported: &SupportedFunctions, states: &mut PageDataState .asus_dbus .proxies() .charge() - .set_charge_control_end_threshold(states.charge_limit as u8) + .set_charge_control_end_threshold(states.power_state.charge_limit as u8) .map_err(|err| { states.error = Some(err.to_string()); })