mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
gfx: asusd config option to not save compute/vfio mode switch
This commit is contained in:
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
new crate `rog-aura`
|
new crate `rog-aura`
|
||||||
- Correctly enable compute mode for nvidia plus no-reboot or logout if switching
|
- Correctly enable compute mode for nvidia plus no-reboot or logout if switching
|
||||||
from vfio/integrated/compute.
|
from vfio/integrated/compute.
|
||||||
|
- Add asusd config option to not save compute/vfio mode switch.
|
||||||
|
- Enable basic multiple user anime configs (asusd-user must still be restarted)
|
||||||
|
|
||||||
# [3.4.1] - 2021-04-11
|
# [3.4.1] - 2021-04-11
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use zbus::dbus_interface;
|
|||||||
use zvariant::ObjectPath;
|
use zvariant::ObjectPath;
|
||||||
use zvariant_derive::Type;
|
use zvariant_derive::Type;
|
||||||
|
|
||||||
use crate::{error::Error, user_config::UserConfig};
|
use crate::{error::Error, user_config::{UserAnimeConfig, UserConfig}};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize, Type)]
|
#[derive(Debug, Clone, Deserialize, Serialize, Type)]
|
||||||
pub enum TimeType {
|
pub enum TimeType {
|
||||||
@@ -111,7 +111,7 @@ impl<'a> CtrlAnimeInner<'static> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct CtrlAnime<'a> {
|
pub struct CtrlAnime<'a> {
|
||||||
config: Arc<Mutex<UserConfig>>,
|
config: Arc<Mutex<UserAnimeConfig>>,
|
||||||
client: AuraDbusClient<'a>,
|
client: AuraDbusClient<'a>,
|
||||||
inner: Arc<Mutex<CtrlAnimeInner<'a>>>,
|
inner: Arc<Mutex<CtrlAnimeInner<'a>>>,
|
||||||
/// Must be the same Atomic as in CtrlAnimeInner
|
/// Must be the same Atomic as in CtrlAnimeInner
|
||||||
@@ -120,7 +120,7 @@ pub struct CtrlAnime<'a> {
|
|||||||
|
|
||||||
impl<'a> CtrlAnime<'static> {
|
impl<'a> CtrlAnime<'static> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
config: Arc<Mutex<UserConfig>>,
|
config: Arc<Mutex<UserAnimeConfig>>,
|
||||||
inner: Arc<Mutex<CtrlAnimeInner<'static>>>,
|
inner: Arc<Mutex<CtrlAnimeInner<'static>>>,
|
||||||
client: AuraDbusClient<'static>,
|
client: AuraDbusClient<'static>,
|
||||||
inner_early_return: &'static AtomicBool,
|
inner_early_return: &'static AtomicBool,
|
||||||
|
|||||||
@@ -24,9 +24,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
let mut config = UserConfig::new();
|
let mut config = UserConfig::new();
|
||||||
config.load_config()?;
|
config.load_config()?;
|
||||||
let anime = config.create_anime()?;
|
|
||||||
|
|
||||||
let config = Arc::new(Mutex::new(config));
|
let anime_config = UserAnimeConfig::load_config(config.active_anime)?;
|
||||||
|
let anime = anime_config.create_anime()?;
|
||||||
|
|
||||||
|
let anime_config = Arc::new(Mutex::new(anime_config));
|
||||||
|
|
||||||
// Create server
|
// Create server
|
||||||
let connection = Connection::new_session()?;
|
let connection = Connection::new_session()?;
|
||||||
@@ -45,7 +47,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
// Need new client object for dbus control part
|
// Need new client object for dbus control part
|
||||||
let (client, _) = AuraDbusClient::new().unwrap();
|
let (client, _) = AuraDbusClient::new().unwrap();
|
||||||
let anime_control =
|
let anime_control =
|
||||||
CtrlAnime::new(config, inner.clone(), client, &ANIME_INNER_EARLY_RETURN)?;
|
CtrlAnime::new(anime_config, inner.clone(), client, &ANIME_INNER_EARLY_RETURN)?;
|
||||||
anime_control.add_to_server(&mut server);
|
anime_control.add_to_server(&mut server);
|
||||||
// Thread using inner
|
// Thread using inner
|
||||||
let _anime_thread = thread::Builder::new()
|
let _anime_thread = thread::Builder::new()
|
||||||
|
|||||||
@@ -1,22 +1,92 @@
|
|||||||
use std::{
|
use std::{fs::{create_dir, OpenOptions}, io::{Read, Write}, time::Duration};
|
||||||
fs::{create_dir, OpenOptions},
|
|
||||||
io::{Read, Write},
|
|
||||||
time::Duration,
|
|
||||||
};
|
|
||||||
|
|
||||||
use rog_anime::{AnimTime, AnimeAction, Sequences, Vec2};
|
use rog_anime::{AnimTime, AnimeAction, Sequences, Vec2};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
|
|
||||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub struct UserConfig {
|
pub struct UserAnimeConfig {
|
||||||
|
pub name: String,
|
||||||
pub anime: Vec<AnimeAction>,
|
pub anime: Vec<AnimeAction>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UserConfig {
|
impl UserAnimeConfig {
|
||||||
pub fn new() -> Self {
|
pub fn create_anime(&self) -> Result<Sequences, Error> {
|
||||||
|
let mut seq = Sequences::new();
|
||||||
|
|
||||||
|
for (idx, action) in self.anime.iter().enumerate() {
|
||||||
|
seq.insert(idx, action)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(seq)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write(&self) -> Result<(), Error> {
|
||||||
|
let mut path = if let Some(dir) = dirs::config_dir() {
|
||||||
|
dir
|
||||||
|
} else {
|
||||||
|
return Err(Error::XdgVars);
|
||||||
|
};
|
||||||
|
|
||||||
|
path.push("rog");
|
||||||
|
if !path.exists() {
|
||||||
|
create_dir(path.clone())?;
|
||||||
|
}
|
||||||
|
let name = self.name.clone();
|
||||||
|
path.push(name + ".cfg");
|
||||||
|
|
||||||
|
let mut file = OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.create(true)
|
||||||
|
.truncate(true)
|
||||||
|
.open(&path)?;
|
||||||
|
|
||||||
|
let json = serde_json::to_string_pretty(&self).unwrap();
|
||||||
|
file.write_all(json.as_bytes())?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_config(name: String) -> Result<UserAnimeConfig, Error> {
|
||||||
|
let mut path = if let Some(dir) = dirs::config_dir() {
|
||||||
|
dir
|
||||||
|
} else {
|
||||||
|
return Err(Error::XdgVars);
|
||||||
|
};
|
||||||
|
|
||||||
|
path.push("rog");
|
||||||
|
if !path.exists() {
|
||||||
|
create_dir(path.clone())?;
|
||||||
|
}
|
||||||
|
|
||||||
|
path.push(name + ".cfg");
|
||||||
|
|
||||||
|
let mut file = OpenOptions::new()
|
||||||
|
.read(true)
|
||||||
|
.write(true)
|
||||||
|
.create(true)
|
||||||
|
.open(&path)?;
|
||||||
|
|
||||||
|
let mut buf = String::new();
|
||||||
|
|
||||||
|
if let Ok(read_len) = file.read_to_string(&mut buf) {
|
||||||
|
if read_len == 0 {
|
||||||
|
let default = UserAnimeConfig::default();
|
||||||
|
let json = serde_json::to_string_pretty(&default).unwrap();
|
||||||
|
file.write_all(json.as_bytes())?;
|
||||||
|
return Ok(default);
|
||||||
|
} else if let Ok(data) = serde_json::from_str::<UserAnimeConfig>(&buf) {
|
||||||
|
return Ok(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(Error::ConfigLoadFail)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for UserAnimeConfig {
|
||||||
|
fn default() -> Self {
|
||||||
let x = Self {
|
let x = Self {
|
||||||
|
name: "default".to_string(),
|
||||||
anime: vec![
|
anime: vec![
|
||||||
AnimeAction::AsusAnimation {
|
AnimeAction::AsusAnimation {
|
||||||
file: "/usr/share/asusd/anime/asus/rog/Sunset.gif".into(),
|
file: "/usr/share/asusd/anime/asus/rog/Sunset.gif".into(),
|
||||||
@@ -52,6 +122,20 @@ impl UserConfig {
|
|||||||
println!("{}", serde_json::to_string_pretty(&x).unwrap());
|
println!("{}", serde_json::to_string_pretty(&x).unwrap());
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||||
|
pub struct UserConfig {
|
||||||
|
/// Name of active anime config file in the user config directory
|
||||||
|
pub active_anime: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UserConfig {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
active_anime: "anime-default".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn load_config(&mut self) -> Result<(), Error> {
|
pub fn load_config(&mut self) -> Result<(), Error> {
|
||||||
let mut path = if let Some(dir) = dirs::config_dir() {
|
let mut path = if let Some(dir) = dirs::config_dir() {
|
||||||
@@ -80,7 +164,7 @@ impl UserConfig {
|
|||||||
let json = serde_json::to_string_pretty(&self).unwrap();
|
let json = serde_json::to_string_pretty(&self).unwrap();
|
||||||
file.write_all(json.as_bytes())?;
|
file.write_all(json.as_bytes())?;
|
||||||
} else if let Ok(data) = serde_json::from_str::<UserConfig>(&buf) {
|
} else if let Ok(data) = serde_json::from_str::<UserConfig>(&buf) {
|
||||||
self.anime = data.anime;
|
self.active_anime = data.active_anime;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,18 +192,7 @@ impl UserConfig {
|
|||||||
.open(&path)?;
|
.open(&path)?;
|
||||||
|
|
||||||
let json = serde_json::to_string_pretty(&self).unwrap();
|
let json = serde_json::to_string_pretty(&self).unwrap();
|
||||||
dbg!(&json);
|
|
||||||
file.write_all(json.as_bytes())?;
|
file.write_all(json.as_bytes())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_anime(&self) -> Result<Sequences, Error> {
|
|
||||||
let mut seq = Sequences::new();
|
|
||||||
|
|
||||||
for (idx, action) in self.anime.iter().enumerate() {
|
|
||||||
seq.insert(idx, action)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(seq)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ pub struct Config {
|
|||||||
pub gfx_last_mode: GfxVendors,
|
pub gfx_last_mode: GfxVendors,
|
||||||
pub gfx_managed: bool,
|
pub gfx_managed: bool,
|
||||||
pub gfx_vfio_enable: bool,
|
pub gfx_vfio_enable: bool,
|
||||||
|
pub gfx_save_compute_vfio: bool,
|
||||||
pub active_profile: String,
|
pub active_profile: String,
|
||||||
pub toggle_profiles: Vec<String>,
|
pub toggle_profiles: Vec<String>,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
@@ -37,6 +38,7 @@ impl Default for Config {
|
|||||||
gfx_last_mode: GfxVendors::Hybrid,
|
gfx_last_mode: GfxVendors::Hybrid,
|
||||||
gfx_managed: true,
|
gfx_managed: true,
|
||||||
gfx_vfio_enable: false,
|
gfx_vfio_enable: false,
|
||||||
|
gfx_save_compute_vfio: true,
|
||||||
active_profile: "normal".into(),
|
active_profile: "normal".into(),
|
||||||
toggle_profiles: vec!["normal".into(), "boost".into(), "silent".into()],
|
toggle_profiles: vec!["normal".into(), "boost".into(), "silent".into()],
|
||||||
curr_fan_mode: 0,
|
curr_fan_mode: 0,
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ impl ConfigV317 {
|
|||||||
gfx_last_mode: GfxVendors::Hybrid,
|
gfx_last_mode: GfxVendors::Hybrid,
|
||||||
gfx_managed: self.gfx_managed,
|
gfx_managed: self.gfx_managed,
|
||||||
gfx_vfio_enable: false,
|
gfx_vfio_enable: false,
|
||||||
|
gfx_save_compute_vfio: false,
|
||||||
active_profile: self.active_profile,
|
active_profile: self.active_profile,
|
||||||
toggle_profiles: self.toggle_profiles,
|
toggle_profiles: self.toggle_profiles,
|
||||||
curr_fan_mode: self.curr_fan_mode,
|
curr_fan_mode: self.curr_fan_mode,
|
||||||
@@ -56,6 +57,7 @@ impl ConfigV324 {
|
|||||||
gfx_last_mode: GfxVendors::Hybrid,
|
gfx_last_mode: GfxVendors::Hybrid,
|
||||||
gfx_managed: self.gfx_managed,
|
gfx_managed: self.gfx_managed,
|
||||||
gfx_vfio_enable: false,
|
gfx_vfio_enable: false,
|
||||||
|
gfx_save_compute_vfio: false,
|
||||||
active_profile: self.active_profile,
|
active_profile: self.active_profile,
|
||||||
toggle_profiles: self.toggle_profiles,
|
toggle_profiles: self.toggle_profiles,
|
||||||
curr_fan_mode: self.curr_fan_mode,
|
curr_fan_mode: self.curr_fan_mode,
|
||||||
@@ -85,6 +87,7 @@ impl ConfigV341 {
|
|||||||
gfx_last_mode: GfxVendors::Hybrid,
|
gfx_last_mode: GfxVendors::Hybrid,
|
||||||
gfx_managed: self.gfx_managed,
|
gfx_managed: self.gfx_managed,
|
||||||
gfx_vfio_enable: false,
|
gfx_vfio_enable: false,
|
||||||
|
gfx_save_compute_vfio: false,
|
||||||
active_profile: self.active_profile,
|
active_profile: self.active_profile,
|
||||||
toggle_profiles: self.toggle_profiles,
|
toggle_profiles: self.toggle_profiles,
|
||||||
curr_fan_mode: self.curr_fan_mode,
|
curr_fan_mode: self.curr_fan_mode,
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ impl CtrlGraphics {
|
|||||||
let mut base = MODPROBE_BASE.to_vec();
|
let mut base = MODPROBE_BASE.to_vec();
|
||||||
base.append(&mut MODPROBE_DRM_MODESET.to_vec());
|
base.append(&mut MODPROBE_DRM_MODESET.to_vec());
|
||||||
base
|
base
|
||||||
},
|
}
|
||||||
GfxVendors::Vfio => Self::get_vfio_conf(devices),
|
GfxVendors::Vfio => Self::get_vfio_conf(devices),
|
||||||
GfxVendors::Integrated => MODPROBE_INTEGRATED.to_vec(),
|
GfxVendors::Integrated => MODPROBE_INTEGRATED.to_vec(),
|
||||||
GfxVendors::Compute => MODPROBE_BASE.to_vec(),
|
GfxVendors::Compute => MODPROBE_BASE.to_vec(),
|
||||||
@@ -423,9 +423,13 @@ impl CtrlGraphics {
|
|||||||
fn logout_required(&self, vendor: GfxVendors) -> GfxRequiredUserAction {
|
fn logout_required(&self, vendor: GfxVendors) -> GfxRequiredUserAction {
|
||||||
if let Ok(config) = self.config.lock() {
|
if let Ok(config) = self.config.lock() {
|
||||||
let current = config.gfx_mode;
|
let current = config.gfx_mode;
|
||||||
if matches!(current, GfxVendors::Integrated | GfxVendors::Vfio | GfxVendors::Compute)
|
if matches!(
|
||||||
&& matches!(vendor, GfxVendors::Integrated | GfxVendors::Vfio | GfxVendors::Compute)
|
current,
|
||||||
{
|
GfxVendors::Integrated | GfxVendors::Vfio | GfxVendors::Compute
|
||||||
|
) && matches!(
|
||||||
|
vendor,
|
||||||
|
GfxVendors::Integrated | GfxVendors::Vfio | GfxVendors::Compute
|
||||||
|
) {
|
||||||
return GfxRequiredUserAction::None;
|
return GfxRequiredUserAction::None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -660,6 +664,13 @@ impl CtrlGraphics {
|
|||||||
let bus = self.bus.clone();
|
let bus = self.bus.clone();
|
||||||
Self::do_vendor_tasks(vendor, vfio_enable, &devices, &bus)?;
|
Self::do_vendor_tasks(vendor, vfio_enable, &devices, &bus)?;
|
||||||
info!("GFX: Graphics mode changed to {}", <&str>::from(vendor));
|
info!("GFX: Graphics mode changed to {}", <&str>::from(vendor));
|
||||||
|
if let Ok(config) = self.config.lock() {
|
||||||
|
if matches!(vendor, GfxVendors::Compute | GfxVendors::Vfio)
|
||||||
|
&& config.gfx_save_compute_vfio
|
||||||
|
{
|
||||||
|
Self::save_gfx_mode(vendor, self.config.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// TODO: undo if failed? Save last mode, catch errors...
|
// TODO: undo if failed? Save last mode, catch errors...
|
||||||
Ok(action_required)
|
Ok(action_required)
|
||||||
|
|||||||
Reference in New Issue
Block a user