diff --git a/daemon/src/config.rs b/daemon/src/config.rs index fa98cdf3..4e804316 100644 --- a/daemon/src/config.rs +++ b/daemon/src/config.rs @@ -14,6 +14,7 @@ pub static AURA_CONFIG_PATH: &str = "/etc/asusd/asusd.conf"; #[derive(Deserialize, Serialize)] pub struct Config { pub gfx_mode: GfxVendors, + pub gfx_last_mode: GfxVendors, pub gfx_managed: bool, pub gfx_vfio_enable: bool, pub active_profile: String, @@ -33,6 +34,7 @@ impl Default for Config { Config { gfx_mode: GfxVendors::Hybrid, + gfx_last_mode: GfxVendors::Hybrid, gfx_managed: true, gfx_vfio_enable: false, active_profile: "normal".into(), @@ -65,6 +67,11 @@ impl Config { } else { if let Ok(data) = serde_json::from_str(&buf) { return data; + } else if let Ok(data) = serde_json::from_str::(&buf) { + let config = data.into_current(); + config.write(); + info!("Updated config version to: {}", VERSION); + return config; } else if let Ok(data) = serde_json::from_str::(&buf) { let config = data.into_current(); config.write(); @@ -75,21 +82,6 @@ impl Config { config.write(); info!("Updated config version to: {}", VERSION); return config; - } else if let Ok(data) = serde_json::from_str::(&buf) { - let config = data.into_current(); - config.write(); - info!("Updated config version to: {}", VERSION); - return config; - } else if let Ok(data) = serde_json::from_str::(&buf) { - let config = data.into_current(); - config.write(); - info!("Updated config version to: {}", VERSION); - return config; - } else if let Ok(data) = serde_json::from_str::(&buf) { - let config = data.into_current(); - config.write(); - info!("Updated config version to: {}", VERSION); - return config; } warn!("Could not deserialise {}", CONFIG_PATH); panic!("Please remove {} then restart asusd", CONFIG_PATH); diff --git a/daemon/src/config_old.rs b/daemon/src/config_old.rs index 0072d0b4..caa507a1 100644 --- a/daemon/src/config_old.rs +++ b/daemon/src/config_old.rs @@ -5,98 +5,6 @@ use std::collections::BTreeMap; use crate::config::Config; -/// for parsing old v2.1.2 config -#[allow(dead_code)] -#[derive(Deserialize)] -pub(crate) struct ConfigV212 { - gfx_managed: bool, - bat_charge_limit: u8, - active_profile: String, - toggle_profiles: Vec, - power_profiles: BTreeMap, - power_profile: u8, - kbd_led_brightness: u8, - kbd_backlight_mode: u8, - kbd_backlight_modes: Vec, -} - -impl ConfigV212 { - pub(crate) fn into_current(self) -> Config { - Config { - gfx_mode: GfxVendors::Hybrid, - gfx_managed: self.gfx_managed, - active_profile: self.active_profile, - gfx_vfio_enable: false, - toggle_profiles: self.toggle_profiles, - curr_fan_mode: self.power_profile, - bat_charge_limit: self.bat_charge_limit, - power_profiles: self.power_profiles, - } - } -} - -/// for parsing old v2.2.2 config -#[allow(dead_code)] -#[derive(Deserialize)] -pub(crate) struct ConfigV222 { - gfx_managed: bool, - bat_charge_limit: u8, - active_profile: String, - toggle_profiles: Vec, - power_profiles: BTreeMap, - power_profile: u8, - kbd_led_brightness: u8, - kbd_backlight_mode: u8, - kbd_backlight_modes: Vec, -} - -impl ConfigV222 { - pub(crate) fn into_current(self) -> Config { - Config { - gfx_mode: GfxVendors::Hybrid, - gfx_managed: self.gfx_managed, - gfx_vfio_enable: false, - active_profile: self.active_profile, - toggle_profiles: self.toggle_profiles, - curr_fan_mode: self.power_profile, - bat_charge_limit: self.bat_charge_limit, - power_profiles: self.power_profiles, - } - } -} - -/// for parsing old v3.0.1 config -#[derive(Deserialize, Serialize)] -pub(crate) struct ConfigV301 { - pub gfx_managed: bool, - pub gfx_nv_mode_is_dedicated: bool, - pub active_profile: String, - pub toggle_profiles: Vec, - // TODO: remove power_profile - #[serde(skip)] - pub curr_fan_mode: u8, - pub bat_charge_limit: u8, - pub kbd_led_brightness: u8, - pub kbd_backlight_mode: u8, - pub kbd_backlight_modes: Vec, - pub power_profiles: BTreeMap, -} - -impl ConfigV301 { - pub(crate) fn into_current(self) -> Config { - Config { - gfx_mode: GfxVendors::Hybrid, - gfx_managed: self.gfx_managed, - gfx_vfio_enable: false, - active_profile: self.active_profile, - toggle_profiles: self.toggle_profiles, - curr_fan_mode: self.curr_fan_mode, - bat_charge_limit: self.bat_charge_limit, - power_profiles: self.power_profiles, - } - } -} - /// for parsing old v3.1.7 config #[derive(Deserialize, Serialize)] pub(crate) struct ConfigV317 { @@ -118,6 +26,7 @@ impl ConfigV317 { pub(crate) fn into_current(self) -> Config { Config { gfx_mode: GfxVendors::Hybrid, + gfx_last_mode: GfxVendors::Hybrid, gfx_managed: self.gfx_managed, gfx_vfio_enable: false, active_profile: self.active_profile, @@ -145,6 +54,7 @@ impl ConfigV324 { pub(crate) fn into_current(self) -> Config { Config { gfx_mode: GfxVendors::Hybrid, + gfx_last_mode: GfxVendors::Hybrid, gfx_managed: self.gfx_managed, gfx_vfio_enable: false, active_profile: self.active_profile, @@ -155,3 +65,33 @@ impl ConfigV324 { } } } + + +#[derive(Deserialize, Serialize)] +pub struct ConfigV341 { + pub gfx_mode: GfxVendors, + pub gfx_managed: bool, + pub gfx_vfio_enable: bool, + pub active_profile: String, + pub toggle_profiles: Vec, + #[serde(skip)] + pub curr_fan_mode: u8, + pub bat_charge_limit: u8, + pub power_profiles: BTreeMap, +} + +impl ConfigV341 { + pub(crate) fn into_current(self) -> Config { + Config { + gfx_mode: GfxVendors::Hybrid, + gfx_last_mode: GfxVendors::Hybrid, + gfx_managed: self.gfx_managed, + gfx_vfio_enable: false, + active_profile: self.active_profile, + toggle_profiles: self.toggle_profiles, + curr_fan_mode: self.curr_fan_mode, + bat_charge_limit: self.bat_charge_limit, + power_profiles: self.power_profiles, + } + } +} \ No newline at end of file diff --git a/daemon/src/ctrl_gfx/gfx.rs b/daemon/src/ctrl_gfx/gfx.rs index 866e1ba5..489b8d43 100644 --- a/daemon/src/ctrl_gfx/gfx.rs +++ b/daemon/src/ctrl_gfx/gfx.rs @@ -168,6 +168,7 @@ impl CtrlGraphics { /// Save the selected `Vendor` mode to config fn save_gfx_mode(vendor: GfxVendors, config: Arc>) { if let Ok(mut config) = config.lock() { + config.gfx_last_mode = config.gfx_mode; config.gfx_mode = vendor; config.write(); } diff --git a/daemon/src/daemon.rs b/daemon/src/daemon.rs index 7bd8b29c..1cdfa2eb 100644 --- a/daemon/src/daemon.rs +++ b/daemon/src/daemon.rs @@ -105,9 +105,10 @@ fn start_daemon() -> Result<(), Box> { // Need to check if a laptop has the dedicated gfx switch if CtrlRogBios::has_dedicated_gfx_toggle() { if let Ok(ded) = CtrlRogBios::get_gfx_mode() { - if let Ok(vendor) = ctrl.get_gfx_mode() { - if ded == 1 && vendor != GfxVendors::Nvidia { + if let Ok(mut config) = config.lock() { + if ded == 1 { warn!("Dedicated GFX toggle is on but driver mode is not nvidia \nSetting to nvidia driver mode"); + config.gfx_last_mode = config.gfx_mode; let devices = ctrl.devices(); let bus = ctrl.bus(); CtrlGraphics::do_vendor_tasks( @@ -118,6 +119,14 @@ fn start_daemon() -> Result<(), Box> { )?; } else if ded == 0 { info!("Dedicated GFX toggle is off"); + let devices = ctrl.devices(); + let bus = ctrl.bus(); + CtrlGraphics::do_vendor_tasks( + config.gfx_last_mode, + false, + &devices, + &bus, + )?; } } }