diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fa312b6..2b897333 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +# [3.2.3] - 2021-03-24 +### Changed +- Better handling of session tracking +### Added +- List all profile data +- Get active profile name +- Get active profile data + # [3.2.2] - 2021-03-23 ### Changed - Fix brightness control, again, for non-RGB keyboards diff --git a/Cargo.lock b/Cargo.lock index c9946bbb..6bc6e92d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,12 +28,13 @@ dependencies = [ "daemon", "notify-rust", "rog_dbus", + "rog_types", "serde_json", ] [[package]] name = "asusctl" -version = "3.1.4" +version = "3.1.5" dependencies = [ "daemon", "gumdrop", @@ -196,7 +197,7 @@ dependencies = [ [[package]] name = "daemon" -version = "3.2.2" +version = "3.2.3" dependencies = [ "env_logger", "intel-pstate", @@ -887,7 +888,7 @@ checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" [[package]] name = "rog_dbus" -version = "3.0.0" +version = "3.1.0" dependencies = [ "rog_fan_curve", "rog_types", @@ -908,7 +909,7 @@ dependencies = [ [[package]] name = "rog_types" -version = "3.1.1" +version = "3.2.0" dependencies = [ "gumdrop", "rog_fan_curve", diff --git a/README.md b/README.md index dfbafa2d..04c29ade 100644 --- a/README.md +++ b/README.md @@ -5,29 +5,26 @@ `asusd` is a utility for Linux to control many aspects of various ASUS laptops but can also be used with non-asus laptops with reduced features. -**NOTICE:** +## Goals -This app is developed and tested on fedora only. Support is not provided for Arch or Arch based distros. +1. To provide an interface for rootless control of some system functions most users wish to control such as fan speeds, keyboard LEDs, graphics modes. +2. Enable third-party apps to use the above with dbus methods +3. To make the above as easy as possible for new users + +Point 3 means that the list of supported distros is very narrow - fedora is explicitly +supported, while Ubuntu and openSUSE are level-2 support. All other distros are *not* +supported (while asusd might still run fine on them). For best support use fedora 32+ Workstation. **NOTICE:** -The following is *not* required for 5.11 kernel versions, as this version includes -all the required patches. ---- -This program requires the kernel patch [here](https://www.spinics.net/lists/linux-input/msg68977.html) to be applied. -Alternatively you may use the dkms module for 'hid-asus-rog` from one of the -repositories [here](https://download.opensuse.org/repositories/home:/luke_nukem:/asus/). +1. The following is *not* required for 5.11 kernel versions, as this version includes all the required patches. +2. 2021 hardware has a new keyboard prod_id and the patch is included in 5.12+ -The patch enables the following in kernel: +'hid-asus-rog` DKMS module from [here](https://download.opensuse.org/repositories/home:/luke_nukem:/asus/). +The module enables the following in kernel: + +- Initialising the keyboard - All hotkeys (FN+Key combos) -- Control of keyboard brightness using FN+Key combos (not RGB) -- FN+F5 (fan) to toggle fan modes - -You will not get RGB control in kernel (yet), and `asusd` + `asusctl` is required -to change modes and RGB settings. - -Many other patches for these laptops, AMD and Intel based, are working their way -in to the kernel. ## Discord @@ -52,13 +49,14 @@ will probably suffer another rename once it becomes generic enough to do so. - [X] User notifications daemon - [X] Setting/modifying built-in LED modes - [X] Per-key LED setting -- [X] Fancy LED modes (See examples) +- [X] Fancy LED modes (See examples) (currently being reworked) - [X] Saving settings for reload - [X] Logging - required for journalctl -- [X] AniMatrix display on G14 models that include it +- [X] AniMatrix display on G14 models that include it (currently being reworked) - [X] Set battery charge limit (with kernel supporting this) -- [X] Fancy fan control on G14 + G15 thanks to @Yarn1 -- [X] Graphics mode switching between iGPU, dGPU, and On-Demand +- [X] Fan curve control on G14 + G15 thanks to @Yarn1 +- [X] Graphics mode switching between iGPU, dGPU, on-demand, and vfio (for VM pass-through) + + [X] Requires only a logout/login - [X] Toggle bios setting for boot/POST sound - [X] Toggle bios setting for "dedicated gfx" mode on supported laptops (g-sync) @@ -66,13 +64,15 @@ will probably suffer another rename once it becomes generic enough to do so. ## Graphics switching -A new feature has been added to enable switching graphics modes. This can be disabled -in the config with `"manage_gfx": false,`. Additionally there is an extra setting -for laptops capable of g-sync dedicated gfx mode to enable the graphics switching -to switch on dedicated gfx for "nvidia" mode. +`asusd` can switch graphics modes between: +- `integrated`, uses the iGPU only and force-disables the dGPU +- `hybrid`, enables Nvidia prime-offload mode +- `nvidia`, uses the Nvidia gpu only +- `vfio`, binds the Nvidia gpu to vfio for VM pass-through -The CLI option for this does not require root until it asks for it, and provides -instructions. +This can be disabled in the config with `"manage_gfx": false,`. Additionally there +is an extra setting for laptops capable of g-sync dedicated gfx mode to enable the +graphics switching to switch on dedicated gfx for "nvidia" mode. This switcher conflicts with other gpu switchers like optimus-manager, suse-prime or ubuntu-prime, system76-power, and bbswitch. If you have issues with `asusd` @@ -109,22 +109,18 @@ Models GA401, GA502, GU502 support LED brightness change only (no RGB). If you model isn't getting the correct led modes, you can edit the file `/etc/asusd/asusd-ledmodes.toml`, the LED Mode numbers are as follows: -``` -0 STATIC -1 BREATHING -2 STROBE -3 RAINBOW -4 STAR -5 RAIN -6 HIGHLIGHT -7 LASER -8 RIPPLE -10 PULSE -11 COMET -12 FLASH -13 MULTISTATIC -255 PER_KEY -``` +- Static +- Breathe +- Strobe +- Rainbow +- Star +- Rain +- Highlight +- Laser +- Ripple +- Pulse +- Comet +- Flash use `cat /sys/class/dmi/id/product_name` to get details about your laptop. @@ -182,26 +178,8 @@ can be added on request). You will need to install the alternative service from Run `sudo make uninstall` in the source repo, and remove `/etc/asusd/`. -## Updating - -If there has been a config file format change your config will be overwritten. This will -become less of an issue once the feature set is nailed down. Work is happening to enable -parsing of older configs and transferring settings to new. - # USAGE -**NOTE! Fan mode toggling requires a newer kernel**. I'm unsure when the patches -required for it got merged - I've tested with the 5.6.6 kernel and above only. -To see if the fan-mode changed cat either: - -- `cat /sys/devices/platform/asus-nb-wmi/throttle_thermal_policy` or -- `cat /sys/devices/platform/asus-nb-wmi/fan_boost_mode` - -The numbers are 0 = Normal/Balanced, 1 = Boost, 2 = Silent. - -Running the program as a daemon manually will require root. Standard (non-daemon) -mode expects to be communicating with the daemon mode over dbus. - Commands are given by: ``` @@ -221,23 +199,6 @@ Some commands may have subcommands: asusctl --help ``` -## Daemon mode - -If the daemon service is enabled then on boot the following will be reloaded from save: - -- LED brightness -- Last used built-in mode -- fan-boost/thermal mode -- battery charging limit - -The daemon also saves the settings per mode as the keyboard does not do this -itself - this means cycling through modes with the Aura keys will use the -settings that were used via CLI. - -Daemon mode creates a config file at `/etc/asusd/asusd.conf` which you can edit a -little of. Most parts will be byte arrays, but you can adjust things like -`mode_performance`. - ## User NOTIFICATIONS via dbus If you have a notifications handler set up, or are using KDE or Gnome then you @@ -249,10 +210,6 @@ systemctl --user start asus-notify.service ``` # OTHER -## DBUS Input - -See [README_DBUS.md](./README_DBUS.md). - ## AniMe input You will want to look at what MeuMeu has done with [https://github.com/Meumeu/ZephyrusBling/](https://github.com/Meumeu/ZephyrusBling/) @@ -278,11 +235,3 @@ omit_drivers+=" nvidia nvidia-drm nvidia-modeset nvidia-uvm " # License Mozilla Public License 2 (MPL-2.0) - -# Credits - -- [flukejones](https://github.com/flukejones/), project maintainer. -- [tuxuser](https://github.com/tuxuser/) -- [aspann](https://github.com/aspann) -- [meumeu](https://github.com/Meumeu) -- Anyone missed? Please contact me diff --git a/README_DBUS.md b/README_DBUS.md deleted file mode 100644 index 618ef6f5..00000000 --- a/README_DBUS.md +++ /dev/null @@ -1,115 +0,0 @@ -# DBUS Guide - -**WARNING: In progress updates** - -Interface name = org.asuslinux.Daemon - -Paths: -- `/org/asuslinux/Gfx` - + `SetVendor` (string) - + `NotifyVendor` (recv vendor label string) -- `/org/asuslinux/Led` - + `LedMode` (AuraMode as json) - + `LedModes` (array[AuraMode] as json) - + `SetLedMode` (AuraMode -> json) - + `NotifyLed` (recv json data) -- `/org/asuslinux/Anime` - + `SetAnime` (byte array data) -- `/org/asuslinux/Charge` - + `Limit` (u8) - + `SetLimit` (u8) - + `NotifyCharge` (recv i8) -- `/org/asuslinux/Profile` - + `Profile` (recv current profile data as json string) - + `Profiles` (recv profiles data as json string (map)) - + `SetProfile` (event -> json) - + `NotifyProfile` (recv current profile name) - -All `Notify*` methods are signals. - -### SetLed - -This method expects a string of JSON as input. The JSON is of format such: - -``` -{ - "Static": { - "colour": [ 255, 0, 0] - } -} -``` - -The possible contents of a mode are: - -- `"colour": [u8, u8, u8],` -- `"speed": ,` -- `"direction": ,` - -Modes may or may not be available for a specific laptop (TODO: dbus getter for -supported modes). Modes are: - -- `"Static": { "colour": },` -- `"Pulse": { "colour": },` -- `"Comet": { "colour": },` -- `"Flash": { "colour": },` -- `"Strobe": { "speed": },` -- `"Rain": { "speed": },` -- `"Laser": { "colour": , "speed": },` -- `"Ripple": { "colour": , "speed": },` -- `"Highlight": { "colour": , "speed": },` -- `"Rainbow": { "direction": , "speed": },` -- `"Breathe": { "colour": , "colour2": , "speed": },` -- `"Star": { "colour": , "colour2": , "speed": },` -- `"MultiStatic": { "colour1": , "colour2": , , "colour3": , "colour4": },` - -Additionally to the above there is `"RGB": [[u8; 64]; 11]` which is for per-key -setting of LED's but this requires some refactoring to make it easily useable over -dbus. - -Lastly, there is `"LedBrightness": ` which accepts 0-3 for off, low, med, high. - -### SetFanMode - -Accepts an integer from the following: - -- `0`: Normal -- `1`: Boost mode -- `2`: Silent mode - -## dbus-send examples: - -``` -dbus-send --system --type=method_call --dest=org.asuslinux.Daemon /org/asuslinux/Profile org.asuslinux.Daemon.NextProfile -``` - -## dbus-send examples OUTDATED - -``` -dbus-send --system --type=method_call --dest=org.asuslinux.Daemon /org/asuslinux/Daemon org.asuslinux.Daemon.SetKeyBacklight string:'{"Static": {"colour": [ 80, 0, 40]}}' -``` - -``` -dbus-send --system --type=method_call --dest=org.asuslinux.Daemon /org/asuslinux/Daemon org.asuslinux.Daemon.SetKeyBacklight string:'{"Star":{"colour":[0,255,255],"colour2":[0,0,0],"speed":"Med"}}' -``` - -**Note:** setting colour2 to `[0,0,255]` activates random star colour. Colour2 has no effect on the -mode otherwise. -``` -dbus-send --system --type=method_call --dest=org.asuslinux.Daemon /org/asuslinux/Daemon org.asuslinux.Daemon.SetKeyBacklight string:'{"Star":{"colour":[0,255,255],"colour2":[0,0,255],"speed":"Med"}}' -``` - -``` -dbus-send --system --type=method_call --dest=org.asuslinux.Daemon /org/asuslinux/Daemon org.asuslinux.Daemon.SetKeyBacklight string:'{"LedBrightness":3}' -``` - -``` -dbus-send --system --type=method_call --dest=org.asuslinux.Daemon /org/asuslinux/Daemon org.asuslinux.Daemon.SetFanMode byte:'2' -``` - -Monitoring dbus while sending commands via `rog-core` will give you the json structure if you are otherwise unsure, e.g: `dbus-monitor --system |grep -A2 asuslinux`. - -## Getting an introspection .xml - -``` -dbus-send --system --print-reply --dest=org.asuslinux.Daemon /org/asuslinux/Charge org.freedesktop.DBus.Introspectable.Introspect > xml/asusd-charge.xml -``` \ No newline at end of file diff --git a/TODO.md b/TODO.md deleted file mode 100644 index a3e0ba4d..00000000 --- a/TODO.md +++ /dev/null @@ -1,7 +0,0 @@ -# TODO - -- There is lots of code duplication. This should be turned in to macros (dbus stuff etc) -- Add a little more information to profile notifications such as freq min/max, fan curves -- Finish splitting out controllers to own crates -- Finish move to zbus in client when zbus has client signal watch -- Consider a rename again because the project is getting a lot less ASUS centric \ No newline at end of file diff --git a/asus-notify/Cargo.toml b/asus-notify/Cargo.toml index 8081b9fd..24b320bf 100644 --- a/asus-notify/Cargo.toml +++ b/asus-notify/Cargo.toml @@ -10,6 +10,7 @@ edition = "2018" # serialisation serde_json = "^1.0" rog_dbus = { path = "../rog-dbus" } +rog_types = { path = "../rog-types" } daemon = { path = "../daemon" } [dependencies.notify-rust] diff --git a/asus-notify/src/main.rs b/asus-notify/src/main.rs index 2e791c27..01dd7206 100644 --- a/asus-notify/src/main.rs +++ b/asus-notify/src/main.rs @@ -1,6 +1,6 @@ -use daemon::config::Profile; use notify_rust::{Hint, Notification, NotificationHandle}; use rog_dbus::{DbusProxies, Signals}; +use rog_types::profile::Profile; use std::error::Error; use std::time::Duration; diff --git a/asusctl/Cargo.toml b/asusctl/Cargo.toml index fb627bc7..293e06a7 100644 --- a/asusctl/Cargo.toml +++ b/asusctl/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "asusctl" -version = "3.1.4" +version = "3.1.5" authors = ["Luke D Jones "] edition = "2018" diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index 9c0796a4..4f414d50 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -389,6 +389,9 @@ fn handle_profile( if !cmd.next && !cmd.create && !cmd.list + && !cmd.active_name + && !cmd.active_data + && !cmd.profiles_data && cmd.remove.is_none() && cmd.curve.is_none() && cmd.max_percentage.is_none() @@ -419,12 +422,34 @@ fn handle_profile( if cmd.next { dbus.proxies().profile().next_fan()?; - } else if cmd.list { - let profile_names = dbus.proxies().profile().profile_names()?; - println!("Available profiles are {}", profile_names); - } else if let Some(profile) = &cmd.remove { + } + if let Some(profile) = &cmd.remove { dbus.proxies().profile().remove(profile)? - } else { + } + if cmd.list { + let profile_names = dbus.proxies().profile().profile_names()?; + println!("Available profiles are {:?}", profile_names); + } + if cmd.active_name { + println!( + "Active profile: {:?}", + dbus.proxies().profile().active_profile_name()? + ); + } + if cmd.active_data { + println!("Active profile:"); + for s in dbus.proxies().profile().active_profile_data()?.lines() { + println!("{}", s); + } + } + if cmd.profiles_data { + println!("Profiles:"); + for s in dbus.proxies().profile().all_profile_data()?.lines() { + println!("{}", s); + } + } + + if cmd.profile.is_some() { dbus.proxies() .profile() .write_command(&ProfileEvent::Cli(cmd.clone()))? diff --git a/daemon/Cargo.toml b/daemon/Cargo.toml index b263cd01..07f18346 100644 --- a/daemon/Cargo.toml +++ b/daemon/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "daemon" -version = "3.2.2" +version = "3.2.3" license = "MPL-2.0" readme = "README.md" authors = ["Luke "] diff --git a/daemon/src/config.rs b/daemon/src/config.rs index 82ef1058..13c10264 100644 --- a/daemon/src/config.rs +++ b/daemon/src/config.rs @@ -1,6 +1,5 @@ use log::{error, info, warn}; -use rog_fan_curve::Curve; -use rog_types::gfx_vendors::GfxVendors; +use rog_types::{gfx_vendors::GfxVendors, profile::Profile}; use serde_derive::{Deserialize, Serialize}; use std::collections::BTreeMap; use std::fs::{File, OpenOptions}; @@ -136,45 +135,3 @@ impl Config { .unwrap_or_else(|err| error!("Could not write config: {}", err)); } } - -#[derive(Deserialize, Serialize)] -pub struct Profile { - pub min_percentage: u8, - pub max_percentage: u8, - pub turbo: bool, - pub fan_preset: u8, - pub fan_curve: Option, -} - -#[deprecated] -pub type CPUSettings = Profile; - -impl Default for Profile { - fn default() -> Self { - Profile { - min_percentage: 0, - max_percentage: 100, - turbo: false, - fan_preset: 0, - fan_curve: None, - } - } -} - -impl Profile { - pub fn new( - min_percentage: u8, - max_percentage: u8, - turbo: bool, - fan_preset: u8, - fan_curve: Option, - ) -> Self { - Profile { - min_percentage, - max_percentage, - turbo, - fan_preset, - fan_curve, - } - } -} diff --git a/daemon/src/config_old.rs b/daemon/src/config_old.rs index fdb8e264..0e307617 100644 --- a/daemon/src/config_old.rs +++ b/daemon/src/config_old.rs @@ -1,8 +1,8 @@ -use rog_types::{aura_modes::AuraEffect, gfx_vendors::GfxVendors}; +use rog_types::{aura_modes::AuraEffect, gfx_vendors::GfxVendors, profile::Profile}; use serde_derive::{Deserialize, Serialize}; use std::collections::BTreeMap; -use crate::config::{Config, Profile}; +use crate::config::Config; /// for parsing old v2.1.2 config #[allow(dead_code)] diff --git a/daemon/src/ctrl_fan_cpu.rs b/daemon/src/ctrl_fan_cpu.rs index 134bd974..a3a67302 100644 --- a/daemon/src/ctrl_fan_cpu.rs +++ b/daemon/src/ctrl_fan_cpu.rs @@ -1,10 +1,7 @@ use crate::error::RogError; -use crate::{ - config::{Config, Profile}, - GetSupported, -}; +use crate::{config::Config, GetSupported}; use log::{info, warn}; -use rog_types::profile::{FanLevel, ProfileEvent}; +use rog_types::profile::{FanLevel, Profile, ProfileEvent}; use serde_derive::{Deserialize, Serialize}; use std::fs::OpenOptions; use std::io::Write; @@ -90,60 +87,61 @@ impl DbusFanAndCpu { } /// Fetch the active profile name - fn active_profile_name(&mut self) -> String { + fn active_profile_name(&mut self) -> zbus::fdo::Result { if let Ok(ctrl) = self.inner.try_lock() { if let Ok(mut cfg) = ctrl.config.try_lock() { cfg.read(); - return cfg.active_profile.clone(); + return Ok(cfg.active_profile.clone()); } } - "Failed".to_string() + Err(Error::Failed( + "Failed to get active profile name".to_string(), + )) } + // TODO: Profile can't implement Type because of Curve /// Fetch the active profile details - fn profile(&mut self) -> String { + fn profile(&mut self) -> zbus::fdo::Result { if let Ok(ctrl) = self.inner.try_lock() { if let Ok(mut cfg) = ctrl.config.try_lock() { cfg.read(); if let Some(profile) = cfg.power_profiles.get(&cfg.active_profile) { - if let Ok(json) = serde_json::to_string(profile) { - return json; + if let Ok(json) = serde_json::to_string_pretty(profile) { + return Ok(json); } } } } - "Failed".to_string() + Err(Error::Failed( + "Failed to get active profile details".to_string(), + )) } - fn profiles(&mut self) -> String { + /// Fetch all profile data + fn profiles(&mut self) -> zbus::fdo::Result { if let Ok(ctrl) = self.inner.try_lock() { if let Ok(mut cfg) = ctrl.config.try_lock() { cfg.read(); - if let Ok(json) = serde_json::to_string(&cfg.power_profiles) { - return json; + if let Ok(json) = serde_json::to_string_pretty(&cfg.power_profiles) { + return Ok(json); } } } - "Failed".to_string() + Err(Error::Failed( + "Failed to get all profile details".to_string(), + )) } - fn profile_names(&self) -> String { + fn profile_names(&self) -> zbus::fdo::Result> { if let Ok(ctrl) = self.inner.try_lock() { if let Ok(mut cfg) = ctrl.config.try_lock() { cfg.read(); - - let profile_names: String = cfg - .power_profiles - .keys() - .cloned() - .collect::>() - .join(", "); - - return profile_names; + let profile_names = cfg.power_profiles.keys().cloned().collect::>(); + return Ok(profile_names); } } - "Failed".to_string() + Err(Error::Failed("Failed to get all profile names".to_string())) } fn remove(&self, profile: &str) -> zbus::fdo::Result<()> { @@ -172,7 +170,7 @@ impl DbusFanAndCpu { } } - return Err(Error::Failed("Failed to lock configuration".to_string())); + Err(Error::Failed("Failed to lock configuration".to_string())) } #[dbus_interface(signal)] diff --git a/daemon/src/ctrl_gfx/error.rs b/daemon/src/ctrl_gfx/error.rs index cdc5a0b1..9030f02f 100644 --- a/daemon/src/ctrl_gfx/error.rs +++ b/daemon/src/ctrl_gfx/error.rs @@ -10,6 +10,8 @@ pub enum GfxError { DisplayManagerAction(String, ExitStatus), DisplayManagerTimeout(String), GsyncModeActive, + VfioBuiltin, + MissingModule(String), } impl fmt::Display for GfxError { @@ -28,6 +30,11 @@ impl fmt::Display for GfxError { f, "Can not switch gfx modes when dedicated/G-Sync mode is active" ), + GfxError::VfioBuiltin => write!( + f, + "Can not switch to vfio mode if the modules are built in to kernel" + ), + GfxError::MissingModule(m) => write!(f, "The module {} is missing", m), } } } diff --git a/daemon/src/ctrl_gfx/gfx.rs b/daemon/src/ctrl_gfx/gfx.rs index 24faf0bf..d7a978b5 100644 --- a/daemon/src/ctrl_gfx/gfx.rs +++ b/daemon/src/ctrl_gfx/gfx.rs @@ -3,7 +3,7 @@ use ctrl_gfx::*; use ctrl_rog_bios::CtrlRogBios; use log::{error, info, warn}; use logind_zbus::{ - types::{SessionClass, SessionInfo, SessionType}, + types::{SessionClass, SessionInfo, SessionState, SessionType}, ManagerProxy, SessionProxy, }; use rog_types::gfx_vendors::{GfxRequiredUserAction, GfxVendors}; @@ -326,6 +326,9 @@ impl CtrlGraphics { { return Ok(()); } + if output.stderr.ends_with("is builtin.\n".as_bytes()) { + return Err(GfxError::VfioBuiltin.into()); + } if output.stderr.ends_with("Permission denied\n".as_bytes()) { warn!( "{} {} failed: {:?}", @@ -336,6 +339,11 @@ impl CtrlGraphics { warn!("GFX: It may be safe to ignore the above error, run `lsmod |grep {}` to confirm modules loaded", driver); return Ok(()); } + if String::from_utf8_lossy(&output.stderr) + .contains(&format!("Module {} not found", driver)) + { + return Err(GfxError::MissingModule(driver.into()).into()); + } if count >= MAX_TRIES { let msg = format!( "{} {} failed: {:?}", @@ -350,7 +358,7 @@ impl CtrlGraphics { } count += 1; - std::thread::sleep(std::time::Duration::from_millis(250)); + std::thread::sleep(std::time::Duration::from_millis(50)); } } @@ -439,6 +447,7 @@ impl CtrlGraphics { } } GfxVendors::Vfio => { + Self::do_driver_action("nouveau", "rmmod")?; for driver in NVIDIA_DRIVERS.iter() { Self::do_driver_action(driver, "rmmod")?; } @@ -446,6 +455,7 @@ impl CtrlGraphics { Self::do_driver_action("vfio-pci", "modprobe")?; } GfxVendors::Integrated => { + Self::do_driver_action("nouveau", "rmmod")?; for driver in VFIO_DRIVERS.iter() { Self::do_driver_action(driver, "rmmod")?; } @@ -455,7 +465,6 @@ impl CtrlGraphics { Self::unbind_remove_nvidia(&devices)?; } } - Ok(()) } @@ -468,9 +477,10 @@ impl CtrlGraphics { if session_proxy.get_class()? == SessionClass::User { match session_proxy.get_type()? { SessionType::X11 | SessionType::Wayland | SessionType::MIR => { - //if session_proxy.get_active()? { - return Ok(true); - //} + match session_proxy.get_state()? { + SessionState::Online | SessionState::Active => return Ok(true), + SessionState::Closing | SessionState::Invalid => {} + } } _ => {} } @@ -499,8 +509,7 @@ impl CtrlGraphics { loop { let tmp = manager.list_sessions()?; if !tmp.iter().eq(&sessions) { - warn!("GFX: Sessions list changed"); - warn!("GFX: Old list:\n{:?}\nNew list:\n{:?}", &sessions, &tmp); + info!("GFX thread: Sessions list changed"); sessions = tmp; } @@ -523,33 +532,18 @@ impl CtrlGraphics { sleep(SLEEP_PERIOD); } - info!("GFX: all graphical user sessions ended, continuing"); + info!("GFX thread: all graphical user sessions ended, continuing"); Self::do_display_manager_action("stop")?; - - match Self::wait_display_manager_state("inactive") { - Ok(_) => info!("GFX: display-manager stopped"), - Err(err) => { - warn!("GFX: {}", err); - warn!("GFX: Retry stop display manager"); - Self::do_display_manager_action("stop")?; - Self::wait_display_manager_state("inactive")?; - } - } + Self::wait_display_manager_state("inactive")?; Self::do_vendor_tasks(vendor, &devices, &bus)?; - Self::do_display_manager_action("start")?; - - if Self::wait_display_manager_state("active").is_err() { - error!("GFX: display-manager failed to start normally, attempting restart"); - Self::do_display_manager_action("restart")?; - Self::wait_display_manager_state("active")?; - } + Self::do_display_manager_action("restart")?; // Save selected mode in case of reboot Self::save_gfx_mode(vendor, config); - info!("GFX: display-manager started"); + info!("GFX thread: display-manager started"); let v: &str = vendor.into(); - info!("GFX: Graphics mode changed to {} successfully", v); + info!("GFX thread: Graphics mode changed to {} successfully", v); Ok(format!("Graphics mode changed to {} successfully", v)) } @@ -560,7 +554,7 @@ impl CtrlGraphics { info!("GFX: Cancelling previous thread"); tx.send(true) .map_err(|err| { - warn!("GFX: {}", err); + warn!("GFX thread: {}", err); }) .ok(); } @@ -619,6 +613,7 @@ impl CtrlGraphics { let devices = self.nvidia.clone(); let bus = self.bus.clone(); Self::do_vendor_tasks(vendor, &devices, &bus)?; + info!("GFX: Graphics mode changed to {}", <&str>::from(vendor)); } // TODO: undo if failed? Save last mode, catch errors... Ok(action_required) diff --git a/rog-dbus/Cargo.toml b/rog-dbus/Cargo.toml index f99a7782..fd1e3778 100644 --- a/rog-dbus/Cargo.toml +++ b/rog-dbus/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rog_dbus" -version = "3.0.0" +version = "3.1.0" license = "MPL-2.0" readme = "README.md" authors = ["Luke "] diff --git a/rog-dbus/src/zbus_profile.rs b/rog-dbus/src/zbus_profile.rs index 504b10dc..99760e46 100644 --- a/rog-dbus/src/zbus_profile.rs +++ b/rog-dbus/src/zbus_profile.rs @@ -42,7 +42,7 @@ trait Daemon { fn profiles(&self) -> zbus::Result; /// ProfileNames method - fn profile_names(&self) -> zbus::Result; + fn profile_names(&self) -> zbus::Result>; /// Remove method fn remove(&self, profile: &str) -> zbus::Result<()>; @@ -72,6 +72,16 @@ impl<'a> ProfileProxy<'a> { self.0.active_profile_name() } + #[inline] + pub fn active_profile_data(&self) -> Result { + self.0.profile() + } + + #[inline] + pub fn all_profile_data(&self) -> Result { + self.0.profiles() + } + #[inline] pub fn next_fan(&self) -> Result<()> { self.0.next_profile() @@ -89,7 +99,7 @@ impl<'a> ProfileProxy<'a> { } #[inline] - pub fn profile_names(&self) -> Result { + pub fn profile_names(&self) -> Result> { self.0.profile_names() } diff --git a/rog-types/Cargo.toml b/rog-types/Cargo.toml index 7b7510f3..f5a47edc 100644 --- a/rog-types/Cargo.toml +++ b/rog-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rog_types" -version = "3.1.1" +version = "3.2.0" license = "MPL-2.0" readme = "README.md" authors = ["Luke "] diff --git a/rog-types/src/profile.rs b/rog-types/src/profile.rs index 415df1e7..a181c186 100644 --- a/rog-types/src/profile.rs +++ b/rog-types/src/profile.rs @@ -3,6 +3,48 @@ use rog_fan_curve::{Curve, Fan}; use serde_derive::{Deserialize, Serialize}; use std::str::FromStr; +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct Profile { + pub min_percentage: u8, + pub max_percentage: u8, + pub turbo: bool, + pub fan_preset: u8, + pub fan_curve: Option, +} + +#[deprecated] +pub type CPUSettings = Profile; + +impl Default for Profile { + fn default() -> Self { + Profile { + min_percentage: 0, + max_percentage: 100, + turbo: false, + fan_preset: 0, + fan_curve: None, + } + } +} + +impl Profile { + pub fn new( + min_percentage: u8, + max_percentage: u8, + turbo: bool, + fan_preset: u8, + fan_curve: Option, + ) -> Self { + Profile { + min_percentage, + max_percentage, + turbo, + fan_preset, + fan_curve, + } + } +} + #[derive(Debug, Serialize, Deserialize)] pub enum ProfileEvent { Cli(ProfileCommand), @@ -80,8 +122,16 @@ pub struct ProfileCommand { pub next: bool, #[options(help = "create the profile if it doesn't exist")] pub create: bool, + #[options(meta = "", help = "remove a profile by name")] + pub remove: Option, #[options(help = "list available profiles")] pub list: bool, + #[options(help = "get active profile name")] + pub active_name: bool, + #[options(help = "get active profile data")] + pub active_data: bool, + #[options(help = "get all profile data")] + pub profiles_data: bool, #[options(meta = "", help = "enable or disable cpu turbo")] pub turbo: Option, @@ -100,6 +150,4 @@ pub struct ProfileCommand { pub curve: Option, #[options(free)] pub profile: Option, - #[options(help = "remove a profile by name")] - pub remove: Option, }