diff --git a/CHANGELOG.md b/CHANGELOG.md index bb85357c..21bfacc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- Adjust gfx controller to assume that the graphics driver is loaded if the + mode is set for nvidia/hybrid + # [2.1.0] - 2021-01-09 ### Changed - Updates to dependencies diff --git a/Cargo.lock b/Cargo.lock index 740b72a4..07e80a87 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,7 +29,7 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "asus-nb" -version = "2.1.1" +version = "2.1.2" dependencies = [ "ctrl-gfx", "dbus", @@ -46,7 +46,7 @@ dependencies = [ [[package]] name = "asus-nb-ctrl" -version = "2.1.1" +version = "2.1.2" dependencies = [ "asus-nb", "ctrl-gfx", @@ -232,7 +232,7 @@ dependencies = [ [[package]] name = "ctrl-gfx" -version = "2.1.3" +version = "2.1.4" dependencies = [ "log", "sysfs-class", diff --git a/Makefile b/Makefile index 9962b76a..bd4528c4 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ ifeq ($(VENDORED),1) ARGS += --frozen endif -all: build install +all: build clean: cargo clean diff --git a/asus-nb-ctrl/Cargo.toml b/asus-nb-ctrl/Cargo.toml index 6a54e010..d5642322 100644 --- a/asus-nb-ctrl/Cargo.toml +++ b/asus-nb-ctrl/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "asus-nb-ctrl" -version = "2.1.1" +version = "2.1.2" license = "MPL-2.0" readme = "README.md" authors = ["Luke "] diff --git a/asus-nb-ctrl/src/ctrl_charge.rs b/asus-nb-ctrl/src/ctrl_charge.rs index c2e565ea..497754bb 100644 --- a/asus-nb-ctrl/src/ctrl_charge.rs +++ b/asus-nb-ctrl/src/ctrl_charge.rs @@ -81,7 +81,8 @@ impl CtrlCharge { Ok(BAT_CHARGE_PATH) } else { Err(RogError::MissingFunction( - "Charge control not available".into(), + "Charge control not available, you may require a v5.8.10 series kernel or newer" + .into(), )) } } diff --git a/asus-nb-ctrl/src/ctrl_fan_cpu.rs b/asus-nb-ctrl/src/ctrl_fan_cpu.rs index 03d30386..820eb352 100644 --- a/asus-nb-ctrl/src/ctrl_fan_cpu.rs +++ b/asus-nb-ctrl/src/ctrl_fan_cpu.rs @@ -192,7 +192,7 @@ impl CtrlFanAndCPU { Ok(FAN_TYPE_2_PATH) } else { Err(RogError::MissingFunction( - "Fan mode not available, you may require a v5.8 series kernel or newer".into(), + "Fan mode not available, you may require a v5.8.10 series kernel or newer".into(), )) } } diff --git a/asus-nb-ctrl/src/ctrl_leds.rs b/asus-nb-ctrl/src/ctrl_leds.rs index 9390e8ab..1f900b76 100644 --- a/asus-nb-ctrl/src/ctrl_leds.rs +++ b/asus-nb-ctrl/src/ctrl_leds.rs @@ -2,14 +2,16 @@ static LED_APPLY: [u8; 17] = [0x5d, 0xb4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; static LED_SET: [u8; 17] = [0x5d, 0xb5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; +static KBD_BRIGHT_PATH: &str = "/sys/class/leds/asus::kbd_backlight/brightness"; + use crate::{config::Config, error::RogError, laptops::HELP_ADDRESS}; use asus_nb::{aura_brightness_bytes, aura_modes::AuraModes, fancy::KeyColourArray, LED_MSG_LEN}; use log::{info, warn}; -use std::convert::TryInto; use std::fs::OpenOptions; use std::io::{Read, Write}; use std::sync::Arc; use std::sync::Mutex; +use std::{convert::TryInto, path::Path}; use zbus::dbus_interface; pub struct CtrlKbdBacklight { @@ -227,16 +229,29 @@ impl CtrlKbdBacklight { condev_iface: Option<&String>, supported_modes: Vec, config: Arc>, - ) -> Self { + ) -> Result { // TODO: return error if *all* nodes are None - CtrlKbdBacklight { + let ctrl = CtrlKbdBacklight { + // Using `ok` here so we can continue without keyboard features but + // still get brightness control at least... maybe... led_node: Self::get_node_failover(id_product, None, Self::scan_led_node).ok(), kbd_node: Self::get_node_failover(id_product, condev_iface, Self::scan_kbd_node).ok(), // TODO: Check for existance - bright_node: "/sys/class/leds/asus::kbd_backlight/brightness".to_string(), + bright_node: Self::get_kbd_bright_path()?.to_owned(), supported_modes, flip_effect_write: false, config, + }; + Ok(ctrl) + } + + fn get_kbd_bright_path() -> Result<&'static str, RogError> { + if Path::new(KBD_BRIGHT_PATH).exists() { + Ok(KBD_BRIGHT_PATH) + } else { + Err(RogError::MissingFunction( + "Keyboard features missing, you may require a v5.11 series kernel or newer".into(), + )) } } @@ -245,6 +260,8 @@ impl CtrlKbdBacklight { iface: Option<&String>, fun: fn(&str, Option<&String>) -> Result, ) -> Result { + // We do three tries here just to be certain that we avoid systemd unit + // load order issues for n in 0..=2 { // 0,1,2 inclusive match fun(id_product, iface) { diff --git a/asus-nb-ctrl/src/daemon.rs b/asus-nb-ctrl/src/daemon.rs index 74a13c3e..077b8d7b 100644 --- a/asus-nb-ctrl/src/daemon.rs +++ b/asus-nb-ctrl/src/daemon.rs @@ -96,29 +96,30 @@ fn start_daemon() -> Result<(), Box> { // Collect tasks for task thread let mut tasks: Vec>> = Vec::new(); - match CtrlFanAndCPU::new(config.clone()) { - Ok(mut ctrl) => { - ctrl.reload() - .unwrap_or_else(|err| warn!("Profile control: {}", err)); - let tmp = Arc::new(Mutex::new(ctrl)); - DbusFanAndCpu::new(tmp.clone()).add_to_server(&mut object_server); - tasks.push(tmp); - } - Err(err) => { - error!("Profile control: {}", err); - } + if let Ok(mut ctrl) = CtrlFanAndCPU::new(config.clone()).map_err(|err| { + error!("Profile control: {}", err); + }) { + ctrl.reload() + .unwrap_or_else(|err| warn!("Profile control: {}", err)); + let tmp = Arc::new(Mutex::new(ctrl)); + DbusFanAndCpu::new(tmp.clone()).add_to_server(&mut object_server); + tasks.push(tmp); }; if let Some(laptop) = laptop { - let ctrl = CtrlKbdBacklight::new( + if let Ok(ctrl) = CtrlKbdBacklight::new( laptop.usb_product(), laptop.condev_iface(), laptop.supported_modes().to_owned(), config, - ); - let tmp = Arc::new(Mutex::new(ctrl)); - DbusKbdBacklight::new(tmp.clone()).add_to_server(&mut object_server); - tasks.push(tmp); + ) + .map_err(|err| { + error!("Keyboard control: {}", err); + }) { + let tmp = Arc::new(Mutex::new(ctrl)); + DbusKbdBacklight::new(tmp.clone()).add_to_server(&mut object_server); + tasks.push(tmp); + } } // TODO: implement messaging between threads to check fails diff --git a/asus-nb/Cargo.toml b/asus-nb/Cargo.toml index 3eedbe5c..c534fe4b 100644 --- a/asus-nb/Cargo.toml +++ b/asus-nb/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "asus-nb" -version = "2.1.1" +version = "2.1.2" license = "MPL-2.0" readme = "README.md" authors = ["Luke "] diff --git a/ctrl-gfx/Cargo.toml b/ctrl-gfx/Cargo.toml index dfd5ba51..3a8053e5 100644 --- a/ctrl-gfx/Cargo.toml +++ b/ctrl-gfx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ctrl-gfx" -version = "2.1.3" +version = "2.1.4" license = "MPL-2.0" readme = "README.md" authors = ["Luke "] diff --git a/ctrl-gfx/src/ctrl_gfx.rs b/ctrl-gfx/src/ctrl_gfx.rs index a3e26734..342fc023 100644 --- a/ctrl-gfx/src/ctrl_gfx.rs +++ b/ctrl-gfx/src/ctrl_gfx.rs @@ -178,27 +178,36 @@ impl CtrlGraphics { /// Associated method to get which vendor mode is set pub fn get_vendor() -> Result { + let mode = match Self::get_prime_discrete() { + Ok(m) => m, + Err(_) => "nvidia".to_string(), + }; let modules = Module::all().map_err(|err| GfxError::Read("get_vendor".into(), err))?; - let vendor = if modules + + let driver_loaded = if modules .iter() .any(|module| module.name == "nouveau" || module.name == "nvidia") { - info!("nvidia or nouveau module found"); - let mode = match Self::get_prime_discrete() { - Ok(m) => m, - Err(_) => "nvidia".to_string(), - }; + true + } else { + false + }; + let vendor = if mode == "off" { + if driver_loaded { + info!("dGPU driver loaded for compute mode"); + "compute".to_string() + } else { + info!("No dGPU driver loaded"); + "integrated".to_string() + } + } else { + info!("Assuming dGPU driver loaded"); if mode == "on-demand" { "hybrid".to_string() - } else if mode == "off" { - "compute".to_string() } else { "nvidia".to_string() } - } else { - info!("No dGPU driver (nouveau or nvidia) loaded"); - "integrated".to_string() }; Ok(vendor)