From 4701c019a8346c7e319569445f285e2b2bbd3a73 Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Fri, 5 Apr 2024 20:19:07 +1300 Subject: [PATCH] Major cleanup of older gui state code --- asusctl/examples/anime-diag-png.rs | 12 +- asusctl/examples/anime-diag.rs | 10 +- asusctl/examples/anime-gif.rs | 12 +- asusctl/examples/anime-grid.rs | 9 +- asusctl/examples/anime-outline.rs | 8 +- asusctl/examples/anime-png.rs | 12 +- asusctl/examples/anime-spinning.rs | 12 +- asusctl/examples/aura-zoned-breathe.rs | 8 +- asusctl/src/main.rs | 142 +++---- asusd-user/src/ctrl_anime.rs | 22 +- asusd-user/src/daemon.rs | 43 +- asusd/src/ctrl_fancurves.rs | 16 +- asusd/src/ctrl_platform.rs | 3 +- rog-aura/src/lib.rs | 4 + rog-control-center/src/lib.rs | 10 - rog-control-center/src/main.rs | 51 +-- rog-control-center/src/system_state.rs | 373 +----------------- rog-control-center/src/tray.rs | 13 +- rog-control-center/src/update_and_notify.rs | 262 +----------- .../translations/en/rog-control-center.po | 2 +- rog-dbus/src/lib.rs | 120 ------ rog-dbus/src/zbus_platform.rs | 3 + rog-platform/src/platform.rs | 33 +- rog-profiles/src/lib.rs | 6 +- 24 files changed, 238 insertions(+), 948 deletions(-) diff --git a/asusctl/examples/anime-diag-png.rs b/asusctl/examples/anime-diag-png.rs index 456d62bf..b4285601 100644 --- a/asusctl/examples/anime-diag-png.rs +++ b/asusctl/examples/anime-diag-png.rs @@ -5,10 +5,12 @@ use std::process::exit; use rog_anime::usb::get_anime_type; use rog_anime::{AnimeDiagonal, AnimeType}; -use rog_dbus::RogDbusClientBlocking; +use rog_dbus::zbus_anime::AnimeProxyBlocking; +use zbus::blocking::Connection; fn main() -> Result<(), Box> { - let (client, _) = RogDbusClientBlocking::new().unwrap(); + let conn = Connection::system().unwrap(); + let proxy = AnimeProxyBlocking::new(&conn).unwrap(); let args: Vec = env::args().collect(); if args.len() != 3 { @@ -26,11 +28,7 @@ fn main() -> Result<(), Box> { let anime_type = get_anime_type()?; - client - .proxies() - .anime() - .write(matrix.into_data_buffer(anime_type)?) - .unwrap(); + proxy.write(matrix.into_data_buffer(anime_type)?).unwrap(); Ok(()) } diff --git a/asusctl/examples/anime-diag.rs b/asusctl/examples/anime-diag.rs index 874689d8..21cc1722 100644 --- a/asusctl/examples/anime-diag.rs +++ b/asusctl/examples/anime-diag.rs @@ -3,7 +3,8 @@ use std::time::Duration; use rog_anime::usb::get_anime_type; use rog_anime::{AnimeDiagonal, AnimeType}; -use rog_dbus::RogDbusClientBlocking; +use rog_dbus::zbus_anime::AnimeProxyBlocking; +use zbus::blocking::Connection; // In usable data: // Top row start at 1, ends at 32 @@ -11,7 +12,8 @@ use rog_dbus::RogDbusClientBlocking; // 74w x 36h diagonal used by the windows app fn main() { - let (client, _) = RogDbusClientBlocking::new().unwrap(); + let conn = Connection::system().unwrap(); + let proxy = AnimeProxyBlocking::new(&conn).unwrap(); for step in (2..50).rev() { let mut matrix = AnimeDiagonal::new(AnimeType::GA401, None); @@ -28,9 +30,7 @@ fn main() { } let anime_type = get_anime_type().unwrap(); - client - .proxies() - .anime() + proxy .write(matrix.into_data_buffer(anime_type).unwrap()) .unwrap(); sleep(Duration::from_millis(300)); diff --git a/asusctl/examples/anime-gif.rs b/asusctl/examples/anime-gif.rs index 994ef70b..044b35ba 100644 --- a/asusctl/examples/anime-gif.rs +++ b/asusctl/examples/anime-gif.rs @@ -4,10 +4,12 @@ use std::thread::sleep; use rog_anime::usb::get_anime_type; use rog_anime::{ActionData, ActionLoader, Sequences}; -use rog_dbus::RogDbusClientBlocking; +use rog_dbus::zbus_anime::AnimeProxyBlocking; +use zbus::blocking::Connection; fn main() { - let (client, _) = RogDbusClientBlocking::new().unwrap(); + let conn = Connection::system().unwrap(); + let proxy = AnimeProxyBlocking::new(&conn).unwrap(); let args: Vec = env::args().collect(); if args.len() != 3 { @@ -33,11 +35,7 @@ fn main() { for action in seq.iter() { if let ActionData::Animation(frames) = action { for frame in frames.frames() { - client - .proxies() - .anime() - .write(frame.frame().clone()) - .unwrap(); + proxy.write(frame.frame().clone()).unwrap(); sleep(frame.delay()); } } diff --git a/asusctl/examples/anime-grid.rs b/asusctl/examples/anime-grid.rs index b66f8529..83def5ea 100644 --- a/asusctl/examples/anime-grid.rs +++ b/asusctl/examples/anime-grid.rs @@ -2,7 +2,8 @@ use std::convert::TryFrom; use rog_anime::usb::get_anime_type; use rog_anime::{AnimeDataBuffer, AnimeGrid}; -use rog_dbus::RogDbusClientBlocking; +use rog_dbus::zbus_anime::AnimeProxyBlocking; +use zbus::blocking::Connection; // In usable data: // Top row start at 1, ends at 32 @@ -10,7 +11,9 @@ use rog_dbus::RogDbusClientBlocking; // 74w x 36h diagonal used by the windows app fn main() { - let (client, _) = RogDbusClientBlocking::new().unwrap(); + let conn = Connection::system().unwrap(); + let proxy = AnimeProxyBlocking::new(&conn).unwrap(); + let anime_type = get_anime_type().unwrap(); let mut matrix = AnimeGrid::new(anime_type); let tmp = matrix.get_mut(); @@ -43,5 +46,5 @@ fn main() { let matrix = ::try_from(matrix).unwrap(); - client.proxies().anime().write(matrix).unwrap(); + proxy.write(matrix).unwrap(); } diff --git a/asusctl/examples/anime-outline.rs b/asusctl/examples/anime-outline.rs index 981a736d..140427a6 100644 --- a/asusctl/examples/anime-outline.rs +++ b/asusctl/examples/anime-outline.rs @@ -1,12 +1,14 @@ use rog_anime::usb::get_anime_type; use rog_anime::AnimeDataBuffer; -use rog_dbus::RogDbusClientBlocking; +use rog_dbus::zbus_anime::AnimeProxyBlocking; +use zbus::blocking::Connection; // In usable data: // Top row start at 1, ends at 32 fn main() { - let (client, _) = RogDbusClientBlocking::new().unwrap(); + let conn = Connection::system().unwrap(); + let proxy = AnimeProxyBlocking::new(&conn).unwrap(); let anime_type = get_anime_type().unwrap(); let mut matrix = AnimeDataBuffer::new(anime_type); matrix.data_mut()[1] = 100; // start = 1 @@ -127,5 +129,5 @@ fn main() { matrix.data_mut()[1244] = 100; // end println!("{:?}", &matrix); - client.proxies().anime().write(matrix).unwrap(); + proxy.write(matrix).unwrap(); } diff --git a/asusctl/examples/anime-png.rs b/asusctl/examples/anime-png.rs index aa874631..add92456 100644 --- a/asusctl/examples/anime-png.rs +++ b/asusctl/examples/anime-png.rs @@ -6,10 +6,12 @@ use std::process::exit; use rog_anime::usb::get_anime_type; use rog_anime::{AnimeDataBuffer, AnimeImage, Vec2}; -use rog_dbus::RogDbusClientBlocking; +use rog_dbus::zbus_anime::AnimeProxyBlocking; +use zbus::blocking::Connection; fn main() -> Result<(), Box> { - let (client, _) = RogDbusClientBlocking::new().unwrap(); + let conn = Connection::system().unwrap(); + let proxy = AnimeProxyBlocking::new(&conn).unwrap(); let args: Vec = env::args().collect(); if args.len() != 7 { @@ -31,11 +33,7 @@ fn main() -> Result<(), Box> { anime_type, )?; - client - .proxies() - .anime() - .write(::try_from(&matrix)?) - .unwrap(); + proxy.write(::try_from(&matrix)?).unwrap(); Ok(()) } diff --git a/asusctl/examples/anime-spinning.rs b/asusctl/examples/anime-spinning.rs index b40a61db..611e7db2 100644 --- a/asusctl/examples/anime-spinning.rs +++ b/asusctl/examples/anime-spinning.rs @@ -9,10 +9,12 @@ use std::time::Duration; use rog_anime::usb::get_anime_type; use rog_anime::{AnimeDataBuffer, AnimeImage, Vec2}; -use rog_dbus::RogDbusClientBlocking; +use rog_dbus::zbus_anime::AnimeProxyBlocking; +use zbus::blocking::Connection; fn main() -> Result<(), Box> { - let (client, _) = RogDbusClientBlocking::new().unwrap(); + let conn = Connection::system().unwrap(); + let proxy = AnimeProxyBlocking::new(&conn).unwrap(); let args: Vec = env::args().collect(); if args.len() != 7 { @@ -41,11 +43,7 @@ fn main() -> Result<(), Box> { } matrix.update(); - client - .proxies() - .anime() - .write(::try_from(&matrix)?) - .unwrap(); + proxy.write(::try_from(&matrix)?).unwrap(); sleep(Duration::from_micros(500)); } } diff --git a/asusctl/examples/aura-zoned-breathe.rs b/asusctl/examples/aura-zoned-breathe.rs index c0c27907..dbbf1f25 100644 --- a/asusctl/examples/aura-zoned-breathe.rs +++ b/asusctl/examples/aura-zoned-breathe.rs @@ -5,12 +5,14 @@ use rog_aura::advanced::LedCode; use rog_aura::effects::{AdvancedEffects, Effect}; use rog_aura::layouts::KeyLayout; use rog_aura::Colour; -use rog_dbus::RogDbusClientBlocking; +use rog_dbus::zbus_aura::AuraProxyBlocking; +use zbus::blocking::Connection; fn main() -> Result<(), Box> { let layout = KeyLayout::default_layout(); - let (client, _) = RogDbusClientBlocking::new().unwrap(); + let conn = Connection::system().unwrap(); + let proxy = AuraProxyBlocking::new(&conn).unwrap(); let mut seq = AdvancedEffects::new(true); @@ -62,7 +64,7 @@ fn main() -> Result<(), Box> { seq.next_state(&layout); let packets = seq.create_packets(); - client.proxies().aura().direct_addressing_raw(packets)?; + proxy.direct_addressing_raw(packets)?; std::thread::sleep(std::time::Duration::from_millis(33)); } } diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index 3d72cb51..596a650a 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -15,10 +15,13 @@ use rog_anime::{AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, use rog_aura::power::KbAuraPowerState; use rog_aura::usb::{AuraDevRog1, AuraDevTuf, AuraDevice, AuraPowerDev}; use rog_aura::{self, AuraEffect}; +use rog_dbus::zbus_anime::AnimeProxyBlocking; use rog_dbus::zbus_aura::AuraProxyBlocking; -use rog_dbus::RogDbusClientBlocking; +use rog_dbus::zbus_fan_curves::FanCurvesProxyBlocking; +use rog_dbus::zbus_platform::PlatformProxyBlocking; use rog_platform::platform::{GpuMode, Properties, ThrottlePolicy}; use rog_profiles::error::ProfileError; +use zbus::blocking::Connection; use crate::aura_cli::{AuraPowerStates, LedBrightness}; use crate::cli_opts::*; @@ -44,13 +47,21 @@ fn main() { } }; - if let Ok((dbus, _)) = RogDbusClientBlocking::new().map_err(|e| { + let conn = Connection::system().unwrap(); + if let Ok(platform_proxy) = PlatformProxyBlocking::new(&conn).map_err(|e| { check_service("asusd"); println!("\nError: {e}\n"); print_info(); }) { - let supported_properties = dbus.proxies().platform().supported_properties().unwrap(); - let supported_interfaces = dbus.proxies().platform().supported_interfaces().unwrap(); + let self_version = env!("CARGO_PKG_VERSION"); + let asusd_version = platform_proxy.version().unwrap(); + if asusd_version != self_version { + println!("Version mismatch: asusctl = {self_version}, asusd = {asusd_version}"); + return; + } + + let supported_properties = platform_proxy.supported_properties().unwrap(); + let supported_interfaces = platform_proxy.supported_interfaces().unwrap(); if parsed.version { println!("asusctl v{}", env!("CARGO_PKG_VERSION")); @@ -58,7 +69,7 @@ fn main() { print_info(); } - if let Err(err) = do_parsed(&parsed, &supported_interfaces, &supported_properties, &dbus) { + if let Err(err) = do_parsed(&parsed, &supported_interfaces, &supported_properties, conn) { print_error_help(&*err, &supported_interfaces, &supported_properties); } } @@ -143,19 +154,23 @@ fn do_parsed( parsed: &CliStart, supported_interfaces: &[String], supported_properties: &[Properties], - dbus: &RogDbusClientBlocking<'_>, + conn: Connection, ) -> Result<(), Box> { match &parsed.command { Some(CliCommand::LedMode(mode)) => handle_led_mode(&find_aura_iface()?, mode)?, Some(CliCommand::LedPow1(pow)) => handle_led_power1(&find_aura_iface()?, pow)?, Some(CliCommand::LedPow2(pow)) => handle_led_power2(&find_aura_iface()?, pow)?, - Some(CliCommand::Profile(cmd)) => handle_throttle_profile(dbus, supported_properties, cmd)?, + Some(CliCommand::Profile(cmd)) => { + handle_throttle_profile(&conn, supported_properties, cmd)? + } Some(CliCommand::FanCurve(cmd)) => { - handle_fan_curve(dbus, supported_interfaces, cmd)?; + handle_fan_curve(&conn, supported_interfaces, cmd)?; } Some(CliCommand::Graphics(_)) => do_gfx(), - Some(CliCommand::Anime(cmd)) => handle_anime(dbus, cmd)?, - Some(CliCommand::Bios(cmd)) => handle_platform_properties(dbus, supported_properties, cmd)?, + Some(CliCommand::Anime(cmd)) => handle_anime(&conn, cmd)?, + Some(CliCommand::Bios(cmd)) => { + handle_platform_properties(&conn, supported_properties, cmd)? + } None => { if (!parsed.show_supported && parsed.kbd_bright.is_none() @@ -261,9 +276,8 @@ fn do_parsed( } if let Some(chg_limit) = parsed.chg_limit { - dbus.proxies() - .platform() - .set_charge_control_end_threshold(chg_limit)?; + let proxy = PlatformProxyBlocking::new(&conn)?; + proxy.set_charge_control_end_threshold(chg_limit)?; } Ok(()) @@ -277,10 +291,7 @@ fn do_gfx() { println!("This command will be removed in future"); } -fn handle_anime( - dbus: &RogDbusClientBlocking<'_>, - cmd: &AnimeCommand, -) -> Result<(), Box> { +fn handle_anime(conn: &Connection, cmd: &AnimeCommand) -> Result<(), Box> { if (cmd.command.is_none() && cmd.enable_display.is_none() && cmd.enable_powersave_anim.is_none() @@ -297,23 +308,24 @@ fn handle_anime( println!("\n{}", lst); } } + let proxy = AnimeProxyBlocking::new(conn)?; if let Some(enable) = cmd.enable_display { - dbus.proxies().anime().set_enable_display(enable)?; + proxy.set_enable_display(enable)?; } if let Some(enable) = cmd.enable_powersave_anim { - dbus.proxies().anime().set_builtins_enabled(enable)?; + proxy.set_builtins_enabled(enable)?; } if let Some(bright) = cmd.brightness { - dbus.proxies().anime().set_brightness(bright)?; + proxy.set_brightness(bright)?; } if let Some(enable) = cmd.off_when_lid_closed { - dbus.proxies().anime().set_off_when_lid_closed(enable)?; + proxy.set_off_when_lid_closed(enable)?; } if let Some(enable) = cmd.off_when_suspended { - dbus.proxies().anime().set_off_when_suspended(enable)?; + proxy.set_off_when_suspended(enable)?; } if let Some(enable) = cmd.off_when_unplugged { - dbus.proxies().anime().set_off_when_unplugged(enable)?; + proxy.set_off_when_unplugged(enable)?; } if cmd.off_with_his_head.is_some() { println!("Did Alice _really_ make it back from Wonderland?"); @@ -329,7 +341,7 @@ fn handle_anime( if cmd.clear { let data = vec![255u8; anime_type.data_length()]; let tmp = AnimeDataBuffer::from_vec(anime_type, data)?; - dbus.proxies().anime().write(tmp)?; + proxy.write(tmp)?; } if let Some(action) = cmd.command.as_ref() { @@ -353,9 +365,7 @@ fn handle_anime( anime_type, )?; - dbus.proxies() - .anime() - .write(::try_from(&matrix)?)?; + proxy.write(::try_from(&matrix)?)?; } AnimeActions::PixelImage(image) => { if image.help_requested() || image.path.is_empty() { @@ -374,9 +384,7 @@ fn handle_anime( anime_type, )?; - dbus.proxies() - .anime() - .write(matrix.into_data_buffer(anime_type)?)?; + proxy.write(matrix.into_data_buffer(anime_type)?)?; } AnimeActions::Gif(gif) => { if gif.help_requested() || gif.path.is_empty() { @@ -401,7 +409,7 @@ fn handle_anime( let mut loops = gif.loops as i32; loop { for frame in matrix.frames() { - dbus.proxies().anime().write(frame.frame().clone())?; + proxy.write(frame.frame().clone())?; sleep(frame.delay()); } if loops >= 0 { @@ -432,7 +440,7 @@ fn handle_anime( let mut loops = gif.loops as i32; loop { for frame in matrix.frames() { - dbus.proxies().anime().write(frame.frame().clone())?; + proxy.write(frame.frame().clone())?; sleep(frame.delay()); } if loops >= 0 { @@ -453,14 +461,12 @@ fn handle_anime( return Ok(()); } - dbus.proxies() - .anime() - .set_builtin_animations(rog_anime::Animations { - boot: builtins.boot, - awake: builtins.awake, - sleep: builtins.sleep, - shutdown: builtins.shutdown, - })?; + proxy.set_builtin_animations(rog_anime::Animations { + boot: builtins.boot, + awake: builtins.awake, + sleep: builtins.sleep, + shutdown: builtins.shutdown, + })?; } } } @@ -716,7 +722,7 @@ fn handle_led_power2( } fn handle_throttle_profile( - dbus: &RogDbusClientBlocking<'_>, + conn: &Connection, supported: &[Properties], cmd: &ProfileCommand, ) -> Result<(), Box> { @@ -736,16 +742,14 @@ fn handle_throttle_profile( } return Ok(()); } - let current = dbus.proxies().platform().throttle_thermal_policy()?; + + let proxy = PlatformProxyBlocking::new(conn)?; + let current = proxy.throttle_thermal_policy()?; if cmd.next { - dbus.proxies() - .platform() - .set_throttle_thermal_policy(current.next())?; + proxy.set_throttle_thermal_policy(current.next())?; } else if let Some(profile) = cmd.profile_set { - dbus.proxies() - .platform() - .set_throttle_thermal_policy(profile)?; + proxy.set_throttle_thermal_policy(profile)?; } if cmd.list { @@ -763,7 +767,7 @@ fn handle_throttle_profile( } fn handle_fan_curve( - dbus: &RogDbusClientBlocking<'_>, + conn: &Connection, supported: &[String], cmd: &FanCurveCommand, ) -> Result<(), Box> { @@ -794,37 +798,35 @@ fn handle_fan_curve( return Ok(()); } + let plat_proxy = PlatformProxyBlocking::new(conn)?; + let fan_proxy = FanCurvesProxyBlocking::new(conn)?; if cmd.get_enabled { - let profile = dbus.proxies().platform().throttle_thermal_policy()?; - let curves = dbus.proxies().fan_curves().fan_curve_data(profile)?; + let profile = plat_proxy.throttle_thermal_policy()?; + let curves = fan_proxy.fan_curve_data(profile)?; for curve in curves.iter() { println!("{}", String::from(curve)); } } if cmd.default { - let active = dbus.proxies().platform().throttle_thermal_policy()?; - dbus.proxies().fan_curves().set_curves_to_defaults(active)?; + let active = plat_proxy.throttle_thermal_policy()?; + fan_proxy.set_curves_to_defaults(active)?; } if let Some(profile) = cmd.mod_profile { if cmd.enable_fan_curves.is_none() && cmd.data.is_none() { - let data = dbus.proxies().fan_curves().fan_curve_data(profile)?; + let data = fan_proxy.fan_curve_data(profile)?; let data = toml::to_string(&data)?; println!("\nFan curves for {:?}\n\n{}", profile, data); } if let Some(enabled) = cmd.enable_fan_curves { - dbus.proxies() - .fan_curves() - .set_fan_curves_enabled(profile, enabled)?; + fan_proxy.set_fan_curves_enabled(profile, enabled)?; } if let Some(enabled) = cmd.enable_fan_curve { if let Some(fan) = cmd.fan { - dbus.proxies() - .fan_curves() - .set_profile_fan_curve_enabled(profile, fan, enabled)?; + fan_proxy.set_profile_fan_curve_enabled(profile, fan, enabled)?; } else { println!( "--enable-fan-curves, --enable-fan-curve, --fan, and --data options require \ @@ -836,7 +838,7 @@ fn handle_fan_curve( if let Some(mut curve) = cmd.data.clone() { let fan = cmd.fan.unwrap_or_default(); curve.set_fan(fan); - dbus.proxies().fan_curves().set_fan_curve(profile, curve)?; + fan_proxy.set_fan_curve(profile, curve)?; } } @@ -844,7 +846,7 @@ fn handle_fan_curve( } fn handle_platform_properties( - dbus: &RogDbusClientBlocking<'_>, + conn: &Connection, supported: &[Properties], cmd: &BiosCommand, ) -> Result<(), Box> { @@ -870,34 +872,34 @@ fn handle_platform_properties( } } + let proxy = PlatformProxyBlocking::new(conn)?; + if let Some(opt) = cmd.post_sound_set { - dbus.proxies().platform().set_boot_sound(opt)?; + proxy.set_boot_sound(opt)?; } if cmd.post_sound_get { - let res = dbus.proxies().platform().boot_sound()?; + let res = proxy.boot_sound()?; println!("Bios POST sound on: {}", res); } if let Some(opt) = cmd.gpu_mux_mode_set { println!("Rebuilding initrd to include drivers"); - dbus.proxies() - .platform() - .set_gpu_mux_mode(GpuMode::from_mux(opt))?; + proxy.set_gpu_mux_mode(GpuMode::from_mux(opt))?; println!( "The mode change is not active until you reboot, on boot the bios will make the \ required change" ); } if cmd.gpu_mux_mode_get { - let res = dbus.proxies().platform().gpu_mux_mode()?; + let res = proxy.gpu_mux_mode()?; println!("Bios GPU MUX: {:?}", res); } if let Some(opt) = cmd.panel_overdrive_set { - dbus.proxies().platform().set_panel_od(opt)?; + proxy.set_panel_od(opt)?; } if cmd.panel_overdrive_get { - let res = dbus.proxies().platform().panel_od()?; + let res = proxy.panel_od()?; println!("Panel overdrive on: {}", res); } } diff --git a/asusd-user/src/ctrl_anime.rs b/asusd-user/src/ctrl_anime.rs index 7966b396..c5097a43 100644 --- a/asusd-user/src/ctrl_anime.rs +++ b/asusd-user/src/ctrl_anime.rs @@ -7,7 +7,7 @@ use std::time::{Duration, Instant}; use config_traits::StdConfig; use rog_anime::error::AnimeError; use rog_anime::{ActionData, ActionLoader, AnimTime, Fade, Sequences, Vec2}; -use rog_dbus::RogDbusClientBlocking; +use rog_dbus::zbus_anime::AnimeProxyBlocking; use serde_derive::{Deserialize, Serialize}; use zbus::interface; use zbus::zvariant::{ObjectPath, Type}; @@ -61,14 +61,14 @@ pub enum TimeType { /// thread and a zbus server behind `Arc>` pub struct CtrlAnimeInner<'a> { sequences: Sequences, - client: RogDbusClientBlocking<'a>, + client: AnimeProxyBlocking<'a>, do_early_return: Arc, } impl<'a> CtrlAnimeInner<'static> { pub fn new( sequences: Sequences, - client: RogDbusClientBlocking<'static>, + client: AnimeProxyBlocking<'static>, do_early_return: Arc, ) -> Result { Ok(Self { @@ -93,19 +93,13 @@ impl<'a> CtrlAnimeInner<'static> { return Ok(true); // Do safe exit } self.client - .proxies() - .anime() .write(output) .map_err(|e| AnimeError::Dbus(format!("{}", e))) .map(|_| false) }); } ActionData::Image(image) => { - self.client - .proxies() - .anime() - .write(image.as_ref().clone()) - .ok(); + self.client.write(image.as_ref().clone()).ok(); } ActionData::Pause(duration) => { let start = Instant::now(); @@ -132,7 +126,7 @@ impl<'a> CtrlAnimeInner<'static> { pub struct CtrlAnime<'a> { config: Arc>, - client: RogDbusClientBlocking<'a>, + client: AnimeProxyBlocking<'a>, inner: Arc>>, /// Must be the same Atomic as in CtrlAnimeInner inner_early_return: Arc, @@ -142,7 +136,7 @@ impl CtrlAnime<'static> { pub fn new( config: Arc>, inner: Arc>>, - client: RogDbusClientBlocking<'static>, + client: AnimeProxyBlocking<'static>, inner_early_return: Arc, ) -> Result { Ok(CtrlAnime { @@ -356,13 +350,13 @@ impl CtrlAnime<'static> { pub fn set_state(&mut self, on: bool) -> zbus::fdo::Result<()> { // Operations here need to be in specific order if on { - self.client.proxies().anime().set_enable_display(on).ok(); + self.client.set_enable_display(on).ok(); // Let the inner loop run self.inner_early_return.store(false, Ordering::SeqCst); } else { // Must make the inner run loop return early self.inner_early_return.store(true, Ordering::SeqCst); - self.client.proxies().anime().set_enable_display(on).ok(); + self.client.set_enable_display(on).ok(); } Ok(()) } diff --git a/asusd-user/src/daemon.rs b/asusd-user/src/daemon.rs index fae00c73..87622b14 100644 --- a/asusd-user/src/daemon.rs +++ b/asusd-user/src/daemon.rs @@ -9,7 +9,10 @@ use config_traits::{StdConfig, StdConfigLoad}; use rog_anime::usb::get_anime_type; use rog_aura::aura_detection::LaptopLedData; use rog_aura::layouts::KeyLayout; -use rog_dbus::{RogDbusClientBlocking, DBUS_NAME}; +use rog_dbus::zbus_anime::AnimeProxyBlocking; +use rog_dbus::zbus_aura::AuraProxyBlocking; +use rog_dbus::zbus_platform::PlatformProxyBlocking; +use rog_dbus::DBUS_NAME; use smol::Executor; use zbus::Connection; @@ -32,10 +35,10 @@ fn main() -> Result<(), Box> { println!(" rog-dbus v{}", rog_dbus::VERSION); println!("rog-platform v{}", rog_platform::VERSION); - let (client, _) = RogDbusClientBlocking::new()?; - let supported = client - .proxies() - .platform() + let conn = zbus::blocking::Connection::system().unwrap(); + let platform_proxy = PlatformProxyBlocking::new(&conn).unwrap(); + + let supported = platform_proxy .supported_interfaces() .unwrap_or_default() .contains(&"Anime".to_string()); @@ -51,6 +54,7 @@ fn main() -> Result<(), Box> { let anime = anime_config.create(anime_type)?; let anime_config = Arc::new(Mutex::new(anime_config)); + let anime_proxy_blocking = AnimeProxyBlocking::new(&conn).unwrap(); executor .spawn(async move { // Create server @@ -59,12 +63,21 @@ fn main() -> Result<(), Box> { // Inner behind mutex required for thread safety let inner = Arc::new(Mutex::new( - CtrlAnimeInner::new(anime, client, early_return.clone()).unwrap(), + CtrlAnimeInner::new( + anime, + anime_proxy_blocking.clone(), + early_return.clone(), + ) + .unwrap(), )); // Need new client object for dbus control part - let (client, _) = RogDbusClientBlocking::new().unwrap(); - let anime_control = - CtrlAnime::new(anime_config, inner.clone(), client, early_return).unwrap(); + let anime_control = CtrlAnime::new( + anime_config, + inner.clone(), + anime_proxy_blocking, + early_return, + ) + .unwrap(); anime_control.add_to_server(&mut connection).await; loop { if let Ok(inner) = inner.clone().try_lock() { @@ -89,22 +102,14 @@ fn main() -> Result<(), Box> { }) .unwrap_or_else(|_| KeyLayout::default_layout()); + let aura_proxy_blocking = AuraProxyBlocking::new(&conn).unwrap(); executor .spawn(async move { - // Create server - let (client, _) = RogDbusClientBlocking::new().unwrap(); - // let connection = Connection::session().await.unwrap(); - // connection.request_name(DBUS_NAME).await.unwrap(); - loop { aura_config.aura.next_state(&layout); let packets = aura_config.aura.create_packets(); - client - .proxies() - .aura() - .direct_addressing_raw(packets) - .unwrap(); + aura_proxy_blocking.direct_addressing_raw(packets).unwrap(); std::thread::sleep(std::time::Duration::from_millis(33)); } }) diff --git a/asusd/src/ctrl_fancurves.rs b/asusd/src/ctrl_fancurves.rs index 4bb3b571..21ceb335 100644 --- a/asusd/src/ctrl_fancurves.rs +++ b/asusd/src/ctrl_fancurves.rs @@ -274,19 +274,13 @@ impl crate::Reloadable for CtrlFanCurveZbus { /// Fetch the active profile and use that to set all related components up async fn reload(&mut self) -> Result<(), RogError> { let active = self.platform.get_throttle_thermal_policy()?.into(); + let mut config = self.config.lock().await; if let Ok(mut device) = find_fan_curve_node() { - // There is a possibility that the curve was default zeroed, so this call - // initialises the data from system read and we need to save it - // after - loop { - if let Ok(mut config) = self.config.try_lock() { - config - .profiles - .write_profile_curve_to_platform(active, &mut device)?; - break; - } - } + config + .profiles + .write_profile_curve_to_platform(active, &mut device)?; } + Ok(()) } } diff --git a/asusd/src/ctrl_platform.rs b/asusd/src/ctrl_platform.rs index 6f0060f7..62003c1a 100644 --- a/asusd/src/ctrl_platform.rs +++ b/asusd/src/ctrl_platform.rs @@ -175,7 +175,7 @@ impl CtrlPlatform { fn set_gfx_mode(&self, mode: GpuMode) -> Result<(), RogError> { self.platform.set_gpu_mux_mode(mode.to_mux_attr())?; // self.update_initramfs(enable)?; - if mode == GpuMode::Discrete { + if mode == GpuMode::Ultimate { info!("Set system-level graphics mode: Dedicated Nvidia"); } else { info!("Set system-level graphics mode: Optimus"); @@ -264,6 +264,7 @@ impl CtrlPlatform { #[interface(name = "org.asuslinux.Platform")] impl CtrlPlatform { + #[zbus(property)] async fn version(&self) -> String { crate::VERSION.to_string() } diff --git a/rog-aura/src/lib.rs b/rog-aura/src/lib.rs index 32b6b423..10971d85 100644 --- a/rog-aura/src/lib.rs +++ b/rog-aura/src/lib.rs @@ -1,3 +1,7 @@ +// TODO: Generic builtin modes +// TODO: Traits for finding device + writing generic modes +// TODO: Traits for writing aura_sync + mod builtin_modes; use advanced::LedCode; pub use builtin_modes::*; diff --git a/rog-control-center/src/lib.rs b/rog-control-center/src/lib.rs index 5217d7c0..cc663c5d 100644 --- a/rog-control-center/src/lib.rs +++ b/rog-control-center/src/lib.rs @@ -23,22 +23,12 @@ pub mod types; pub mod ui; pub mod update_and_notify; -#[cfg(feature = "mocking")] -pub use mocking::RogDbusClientBlocking; use nix::sys::stat; use nix::unistd; -#[cfg(not(feature = "mocking"))] -pub use rog_dbus::RogDbusClientBlocking; use tempfile::TempDir; // use log::{error, info, warn}; pub const VERSION: &str = env!("CARGO_PKG_VERSION"); - -#[cfg(not(feature = "mocking"))] -const DATA_DIR: &str = "/usr/share/rog-gui/"; -#[cfg(feature = "mocking")] -const DATA_DIR: &str = env!("CARGO_MANIFEST_DIR"); -const BOARD_NAME: &str = "/sys/class/dmi/id/board_name"; pub const APP_ICON_PATH: &str = "/usr/share/icons/hicolor/512x512/apps/rog-control-center.png"; pub fn print_versions() { diff --git a/rog-control-center/src/main.rs b/rog-control-center/src/main.rs index e754a3f8..3787831b 100644 --- a/rog-control-center/src/main.rs +++ b/rog-control-center/src/main.rs @@ -15,19 +15,28 @@ use rog_control_center::cli_options::CliStart; use rog_control_center::config::Config; use rog_control_center::error::Result; use rog_control_center::slint::ComponentHandle; -use rog_control_center::system_state::{AuraCreation, SystemState}; +use rog_control_center::system_state::SystemState; use rog_control_center::tray::init_tray; use rog_control_center::ui::setup_window; use rog_control_center::update_and_notify::{start_notifications, EnabledNotifications}; use rog_control_center::{ - get_ipc_file, on_tmp_dir_exists, print_versions, MainWindow, RogDbusClientBlocking, QUIT_APP, - SHOWING_GUI, SHOW_GUI, + get_ipc_file, on_tmp_dir_exists, print_versions, MainWindow, QUIT_APP, SHOWING_GUI, SHOW_GUI, }; use tokio::runtime::Runtime; // use winit::monitor::VideoMode; // use winit::window::{Fullscreen, WindowLevel}; -fn main() -> Result<()> { +#[tokio::main] +async fn main() -> Result<()> { + let self_version = env!("CARGO_PKG_VERSION"); + let conn = zbus::blocking::Connection::system()?; + let proxy = rog_dbus::zbus_platform::PlatformProxyBlocking::new(&conn)?; + let asusd_version = proxy.version().unwrap(); + if asusd_version != self_version { + println!("Version mismatch: asusctl = {self_version}, asusd = {asusd_version}"); + return Ok(()); + } + let dmi = DMIID::new().unwrap_or_default(); let board_name = dmi.board_name; let prod_family = dmi.product_family; @@ -70,13 +79,7 @@ fn main() -> Result<()> { // Enter the runtime so that `tokio::spawn` is available immediately. let _enter = rt.enter(); - let (dbus, _) = RogDbusClientBlocking::new() - .map_err(|_| { - // TODO: show an error window - }) - .unwrap(); - - let supported_properties = match dbus.proxies().platform().supported_properties() { + let supported_properties = match proxy.supported_properties() { Ok(s) => s, Err(_e) => { // TODO: show an error window @@ -113,10 +116,9 @@ fn main() -> Result<()> { config.write(); let enabled_notifications = EnabledNotifications::tokio_mutex(&config); - let aura_creation = AuraCreation::new(cli_parsed.board_name, cli_parsed.layout_viewing)?; // TODO: config mutex to share config in various places - let states = setup_page_state_and_notifs(aura_creation, &enabled_notifications, &config)?; + let states = setup_page_state_and_notifs(&enabled_notifications, &config).await?; let enable_tray_icon = config.enable_tray_icon; let startup_in_background = config.startup_in_background; @@ -214,17 +216,18 @@ fn main() -> Result<()> { Ok(()) } -fn setup_page_state_and_notifs( - aura_creation: AuraCreation, +async fn setup_page_state_and_notifs( enabled_notifications: &Arc>, config: &Config, ) -> Result>> { - let page_states = Arc::new(Mutex::new(SystemState::new( - aura_creation, - enabled_notifications.clone(), - config.enable_tray_icon, - config.run_in_background, - )?)); + let page_states = Arc::new(Mutex::new( + SystemState::new( + enabled_notifications.clone(), + config.enable_tray_icon, + config.run_in_background, + ) + .await?, + )); start_notifications(config, &page_states, enabled_notifications)?; @@ -261,8 +264,10 @@ fn setup_page_state_and_notifs( // IconData { // height, // width, -// rgba, -// } +// rgba +// +// +// / } // } fn do_cli_help(parsed: &CliStart) -> bool { diff --git a/rog-control-center/src/system_state.rs b/rog-control-center/src/system_state.rs index cab71e85..a6aecc9d 100644 --- a/rog-control-center/src/system_state.rs +++ b/rog-control-center/src/system_state.rs @@ -1,190 +1,15 @@ -use std::collections::{BTreeMap, HashSet}; -use std::path::PathBuf; use std::sync::{Arc, Mutex}; -use std::time::SystemTime; -use log::{error, warn}; -use rog_anime::{Animations, DeviceState}; -use rog_aura::aura_detection::{LaptopLedData, LedSupportFile}; -use rog_aura::layouts::KeyLayout; -use rog_aura::usb::AuraPowerDev; -use rog_aura::{AuraEffect, AuraModeNum, LedBrightness}; -use rog_platform::platform::{GpuMode, ThrottlePolicy}; -use rog_profiles::fan_curve_set::CurveData; -use rog_profiles::FanCurvePU; +use log::error; use supergfxctl::pci_device::{GfxMode, GfxPower}; #[cfg(not(feature = "mocking"))] -use supergfxctl::zbus_proxy::DaemonProxyBlocking as GfxProxyBlocking; +use supergfxctl::zbus_proxy::DaemonProxy as GfxProxy; +use zbus::Connection; use crate::error::Result; #[cfg(feature = "mocking")] use crate::mocking::DaemonProxyBlocking as GfxProxyBlocking; use crate::update_and_notify::EnabledNotifications; -use crate::{RogDbusClientBlocking, BOARD_NAME, DATA_DIR}; - -#[derive(Clone, Debug, Default)] -pub struct PlatformState { - /// To be shared to a thread that checks notifications. - /// It's a bit general in that it won't provide *what* was - /// updated, so the full state needs refresh - pub post_sound: Option, - pub gpu_mux_mode: Option, - pub panel_overdrive: Option, - pub mini_led_mode: Option, - pub dgpu_disable: Option, - pub egpu_enable: Option, - pub throttle: Option, - pub charge_limit: Option, -} - -impl PlatformState { - pub fn new(dbus: &RogDbusClientBlocking<'_>) -> Result { - Ok(Self { - post_sound: dbus.proxies().platform().boot_sound().ok(), - gpu_mux_mode: dbus - .proxies() - .platform() - .gpu_mux_mode() - .map(GpuMode::from) - .ok(), - panel_overdrive: dbus.proxies().platform().panel_od().ok(), - mini_led_mode: dbus.proxies().platform().mini_led_mode().ok(), - // TODO: needs supergfx - dgpu_disable: dbus.proxies().platform().dgpu_disable().ok(), - egpu_enable: dbus.proxies().platform().egpu_enable().ok(), - throttle: dbus.proxies().platform().throttle_thermal_policy().ok(), - charge_limit: dbus - .proxies() - .platform() - .charge_control_end_threshold() - .ok(), - }) - } -} - -#[derive(Clone, Debug, Default)] -pub struct FanCurvesState { - pub show_curve: ThrottlePolicy, - pub show_graph: FanCurvePU, - pub curves: BTreeMap>, - pub available_fans: HashSet, - // pub drag_delta: Vec2, -} - -impl FanCurvesState { - pub fn new(dbus: &RogDbusClientBlocking<'_>) -> Result { - let profiles = vec![ - ThrottlePolicy::Balanced, - ThrottlePolicy::Quiet, - ThrottlePolicy::Performance, - ]; - - let mut available_fans = HashSet::new(); - let mut curves: BTreeMap> = BTreeMap::new(); - for p in &profiles { - if let Ok(curve) = dbus.proxies().fan_curves().fan_curve_data(*p) { - if available_fans.is_empty() { - for fan in &curve { - available_fans.insert(fan.fan); - } - } - curves.insert(*p, curve); - } else { - curves.insert(*p, Default::default()); - } - } - - let show_curve = dbus.proxies().platform().throttle_thermal_policy()?; - - Ok(Self { - show_curve, - show_graph: FanCurvePU::CPU, - curves, - available_fans, - // drag_delta: Vec2::default(), - }) - } -} - -#[derive(Clone, Debug, Default)] -pub struct AuraState { - pub current_mode: AuraModeNum, - pub modes: BTreeMap, - pub enabled: AuraPowerDev, - /// Brightness from 0-3 - pub bright: LedBrightness, - pub wave_red: [u8; 22], - pub wave_green: [u8; 22], - pub wave_blue: [u8; 22], -} - -impl AuraState { - pub fn new(layout: &KeyLayout, dbus: &RogDbusClientBlocking<'_>) -> Result { - Ok(Self { - current_mode: if !layout.basic_modes().is_empty() { - dbus.proxies().aura().led_mode().unwrap_or_default() - } else { - AuraModeNum::Static - }, - - modes: if !layout.basic_modes().is_empty() { - dbus.proxies().aura().all_mode_data().unwrap_or_default() - } else { - BTreeMap::new() - }, - enabled: dbus.proxies().aura().led_power().unwrap_or_default(), - bright: Default::default(), - wave_red: [0u8; 22], - wave_green: [0u8; 22], - wave_blue: [0u8; 22], - }) - } - - /// Bump value in to the wave and surf all along. - pub fn nudge_wave(&mut self, r: u8, g: u8, b: u8) { - for i in (0..self.wave_red.len()).rev() { - if i > 0 { - self.wave_red[i] = self.wave_red[i - 1]; - self.wave_green[i] = self.wave_green[i - 1]; - self.wave_blue[i] = self.wave_blue[i - 1]; - } - } - self.wave_red[0] = r; - self.wave_green[0] = g; - self.wave_blue[0] = b; - } -} - -#[derive(Clone, Debug, Default)] -pub struct AnimeState { - pub display_enabled: bool, - pub display_brightness: u8, - pub builtin_anims_enabled: bool, - pub builtin_anims: Animations, -} - -impl AnimeState { - pub fn new(dbus: &RogDbusClientBlocking<'_>) -> Result { - let device_state = dbus.proxies().anime().device_state()?; - Ok(Self { - display_enabled: device_state.display_enabled, - display_brightness: device_state.display_brightness as u8, - builtin_anims_enabled: device_state.builtin_anims_enabled, - builtin_anims: device_state.builtin_anims, - }) - } -} - -impl From for AnimeState { - fn from(dev: DeviceState) -> Self { - Self { - display_enabled: dev.display_enabled, - display_brightness: dev.display_brightness as u8, - builtin_anims_enabled: dev.builtin_anims_enabled, - builtin_anims: dev.builtin_anims, - } - } -} #[derive(Clone, Debug)] pub struct GfxState { @@ -194,11 +19,11 @@ pub struct GfxState { } impl GfxState { - pub fn new(dbus: &GfxProxyBlocking<'_>) -> Result { + pub async fn new(dbus: &GfxProxy<'_>) -> Result { Ok(Self { - has_supergfx: dbus.mode().is_ok(), - mode: dbus.mode().unwrap_or(GfxMode::None), - power_status: dbus.power().unwrap_or(GfxPower::Unknown), + has_supergfx: dbus.mode().await.is_ok(), + mode: dbus.mode().await.unwrap_or(GfxMode::None), + power_status: dbus.power().await.unwrap_or(GfxPower::Unknown), }) } } @@ -213,115 +38,16 @@ impl Default for GfxState { } } -/// The keyboard layout, used for such things as per-key and zones -#[derive(Clone, Debug)] -pub struct AuraCreation { - /// Specifically for testing the development of keyboard layouts (combined - /// with `--layout-name` CLI option) - pub layout_testing: Option, - pub layout_last_modified: SystemTime, - pub keyboard_layout: KeyLayout, - pub keyboard_layouts: Vec, - /// current index in to `self.keyboard_layouts` - pub keyboard_layout_index: usize, -} - -impl AuraCreation { - pub fn new(test_name: Option, view_layout: bool) -> Result { - let mut led_support = LaptopLedData::get_data(); - - let mut path = PathBuf::from(DATA_DIR); - let mut layout_testing = None; - let mut keyboard_layouts = Vec::new(); - - // Find and load a matching layout for laptop - let mut board_name = std::fs::read_to_string(BOARD_NAME).map_err(|e| { - println!("DOH! {BOARD_NAME}, {e}"); - e - })?; - - if test_name.is_some() || view_layout { - if cfg!(feature = "mocking") { - path.pop(); - path.push("rog-aura"); - path.push("data"); - } - keyboard_layouts = KeyLayout::layout_files(path.clone()).unwrap(); - - if let Some(name) = test_name { - if let Some(modes) = LedSupportFile::load_from_supoprt_db() { - if let Some(data) = modes.matcher(&name) { - led_support = data; - } - } - board_name = name; - for layout in &keyboard_layouts { - if layout - .file_name() - .unwrap() - .to_string_lossy() - .contains(&led_support.layout_name.to_lowercase()) - { - layout_testing = Some(layout.clone()); - } - } - } else { - board_name = "GQ401QM".to_owned(); - }; - - if view_layout { - layout_testing = Some(keyboard_layouts[0].clone()); - board_name = keyboard_layouts[0] - .file_name() - .unwrap() - .to_string_lossy() - .split_once('_') - .unwrap() - .0 - .to_owned(); - led_support.layout_name = board_name.clone(); - } - } - - let keyboard_layout = KeyLayout::find_layout(led_support, path) - .map_err(|e| { - println!("DERP! , {e}"); - }) - .unwrap_or_else(|_| { - warn!("Did not find a keyboard layout matching {board_name}"); - KeyLayout::default_layout() - }); - - Ok(Self { - layout_testing, - layout_last_modified: SystemTime::now(), - keyboard_layout, - keyboard_layouts, - keyboard_layout_index: 0, - }) - } -} - /// State stored from system daemons. This is shared with: tray, zbus /// notifications thread and the GUI app thread. pub struct SystemState { - pub aura_creation: AuraCreation, - //-- pub enabled_notifications: Arc>, - /// Because much of the app state here is the same as - /// `RogBiosSupportedFunctions` we can re-use that structure. - pub bios: PlatformState, - pub aura: AuraState, - pub anime: AnimeState, - pub fan_curves: FanCurvesState, pub gfx_state: GfxState, 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. pub tray_should_update: bool, pub app_should_update: bool, - pub asus_dbus: RogDbusClientBlocking<'static>, - pub gfx_dbus: GfxProxyBlocking<'static>, pub tray_enabled: bool, pub run_in_bg: bool, } @@ -329,47 +55,22 @@ pub struct SystemState { impl SystemState { /// Creates self, including the relevant dbus connections and proixies for /// internal use - pub fn new( - aura_creation: AuraCreation, + pub async fn new( enabled_notifications: Arc>, tray_enabled: bool, run_in_bg: bool, ) -> Result { - let (asus_dbus, conn) = RogDbusClientBlocking::new()?; - let aura = AuraState::new(&aura_creation.keyboard_layout, &asus_dbus) - .map_err(|e| { - let e = format!("Could not get AuraState state: {e}"); - error!("{e}"); - }) - .unwrap_or_default(); + let conn = Connection::system().await?; - let gfx_dbus = GfxProxyBlocking::builder(&conn) + let gfx_dbus = GfxProxy::builder(&conn) .destination(":org.supergfxctl.Daemon")? .build() + .await .expect("Couldn't connect to supergfxd"); Ok(Self { - aura_creation, enabled_notifications, - bios: PlatformState::new(&asus_dbus) - .map_err(|e| { - let e = format!("Could not get BiosState state: {e}"); - error!("{e}"); - }) - .unwrap_or_default(), - aura, - anime: AnimeState::new(&asus_dbus) - .map_err(|e| { - let e = format!("Could not get AnimeState state: {e}"); - error!("{e}"); - }) - .unwrap_or_default(), - fan_curves: FanCurvesState::new(&asus_dbus) - .map_err(|e| { - let e = format!("Could not get FanCurvesState state: {e}"); - error!("{e}"); - }) - .unwrap_or_default(), gfx_state: GfxState::new(&gfx_dbus) + .await .map_err(|e| { let e = format!("Could not get supergfxd state: {e}"); error!("{e}"); @@ -378,8 +79,6 @@ impl SystemState { error: None, tray_should_update: true, app_should_update: true, - asus_dbus, - gfx_dbus, tray_enabled, run_in_bg, }) @@ -390,51 +89,3 @@ impl SystemState { self.app_should_update = true; } } - -impl Default for SystemState { - fn default() -> Self { - let (asus_dbus, conn) = RogDbusClientBlocking::new().expect("Couldn't connect to asusd"); - let gfx_dbus = GfxProxyBlocking::builder(&conn) - .build() - .expect("Couldn't connect to supergfxd"); - - Self { - aura_creation: AuraCreation { - layout_testing: None, - layout_last_modified: SystemTime::now(), - keyboard_layout: KeyLayout::default_layout(), - keyboard_layouts: Default::default(), - keyboard_layout_index: 0, - }, - enabled_notifications: Default::default(), - bios: PlatformState { - post_sound: Default::default(), - gpu_mux_mode: None, - charge_limit: Some(100), - ..Default::default() - }, - aura: AuraState { - current_mode: AuraModeNum::Static, - modes: Default::default(), - enabled: AuraPowerDev::default(), - ..Default::default() - }, - anime: AnimeState::default(), - fan_curves: FanCurvesState { - ..Default::default() - }, - gfx_state: GfxState { - has_supergfx: false, - mode: GfxMode::None, - power_status: GfxPower::Unknown, - }, - error: Default::default(), - tray_should_update: true, - app_should_update: true, - asus_dbus, - gfx_dbus, - tray_enabled: true, - run_in_bg: true, - } - } -} diff --git a/rog-control-center/src/tray.rs b/rog-control-center/src/tray.rs index 4fa4ed61..baa30273 100644 --- a/rog-control-center/src/tray.rs +++ b/rog-control-center/src/tray.rs @@ -11,7 +11,7 @@ use std::time::Duration; use betrayer::{Icon, Menu, MenuItem, TrayEvent, TrayIcon, TrayIconBuilder}; use log::{debug, error, info, warn}; -use rog_platform::platform::{GpuMode, Properties}; +use rog_platform::platform::Properties; use supergfxctl::pci_device::{GfxMode, GfxPower}; use supergfxctl::zbus_proxy::DaemonProxyBlocking as GfxProxy; use versions::Versioning; @@ -113,16 +113,7 @@ fn set_tray_icon_and_tip(lock: &SystemState, tray: &TrayIcon, superg } }; - let current_gpu_mode = if supergfx_active { - lock.gfx_state.mode - } else if let Some(mode) = lock.bios.gpu_mux_mode { - match mode { - GpuMode::Discrete => GfxMode::AsusMuxDgpu, - _ => GfxMode::Hybrid, - } - } else { - GfxMode::Hybrid - }; + let current_gpu_mode = lock.gfx_state.mode; tray.set_tooltip(format!( "ROG: gpu mode = {current_gpu_mode:?}, gpu power = {gpu_status:?}" diff --git a/rog-control-center/src/update_and_notify.rs b/rog-control-center/src/update_and_notify.rs index db760390..5418d049 100644 --- a/rog-control-center/src/update_and_notify.rs +++ b/rog-control-center/src/update_and_notify.rs @@ -11,10 +11,8 @@ use std::time::Duration; use log::{error, info, trace, warn}; use notify_rust::{Hint, Notification, NotificationHandle, Urgency}; -use rog_dbus::zbus_anime::AnimeProxy; -use rog_dbus::zbus_aura::AuraProxy; use rog_dbus::zbus_platform::PlatformProxy; -use rog_platform::platform::{GpuMode, ThrottlePolicy}; +use rog_platform::platform::GpuMode; use serde::{Deserialize, Serialize}; use supergfxctl::actions::UserActionRequired as GfxUserAction; use supergfxctl::pci_device::{GfxMode, GfxPower}; @@ -31,45 +29,12 @@ const NOTIF_HEADER: &str = "ROG Control"; static mut POWER_AC_CMD: Option = None; static mut POWER_BAT_CMD: Option = None; -#[derive(Debug, Clone, Deserialize, Serialize)] +#[derive(Debug, Default, Clone, Deserialize, Serialize)] #[serde(default)] pub struct EnabledNotifications { - pub receive_boot_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_gpu_mux_mode_changed: bool, - pub receive_charge_control_end_threshold_changed: bool, - pub receive_notify_mains_online: bool, - pub receive_throttle_thermal_policy_changed: bool, - pub receive_led_mode_data_changed: bool, - /// Anime pub receive_power_states: bool, pub receive_notify_gfx: bool, pub receive_notify_gfx_status: bool, - pub all_enabled: bool, -} - -impl Default for EnabledNotifications { - fn default() -> Self { - Self { - receive_boot_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_gpu_mux_mode_changed: true, - receive_charge_control_end_threshold_changed: true, - receive_notify_mains_online: false, - receive_throttle_thermal_policy_changed: true, - receive_led_mode_data_changed: true, - receive_power_states: false, - receive_notify_gfx: false, - receive_notify_gfx_status: false, - all_enabled: false, - } - } } impl EnabledNotifications { @@ -78,6 +43,18 @@ impl EnabledNotifications { } } +fn gpu_to_gfx(value: GpuMode) -> GfxMode { + match value { + GpuMode::Optimus => GfxMode::Hybrid, + GpuMode::Integrated => GfxMode::Integrated, + GpuMode::Egpu => GfxMode::AsusEgpu, + GpuMode::Vfio => GfxMode::Vfio, + GpuMode::Ultimate => GfxMode::AsusMuxDgpu, + GpuMode::Error => GfxMode::None, + GpuMode::NotSupported => GfxMode::None, + } +} + // TODO: drop the macro and use generics plus closure macro_rules! recv_notif { ($proxy:ident, @@ -107,7 +84,7 @@ macro_rules! recv_notif { while let Some(e) = p.next().await { if let Ok(out) = e.args() { if let Ok(config) = notifs_enabled1.lock() { - if config.all_enabled && config.$signal { + if config.$signal { trace!("zbus signal {}", stringify!($signal)); $notifier($msg, &out.$($out_arg)+()).ok(); } @@ -124,49 +101,6 @@ 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.into(); - lock.set_notified(); - } - } - sleep(Duration::from_millis(500)).await; - } - }); - }; -} - pub fn start_notifications( config: &Config, page_states: &Arc>, @@ -196,155 +130,6 @@ pub fn start_notifications( } } - // BIOS notif - recv_changed!( - PlatformProxy, - receive_boot_sound_changed, - last_notification, - enabled_notifications, - page_states, - (bios.post_sound), - "BIOS Post sound", - do_notification - ); - - recv_changed!( - PlatformProxy, - receive_panel_od_changed, - last_notification, - enabled_notifications, - page_states, - (bios.panel_overdrive), - "Panel Overdrive enabled:", - do_notification - ); - - recv_changed!( - PlatformProxy, - receive_mini_led_mode_changed, - last_notification, - enabled_notifications, - page_states, - (bios.mini_led_mode), - "MiniLED mode enabled:", - do_notification - ); - - recv_changed!( - PlatformProxy, - receive_dgpu_disable_changed, - last_notification, - enabled_notifications, - page_states, - (bios.dgpu_disable), - "BIOS dGPU disabled", - do_notification - ); - - recv_changed!( - PlatformProxy, - receive_egpu_enable_changed, - last_notification, - enabled_notifications, - page_states, - (bios.egpu_enable), - "BIOS eGPU enabled", - do_notification - ); - - // Charge notif - recv_changed!( - PlatformProxy, - receive_charge_control_end_threshold_changed, - last_notification, - enabled_notifications, - page_states, - (bios.charge_limit), - "Battery charge limit changed to", - do_notification - ); - - // Profile notif - recv_changed!( - PlatformProxy, - receive_throttle_thermal_policy_changed, - last_notification, - enabled_notifications, - page_states, - (bios.throttle), - "Profile changed to", - do_thermal_notif - ); - // notify!(do_thermal_notif(&out.profile), lock); - - // LED notif - recv_changed!( - AuraProxy, - receive_led_mode_data_changed, - last_notification, - enabled_notifications, - page_states, - (aura.current_mode), - "Keyboard LED mode changed to", - do_notification - ); - - // let page_states1 = page_states.clone(); - // tokio::spawn(async move { - // let conn = zbus::Connection::system() - // .await - // .map_err(|e| { - // error!("zbus signal: receive_device_state: {e}"); - // e - // }) - // .unwrap(); - // let proxy = AuraProxy::new(&conn) - // .await - // .map_err(|e| { - // error!("zbus signal: receive_device_state: {e}"); - // e - // }) - // .unwrap(); - // let p = proxy.receive_led_power_changed().await; - // info!("Started zbus signal thread: receive_notify_power_states"); - // while let Some(e) = p.next().await { - // if let Ok(out) = e.get().await { - // if let Ok(mut lock) = page_states1.lock() { - // lock.aura.enabled = out; - // lock.set_notified(); - // } - // } - // } - // }); - - let page_states1 = page_states.clone(); - tokio::spawn(async move { - let conn = zbus::Connection::system() - .await - .map_err(|e| { - error!("zbus signal: receive_device_state: {e}"); - e - }) - .unwrap(); - let proxy = AnimeProxy::new(&conn) - .await - .map_err(|e| { - error!("zbus signal: receive_device_state: {e}"); - e - }) - .unwrap(); - 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() { - if let Ok(mut lock) = page_states1.lock() { - lock.anime = out.data.into(); - } - } - } - }; - }); - let page_states1 = page_states.clone(); tokio::spawn(async move { let conn = zbus::Connection::system() @@ -375,7 +160,7 @@ pub fn start_notifications( continue; } if let Ok(mut lock) = page_states1.lock() { - lock.bios.gpu_mux_mode = Some(mode); + lock.gfx_state.mode = gpu_to_gfx(mode); lock.set_notified(); } do_mux_notification("Reboot required. BIOS GPU MUX mode set to", &mode).ok(); @@ -397,7 +182,7 @@ pub fn start_notifications( if let Ok(status) = dev.get_runtime_status() { if status != GfxPower::Unknown && status != last_status { if let Ok(config) = notifs_enabled1.lock() { - if config.all_enabled && config.receive_notify_gfx_status { + if config.receive_notify_gfx_status { // Required check because status cycles through // active/unknown/suspended do_gpu_status_notif("dGPU status changed:", &status).ok(); @@ -498,7 +283,7 @@ fn convert_gfx_mode(gfx: GfxMode) -> GpuMode { match gfx { GfxMode::Hybrid => GpuMode::Optimus, GfxMode::Integrated => GpuMode::Integrated, - GfxMode::NvidiaNoModeset => GpuMode::Discrete, + GfxMode::NvidiaNoModeset => GpuMode::Optimus, GfxMode::Vfio => GpuMode::Vfio, GfxMode::AsusEgpu => GpuMode::Egpu, GfxMode::AsusMuxDgpu => GpuMode::Ultimate, @@ -553,17 +338,6 @@ fn _ac_power_notification(message: &str, on: &bool) -> Result Result { - let icon = match profile { - ThrottlePolicy::Balanced => "asus_notif_yellow", - ThrottlePolicy::Performance => "asus_notif_red", - ThrottlePolicy::Quiet => "asus_notif_green", - }; - let profile: &str = (*profile).into(); - let mut notif = base_notification(message, &profile.to_uppercase()); - Ok(notif.icon(icon).show()?) -} - fn do_gpu_status_notif(message: &str, data: &GfxPower) -> Result { // eww let mut notif = base_notification(message, &<&str>::from(data).to_owned()); diff --git a/rog-control-center/translations/en/rog-control-center.po b/rog-control-center/translations/en/rog-control-center.po index a5ac5b60..e2833c70 100644 --- a/rog-control-center/translations/en/rog-control-center.po +++ b/rog-control-center/translations/en/rog-control-center.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2024-04-03 20:58+0000\n" +"POT-Creation-Date: 2024-04-05 03:00+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/rog-dbus/src/lib.rs b/rog-dbus/src/lib.rs index 0059de43..d619d4c9 100644 --- a/rog-dbus/src/lib.rs +++ b/rog-dbus/src/lib.rs @@ -4,124 +4,4 @@ pub mod zbus_aura; pub mod zbus_fan_curves; pub mod zbus_platform; -// use rog_anime::AnimePowerStates; -// use rog_aura::{AuraEffect, LedPowerStates}; -// use rog_profiles::Profile; -// use std::sync::mpsc::{channel, Receiver}; -use zbus::{blocking, Connection, Result}; - pub const VERSION: &str = env!("CARGO_PKG_VERSION"); - -pub struct DbusProxiesBlocking<'a> { - anime: zbus_anime::AnimeProxyBlocking<'a>, - led: zbus_aura::AuraProxyBlocking<'a>, - profile: zbus_fan_curves::FanCurvesProxyBlocking<'a>, - rog_bios: zbus_platform::PlatformProxyBlocking<'a>, -} - -impl<'a> DbusProxiesBlocking<'a> { - #[inline] - pub fn new() -> Result<(Self, blocking::Connection)> { - let conn = blocking::Connection::system()?; - - Ok(( - DbusProxiesBlocking { - anime: zbus_anime::AnimeProxyBlocking::new(&conn)?, - led: zbus_aura::AuraProxyBlocking::new(&conn)?, - profile: zbus_fan_curves::FanCurvesProxyBlocking::new(&conn)?, - rog_bios: zbus_platform::PlatformProxyBlocking::new(&conn)?, - }, - conn, - )) - } - - pub fn anime(&self) -> &zbus_anime::AnimeProxyBlocking<'a> { - &self.anime - } - - pub fn aura(&self) -> &zbus_aura::AuraProxyBlocking<'a> { - &self.led - } - - pub fn fan_curves(&self) -> &zbus_fan_curves::FanCurvesProxyBlocking<'a> { - &self.profile - } - - pub fn platform(&self) -> &zbus_platform::PlatformProxyBlocking<'a> { - &self.rog_bios - } -} - -/// This is the main way to communicate with the DBUS interface -pub struct RogDbusClientBlocking<'a> { - proxies: DbusProxiesBlocking<'a>, -} - -impl<'a> RogDbusClientBlocking<'a> { - #[inline] - pub fn new() -> Result<(Self, blocking::Connection)> { - let (proxies, conn) = DbusProxiesBlocking::new()?; - Ok((RogDbusClientBlocking { proxies }, conn)) - } - - pub fn proxies(&self) -> &DbusProxiesBlocking<'_> { - &self.proxies - } -} - -pub struct DbusProxies<'a> { - anime: zbus_anime::AnimeProxy<'a>, - led: zbus_aura::AuraProxy<'a>, - profile: zbus_fan_curves::FanCurvesProxy<'a>, - rog_bios: zbus_platform::PlatformProxy<'a>, -} - -impl<'a> DbusProxies<'a> { - #[inline] - pub async fn new() -> Result<(DbusProxies<'a>, Connection)> { - let conn = Connection::system().await?; - - Ok(( - DbusProxies { - anime: zbus_anime::AnimeProxy::new(&conn).await?, - led: zbus_aura::AuraProxy::new(&conn).await?, - profile: zbus_fan_curves::FanCurvesProxy::new(&conn).await?, - rog_bios: zbus_platform::PlatformProxy::new(&conn).await?, - }, - conn, - )) - } - - pub fn anime(&self) -> &zbus_anime::AnimeProxy<'a> { - &self.anime - } - - pub fn led(&self) -> &zbus_aura::AuraProxy<'a> { - &self.led - } - - pub fn profile(&self) -> &zbus_fan_curves::FanCurvesProxy<'a> { - &self.profile - } - - pub fn rog_bios(&self) -> &zbus_platform::PlatformProxy<'a> { - &self.rog_bios - } -} - -/// This is the main way to communicate with the DBUS interface -pub struct RogDbusClient<'a> { - proxies: DbusProxies<'a>, -} - -impl<'a> RogDbusClient<'a> { - #[inline] - pub async fn new() -> Result<(RogDbusClient<'a>, Connection)> { - let (proxies, conn) = DbusProxies::new().await?; - Ok((RogDbusClient { proxies }, conn)) - } - - pub fn proxies(&self) -> &DbusProxies<'_> { - &self.proxies - } -} diff --git a/rog-dbus/src/zbus_platform.rs b/rog-dbus/src/zbus_platform.rs index b7be05ce..a79ac36a 100644 --- a/rog-dbus/src/zbus_platform.rs +++ b/rog-dbus/src/zbus_platform.rs @@ -30,6 +30,9 @@ use zbus::proxy; default_path = "/org/asuslinux" )] trait Platform { + #[zbus(property)] + fn version(&self) -> zbus::Result; + /// NextThrottleThermalPolicy method fn next_throttle_thermal_policy(&self) -> zbus::Result<()>; diff --git a/rog-platform/src/platform.rs b/rog-platform/src/platform.rs index 6ae7ef1b..f1f1aabd 100644 --- a/rog-platform/src/platform.rs +++ b/rog-platform/src/platform.rs @@ -154,27 +154,25 @@ impl Default for RogPlatform { Serialize, Deserialize, Default, Type, Value, OwnedValue, Debug, PartialEq, Eq, Clone, Copy, )] pub enum GpuMode { - Discrete = 0, - Optimus = 1, - Integrated = 2, - Egpu = 3, - Vfio = 4, - Ultimate = 5, + Optimus = 0, + Integrated = 1, + Egpu = 2, + Vfio = 3, + Ultimate = 4, #[default] - Error = 6, - NotSupported = 7, + Error = 254, + NotSupported = 255, } impl From for GpuMode { fn from(v: u8) -> Self { match v { - 0 => GpuMode::Discrete, - 1 => GpuMode::Optimus, - 2 => GpuMode::Integrated, - 3 => GpuMode::Egpu, - 4 => GpuMode::Vfio, - 5 => GpuMode::Ultimate, - 6 => GpuMode::Error, + 0 => GpuMode::Optimus, + 1 => GpuMode::Integrated, + 2 => GpuMode::Egpu, + 3 => GpuMode::Vfio, + 4 => GpuMode::Ultimate, + 5 => GpuMode::Error, _ => GpuMode::NotSupported, } } @@ -189,7 +187,7 @@ impl From for u8 { impl GpuMode { /// For writing to `gpu_mux_mode` attribute pub fn to_mux_attr(&self) -> u8 { - if *self == Self::Discrete { + if *self == Self::Ultimate { return 0; } 1 @@ -211,7 +209,7 @@ impl GpuMode { pub fn from_mux(num: u8) -> Self { if num == 0 { - return Self::Discrete; + return Self::Ultimate; } Self::Optimus } @@ -236,7 +234,6 @@ impl GpuMode { impl Display for GpuMode { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - GpuMode::Discrete => write!(f, "Discrete"), GpuMode::Optimus => write!(f, "Optimus"), GpuMode::Integrated => write!(f, "Integrated"), GpuMode::Egpu => write!(f, "eGPU"), diff --git a/rog-profiles/src/lib.rs b/rog-profiles/src/lib.rs index 677422ee..a364b36a 100644 --- a/rog-profiles/src/lib.rs +++ b/rog-profiles/src/lib.rs @@ -14,6 +14,8 @@ use zbus::zvariant::{OwnedValue, Value}; pub const VERSION: &str = env!("CARGO_PKG_VERSION"); +/// Use udev system to find the fan curve path/node which is labelled with +/// "asus_custom_fan_curve" in the kernel pub fn find_fan_curve_node() -> Result { let mut enumerator = udev::Enumerator::new()?; enumerator.match_subsystem("hwmon")?; @@ -170,9 +172,7 @@ impl FanCurveProfiles { } /// Write the curves for the selected profile to the device. If the curve is - /// in the enabled list it will become active. If the curve is zeroed it - /// will be initialised to a default read from the system. - // TODO: Make this return an error if curve is zeroed + /// in the enabled list it will become active. pub fn write_profile_curve_to_platform( &mut self, profile: ThrottlePolicy,