diff --git a/daemon/src/config.rs b/daemon/src/config.rs index a9d3f155..93e98e25 100644 --- a/daemon/src/config.rs +++ b/daemon/src/config.rs @@ -14,7 +14,9 @@ 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, + /// Only for informational purposes. + #[serde(skip)] + pub gfx_tmp_mode: Option, pub gfx_managed: bool, pub gfx_vfio_enable: bool, pub active_profile: String, @@ -34,7 +36,7 @@ impl Default for Config { Config { gfx_mode: GfxVendors::Hybrid, - gfx_last_mode: GfxVendors::Hybrid, + gfx_tmp_mode: None, gfx_managed: true, gfx_vfio_enable: false, active_profile: "normal".into(), diff --git a/daemon/src/config_old.rs b/daemon/src/config_old.rs index e6ebb023..4ea03830 100644 --- a/daemon/src/config_old.rs +++ b/daemon/src/config_old.rs @@ -25,7 +25,7 @@ impl ConfigV317 { pub(crate) fn into_current(self) -> Config { Config { gfx_mode: GfxVendors::Hybrid, - gfx_last_mode: GfxVendors::Hybrid, + gfx_tmp_mode: None, gfx_managed: self.gfx_managed, gfx_vfio_enable: false, active_profile: self.active_profile, @@ -53,7 +53,7 @@ impl ConfigV324 { pub(crate) fn into_current(self) -> Config { Config { gfx_mode: GfxVendors::Hybrid, - gfx_last_mode: GfxVendors::Hybrid, + gfx_tmp_mode: None, gfx_managed: self.gfx_managed, gfx_vfio_enable: false, active_profile: self.active_profile, @@ -82,7 +82,7 @@ impl ConfigV341 { pub(crate) fn into_current(self) -> Config { Config { gfx_mode: GfxVendors::Hybrid, - gfx_last_mode: GfxVendors::Hybrid, + gfx_tmp_mode: None, gfx_managed: self.gfx_managed, gfx_vfio_enable: false, active_profile: self.active_profile, @@ -114,7 +114,7 @@ impl ConfigV352 { pub(crate) fn into_current(self) -> Config { Config { gfx_mode: GfxVendors::Hybrid, - gfx_last_mode: GfxVendors::Hybrid, + gfx_tmp_mode: None, gfx_managed: self.gfx_managed, gfx_vfio_enable: false, active_profile: self.active_profile, diff --git a/daemon/src/ctrl_gfx/controller.rs b/daemon/src/ctrl_gfx/controller.rs index 6de3d42b..b7263f9b 100644 --- a/daemon/src/ctrl_gfx/controller.rs +++ b/daemon/src/ctrl_gfx/controller.rs @@ -111,7 +111,6 @@ 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(); } @@ -120,6 +119,9 @@ impl CtrlGraphics { /// Associated method to get which vendor mode is set pub fn get_gfx_mode(&self) -> Result { if let Ok(config) = self.config.lock() { + if let Some(mode) = config.gfx_tmp_mode { + return Ok(mode); + } return Ok(config.gfx_mode); } // TODO: Error here @@ -511,7 +513,11 @@ impl CtrlGraphics { Self::do_display_manager_action("stop")?; Self::wait_display_manager_state("inactive")?; - let vfio_enable = if let Ok(config) = config.lock() { + let vfio_enable = if let Ok(mut config) = config.try_lock() { + // Since we have a lock, reset tmp to none. This thread should only ever run + // for Integrated, Hybrid, or Nvidia. Tmp is also only for informational + config.gfx_tmp_mode = None; + // config.gfx_vfio_enable } else { false @@ -582,7 +588,7 @@ impl CtrlGraphics { } } - let vfio_enable = if let Ok(config) = self.config.lock() { + let vfio_enable = if let Ok(config) = self.config.try_lock() { config.gfx_vfio_enable } else { false @@ -607,6 +613,11 @@ impl CtrlGraphics { let bus = self.bus.clone(); Self::do_vendor_tasks(vendor, vfio_enable, &devices, &bus)?; info!("GFX: Graphics mode changed to {}", <&str>::from(vendor)); + if matches!(vendor, GfxVendors::Vfio | GfxVendors::Compute) { + if let Ok(mut config) = self.config.try_lock() { + config.gfx_tmp_mode = Some(vendor); + }; + } } // TODO: undo if failed? Save last mode, catch errors... Ok(action_required) diff --git a/daemon/src/daemon.rs b/daemon/src/daemon.rs index f0d9d5ee..5e9d3ea9 100644 --- a/daemon/src/daemon.rs +++ b/daemon/src/daemon.rs @@ -145,10 +145,9 @@ 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(mut config) = config.lock() { + if let Ok(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( @@ -162,7 +161,7 @@ fn start_daemon() -> Result<(), Box> { let devices = ctrl.devices(); let bus = ctrl.bus(); CtrlGraphics::do_vendor_tasks( - config.gfx_last_mode, + config.gfx_mode, false, &devices, &bus,