mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-23 09:53:20 +01:00
Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bdb6c5b2ff | ||
|
|
a318fbceec | ||
|
|
8feacf863a | ||
|
|
0c62582515 | ||
|
|
3c575e4d2a | ||
|
|
dbfd73da5e | ||
|
|
b1ee449b97 | ||
|
|
245c035dc9 | ||
|
|
07daa0df61 | ||
|
|
c7893b16f9 | ||
|
|
8e8681c190 | ||
|
|
b26c6a55f0 | ||
|
|
93d472fe74 | ||
|
|
5469c73f11 | ||
|
|
ad95765954 | ||
|
|
e42a5bc3e9 | ||
|
|
28347e87eb | ||
|
|
b34cb672c3 | ||
|
|
559ddc9a22 | ||
|
|
a8c014881f | ||
|
|
f417032ed9 | ||
|
|
616fb3aea6 | ||
|
|
6e6e057995 | ||
|
|
085e63ebab | ||
|
|
fdadffcdde | ||
|
|
5f51527dd7 | ||
|
|
39525980a0 | ||
|
|
83a0b570e0 | ||
|
|
2bfbce36b0 | ||
|
|
2705b08dca | ||
|
|
2fca7a09c4 | ||
|
|
ef0da62c55 | ||
|
|
9dab120bcf |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@
|
||||
vendor.tar.xz
|
||||
cargo-config
|
||||
.idea
|
||||
vendor
|
||||
vendor-*
|
||||
vendor_*
|
||||
.vscode-ctags
|
||||
|
||||
@@ -1,27 +1,62 @@
|
||||
image: rust:latest
|
||||
|
||||
cache:
|
||||
key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
|
||||
paths:
|
||||
# Don't include `incremental` to save space
|
||||
# Debug
|
||||
- target/debug/build/
|
||||
- target/debug/deps/
|
||||
- target/debug/.fingerprint/
|
||||
- target/debug/.cargo-lock
|
||||
- target/debug/df_storyteller
|
||||
# Release
|
||||
- target/release/build/
|
||||
- target/release/deps/
|
||||
- target/release/.fingerprint/
|
||||
- target/release/.cargo-lock
|
||||
|
||||
before_script:
|
||||
- apt-get update -qq && apt-get install -y -qq libudev-dev libgtk-3-dev
|
||||
- apt-get update -qq && apt-get install -y -qq libudev-dev libgtk-3-dev grep
|
||||
|
||||
stages:
|
||||
- format
|
||||
- check
|
||||
- test
|
||||
- build
|
||||
- release
|
||||
|
||||
test:
|
||||
format:
|
||||
except:
|
||||
- tags
|
||||
script:
|
||||
- echo "nightly" > rust-toolchain
|
||||
- rustup component add rustfmt
|
||||
- cargo fmt --check
|
||||
|
||||
check:
|
||||
except:
|
||||
- tags
|
||||
script:
|
||||
- rustup component add clippy
|
||||
- cargo check
|
||||
- cargo clippy
|
||||
# deny currently catches too much
|
||||
#- cargo install cargo-deny && cargo deny
|
||||
- cargo install cargo-cranky && cargo cranky
|
||||
|
||||
test:
|
||||
except:
|
||||
- tags
|
||||
script:
|
||||
- cargo test
|
||||
|
||||
build:
|
||||
release:
|
||||
only:
|
||||
- main
|
||||
- tags
|
||||
script:
|
||||
- make && make vendor
|
||||
artifacts:
|
||||
paths:
|
||||
- vendor_asus-nb-ctrl_*.tar.xz
|
||||
- vendor_asusctl_*.tar.xz
|
||||
- cargo-config
|
||||
|
||||
variables:
|
||||
|
||||
35
CHANGELOG.md
35
CHANGELOG.md
@@ -5,6 +5,41 @@ 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]
|
||||
## [v4.5.6]
|
||||
### Changed
|
||||
- Fix tasks not always running correctly on boot/sleep/wake/shutdown by finishing the move to async
|
||||
- Change how the profile/fan change task monitors changes due to TUF laptops behaving slightly different
|
||||
- ROGCC: Better handle the use of GPU MUX without supergfxd
|
||||
- ROGCC: Track if reboot required when not using supergfxd
|
||||
- Add env var for logging levels to daemon and gui (`RUST_LOG=<error|warn|info|debug|trace>`)
|
||||
- ROGCC: Very basic support for running a command on AC/Battery switching, this is in config at `~/.config/rog/rog-control-center.cfg`, and for now must be edited by hand and ROGCC restarted (run ROGCC in BG to use effectively)
|
||||
+ Run ROGCC from terminal to see errors of the AC/Battery command
|
||||
+ Support for editing via ROGCC GUI will come in future
|
||||
+ This is ideal for userspace tasks
|
||||
- asusd: Very basic support for running a command on AC/Battery switching, this is in config at `/etc/asusd/asusd.conf`. A restart of asusd is not required if edited.
|
||||
+ This is ideal for tasks that require root access (BE SAFE!)
|
||||
- The above AC/Battery commands are probably best set to run a script for more complex tasks
|
||||
- asusd: check if nvidia-powerd enabled before toggling
|
||||
|
||||
## [v4.5.5]
|
||||
### Changed
|
||||
- remove an unwrap() causing panic on main ROGCC thread
|
||||
|
||||
## [v4.5.4]
|
||||
### Changed
|
||||
- ROGCC:: Allow ROGCC to run without supergfxd
|
||||
- ROGCC: Tray/notifs now reads dGPU status directly via supergfx crate (supergfxd not required)
|
||||
- Add rust-toolchain to force minimum rust version
|
||||
|
||||
## [v4.5.3]
|
||||
### Changed
|
||||
- Adjust how fan graph in ROGCC works, deny incorrect graphs
|
||||
- Fix to apply the fan curve change in ROGCC to the correct profile
|
||||
- Support for G713RS LED modes (Author: Peter Ivanov)
|
||||
- Support for G713RM LED modes (Author: maxbachmann)
|
||||
- Fix VivoBook detection
|
||||
- Update dependencies to get latest winit crate (fixes various small issues)
|
||||
|
||||
## [v4.5.2]
|
||||
### Changed
|
||||
- Update dependencies and bump version
|
||||
|
||||
619
Cargo.lock
generated
619
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
16
Cargo.toml
16
Cargo.toml
@@ -2,14 +2,14 @@
|
||||
members = ["asusctl", "daemon", "daemon-user", "rog-platform", "rog-dbus", "rog-anime", "rog-aura", "rog-profiles", "rog-control-center"]
|
||||
|
||||
[workspace.package]
|
||||
version = "4.5.2"
|
||||
version = "4.5.6"
|
||||
|
||||
[workspace.dependencies]
|
||||
async-trait = "^0.1"
|
||||
tokio = { version = "^1.21.2", features = ["macros", "rt-multi-thread", "time", "sync"]}
|
||||
tokio = { version = "^1.22.0", features = ["macros", "rt-multi-thread", "time", "sync"]}
|
||||
concat-idents = "^1.1"
|
||||
dirs = "^4.0"
|
||||
smol = "^1.2"
|
||||
smol = "^1.3"
|
||||
|
||||
zbus = "^3.5"
|
||||
logind-zbus = { version = "^3.0.3" } #, default-features = false, features = ["non_blocking"] }
|
||||
@@ -20,19 +20,19 @@ serde_json = "^1.0"
|
||||
toml = "^0.5.9"
|
||||
|
||||
log = "^0.4"
|
||||
env_logger = "^0.9.3"
|
||||
env_logger = "^0.10.0"
|
||||
|
||||
glam = { version = "^0.22", features = ["serde"] }
|
||||
gumdrop = "^0.8"
|
||||
udev = "^0.6"
|
||||
udev = "^0.7"
|
||||
rusb = "^0.9"
|
||||
sysfs-class = "^0.1.2"
|
||||
sysfs-class = "^0.1.3"
|
||||
inotify = "^0.10.0"
|
||||
|
||||
png_pong = "^0.8"
|
||||
pix = "^0.13"
|
||||
tinybmp = "^0.3"
|
||||
gif = "^0.11"
|
||||
tinybmp = "^0.4.0"
|
||||
gif = "^0.12.0"
|
||||
|
||||
notify-rust = { git = "https://github.com/flukejones/notify-rust.git", default-features = false, features = ["z"] }
|
||||
|
||||
|
||||
121
Cranky.toml
Normal file
121
Cranky.toml
Normal file
@@ -0,0 +1,121 @@
|
||||
# https://github.com/ericseppanen/cargo-cranky
|
||||
# cargo install cargo-cranky && cargo cranky
|
||||
|
||||
warn = [
|
||||
"clippy::all",
|
||||
"clippy::await_holding_lock",
|
||||
"clippy::bool_to_int_with_if",
|
||||
"clippy::char_lit_as_u8",
|
||||
"clippy::checked_conversions",
|
||||
"clippy::dbg_macro",
|
||||
"clippy::debug_assert_with_mut_call",
|
||||
"clippy::disallowed_methods",
|
||||
"clippy::disallowed_script_idents",
|
||||
"clippy::doc_link_with_quotes",
|
||||
"clippy::doc_markdown",
|
||||
"clippy::empty_enum",
|
||||
"clippy::enum_glob_use",
|
||||
"clippy::equatable_if_let",
|
||||
"clippy::exit",
|
||||
"clippy::expl_impl_clone_on_copy",
|
||||
"clippy::explicit_deref_methods",
|
||||
"clippy::explicit_into_iter_loop",
|
||||
"clippy::explicit_iter_loop",
|
||||
"clippy::fallible_impl_from",
|
||||
"clippy::filter_map_next",
|
||||
"clippy::flat_map_option",
|
||||
"clippy::float_cmp_const",
|
||||
"clippy::fn_params_excessive_bools",
|
||||
"clippy::fn_to_numeric_cast_any",
|
||||
"clippy::from_iter_instead_of_collect",
|
||||
"clippy::if_let_mutex",
|
||||
"clippy::implicit_clone",
|
||||
"clippy::imprecise_flops",
|
||||
"clippy::index_refutable_slice",
|
||||
"clippy::inefficient_to_string",
|
||||
"clippy::invalid_upcast_comparisons",
|
||||
"clippy::iter_not_returning_iterator",
|
||||
"clippy::iter_on_empty_collections",
|
||||
"clippy::iter_on_single_items",
|
||||
"clippy::large_digit_groups",
|
||||
"clippy::large_stack_arrays",
|
||||
"clippy::large_types_passed_by_value",
|
||||
"clippy::let_unit_value",
|
||||
"clippy::linkedlist",
|
||||
"clippy::lossy_float_literal",
|
||||
"clippy::macro_use_imports",
|
||||
"clippy::manual_assert",
|
||||
"clippy::manual_instant_elapsed",
|
||||
"clippy::manual_ok_or",
|
||||
"clippy::manual_string_new",
|
||||
"clippy::map_err_ignore",
|
||||
"clippy::map_flatten",
|
||||
"clippy::map_unwrap_or",
|
||||
"clippy::match_on_vec_items",
|
||||
"clippy::match_same_arms",
|
||||
"clippy::match_wild_err_arm",
|
||||
"clippy::match_wildcard_for_single_variants",
|
||||
"clippy::mem_forget",
|
||||
"clippy::mismatched_target_os",
|
||||
"clippy::mismatching_type_param_order",
|
||||
"clippy::missing_enforced_import_renames",
|
||||
# "clippy::missing_errors_doc",
|
||||
"clippy::missing_safety_doc",
|
||||
"clippy::mut_mut",
|
||||
"clippy::mutex_integer",
|
||||
"clippy::needless_borrow",
|
||||
"clippy::needless_continue",
|
||||
"clippy::needless_for_each",
|
||||
"clippy::needless_pass_by_value",
|
||||
"clippy::negative_feature_names",
|
||||
"clippy::nonstandard_macro_braces",
|
||||
"clippy::option_option",
|
||||
"clippy::path_buf_push_overwrite",
|
||||
"clippy::ptr_as_ptr",
|
||||
"clippy::rc_mutex",
|
||||
"clippy::ref_option_ref",
|
||||
"clippy::rest_pat_in_fully_bound_structs",
|
||||
"clippy::same_functions_in_if_condition",
|
||||
"clippy::semicolon_if_nothing_returned",
|
||||
"clippy::single_match_else",
|
||||
"clippy::str_to_string",
|
||||
"clippy::string_add_assign",
|
||||
"clippy::string_add",
|
||||
"clippy::string_lit_as_bytes",
|
||||
"clippy::string_to_string",
|
||||
"clippy::todo",
|
||||
"clippy::trailing_empty_array",
|
||||
"clippy::trait_duplication_in_bounds",
|
||||
"clippy::unimplemented",
|
||||
"clippy::unnecessary_wraps",
|
||||
"clippy::unnested_or_patterns",
|
||||
"clippy::unused_peekable",
|
||||
"clippy::unused_rounding",
|
||||
# "clippy::unused_self",
|
||||
"clippy::useless_transmute",
|
||||
"clippy::verbose_file_reads",
|
||||
"clippy::zero_sized_map_values",
|
||||
"elided_lifetimes_in_paths",
|
||||
"future_incompatible",
|
||||
"nonstandard_style",
|
||||
"rust_2018_idioms",
|
||||
"rust_2021_prelude_collisions",
|
||||
"rustdoc::missing_crate_level_docs",
|
||||
"semicolon_in_expressions_from_macros",
|
||||
"trivial_numeric_casts",
|
||||
"unused_extern_crates",
|
||||
"unused_import_braces",
|
||||
"unused_lifetimes",
|
||||
]
|
||||
|
||||
allow = [
|
||||
# TODO(emilk): enable more lints
|
||||
"clippy::cloned_instead_of_copied",
|
||||
"clippy::derive_partial_eq_without_eq",
|
||||
"clippy::type_complexity",
|
||||
"clippy::undocumented_unsafe_blocks",
|
||||
"trivial_casts",
|
||||
"unsafe_op_in_unsafe_fn", # `unsafe_op_in_unsafe_fn` may become the default in future Rust versions: https://github.com/rust-lang/rust/issues/71668
|
||||
"unused_qualifications",
|
||||
]
|
||||
|
||||
2
Makefile
2
Makefile
@@ -1,4 +1,4 @@
|
||||
VERSION := $(shell grep -Pm1 'version = "(\d.\d.\d)"' daemon/Cargo.toml | cut -d'"' -f2)
|
||||
VERSION := $(shell /usr/bin/grep -Pm1 'version = "(\d.\d.\d)"' Cargo.toml | cut -d'"' -f2)
|
||||
|
||||
INSTALL = install
|
||||
INSTALL_PROGRAM = ${INSTALL} -D -m 0755
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
[package]
|
||||
name = "asusctl"
|
||||
license = "MPL-2.0"
|
||||
authors = ["Luke D Jones <luke@ljones.dev>"]
|
||||
edition = "2021"
|
||||
version.workspace = true
|
||||
|
||||
@@ -20,7 +20,7 @@ fn main() {
|
||||
}
|
||||
|
||||
for c in (0..35).into_iter().step_by(step) {
|
||||
for i in matrix.get_mut()[c].iter_mut() {
|
||||
for i in &mut matrix.get_mut()[c] {
|
||||
*i = 50;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ fn main() {
|
||||
for (y, row) in tmp.iter_mut().enumerate() {
|
||||
if y % 2 == 0 && i + 1 != row.len() - 1 {
|
||||
i += 1;
|
||||
dbg!(i);
|
||||
}
|
||||
row[row.len() - i] = 0x22;
|
||||
if i > 5 {
|
||||
|
||||
@@ -35,7 +35,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
loop {
|
||||
matrix.angle += 0.05;
|
||||
if matrix.angle > PI * 2.0 {
|
||||
matrix.angle = 0.0
|
||||
matrix.angle = 0.0;
|
||||
}
|
||||
matrix.update();
|
||||
|
||||
|
||||
@@ -6,17 +6,17 @@ use rog_aura::{
|
||||
KeyColourArray,
|
||||
};
|
||||
use rog_dbus::RogDbusClientBlocking;
|
||||
use std::collections::LinkedList;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct Ball {
|
||||
position: (f32, f32),
|
||||
direction: (f32, f32),
|
||||
trail: LinkedList<(f32, f32)>,
|
||||
trail: VecDeque<(f32, f32)>,
|
||||
}
|
||||
impl Ball {
|
||||
fn new(x: f32, y: f32, trail_len: u32) -> Self {
|
||||
let mut trail = LinkedList::new();
|
||||
let mut trail = VecDeque::new();
|
||||
for _ in 1..=trail_len {
|
||||
trail.push_back((x, y));
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ impl ToString for LedBrightness {
|
||||
Some(0x02) => "high",
|
||||
_ => "unknown",
|
||||
};
|
||||
s.to_string()
|
||||
s.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ mod aura_cli;
|
||||
mod cli_opts;
|
||||
mod profiles_cli;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn main() {
|
||||
let args: Vec<String> = args().skip(1).collect();
|
||||
|
||||
let missing_argument_k = gumdrop::Error::missing_argument(Opt::Short('k'));
|
||||
@@ -44,7 +44,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let (dbus, _) = RogDbusClientBlocking::new()
|
||||
.map_err(|e| {
|
||||
print_error_help(Box::new(e), None);
|
||||
print_error_help(&e, None);
|
||||
std::process::exit(3);
|
||||
})
|
||||
.unwrap();
|
||||
@@ -54,7 +54,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.supported()
|
||||
.supported_functions()
|
||||
.map_err(|e| {
|
||||
print_error_help(Box::new(e), None);
|
||||
print_error_help(&e, None);
|
||||
std::process::exit(4);
|
||||
})
|
||||
.unwrap();
|
||||
@@ -63,17 +63,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
print_versions();
|
||||
println!();
|
||||
print_laptop_info();
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Err(err) = do_parsed(&parsed, &supported, &dbus) {
|
||||
print_error_help(err, Some(&supported));
|
||||
print_error_help(&*err, Some(&supported));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_error_help(err: Box<dyn std::error::Error>, supported: Option<&SupportedFunctions>) {
|
||||
fn print_error_help(err: &dyn std::error::Error, supported: Option<&SupportedFunctions>) {
|
||||
check_service("asusd");
|
||||
println!("\nError: {}\n", err);
|
||||
print_versions();
|
||||
@@ -126,7 +123,7 @@ fn check_service(name: &str) -> bool {
|
||||
fn do_parsed(
|
||||
parsed: &CliStart,
|
||||
supported: &SupportedFunctions,
|
||||
dbus: &RogDbusClientBlocking,
|
||||
dbus: &RogDbusClientBlocking<'_>,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
match &parsed.command {
|
||||
Some(CliCommand::LedMode(mode)) => handle_led_mode(dbus, &supported.keyboard_led, mode)?,
|
||||
@@ -134,9 +131,9 @@ fn do_parsed(
|
||||
Some(CliCommand::LedPow2(pow)) => handle_led_power2(dbus, &supported.keyboard_led, pow)?,
|
||||
Some(CliCommand::Profile(cmd)) => handle_profile(dbus, &supported.platform_profile, cmd)?,
|
||||
Some(CliCommand::FanCurve(cmd)) => {
|
||||
handle_fan_curve(dbus, &supported.platform_profile, cmd)?
|
||||
handle_fan_curve(dbus, &supported.platform_profile, cmd)?;
|
||||
}
|
||||
Some(CliCommand::Graphics(_)) => do_gfx()?,
|
||||
Some(CliCommand::Graphics(_)) => do_gfx(),
|
||||
Some(CliCommand::Anime(cmd)) => handle_anime(dbus, &supported.anime_ctrl, cmd)?,
|
||||
Some(CliCommand::Bios(cmd)) => handle_bios_option(dbus, &supported.rog_bios_ctrl, cmd)?,
|
||||
None => {
|
||||
@@ -150,7 +147,7 @@ fn do_parsed(
|
||||
println!("{}", CliStart::usage());
|
||||
println!();
|
||||
if let Some(cmdlist) = CliStart::command_list() {
|
||||
let commands: Vec<String> = cmdlist.lines().map(|s| s.to_string()).collect();
|
||||
let commands: Vec<String> = cmdlist.lines().map(|s| s.to_owned()).collect();
|
||||
for command in commands.iter().filter(|command| {
|
||||
if !matches!(
|
||||
supported.keyboard_led.prod_id,
|
||||
@@ -214,14 +211,13 @@ fn do_parsed(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn do_gfx() -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn do_gfx() {
|
||||
println!("Please use supergfxctl for graphics switching. supergfxctl is the result of making asusctl graphics switching generic so all laptops can use it");
|
||||
println!("This command will be removed in future");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_anime(
|
||||
dbus: &RogDbusClientBlocking,
|
||||
dbus: &RogDbusClientBlocking<'_>,
|
||||
_supported: &AnimeSupportedFunctions,
|
||||
cmd: &AnimeCommand,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
@@ -237,14 +233,14 @@ fn handle_anime(
|
||||
}
|
||||
}
|
||||
if let Some(anime_turn) = cmd.enable {
|
||||
dbus.proxies().anime().set_on_off(anime_turn)?
|
||||
dbus.proxies().anime().set_on_off(anime_turn)?;
|
||||
}
|
||||
if let Some(anime_boot) = cmd.boot_enable {
|
||||
dbus.proxies().anime().set_boot_on_off(anime_boot)?
|
||||
dbus.proxies().anime().set_boot_on_off(anime_boot)?;
|
||||
}
|
||||
if let Some(bright) = cmd.brightness {
|
||||
verify_brightness(bright);
|
||||
dbus.proxies().anime().set_brightness(bright)?
|
||||
dbus.proxies().anime().set_brightness(bright)?;
|
||||
}
|
||||
if cmd.clear {
|
||||
let anime_type = get_anime_type()?;
|
||||
@@ -381,7 +377,7 @@ fn verify_brightness(brightness: f32) {
|
||||
}
|
||||
|
||||
fn handle_led_mode(
|
||||
dbus: &RogDbusClientBlocking,
|
||||
dbus: &RogDbusClientBlocking<'_>,
|
||||
supported: &LedSupportedFunctions,
|
||||
mode: &LedModeCommand,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
@@ -438,7 +434,7 @@ fn handle_led_mode(
|
||||
}
|
||||
|
||||
fn handle_led_power1(
|
||||
dbus: &RogDbusClientBlocking,
|
||||
dbus: &RogDbusClientBlocking<'_>,
|
||||
supported: &LedSupportedFunctions,
|
||||
power: &LedPowerCommand1,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
@@ -473,7 +469,7 @@ fn handle_led_power1(
|
||||
}
|
||||
|
||||
fn handle_led_power_1_do_1866(
|
||||
dbus: &RogDbusClientBlocking,
|
||||
dbus: &RogDbusClientBlocking<'_>,
|
||||
power: &LedPowerCommand1,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut enabled: Vec<AuraDev1866> = Vec::new();
|
||||
@@ -513,7 +509,7 @@ fn handle_led_power_1_do_1866(
|
||||
}
|
||||
|
||||
fn handle_led_power_1_do_tuf(
|
||||
dbus: &RogDbusClientBlocking,
|
||||
dbus: &RogDbusClientBlocking<'_>,
|
||||
power: &LedPowerCommand1,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut enabled: Vec<AuraDevTuf> = Vec::new();
|
||||
@@ -552,7 +548,7 @@ fn handle_led_power_1_do_tuf(
|
||||
}
|
||||
|
||||
fn handle_led_power2(
|
||||
dbus: &RogDbusClientBlocking,
|
||||
dbus: &RogDbusClientBlocking<'_>,
|
||||
supported: &LedSupportedFunctions,
|
||||
power: &LedPowerCommand2,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
@@ -564,8 +560,8 @@ fn handle_led_power2(
|
||||
println!("Commands available");
|
||||
|
||||
if let Some(cmdlist) = LedPowerCommand2::command_list() {
|
||||
let commands: Vec<String> = cmdlist.lines().map(|s| s.to_string()).collect();
|
||||
for command in commands.iter() {
|
||||
let commands: Vec<String> = cmdlist.lines().map(|s| s.to_owned()).collect();
|
||||
for command in &commands {
|
||||
println!("{}", command);
|
||||
}
|
||||
}
|
||||
@@ -581,7 +577,7 @@ fn handle_led_power2(
|
||||
}
|
||||
|
||||
if supported.prod_id != AuraDevice::X19B6 {
|
||||
println!("This option applies only to keyboards with product ID 0x19b6")
|
||||
println!("This option applies only to keyboards with product ID 0x19b6");
|
||||
}
|
||||
|
||||
let mut enabled: Vec<AuraDev19b6> = Vec::new();
|
||||
@@ -646,7 +642,7 @@ fn handle_led_power2(
|
||||
}
|
||||
|
||||
fn handle_profile(
|
||||
dbus: &RogDbusClientBlocking,
|
||||
dbus: &RogDbusClientBlocking<'_>,
|
||||
supported: &PlatformProfileFunctions,
|
||||
cmd: &ProfileCommand,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
@@ -675,7 +671,9 @@ fn handle_profile(
|
||||
|
||||
if cmd.list {
|
||||
let res = dbus.proxies().profile().profiles()?;
|
||||
res.iter().for_each(|p| println!("{:?}", p));
|
||||
for p in &res {
|
||||
println!("{:?}", p);
|
||||
}
|
||||
}
|
||||
|
||||
if cmd.profile_get {
|
||||
@@ -687,7 +685,7 @@ fn handle_profile(
|
||||
}
|
||||
|
||||
fn handle_fan_curve(
|
||||
dbus: &RogDbusClientBlocking,
|
||||
dbus: &RogDbusClientBlocking<'_>,
|
||||
supported: &PlatformProfileFunctions,
|
||||
cmd: &FanCurveCommand,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
@@ -749,7 +747,7 @@ fn handle_fan_curve(
|
||||
}
|
||||
|
||||
fn handle_bios_option(
|
||||
dbus: &RogDbusClientBlocking,
|
||||
dbus: &RogDbusClientBlocking<'_>,
|
||||
supported: &RogBiosSupportedFunctions,
|
||||
cmd: &BiosCommand,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
@@ -764,10 +762,7 @@ fn handle_bios_option(
|
||||
{
|
||||
println!("Missing arg or command\n");
|
||||
|
||||
let usage: Vec<String> = BiosCommand::usage()
|
||||
.lines()
|
||||
.map(|s| s.to_string())
|
||||
.collect();
|
||||
let usage: Vec<String> = BiosCommand::usage().lines().map(|s| s.to_owned()).collect();
|
||||
|
||||
for line in usage.iter().filter(|line| {
|
||||
line.contains("sound") && supported.post_sound
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
[package]
|
||||
name = "daemon-user"
|
||||
license = "MPL-2.0"
|
||||
version.workspace = true
|
||||
authors = ["Luke D Jones <luke@ljones.dev>"]
|
||||
edition = "2021"
|
||||
@@ -27,4 +28,4 @@ rog_aura = { path = "../rog-aura" }
|
||||
rog_dbus = { path = "../rog-dbus" }
|
||||
rog_platform = { path = "../rog-platform" }
|
||||
|
||||
zbus.workspace = true
|
||||
zbus.workspace = true
|
||||
|
||||
@@ -103,7 +103,7 @@ impl<'a> CtrlAnimeInner<'static> {
|
||||
.write(output)
|
||||
.map_err(|e| AnimeError::Dbus(format!("{}", e)))
|
||||
.map(|_| false)
|
||||
})?;
|
||||
});
|
||||
}
|
||||
ActionData::Image(image) => {
|
||||
self.client
|
||||
@@ -124,10 +124,10 @@ impl<'a> CtrlAnimeInner<'static> {
|
||||
sleep(Duration::from_millis(1));
|
||||
}
|
||||
}
|
||||
ActionData::AudioEq => {}
|
||||
ActionData::SystemInfo => {}
|
||||
ActionData::TimeDate => {}
|
||||
ActionData::Matrix => {}
|
||||
ActionData::AudioEq
|
||||
| ActionData::SystemInfo
|
||||
| ActionData::TimeDate
|
||||
| ActionData::Matrix => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ pub struct CtrlAnime<'a> {
|
||||
inner_early_return: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
impl<'a> CtrlAnime<'static> {
|
||||
impl CtrlAnime<'static> {
|
||||
pub fn new(
|
||||
config: Arc<Mutex<UserAnimeConfig>>,
|
||||
inner: Arc<Mutex<CtrlAnimeInner<'static>>>,
|
||||
@@ -185,7 +185,7 @@ impl CtrlAnime<'static> {
|
||||
pub fn insert_asus_gif(
|
||||
&mut self,
|
||||
index: u32,
|
||||
file: String,
|
||||
file: &str,
|
||||
time: Timer,
|
||||
brightness: f32,
|
||||
) -> zbus::fdo::Result<String> {
|
||||
@@ -223,7 +223,7 @@ impl CtrlAnime<'static> {
|
||||
pub fn insert_image_gif(
|
||||
&mut self,
|
||||
index: u32,
|
||||
file: String,
|
||||
file: &str,
|
||||
scale: f32,
|
||||
angle: f32,
|
||||
xy: (f32, f32),
|
||||
@@ -269,7 +269,7 @@ impl CtrlAnime<'static> {
|
||||
pub fn insert_image(
|
||||
&mut self,
|
||||
index: u32,
|
||||
file: String,
|
||||
file: &str,
|
||||
scale: f32,
|
||||
angle: f32,
|
||||
xy: (f32, f32),
|
||||
|
||||
@@ -13,7 +13,7 @@ pub enum Error {
|
||||
|
||||
impl fmt::Display for Error {
|
||||
// This trait requires `fmt` with this exact signature.
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Error::Io(err) => write!(f, "Failed to open: {}", err),
|
||||
Error::ConfigLoadFail => write!(f, "Failed to load user config"),
|
||||
|
||||
@@ -114,7 +114,7 @@ impl ConfigLoadSave<UserAnimeConfig> for UserAnimeConfig {
|
||||
impl Default for UserAnimeConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: "default".to_string(),
|
||||
name: "default".to_owned(),
|
||||
anime: vec![
|
||||
ActionLoader::AsusImage {
|
||||
file: "/usr/share/asusd/anime/custom/diagonal-template.png".into(),
|
||||
@@ -233,7 +233,7 @@ impl Default for UserAuraConfig {
|
||||
seq.push(key);
|
||||
|
||||
Self {
|
||||
name: "default".to_string(),
|
||||
name: "default".to_owned(),
|
||||
aura: seq,
|
||||
}
|
||||
}
|
||||
@@ -251,8 +251,8 @@ pub struct UserConfig {
|
||||
impl UserConfig {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
active_anime: Some("anime-default".to_string()),
|
||||
active_aura: Some("aura-default".to_string()),
|
||||
active_anime: Some("anime-default".to_owned()),
|
||||
active_aura: Some("aura-default".to_owned()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "daemon"
|
||||
version.workspace = true
|
||||
license = "MPL-2.0"
|
||||
version.workspace = true
|
||||
readme = "README.md"
|
||||
authors = ["Luke <luke@ljones.dev>"]
|
||||
repository = "https://gitlab.com/asus-linux/asus-nb-ctrl"
|
||||
@@ -43,4 +43,4 @@ toml.workspace = true
|
||||
# Device control
|
||||
sysfs-class.workspace = true # used for backlight control and baord ID
|
||||
|
||||
concat-idents.workspace = true
|
||||
concat-idents.workspace = true
|
||||
|
||||
@@ -7,11 +7,12 @@ use std::path::PathBuf;
|
||||
pub static CONFIG_PATH: &str = "/etc/asusd/asusd.conf";
|
||||
|
||||
#[derive(Deserialize, Serialize, Default)]
|
||||
#[serde(default)]
|
||||
pub struct Config {
|
||||
/// Save charge limit for restoring on boot
|
||||
pub bat_charge_limit: u8,
|
||||
pub panel_od: bool,
|
||||
pub ac_command: String,
|
||||
pub bat_command: String,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
@@ -19,6 +20,8 @@ impl Config {
|
||||
Config {
|
||||
bat_charge_limit: 100,
|
||||
panel_od: false,
|
||||
ac_command: String::new(),
|
||||
bat_command: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,12 +40,14 @@ impl Config {
|
||||
config = Self::new();
|
||||
} else if let Ok(data) = serde_json::from_str(&buf) {
|
||||
config = data;
|
||||
} else if let Ok(data) = serde_json::from_str::<Config455>(&buf) {
|
||||
config = data.into();
|
||||
} else {
|
||||
warn!(
|
||||
"Could not deserialise {}.\nWill rename to {}-old and recreate config",
|
||||
CONFIG_PATH, CONFIG_PATH
|
||||
);
|
||||
let cfg_old = CONFIG_PATH.to_string() + "-old";
|
||||
let cfg_old = CONFIG_PATH.to_owned() + "-old";
|
||||
std::fs::rename(CONFIG_PATH, cfg_old).unwrap_or_else(|err| {
|
||||
panic!(
|
||||
"Could not rename. Please remove {} then restart service: Error {}",
|
||||
@@ -52,7 +57,7 @@ impl Config {
|
||||
config = Self::new();
|
||||
}
|
||||
} else {
|
||||
config = Self::new()
|
||||
config = Self::new();
|
||||
}
|
||||
config.write();
|
||||
config
|
||||
@@ -81,3 +86,22 @@ impl Config {
|
||||
.unwrap_or_else(|err| error!("Could not write config: {}", err));
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Default)]
|
||||
#[serde(default)]
|
||||
pub struct Config455 {
|
||||
/// Save charge limit for restoring on boot
|
||||
pub bat_charge_limit: u8,
|
||||
pub panel_od: bool,
|
||||
}
|
||||
|
||||
impl From<Config455> for Config {
|
||||
fn from(c: Config455) -> Self {
|
||||
Self {
|
||||
bat_charge_limit: c.bat_charge_limit,
|
||||
panel_od: c.panel_od,
|
||||
ac_command: String::new(),
|
||||
bat_command: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,25 +86,25 @@ impl AnimeConfigCached {
|
||||
anime_type: AnimeType,
|
||||
) -> Result<(), AnimeError> {
|
||||
let mut sys = Vec::with_capacity(config.system.len());
|
||||
for ani in config.system.iter() {
|
||||
for ani in &config.system {
|
||||
sys.push(ActionData::from_anime_action(anime_type, ani)?);
|
||||
}
|
||||
self.system = sys;
|
||||
|
||||
let mut boot = Vec::with_capacity(config.boot.len());
|
||||
for ani in config.boot.iter() {
|
||||
for ani in &config.boot {
|
||||
boot.push(ActionData::from_anime_action(anime_type, ani)?);
|
||||
}
|
||||
self.boot = boot;
|
||||
|
||||
let mut wake = Vec::with_capacity(config.wake.len());
|
||||
for ani in config.wake.iter() {
|
||||
for ani in &config.wake {
|
||||
wake.push(ActionData::from_anime_action(anime_type, ani)?);
|
||||
}
|
||||
self.wake = wake;
|
||||
|
||||
let mut shutdown = Vec::with_capacity(config.shutdown.len());
|
||||
for ani in config.shutdown.iter() {
|
||||
for ani in &config.shutdown {
|
||||
shutdown.push(ActionData::from_anime_action(anime_type, ani)?);
|
||||
}
|
||||
self.shutdown = shutdown;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
pub mod config;
|
||||
/// Implements CtrlTask, Reloadable, ZbusRun
|
||||
/// Implements `CtrlTask`, Reloadable, `ZbusRun`
|
||||
pub mod trait_impls;
|
||||
|
||||
use self::config::{AnimeConfig, AnimeConfigCached};
|
||||
@@ -62,7 +62,7 @@ impl CtrlAnime {
|
||||
/// one running - so the thread uses atomics to signal run/exit.
|
||||
///
|
||||
/// Because this also writes to the usb device, other write tries (display only) *must*
|
||||
/// get the mutex lock and set the thread_exit atomic.
|
||||
/// get the mutex lock and set the `thread_exit` atomic.
|
||||
fn run_thread(inner: Arc<Mutex<CtrlAnime>>, actions: Vec<ActionData>, mut once: bool) {
|
||||
if actions.is_empty() {
|
||||
warn!("AniMe system actions was empty");
|
||||
@@ -106,13 +106,13 @@ impl CtrlAnime {
|
||||
|
||||
'main: loop {
|
||||
thread_running.store(true, Ordering::SeqCst);
|
||||
for action in actions.iter() {
|
||||
for action in &actions {
|
||||
if thread_exit.load(Ordering::SeqCst) {
|
||||
break 'main;
|
||||
}
|
||||
match action {
|
||||
ActionData::Animation(frames) => {
|
||||
if let Err(err) = rog_anime::run_animation(frames, &|frame| {
|
||||
rog_anime::run_animation(frames, &|frame| {
|
||||
if thread_exit.load(Ordering::Acquire) {
|
||||
info!("rog-anime: frame-loop was asked to exit");
|
||||
return Ok(true); // Do safe exit
|
||||
@@ -130,15 +130,14 @@ impl CtrlAnime {
|
||||
.ok();
|
||||
false // Don't exit yet
|
||||
})
|
||||
.map(Ok)
|
||||
.unwrap_or_else(|| {
|
||||
warn!("rog_anime::run_animation:callback failed");
|
||||
Err(AnimeError::NoFrames)
|
||||
})
|
||||
}) {
|
||||
warn!("rog_anime::run_animation:Animation {}", err);
|
||||
break 'main;
|
||||
};
|
||||
.map_or_else(
|
||||
|| {
|
||||
warn!("rog_anime::run_animation:callback failed");
|
||||
Err(AnimeError::NoFrames)
|
||||
},
|
||||
Ok,
|
||||
)
|
||||
});
|
||||
}
|
||||
ActionData::Image(image) => {
|
||||
once = false;
|
||||
@@ -149,10 +148,10 @@ impl CtrlAnime {
|
||||
}
|
||||
}
|
||||
ActionData::Pause(duration) => sleep(*duration),
|
||||
ActionData::AudioEq => {}
|
||||
ActionData::SystemInfo => {}
|
||||
ActionData::TimeDate => {}
|
||||
ActionData::Matrix => {}
|
||||
ActionData::AudioEq
|
||||
| ActionData::SystemInfo
|
||||
| ActionData::TimeDate
|
||||
| ActionData::Matrix => {}
|
||||
}
|
||||
}
|
||||
if thread_exit.load(Ordering::SeqCst) {
|
||||
@@ -194,7 +193,7 @@ impl CtrlAnime {
|
||||
*led = bright as u8;
|
||||
}
|
||||
let data = AnimePacketType::try_from(buffer)?;
|
||||
for row in data.iter() {
|
||||
for row in &data {
|
||||
self.node.write_bytes(row)?;
|
||||
}
|
||||
self.node.write_bytes(&pkt_for_flush())?;
|
||||
|
||||
@@ -47,7 +47,7 @@ impl CtrlAnimeZbus {
|
||||
let mut lock = self.0.lock().await;
|
||||
let mut bright = bright;
|
||||
if bright < 0.0 {
|
||||
bright = 0.0
|
||||
bright = 0.0;
|
||||
} else if bright > 1.0 {
|
||||
bright = 1.0;
|
||||
}
|
||||
@@ -149,7 +149,7 @@ impl crate::CtrlTask for CtrlAnimeZbus {
|
||||
|
||||
async fn create_tasks(&self, _: SignalContext<'static>) -> Result<(), RogError> {
|
||||
let run_action =
|
||||
|start: bool, lock: MutexGuard<CtrlAnime>, inner: Arc<Mutex<CtrlAnime>>| {
|
||||
|start: bool, lock: MutexGuard<'_, CtrlAnime>, inner: Arc<Mutex<CtrlAnime>>| {
|
||||
if start {
|
||||
info!("CtrlAnimeTask running sleep animation");
|
||||
CtrlAnime::run_thread(inner, lock.cache.shutdown.clone(), true);
|
||||
@@ -166,28 +166,32 @@ impl crate::CtrlTask for CtrlAnimeZbus {
|
||||
self.create_sys_event_tasks(
|
||||
// Loop is required to try an attempt to get the mutex *without* blocking
|
||||
// other threads - it is possible to end up with deadlocks otherwise.
|
||||
move || loop {
|
||||
if let Some(lock) = inner1.try_lock() {
|
||||
move || {
|
||||
let inner1 = inner1.clone();
|
||||
async move {
|
||||
let lock = inner1.lock().await;
|
||||
run_action(true, lock, inner1.clone());
|
||||
break;
|
||||
}
|
||||
},
|
||||
move || loop {
|
||||
if let Some(lock) = inner2.try_lock() {
|
||||
run_action(false, lock, inner2.clone());
|
||||
break;
|
||||
move || {
|
||||
let inner2 = inner2.clone();
|
||||
async move {
|
||||
let lock = inner2.lock().await;
|
||||
run_action(true, lock, inner2.clone());
|
||||
}
|
||||
},
|
||||
move || loop {
|
||||
if let Some(lock) = inner3.try_lock() {
|
||||
move || {
|
||||
let inner3 = inner3.clone();
|
||||
async move {
|
||||
let lock = inner3.lock().await;
|
||||
run_action(true, lock, inner3.clone());
|
||||
break;
|
||||
}
|
||||
},
|
||||
move || loop {
|
||||
if let Some(lock) = inner4.try_lock() {
|
||||
run_action(false, lock, inner4.clone());
|
||||
break;
|
||||
move || {
|
||||
let inner4 = inner4.clone();
|
||||
async move {
|
||||
let lock = inner4.lock().await;
|
||||
run_action(true, lock, inner4.clone());
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@@ -127,7 +127,7 @@ pub struct AuraConfig {
|
||||
impl Default for AuraConfig {
|
||||
fn default() -> Self {
|
||||
let mut prod_id = AuraDevice::Unknown;
|
||||
for prod in ASUS_KEYBOARD_DEVICES.iter() {
|
||||
for prod in &ASUS_KEYBOARD_DEVICES {
|
||||
if HidRaw::new(prod).is_ok() {
|
||||
prod_id = AuraDevice::from(*prod);
|
||||
break;
|
||||
@@ -242,7 +242,7 @@ impl AuraConfig {
|
||||
colour2: *GRADIENT.get(GRADIENT.len() - i).unwrap_or(&GRADIENT[6]),
|
||||
speed: Speed::Med,
|
||||
direction: Direction::Left,
|
||||
})
|
||||
});
|
||||
}
|
||||
if let Some(m) = config.multizone.as_mut() {
|
||||
m.insert(*n, default);
|
||||
@@ -287,34 +287,31 @@ impl AuraConfig {
|
||||
|
||||
/// Set the mode data, current mode, and if multizone enabled.
|
||||
///
|
||||
/// Multipurpose, will accept AuraEffect with zones and put in the correct store.
|
||||
/// Multipurpose, will accept `AuraEffect` with zones and put in the correct store.
|
||||
pub fn set_builtin(&mut self, effect: AuraEffect) {
|
||||
self.current_mode = effect.mode;
|
||||
match effect.zone() {
|
||||
AuraZone::None => {
|
||||
self.builtins.insert(*effect.mode(), effect);
|
||||
self.multizone_on = false;
|
||||
}
|
||||
_ => {
|
||||
if let Some(multi) = self.multizone.as_mut() {
|
||||
if let Some(fx) = multi.get_mut(effect.mode()) {
|
||||
for fx in fx.iter_mut() {
|
||||
if fx.zone == effect.zone {
|
||||
*fx = effect;
|
||||
return;
|
||||
}
|
||||
if effect.zone() == AuraZone::None {
|
||||
self.builtins.insert(*effect.mode(), effect);
|
||||
self.multizone_on = false;
|
||||
} else {
|
||||
if let Some(multi) = self.multizone.as_mut() {
|
||||
if let Some(fx) = multi.get_mut(effect.mode()) {
|
||||
for fx in fx.iter_mut() {
|
||||
if fx.zone == effect.zone {
|
||||
*fx = effect;
|
||||
return;
|
||||
}
|
||||
fx.push(effect);
|
||||
} else {
|
||||
multi.insert(*effect.mode(), vec![effect]);
|
||||
}
|
||||
fx.push(effect);
|
||||
} else {
|
||||
let mut tmp = BTreeMap::new();
|
||||
tmp.insert(*effect.mode(), vec![effect]);
|
||||
self.multizone = Some(tmp);
|
||||
multi.insert(*effect.mode(), vec![effect]);
|
||||
}
|
||||
self.multizone_on = true;
|
||||
} else {
|
||||
let mut tmp = BTreeMap::new();
|
||||
tmp.insert(*effect.mode(), vec![effect]);
|
||||
self.multizone = Some(tmp);
|
||||
}
|
||||
self.multizone_on = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ impl GetSupported for CtrlKbdLed {
|
||||
let per_key_led_mode = laptop.per_key;
|
||||
|
||||
let mut prod_id = AuraDevice::Unknown;
|
||||
for prod in ASUS_KEYBOARD_DEVICES.iter() {
|
||||
for prod in &ASUS_KEYBOARD_DEVICES {
|
||||
if HidRaw::new(prod).is_ok() {
|
||||
prod_id = AuraDevice::from(*prod);
|
||||
break;
|
||||
@@ -72,10 +72,10 @@ impl CtrlKbdLed {
|
||||
pub fn new(supported_modes: LaptopLedData, config: AuraConfig) -> Result<Self, RogError> {
|
||||
let mut led_prod = None;
|
||||
let mut led_node = None;
|
||||
for prod in ASUS_KEYBOARD_DEVICES.iter() {
|
||||
for prod in &ASUS_KEYBOARD_DEVICES {
|
||||
match HidRaw::new(prod) {
|
||||
Ok(node) => {
|
||||
led_prod = Some(prod.to_string());
|
||||
led_prod = Some((*prod).to_owned());
|
||||
led_node = Some(node);
|
||||
info!("Looked for keyboard controller 0x{prod}: Found");
|
||||
break;
|
||||
@@ -335,7 +335,7 @@ impl CtrlKbdLed {
|
||||
colour2: *GRADIENT.get(GRADIENT.len() - i).unwrap_or(&GRADIENT[6]),
|
||||
speed: Speed::Med,
|
||||
direction: Direction::Left,
|
||||
})
|
||||
});
|
||||
}
|
||||
if default.is_empty() {
|
||||
return Err(RogError::AuraEffectNotSupported);
|
||||
@@ -370,7 +370,7 @@ mod tests {
|
||||
// Checking to ensure set_mode errors when unsupported modes are tried
|
||||
let config = AuraConfig::default();
|
||||
let supported_modes = LaptopLedData {
|
||||
prod_family: "".into(),
|
||||
prod_family: String::new(),
|
||||
board_names: vec![],
|
||||
standard: vec![AuraModeNum::Static],
|
||||
multizone: vec![],
|
||||
@@ -432,7 +432,7 @@ mod tests {
|
||||
// Checking to ensure set_mode errors when unsupported modes are tried
|
||||
let config = AuraConfig::default();
|
||||
let supported_modes = LaptopLedData {
|
||||
prod_family: "".into(),
|
||||
prod_family: String::new(),
|
||||
board_names: vec![],
|
||||
standard: vec![AuraModeNum::Static],
|
||||
multizone: vec![],
|
||||
@@ -470,7 +470,7 @@ mod tests {
|
||||
// Checking to ensure set_mode errors when unsupported modes are tried
|
||||
let config = AuraConfig::default();
|
||||
let supported_modes = LaptopLedData {
|
||||
prod_family: "".into(),
|
||||
prod_family: String::new(),
|
||||
board_names: vec![],
|
||||
standard: vec![AuraModeNum::Static],
|
||||
multizone: vec![AuraZone::Key1, AuraZone::Key2],
|
||||
|
||||
@@ -237,7 +237,7 @@ impl CtrlTask for CtrlKbdLedZbus {
|
||||
}
|
||||
|
||||
async fn create_tasks(&self, _: SignalContext<'static>) -> Result<(), RogError> {
|
||||
let load_save = |start: bool, mut lock: MutexGuard<CtrlKbdLed>| {
|
||||
let load_save = |start: bool, mut lock: MutexGuard<'_, CtrlKbdLed>| {
|
||||
// If waking up
|
||||
if !start {
|
||||
info!("CtrlKbdLedTask reloading brightness and modes");
|
||||
@@ -262,28 +262,32 @@ impl CtrlTask for CtrlKbdLedZbus {
|
||||
self.create_sys_event_tasks(
|
||||
// Loop so that we do aquire the lock but also don't block other
|
||||
// threads (prevents potential deadlocks)
|
||||
move || loop {
|
||||
if let Some(lock) = inner1.try_lock() {
|
||||
move || {
|
||||
let inner1 = inner1.clone();
|
||||
async move {
|
||||
let lock = inner1.lock().await;
|
||||
load_save(true, lock);
|
||||
break;
|
||||
}
|
||||
},
|
||||
move || loop {
|
||||
if let Some(lock) = inner2.try_lock() {
|
||||
move || {
|
||||
let inner2 = inner2.clone();
|
||||
async move {
|
||||
let lock = inner2.lock().await;
|
||||
load_save(false, lock);
|
||||
break;
|
||||
}
|
||||
},
|
||||
move || loop {
|
||||
if let Some(lock) = inner3.try_lock() {
|
||||
load_save(true, lock);
|
||||
break;
|
||||
}
|
||||
},
|
||||
move || loop {
|
||||
if let Some(lock) = inner4.try_lock() {
|
||||
move || {
|
||||
let inner3 = inner3.clone();
|
||||
async move {
|
||||
let lock = inner3.lock().await;
|
||||
load_save(false, lock);
|
||||
}
|
||||
},
|
||||
move || {
|
||||
let inner4 = inner4.clone();
|
||||
async move {
|
||||
let lock = inner4.lock().await;
|
||||
load_save(false, lock);
|
||||
break;
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@@ -319,7 +319,8 @@ impl CtrlPlatform {
|
||||
task_watch_item!(panel_od platform);
|
||||
task_watch_item!(dgpu_disable platform);
|
||||
task_watch_item!(egpu_enable platform);
|
||||
task_watch_item!(gpu_mux_mode platform);
|
||||
// NOTE: see note further below
|
||||
//task_watch_item!(gpu_mux_mode platform);
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -332,10 +333,12 @@ impl CtrlTask for CtrlPlatform {
|
||||
let platform1 = self.clone();
|
||||
let platform2 = self.clone();
|
||||
self.create_sys_event_tasks(
|
||||
move || {},
|
||||
move || async { {} },
|
||||
move || {
|
||||
info!("CtrlRogBios reloading panel_od");
|
||||
if let Some(lock) = platform1.config.try_lock() {
|
||||
let platform1 = platform1.clone();
|
||||
async move {
|
||||
info!("CtrlRogBios reloading panel_od");
|
||||
let lock = platform1.config.lock().await;
|
||||
if platform1.platform.has_panel_od() {
|
||||
platform1
|
||||
.set_panel_overdrive(lock.panel_od)
|
||||
@@ -347,10 +350,12 @@ impl CtrlTask for CtrlPlatform {
|
||||
}
|
||||
}
|
||||
},
|
||||
move || {},
|
||||
move || async { {} },
|
||||
move || {
|
||||
info!("CtrlRogBios reloading panel_od");
|
||||
if let Some(lock) = platform2.config.try_lock() {
|
||||
let platform2 = platform2.clone();
|
||||
async move {
|
||||
info!("CtrlRogBios reloading panel_od");
|
||||
let lock = platform2.config.lock().await;
|
||||
if platform2.platform.has_panel_od() {
|
||||
platform2
|
||||
.set_panel_overdrive(lock.panel_od)
|
||||
@@ -368,7 +373,9 @@ impl CtrlTask for CtrlPlatform {
|
||||
self.watch_panel_od(signal_ctxt.clone()).await?;
|
||||
self.watch_dgpu_disable(signal_ctxt.clone()).await?;
|
||||
self.watch_egpu_enable(signal_ctxt.clone()).await?;
|
||||
self.watch_gpu_mux_mode(signal_ctxt.clone()).await?;
|
||||
// NOTE: Can't have this as a watch because on a write to it, it reverts back to booted-with value
|
||||
// as it does not actually change until reboot.
|
||||
//self.watch_gpu_mux_mode(signal_ctxt.clone()).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
use crate::systemd::{do_systemd_unit_action, SystemdUnitAction};
|
||||
use crate::systemd::{
|
||||
do_systemd_unit_action, is_systemd_unit_enabled, SystemdUnitAction, SystemdUnitState,
|
||||
};
|
||||
use crate::{config::Config, error::RogError, GetSupported};
|
||||
use crate::{task_watch_item, CtrlTask};
|
||||
use async_trait::async_trait;
|
||||
use log::{info, warn};
|
||||
use log::{error, info, warn};
|
||||
use rog_platform::power::AsusPower;
|
||||
use rog_platform::supported::ChargeSupportedFunctions;
|
||||
use std::process::Command;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use tokio::time::sleep;
|
||||
@@ -155,10 +158,12 @@ impl CtrlTask for CtrlPower {
|
||||
let power1 = self.clone();
|
||||
let power2 = self.clone();
|
||||
self.create_sys_event_tasks(
|
||||
move || {},
|
||||
move || async {},
|
||||
move || {
|
||||
info!("CtrlCharge reloading charge limit");
|
||||
if let Some(lock) = power1.config.try_lock() {
|
||||
let power1 = power1.clone();
|
||||
async move {
|
||||
info!("CtrlCharge reloading charge limit");
|
||||
let lock = power1.config.lock().await;
|
||||
power1
|
||||
.set(lock.bat_charge_limit)
|
||||
.map_err(|err| {
|
||||
@@ -166,22 +171,18 @@ impl CtrlTask for CtrlPower {
|
||||
err
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
if let Ok(value) = power1.power.get_online() {
|
||||
let action = if value == 1 {
|
||||
SystemdUnitAction::Restart
|
||||
} else {
|
||||
SystemdUnitAction::Stop
|
||||
};
|
||||
if do_systemd_unit_action(action, NVIDIA_POWERD).is_ok() {
|
||||
info!("CtrlPower task: did {action:?} on {NVIDIA_POWERD}");
|
||||
|
||||
if let Ok(value) = power1.power.get_online() {
|
||||
do_nvidia_powerd_action(value == 1);
|
||||
}
|
||||
}
|
||||
},
|
||||
move || {},
|
||||
move || async {},
|
||||
move || {
|
||||
info!("CtrlCharge reloading charge limit");
|
||||
if let Some(lock) = power2.config.try_lock() {
|
||||
let power2 = power2.clone();
|
||||
async move {
|
||||
info!("CtrlCharge reloading charge limit");
|
||||
let lock = power2.config.lock().await;
|
||||
power2
|
||||
.set(lock.bat_charge_limit)
|
||||
.map_err(|err| {
|
||||
@@ -189,21 +190,16 @@ impl CtrlTask for CtrlPower {
|
||||
err
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
if let Ok(value) = power2.power.get_online() {
|
||||
let action = if value == 1 {
|
||||
SystemdUnitAction::Restart
|
||||
} else {
|
||||
SystemdUnitAction::Stop
|
||||
};
|
||||
if do_systemd_unit_action(action, NVIDIA_POWERD).is_ok() {
|
||||
info!("CtrlPower task: did {action:?} on {NVIDIA_POWERD}");
|
||||
|
||||
if let Ok(value) = power2.power.get_online() {
|
||||
do_nvidia_powerd_action(value == 1);
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
||||
let config = self.config.clone();
|
||||
self.watch_charge_control_end_threshold(signal_ctxt.clone())
|
||||
.await?;
|
||||
|
||||
@@ -214,18 +210,36 @@ impl CtrlTask for CtrlPower {
|
||||
if let Ok(value) = ctrl.power.get_online() {
|
||||
if online != value {
|
||||
online = value;
|
||||
let action = if value == 1 {
|
||||
SystemdUnitAction::Restart
|
||||
} else {
|
||||
SystemdUnitAction::Stop
|
||||
};
|
||||
if do_systemd_unit_action(action, NVIDIA_POWERD).is_ok() {
|
||||
info!("CtrlPower task: did {action:?} on {NVIDIA_POWERD}");
|
||||
}
|
||||
do_nvidia_powerd_action(value == 1);
|
||||
|
||||
Self::notify_mains_online(&signal_ctxt, value == 1)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let mut config = config.lock().await;
|
||||
config.read();
|
||||
let mut prog: Vec<&str> = Vec::new();
|
||||
if value == 1 {
|
||||
// AC ONLINE
|
||||
prog = config.ac_command.split_whitespace().collect();
|
||||
} else if value == 0 {
|
||||
// BATTERY
|
||||
prog = config.bat_command.split_whitespace().collect();
|
||||
}
|
||||
|
||||
if prog.len() > 1 {
|
||||
let mut cmd = Command::new(prog[0]);
|
||||
for arg in prog.iter().skip(1) {
|
||||
cmd.arg(*arg);
|
||||
}
|
||||
if let Err(e) = cmd.spawn() {
|
||||
if value == 1 {
|
||||
error!("AC power command error: {e}");
|
||||
} else {
|
||||
error!("Battery power command error: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// The inotify doesn't pick up events when the kernel changes internal value
|
||||
@@ -237,3 +251,17 @@ impl CtrlTask for CtrlPower {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn do_nvidia_powerd_action(ac_on: bool) {
|
||||
let action = if ac_on {
|
||||
SystemdUnitAction::Restart
|
||||
} else {
|
||||
SystemdUnitAction::Stop
|
||||
};
|
||||
|
||||
if let Ok(res) = is_systemd_unit_enabled(SystemdUnitState::Enabled, NVIDIA_POWERD) {
|
||||
if res && do_systemd_unit_action(action, NVIDIA_POWERD).is_ok() {
|
||||
info!("CtrlPower task: did {action:?} on {NVIDIA_POWERD}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,8 @@ impl ProfileConfig {
|
||||
"Could not deserialise {}.\nWill rename to {}-old and recreate config",
|
||||
config_path, config_path
|
||||
);
|
||||
let cfg_old = config_path.clone() + "-old";
|
||||
let mut cfg_old = config_path.clone();
|
||||
cfg_old.push_str("-old");
|
||||
std::fs::rename(config_path.clone(), cfg_old).unwrap_or_else(|err| {
|
||||
panic!(
|
||||
"Could not rename. Please remove {} then restart service: Error {}",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
pub mod config;
|
||||
pub mod controller;
|
||||
/// Implements CtrlTask, Reloadable, ZbusRun
|
||||
/// Implements `CtrlTask`, Reloadable, `ZbusRun`
|
||||
pub mod trait_impls;
|
||||
|
||||
@@ -32,7 +32,7 @@ impl ProfileZbus {
|
||||
return Ok(profiles);
|
||||
}
|
||||
Err(Error::Failed(
|
||||
"Failed to get all profile details".to_string(),
|
||||
"Failed to get all profile details".to_owned(),
|
||||
))
|
||||
}
|
||||
|
||||
@@ -85,9 +85,9 @@ impl ProfileZbus {
|
||||
let mut ctrl = self.0.lock().await;
|
||||
ctrl.config.read();
|
||||
if let Some(curves) = &ctrl.config.fan_curves {
|
||||
return Ok(curves.get_enabled_curve_profiles().to_vec());
|
||||
return Ok(curves.get_enabled_curve_profiles());
|
||||
}
|
||||
Err(Error::Failed(UNSUPPORTED_MSG.to_string()))
|
||||
Err(Error::Failed(UNSUPPORTED_MSG.to_owned()))
|
||||
}
|
||||
|
||||
/// Set a profile fan curve enabled status. Will also activate a fan curve if in the
|
||||
@@ -109,7 +109,7 @@ impl ProfileZbus {
|
||||
ctrl.save_config();
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::Failed(UNSUPPORTED_MSG.to_string()))
|
||||
Err(Error::Failed(UNSUPPORTED_MSG.to_owned()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ impl ProfileZbus {
|
||||
let curve = curves.get_fan_curves_for(profile);
|
||||
return Ok(curve.clone());
|
||||
}
|
||||
Err(Error::Failed(UNSUPPORTED_MSG.to_string()))
|
||||
Err(Error::Failed(UNSUPPORTED_MSG.to_owned()))
|
||||
}
|
||||
|
||||
/// Set the fan curve for the specified profile.
|
||||
@@ -134,7 +134,7 @@ impl ProfileZbus {
|
||||
.save_fan_curve(curve, profile)
|
||||
.map_err(|err| zbus::fdo::Error::Failed(err.to_string()))?;
|
||||
} else {
|
||||
return Err(Error::Failed(UNSUPPORTED_MSG.to_string()));
|
||||
return Err(Error::Failed(UNSUPPORTED_MSG.to_owned()));
|
||||
}
|
||||
ctrl.write_profile_curve_to_platform()
|
||||
.map_err(|e| warn!("Profile::set_profile, {}", e))
|
||||
@@ -200,8 +200,36 @@ impl CtrlTask for ProfileZbus {
|
||||
}
|
||||
|
||||
async fn create_tasks(&self, signal_ctxt: SignalContext<'static>) -> Result<(), RogError> {
|
||||
// let ctrl = self.0.clone();
|
||||
// let mut watch = self.0.lock().await.platform.monitor_platform_profile()?;
|
||||
// let sig_ctx = signal_ctxt.clone();
|
||||
// tokio::spawn(async move {
|
||||
// let mut buffer = [0; 32];
|
||||
// watch
|
||||
// .event_stream(&mut buffer)
|
||||
// .unwrap()
|
||||
// .for_each(|_| async {
|
||||
// let mut lock = ctrl.lock().await;
|
||||
// let new_profile = Profile::get_active_profile().unwrap();
|
||||
// if new_profile != lock.config.active_profile {
|
||||
// lock.config.active_profile = new_profile;
|
||||
// lock.write_profile_curve_to_platform().unwrap();
|
||||
// lock.save_config();
|
||||
// }
|
||||
// Self::notify_profile(&sig_ctx, lock.config.active_profile)
|
||||
// .await
|
||||
// .ok();
|
||||
// })
|
||||
// .await;
|
||||
// });
|
||||
|
||||
let ctrl = self.0.clone();
|
||||
let mut watch = self.0.lock().await.platform.monitor_platform_profile()?;
|
||||
let mut watch = self
|
||||
.0
|
||||
.lock()
|
||||
.await
|
||||
.platform
|
||||
.monitor_throttle_thermal_policy()?;
|
||||
|
||||
tokio::spawn(async move {
|
||||
let mut buffer = [0; 32];
|
||||
@@ -210,13 +238,15 @@ impl CtrlTask for ProfileZbus {
|
||||
.unwrap()
|
||||
.for_each(|_| async {
|
||||
let mut lock = ctrl.lock().await;
|
||||
let new_profile = Profile::get_active_profile().unwrap();
|
||||
let new_thermal = lock.platform.get_throttle_thermal_policy().unwrap();
|
||||
let new_profile = Profile::from_throttle_thermal_policy(new_thermal);
|
||||
if new_profile != lock.config.active_profile {
|
||||
lock.config.active_profile = new_profile;
|
||||
lock.write_profile_curve_to_platform().unwrap();
|
||||
lock.save_config();
|
||||
Profile::set_profile(lock.config.active_profile).unwrap();
|
||||
}
|
||||
Self::notify_profile(&signal_ctxt.clone(), lock.config.active_profile)
|
||||
Self::notify_profile(&signal_ctxt, lock.config.active_profile)
|
||||
.await
|
||||
.ok();
|
||||
})
|
||||
|
||||
@@ -7,7 +7,6 @@ use std::time::Duration;
|
||||
use ::zbus::export::futures_util::lock::Mutex;
|
||||
use ::zbus::Connection;
|
||||
use daemon::ctrl_anime::CtrlAnime;
|
||||
use log::LevelFilter;
|
||||
use log::{error, info, warn};
|
||||
use tokio::time::sleep;
|
||||
use zbus::SignalContext;
|
||||
@@ -33,9 +32,9 @@ static PROFILE_CONFIG_PATH: &str = "/etc/asusd/profile.conf";
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut logger = env_logger::Builder::new();
|
||||
logger
|
||||
.parse_default_env()
|
||||
.target(env_logger::Target::Stdout)
|
||||
.format(|buf, record| writeln!(buf, "{}: {}", record.level(), record.args()))
|
||||
.filter(None, LevelFilter::Info)
|
||||
.init();
|
||||
|
||||
let is_service = match env::var_os("IS_SERVICE") {
|
||||
|
||||
@@ -37,7 +37,7 @@ pub enum RogError {
|
||||
|
||||
impl fmt::Display for RogError {
|
||||
// This trait requires `fmt` with this exact signature.
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
RogError::ParseVendor => write!(f, "Parse gfx vendor error"),
|
||||
RogError::ParseLed => write!(f, "Parse LED error"),
|
||||
@@ -51,7 +51,7 @@ impl fmt::Display for RogError {
|
||||
RogError::DoTask(deets) => write!(f, "Task error: {}", deets),
|
||||
RogError::MissingFunction(deets) => write!(f, "Missing functionality: {}", deets),
|
||||
RogError::MissingLedBrightNode(path, error) => write!(f, "Led node at {} is missing, please check you have the required patch or dkms module installed: {}", path, error),
|
||||
RogError::ReloadFail(deets) => write!(f, "Task error: {}", deets),
|
||||
RogError::ReloadFail(deets) => write!(f, "Reload error: {}", deets),
|
||||
RogError::Profiles(deets) => write!(f, "Profile error: {}", deets),
|
||||
RogError::Initramfs(detail) => write!(f, "Initiramfs error: {}", detail),
|
||||
RogError::Modprobe(detail) => write!(f, "Modprobe error: {}", detail),
|
||||
|
||||
@@ -71,7 +71,7 @@ impl LaptopLedData {
|
||||
}
|
||||
|
||||
impl LedSupportFile {
|
||||
/// Consumes the LEDModes
|
||||
/// Consumes the `LEDModes`
|
||||
fn matcher(self, prod_family: &str, board_name: &str) -> Option<LaptopLedData> {
|
||||
for config in self.led_data {
|
||||
if prod_family.contains(&config.prod_family) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#![deny(unused_must_use)]
|
||||
/// Configuration loading, saving
|
||||
pub mod config;
|
||||
/// Control of AniMe matrix display
|
||||
/// Control of anime matrix display
|
||||
pub mod ctrl_anime;
|
||||
/// Keyboard LED brightness control, RGB, and LED display modes
|
||||
pub mod ctrl_aura;
|
||||
@@ -21,9 +21,11 @@ pub mod ctrl_supported;
|
||||
|
||||
pub mod error;
|
||||
|
||||
use std::future::Future;
|
||||
|
||||
use crate::error::RogError;
|
||||
use async_trait::async_trait;
|
||||
use log::warn;
|
||||
use log::{debug, warn};
|
||||
use logind_zbus::manager::ManagerProxy;
|
||||
use zbus::{export::futures_util::StreamExt, zvariant::ObjectPath, Connection, SignalContext};
|
||||
|
||||
@@ -134,13 +136,31 @@ pub trait CtrlTask {
|
||||
///
|
||||
/// The closures can potentially block, so execution time should be the minimal possible
|
||||
/// such as save a variable.
|
||||
async fn create_sys_event_tasks(
|
||||
async fn create_sys_event_tasks<
|
||||
Fut1,
|
||||
Fut2,
|
||||
Fut3,
|
||||
Fut4,
|
||||
F1: Send + 'static,
|
||||
F2: Send + 'static,
|
||||
F3: Send + 'static,
|
||||
F4: Send + 'static,
|
||||
>(
|
||||
&self,
|
||||
mut on_sleep: impl FnMut() + Send + 'static,
|
||||
mut on_wake: impl FnMut() + Send + 'static,
|
||||
mut on_shutdown: impl FnMut() + Send + 'static,
|
||||
mut on_boot: impl FnMut() + Send + 'static,
|
||||
) {
|
||||
mut on_sleep: F1,
|
||||
mut on_wake: F2,
|
||||
mut on_shutdown: F3,
|
||||
mut on_boot: F4,
|
||||
) where
|
||||
F1: FnMut() -> Fut1,
|
||||
F2: FnMut() -> Fut2,
|
||||
F3: FnMut() -> Fut3,
|
||||
F4: FnMut() -> Fut4,
|
||||
Fut1: Future<Output = ()> + Send,
|
||||
Fut2: Future<Output = ()> + Send,
|
||||
Fut3: Future<Output = ()> + Send,
|
||||
Fut4: Future<Output = ()> + Send,
|
||||
{
|
||||
let connection = Connection::system()
|
||||
.await
|
||||
.expect("Controller could not create dbus connection");
|
||||
@@ -154,9 +174,11 @@ pub trait CtrlTask {
|
||||
while let Some(event) = notif.next().await {
|
||||
if let Ok(args) = event.args() {
|
||||
if args.start {
|
||||
on_sleep();
|
||||
debug!("Doing on_sleep()");
|
||||
on_sleep().await;
|
||||
} else if !args.start() {
|
||||
on_wake();
|
||||
debug!("Doing on_wake()");
|
||||
on_wake().await;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -172,9 +194,11 @@ pub trait CtrlTask {
|
||||
while let Some(event) = notif.next().await {
|
||||
if let Ok(args) = event.args() {
|
||||
if args.start {
|
||||
on_shutdown();
|
||||
debug!("Doing on_shutdown()");
|
||||
on_shutdown().await;
|
||||
} else if !args.start() {
|
||||
on_boot();
|
||||
debug!("Doing on_boot()");
|
||||
on_boot().await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ impl From<SystemdUnitAction> for &str {
|
||||
pub enum SystemdUnitState {
|
||||
Active,
|
||||
Inactive,
|
||||
Masked,
|
||||
Disabled,
|
||||
Enabled,
|
||||
}
|
||||
|
||||
impl From<SystemdUnitState> for &str {
|
||||
@@ -31,6 +34,9 @@ impl From<SystemdUnitState> for &str {
|
||||
match s {
|
||||
SystemdUnitState::Active => "active",
|
||||
SystemdUnitState::Inactive => "inactive",
|
||||
SystemdUnitState::Masked => "masked",
|
||||
SystemdUnitState::Disabled => "disabled",
|
||||
SystemdUnitState::Enabled => "enabled",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,6 +72,21 @@ pub fn is_systemd_unit_state(state: SystemdUnitState, unit: &str) -> Result<bool
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
/// Get systemd unit state. Blocks while command is run.
|
||||
pub fn is_systemd_unit_enabled(state: SystemdUnitState, unit: &str) -> Result<bool, RogError> {
|
||||
let mut cmd = Command::new("systemctl");
|
||||
cmd.arg("is-enabled");
|
||||
cmd.arg(unit);
|
||||
|
||||
let output = cmd
|
||||
.output()
|
||||
.map_err(|err| RogError::Command(format!("{:?}", cmd), err))?;
|
||||
if output.stdout.starts_with(<&str>::from(state).as_bytes()) {
|
||||
return Ok(true);
|
||||
}
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
/// Wait for a systemd unit to change to `state`. Checks state every 250ms for 3 seconds. Blocks while running wait.
|
||||
pub fn wait_systemd_unit_state(state: SystemdUnitState, unit: &str) -> Result<(), RogError> {
|
||||
let mut cmd = Command::new("systemctl");
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
[[led_data]]
|
||||
prod_family = "ASUS TUF Gaming F15"
|
||||
board_names = ["FX506HC"]
|
||||
standard = ["Static", "Breathe", "Strobe", "Pulse"]
|
||||
multizone = []
|
||||
per_key = false
|
||||
|
||||
[[led_data]]
|
||||
prod_family = "TUF"
|
||||
board_names = ["FA507"]
|
||||
@@ -78,7 +85,7 @@ per_key = true
|
||||
|
||||
[[led_data]]
|
||||
prod_family = "ROG Strix"
|
||||
board_names = ["G513QE", "GX531", "G512LV", "G712LV", "G712LW", "G513IH", "G513QY", "G713QM", "G512", "G713RW"]
|
||||
board_names = ["G513QE", "GX531", "G512LV", "G712LV", "G712LW", "G513IH", "G513QY", "G713QM", "G512", "G713RM", "G713RW"]
|
||||
standard = ["Static", "Breathe", "Strobe", "Rainbow", "Pulse"]
|
||||
multizone = ["Key1", "Key2", "Key3", "Key4"]
|
||||
per_key = false
|
||||
@@ -184,7 +191,7 @@ per_key = false
|
||||
|
||||
[[led_data]]
|
||||
prod_family = "ROG Strix"
|
||||
board_names = ["G513IC", "G513RC"]
|
||||
board_names = ["G513IC", "G513RC", "G513RM"]
|
||||
standard = ["Static", "Breathe", "Strobe", "Rainbow", "Pulse"]
|
||||
multizone = []
|
||||
per_key = false
|
||||
|
||||
@@ -6,6 +6,7 @@ Before=multi-user.target
|
||||
|
||||
[Service]
|
||||
Environment=IS_SERVICE=1
|
||||
Environment=RUST_LOG="info"
|
||||
ExecStartPre=/bin/sleep 2
|
||||
ExecStart=/usr/bin/asusd
|
||||
Restart=on-failure
|
||||
|
||||
69
deny.toml
Normal file
69
deny.toml
Normal file
@@ -0,0 +1,69 @@
|
||||
# https://embarkstudios.github.io/cargo-deny/
|
||||
|
||||
targets = [
|
||||
{ triple = "aarch64-apple-darwin" },
|
||||
{ triple = "aarch64-linux-android" },
|
||||
{ triple = "wasm32-unknown-unknown" },
|
||||
{ triple = "x86_64-apple-darwin" },
|
||||
{ triple = "x86_64-pc-windows-msvc" },
|
||||
{ triple = "x86_64-unknown-linux-gnu" },
|
||||
{ triple = "x86_64-unknown-linux-musl" },
|
||||
]
|
||||
|
||||
[advisories]
|
||||
vulnerability = "deny"
|
||||
unmaintained = "warn"
|
||||
yanked = "deny"
|
||||
ignore = [
|
||||
"RUSTSEC-2020-0071", # https://rustsec.org/advisories/RUSTSEC-2020-0071 - chrono/time: Potential segfault in the time crate
|
||||
"RUSTSEC-2020-0159", # https://rustsec.org/advisories/RUSTSEC-2020-0159 - chrono/time: Potential segfault in localtime_r invocations
|
||||
"RUSTSEC-2021-0127", # https://rustsec.org/advisories/RUSTSEC-2021-0127 - https://github.com/bheisler/criterion.rs/issues/534
|
||||
]
|
||||
|
||||
[bans]
|
||||
multiple-versions = "deny"
|
||||
wildcards = "allow" # at least until https://github.com/EmbarkStudios/cargo-deny/issues/241 is fixed
|
||||
deny = [
|
||||
{ name = "openssl" }, # prefer rustls
|
||||
{ name = "openssl-sys" }, # prefer rustls
|
||||
]
|
||||
|
||||
skip-tree = [
|
||||
{ name = "criterion" }, # dev-dependency
|
||||
{ name = "glium" }, # legacy crate, lots of old dependencies
|
||||
{ name = "rfd" }, # example dependency
|
||||
{ name = "three-d" }, # example dependency
|
||||
]
|
||||
|
||||
|
||||
[licenses]
|
||||
unlicensed = "deny"
|
||||
allow-osi-fsf-free = "neither"
|
||||
confidence-threshold = 0.92 # We want really high confidence when inferring licenses from text
|
||||
copyleft = "deny"
|
||||
allow = [
|
||||
"Apache-2.0", # https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)
|
||||
"BSD-2-Clause", # https://tldrlegal.com/license/bsd-2-clause-license-(freebsd)
|
||||
"BSD-3-Clause", # https://tldrlegal.com/license/bsd-3-clause-license-(revised)
|
||||
"BSL-1.0", # https://tldrlegal.com/license/boost-software-license-1.0-explained
|
||||
"CC0-1.0", # https://creativecommons.org/publicdomain/zero/1.0/
|
||||
"ISC", # https://tldrlegal.com/license/-isc-license
|
||||
"LicenseRef-UFL-1.0", # https://tldrlegal.com/license/ubuntu-font-license,-1.0 - no official SPDX, see https://github.com/emilk/egui/issues/2321
|
||||
"MIT", # https://tldrlegal.com/license/mit-license
|
||||
"MPL-2.0", # https://www.mozilla.org/en-US/MPL/2.0/FAQ/ - see Q11
|
||||
"OFL-1.1", # https://spdx.org/licenses/OFL-1.1.html
|
||||
"OpenSSL", # https://www.openssl.org/source/license.html
|
||||
"Unicode-DFS-2016", # https://spdx.org/licenses/Unicode-DFS-2016.html
|
||||
"Zlib", # https://tldrlegal.com/license/zlib-libpng-license-(zlib)
|
||||
]
|
||||
|
||||
[[licenses.clarify]]
|
||||
name = "webpki"
|
||||
expression = "ISC"
|
||||
license-files = [{ path = "LICENSE", hash = 0x001c7e6c }]
|
||||
|
||||
[[licenses.clarify]]
|
||||
name = "ring"
|
||||
expression = "MIT AND ISC AND OpenSSL"
|
||||
license-files = [{ path = "LICENSE", hash = 0xbd0eed23 }]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "rog_anime"
|
||||
version.workspace = true
|
||||
license = "MPL-2.0"
|
||||
version.workspace = true
|
||||
readme = "README.md"
|
||||
authors = ["Luke <luke@ljones.dev>"]
|
||||
repository = "https://gitlab.com/asus-linux/asus-nb-ctrl"
|
||||
@@ -30,4 +30,4 @@ glam.workspace = true
|
||||
|
||||
zbus = { workspace = true, optional = true }
|
||||
|
||||
sysfs-class = { workspace = true, optional = true }
|
||||
sysfs-class = { workspace = true, optional = true }
|
||||
|
||||
@@ -47,8 +47,7 @@ impl AnimeType {
|
||||
/// The width of diagonal images
|
||||
pub fn width(&self) -> usize {
|
||||
match self {
|
||||
AnimeType::GA401 => 74,
|
||||
AnimeType::GA402 => 74,
|
||||
AnimeType::GA401 | AnimeType::GA402 => 74,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,8 +102,8 @@ impl AnimeDataBuffer {
|
||||
|
||||
/// Create from a vector of bytes
|
||||
///
|
||||
/// # Panics
|
||||
/// Will panic if the vector length is not `ANIME_DATA_LEN`
|
||||
/// # Errors
|
||||
/// Will error if the vector length is not `ANIME_DATA_LEN`
|
||||
#[inline]
|
||||
pub fn from_vec(anime: AnimeType, data: Vec<u8>) -> Result<Self> {
|
||||
if data.len() != anime.data_length() {
|
||||
@@ -147,10 +146,7 @@ impl TryFrom<AnimeDataBuffer> for AnimePacketType {
|
||||
/// This runs the animations as a blocking loop by using the `callback` to write data
|
||||
///
|
||||
/// If `callback` is `Ok(true)` then `run_animation` will exit the animation loop early.
|
||||
pub fn run_animation(
|
||||
frames: &AnimeGif,
|
||||
callback: &dyn Fn(AnimeDataBuffer) -> Result<bool>,
|
||||
) -> Result<()> {
|
||||
pub fn run_animation(frames: &AnimeGif, callback: &dyn Fn(AnimeDataBuffer) -> Result<bool>) {
|
||||
let mut count = 0;
|
||||
let start = Instant::now();
|
||||
|
||||
@@ -215,9 +211,10 @@ pub fn run_animation(
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Log this error
|
||||
if matches!(callback(output), Ok(true)) {
|
||||
info!("rog-anime: frame-loop callback asked to exit early");
|
||||
return Ok(());
|
||||
return;
|
||||
}
|
||||
|
||||
if timed && Instant::now().duration_since(start) > run_time {
|
||||
@@ -232,5 +229,4 @@ pub fn run_animation(
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -52,39 +52,43 @@ impl AnimeDiagonal {
|
||||
|
||||
let mut matrix = AnimeDiagonal::new(anime_type, duration);
|
||||
|
||||
match raster {
|
||||
match &raster {
|
||||
png_pong::PngRaster::Gray8(ras) => {
|
||||
Self::pixels_from_8bit(ras, &mut matrix, bright, true)
|
||||
Self::pixels_from_8bit(ras, &mut matrix, bright, true);
|
||||
}
|
||||
png_pong::PngRaster::Graya8(ras) => {
|
||||
Self::pixels_from_8bit(ras, &mut matrix, bright, true)
|
||||
Self::pixels_from_8bit(ras, &mut matrix, bright, true);
|
||||
}
|
||||
png_pong::PngRaster::Rgb8(ras) => {
|
||||
Self::pixels_from_8bit(ras, &mut matrix, bright, false)
|
||||
Self::pixels_from_8bit(ras, &mut matrix, bright, false);
|
||||
}
|
||||
png_pong::PngRaster::Rgba8(ras) => {
|
||||
Self::pixels_from_8bit(ras, &mut matrix, bright, false)
|
||||
Self::pixels_from_8bit(ras, &mut matrix, bright, false);
|
||||
}
|
||||
png_pong::PngRaster::Gray16(ras) => {
|
||||
Self::pixels_from_16bit(ras, &mut matrix, bright, true)
|
||||
Self::pixels_from_16bit(ras, &mut matrix, bright, true);
|
||||
}
|
||||
png_pong::PngRaster::Rgb16(ras) => {
|
||||
Self::pixels_from_16bit(ras, &mut matrix, bright, false)
|
||||
Self::pixels_from_16bit(ras, &mut matrix, bright, false);
|
||||
}
|
||||
png_pong::PngRaster::Graya16(ras) => {
|
||||
Self::pixels_from_16bit(ras, &mut matrix, bright, true)
|
||||
Self::pixels_from_16bit(ras, &mut matrix, bright, true);
|
||||
}
|
||||
png_pong::PngRaster::Rgba16(ras) => {
|
||||
Self::pixels_from_16bit(ras, &mut matrix, bright, false)
|
||||
Self::pixels_from_16bit(ras, &mut matrix, bright, false);
|
||||
}
|
||||
_ => return Err(AnimeError::Format),
|
||||
png_pong::PngRaster::Palette(..) => return Err(AnimeError::Format),
|
||||
};
|
||||
|
||||
Ok(matrix)
|
||||
}
|
||||
|
||||
fn pixels_from_8bit<P>(ras: pix::Raster<P>, matrix: &mut AnimeDiagonal, bright: f32, grey: bool)
|
||||
where
|
||||
fn pixels_from_8bit<P>(
|
||||
ras: &pix::Raster<P>,
|
||||
matrix: &mut AnimeDiagonal,
|
||||
bright: f32,
|
||||
grey: bool,
|
||||
) where
|
||||
P: pix::el::Pixel<Chan = pix::chan::Ch8>,
|
||||
{
|
||||
let width = ras.width();
|
||||
@@ -105,7 +109,7 @@ impl AnimeDiagonal {
|
||||
}
|
||||
|
||||
fn pixels_from_16bit<P>(
|
||||
ras: pix::Raster<P>,
|
||||
ras: &pix::Raster<P>,
|
||||
matrix: &mut AnimeDiagonal,
|
||||
bright: f32,
|
||||
grey: bool,
|
||||
@@ -136,7 +140,7 @@ impl AnimeDiagonal {
|
||||
}
|
||||
}
|
||||
|
||||
/// Do conversion from the nested Vec in AnimeMatrix to the two required
|
||||
/// Do conversion from the nested Vec in `AnimeMatrix` to the two required
|
||||
/// packets suitable for sending over USB
|
||||
fn to_ga401_packets(&self) -> Result<AnimeDataBuffer> {
|
||||
let mut buf = vec![0u8; AnimeType::GA401.data_length()];
|
||||
|
||||
@@ -26,7 +26,7 @@ pub enum AnimeError {
|
||||
|
||||
impl fmt::Display for AnimeError {
|
||||
#[inline]
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
AnimeError::NoFrames => write!(f, "No frames in PNG"),
|
||||
AnimeError::Io(e) => write!(f, "Could not open: {}", e),
|
||||
|
||||
@@ -93,7 +93,7 @@ impl AnimeGrid {
|
||||
impl TryFrom<AnimeGrid> for AnimeDataBuffer {
|
||||
type Error = AnimeError;
|
||||
|
||||
/// Do conversion from the nested Vec in AniMeMatrix to the two required
|
||||
/// Do conversion from the nested Vec in anime matrix to the two required
|
||||
/// packets suitable for sending over USB
|
||||
fn try_from(anime: AnimeGrid) -> Result<Self> {
|
||||
let mut buf = vec![0u8; anime.anime_type.data_length()];
|
||||
|
||||
@@ -30,7 +30,7 @@ impl Default for Pixel {
|
||||
/// is to be used to sample an image and set the LED brightness.
|
||||
///
|
||||
/// The position of the Led in `LedPositions` determines the placement in the final
|
||||
/// data packets when written to the AniMe.
|
||||
/// data packets when written to the `AniMe`.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct Led(f32, f32, u8);
|
||||
|
||||
@@ -58,7 +58,7 @@ impl Led {
|
||||
|
||||
/// Container of `Led`, each of which specifies a position within the image
|
||||
/// The main use of this is to position and sample colours for the final image
|
||||
/// to show on AniMe
|
||||
/// to show on `AniMe`
|
||||
pub struct AnimeImage {
|
||||
pub scale: Vec2,
|
||||
/// Angle in radians
|
||||
@@ -294,8 +294,8 @@ impl AnimeImage {
|
||||
let x0 = led_from_px.mul_vec3(pos + Vec3::new(0.0, -0.5, 0.0));
|
||||
|
||||
const GROUP: [f32; 4] = [0.0, 0.5, 1.0, 1.5];
|
||||
for u in GROUP.iter() {
|
||||
for v in GROUP.iter() {
|
||||
for u in &GROUP {
|
||||
for v in &GROUP {
|
||||
let sample = x0 + *u * du + *v * dv;
|
||||
|
||||
let x = sample.x as i32;
|
||||
@@ -399,7 +399,7 @@ impl AnimeImage {
|
||||
let png_pong::Step { raster, delay: _ } = decoder.last().ok_or(AnimeError::NoFrames)??;
|
||||
|
||||
let width;
|
||||
let pixels = match raster {
|
||||
let pixels = match &raster {
|
||||
png_pong::PngRaster::Gray8(ras) => {
|
||||
width = ras.width();
|
||||
Self::pixels_from_8bit(ras, true)
|
||||
@@ -432,7 +432,7 @@ impl AnimeImage {
|
||||
width = ras.width();
|
||||
Self::pixels_from_16bit(ras, false)
|
||||
}
|
||||
_ => return Err(AnimeError::Format),
|
||||
png_pong::PngRaster::Palette(..) => return Err(AnimeError::Format),
|
||||
};
|
||||
|
||||
let mut matrix = AnimeImage::new(
|
||||
@@ -449,7 +449,7 @@ impl AnimeImage {
|
||||
Ok(matrix)
|
||||
}
|
||||
|
||||
fn pixels_from_8bit<P>(ras: pix::Raster<P>, grey: bool) -> Vec<Pixel>
|
||||
fn pixels_from_8bit<P>(ras: &pix::Raster<P>, grey: bool) -> Vec<Pixel>
|
||||
where
|
||||
P: pix::el::Pixel<Chan = pix::chan::Ch8>,
|
||||
{
|
||||
@@ -468,7 +468,7 @@ impl AnimeImage {
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn pixels_from_16bit<P>(ras: pix::Raster<P>, grey: bool) -> Vec<Pixel>
|
||||
fn pixels_from_16bit<P>(ras: &pix::Raster<P>, grey: bool) -> Vec<Pixel>
|
||||
where
|
||||
P: pix::el::Pixel<Chan = pix::chan::Ch16>,
|
||||
{
|
||||
@@ -491,7 +491,7 @@ impl AnimeImage {
|
||||
impl TryFrom<&AnimeImage> for AnimeDataBuffer {
|
||||
type Error = AnimeError;
|
||||
|
||||
/// Do conversion from the nested Vec in AnimeDataBuffer to the two required
|
||||
/// Do conversion from the nested Vec in `AnimeDataBuffer` to the two required
|
||||
/// packets suitable for sending over USB
|
||||
fn try_from(leds: &AnimeImage) -> Result<Self> {
|
||||
let mut l: Vec<u8> = leds
|
||||
|
||||
@@ -7,11 +7,11 @@ pub use data::*;
|
||||
mod grid;
|
||||
pub use grid::*;
|
||||
|
||||
/// Transform a PNG image for displaying on AniMe matrix display
|
||||
/// Transform a PNG image for displaying on `AniMe` matrix display
|
||||
mod image;
|
||||
pub use image::*;
|
||||
|
||||
/// A grid of data that is intended to be read out and displayed on the ANiMe as
|
||||
/// A grid of data that is intended to be read out and displayed on the `AniMe` as
|
||||
/// a diagonal
|
||||
mod diagonal;
|
||||
pub use diagonal::*;
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
error::Result, AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, AnimeType,
|
||||
};
|
||||
|
||||
/// All the possible AniMe actions that can be used. This enum is intended to be
|
||||
/// All the possible `AniMe` actions that can be used. This enum is intended to be
|
||||
/// a helper for loading up `ActionData`.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub enum ActionLoader {
|
||||
@@ -44,7 +44,7 @@ pub enum ActionLoader {
|
||||
Pause(Duration),
|
||||
}
|
||||
|
||||
/// All the possible AniMe actions that can be used. The enum is intended to be
|
||||
/// All the possible `AniMe` actions that can be used. The enum is intended to be
|
||||
/// used in a array allowing the user to cycle through a series of actions.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub enum ActionData {
|
||||
@@ -194,7 +194,7 @@ impl Sequences {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> ActionIterator {
|
||||
pub fn iter(&self) -> ActionIterator<'_> {
|
||||
ActionIterator {
|
||||
actions: self,
|
||||
next_idx: 0,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Utils for writing to the AniMe USB device
|
||||
//! Utils for writing to the `AniMe` USB device
|
||||
//!
|
||||
//! Use of the device requires a few steps:
|
||||
//! 1. Initialise the device by writing the two packets from `get_init_packets()`
|
||||
@@ -63,7 +63,7 @@ pub const fn pkt_for_flush() -> [u8; PACKET_SIZE] {
|
||||
}
|
||||
|
||||
/// Get the packet required for setting the device to on, on boot. Requires
|
||||
/// pkt_for_apply()` to be written after.
|
||||
/// `pkt_for_apply()` to be written after.
|
||||
#[inline]
|
||||
pub const fn pkt_for_set_boot(status: bool) -> [u8; PACKET_SIZE] {
|
||||
let mut pkt = [0; PACKET_SIZE];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "rog_aura"
|
||||
version.workspace = true
|
||||
license = "MPL-2.0"
|
||||
version.workspace = true
|
||||
readme = "README.md"
|
||||
authors = ["Luke <luke@ljones.dev>"]
|
||||
repository = "https://gitlab.com/asus-linux/asusctl"
|
||||
@@ -23,4 +23,4 @@ toml = { workspace = true, optional = true }
|
||||
zbus = { workspace = true, optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json.workspace = true
|
||||
serde_json.workspace = true
|
||||
|
||||
@@ -25,7 +25,6 @@ impl From<u32> for LedBrightness {
|
||||
match bright {
|
||||
0 => LedBrightness::Off,
|
||||
1 => LedBrightness::Low,
|
||||
2 => LedBrightness::Med,
|
||||
3 => LedBrightness::High,
|
||||
_ => LedBrightness::Med,
|
||||
}
|
||||
@@ -179,21 +178,7 @@ impl Display for AuraModeNum {
|
||||
|
||||
impl From<AuraModeNum> for String {
|
||||
fn from(mode: AuraModeNum) -> Self {
|
||||
match mode {
|
||||
AuraModeNum::Static => "Static",
|
||||
AuraModeNum::Breathe => "Breathe",
|
||||
AuraModeNum::Strobe => "Strobe",
|
||||
AuraModeNum::Rainbow => "Rainbow",
|
||||
AuraModeNum::Star => "Stars",
|
||||
AuraModeNum::Rain => "Rain",
|
||||
AuraModeNum::Highlight => "Highlight",
|
||||
AuraModeNum::Laser => "Laser",
|
||||
AuraModeNum::Ripple => "Ripple",
|
||||
AuraModeNum::Pulse => "Pulse",
|
||||
AuraModeNum::Comet => "Comet",
|
||||
AuraModeNum::Flash => "Flash",
|
||||
}
|
||||
.to_string()
|
||||
<&str>::from(&mode).to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +203,6 @@ impl From<&AuraModeNum> for &str {
|
||||
impl From<&str> for AuraModeNum {
|
||||
fn from(mode: &str) -> Self {
|
||||
match mode {
|
||||
"Static" => AuraModeNum::Static,
|
||||
"Breathe" => AuraModeNum::Breathe,
|
||||
"Strobe" => AuraModeNum::Strobe,
|
||||
"Rainbow" => AuraModeNum::Rainbow,
|
||||
@@ -238,7 +222,6 @@ impl From<&str> for AuraModeNum {
|
||||
impl From<u8> for AuraModeNum {
|
||||
fn from(mode: u8) -> Self {
|
||||
match mode {
|
||||
0 => AuraModeNum::Static,
|
||||
1 => AuraModeNum::Breathe,
|
||||
2 => AuraModeNum::Strobe,
|
||||
3 => AuraModeNum::Rainbow,
|
||||
@@ -284,22 +267,14 @@ impl FromStr for AuraZone {
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let s = s.to_lowercase();
|
||||
match s.to_ascii_lowercase().as_str() {
|
||||
"0" => Ok(AuraZone::None),
|
||||
"none" => Ok(AuraZone::None),
|
||||
"1" => Ok(AuraZone::Key1),
|
||||
"one" => Ok(AuraZone::Key1),
|
||||
"2" => Ok(AuraZone::Key2),
|
||||
"two" => Ok(AuraZone::Key2),
|
||||
"3" => Ok(AuraZone::Key3),
|
||||
"three" => Ok(AuraZone::Key3),
|
||||
"4" => Ok(AuraZone::Key4),
|
||||
"four" => Ok(AuraZone::Key4),
|
||||
"5" => Ok(AuraZone::Logo),
|
||||
"logo" => Ok(AuraZone::Logo),
|
||||
"6" => Ok(AuraZone::BarLeft),
|
||||
"lightbar-left" => Ok(AuraZone::BarLeft),
|
||||
"7" => Ok(AuraZone::BarRight),
|
||||
"lightbar-right" => Ok(AuraZone::BarRight),
|
||||
"0" | "none" => Ok(AuraZone::None),
|
||||
"1" | "one" => Ok(AuraZone::Key1),
|
||||
"2" | "two" => Ok(AuraZone::Key2),
|
||||
"3" | "three" => Ok(AuraZone::Key3),
|
||||
"4" | "four" => Ok(AuraZone::Key4),
|
||||
"5" | "logo" => Ok(AuraZone::Logo),
|
||||
"6" | "lightbar-left" => Ok(AuraZone::BarLeft),
|
||||
"7" | "lightbar-right" => Ok(AuraZone::BarRight),
|
||||
_ => Err(Error::ParseSpeed),
|
||||
}
|
||||
}
|
||||
@@ -395,18 +370,20 @@ impl AuraEffect {
|
||||
/// factory mode accepts only one colour.
|
||||
pub const fn allowed_parameters(mode: AuraModeNum) -> AuraParameters {
|
||||
match mode {
|
||||
AuraModeNum::Static => AuraParameters::new(true, true, false, false, false),
|
||||
AuraModeNum::Static
|
||||
| AuraModeNum::Highlight
|
||||
| AuraModeNum::Pulse
|
||||
| AuraModeNum::Comet
|
||||
| AuraModeNum::Flash => AuraParameters::new(true, true, false, false, false),
|
||||
AuraModeNum::Breathe => AuraParameters::new(true, true, true, true, false),
|
||||
AuraModeNum::Strobe => AuraParameters::new(true, false, false, true, false),
|
||||
AuraModeNum::Strobe | AuraModeNum::Rain => {
|
||||
AuraParameters::new(true, false, false, true, false)
|
||||
}
|
||||
AuraModeNum::Rainbow => AuraParameters::new(true, false, false, true, true),
|
||||
AuraModeNum::Star => AuraParameters::new(true, true, true, true, true),
|
||||
AuraModeNum::Rain => AuraParameters::new(true, false, false, true, false),
|
||||
AuraModeNum::Highlight => AuraParameters::new(true, true, false, false, false),
|
||||
AuraModeNum::Laser => AuraParameters::new(true, true, false, true, false),
|
||||
AuraModeNum::Ripple => AuraParameters::new(true, true, false, true, false),
|
||||
AuraModeNum::Pulse => AuraParameters::new(true, true, false, false, false),
|
||||
AuraModeNum::Comet => AuraParameters::new(true, true, false, false, false),
|
||||
AuraModeNum::Flash => AuraParameters::new(true, true, false, false, false),
|
||||
AuraModeNum::Laser | AuraModeNum::Ripple => {
|
||||
AuraParameters::new(true, true, false, true, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ pub enum Error {
|
||||
|
||||
impl fmt::Display for Error {
|
||||
// This trait requires `fmt` with this exact signature.
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Error::ParseColour => write!(f, "Could not parse colour"),
|
||||
Error::ParseSpeed => write!(f, "Could not parse speed"),
|
||||
|
||||
@@ -139,17 +139,17 @@ impl From<&Key> for &str {
|
||||
Key::MediaStop => "Media Stop",
|
||||
Key::MediaNext => "Media Next",
|
||||
Key::MediaPrev => "Media Previous",
|
||||
Key::NormalBlank => "",
|
||||
Key::NormalSpacer => "",
|
||||
Key::FuncBlank => "",
|
||||
Key::FuncSpacer => "",
|
||||
Key::ArrowBlank => "",
|
||||
Key::ArrowSpacer => "",
|
||||
Key::ArrowRegularBlank => "",
|
||||
Key::ArrowRegularSpacer => "",
|
||||
Key::ArrowSplitBlank => "",
|
||||
Key::ArrowSplitSpacer => "",
|
||||
Key::RowEndSpacer => "",
|
||||
Key::NormalBlank
|
||||
| Key::NormalSpacer
|
||||
| Key::FuncBlank
|
||||
| Key::FuncSpacer
|
||||
| Key::ArrowBlank
|
||||
| Key::ArrowSpacer
|
||||
| Key::ArrowRegularBlank
|
||||
| Key::ArrowRegularSpacer
|
||||
| Key::ArrowSplitBlank
|
||||
| Key::ArrowSplitSpacer
|
||||
| Key::RowEndSpacer => "",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,17 +203,22 @@ pub enum KeyShape {
|
||||
impl KeyShape {
|
||||
pub const fn width(&self) -> f32 {
|
||||
match self {
|
||||
Self::Tilde => 0.8,
|
||||
Self::Normal => 1.0,
|
||||
Self::NormalBlank => 1.0,
|
||||
Self::NormalSpacer => 1.0,
|
||||
Self::Func => 1.0,
|
||||
Self::FuncBlank => 1.0,
|
||||
Self::Tilde | Self::Arrow => 0.8,
|
||||
Self::Normal
|
||||
| Self::NormalBlank
|
||||
| Self::NormalSpacer
|
||||
| Self::Func
|
||||
| Self::FuncBlank
|
||||
| Self::Space5
|
||||
| Self::ArrowBlank
|
||||
| Self::ArrowSpacer
|
||||
| Self::ArrowSplit
|
||||
| Self::ArrowSplitBlank
|
||||
| Self::ArrowSplitSpacer => 1.0,
|
||||
Self::FuncSpacer => 0.6,
|
||||
Self::Space => 5.0,
|
||||
Self::Space5 => 1.0,
|
||||
Self::LCtrlMed => 1.1,
|
||||
Self::LShift => 2.0,
|
||||
Self::LShift | Self::Backspace => 2.0,
|
||||
Self::LShift3 => 0.67,
|
||||
Self::RShift => 2.8,
|
||||
Self::RshiftSmall => 1.8,
|
||||
@@ -222,12 +227,9 @@ impl KeyShape {
|
||||
Self::Return3 => 0.7333,
|
||||
Self::Tab => 1.4,
|
||||
Self::Caps => 1.6,
|
||||
Self::Backspace => 2.0,
|
||||
Self::Backspace3 => 0.666,
|
||||
Self::ArrowRegularBlank | Self::ArrowRegularSpacer => 0.7,
|
||||
Self::Arrow => 0.8,
|
||||
Self::ArrowBlank | Self::ArrowSpacer => 1.0,
|
||||
Self::ArrowSplit | Self::ArrowSplitBlank | Self::ArrowSplitSpacer => 1.0,
|
||||
|
||||
Self::RowEndSpacer => 0.1,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ impl KeyLayout {
|
||||
pub fn g513_layout() -> Self {
|
||||
Self {
|
||||
matches: vec!["G513".into()],
|
||||
locale: "US".to_string(),
|
||||
locale: "US".to_owned(),
|
||||
rows: vec![
|
||||
KeyRow::new(
|
||||
0.8,
|
||||
|
||||
@@ -5,7 +5,7 @@ impl KeyLayout {
|
||||
pub fn ga401_layout() -> Self {
|
||||
Self {
|
||||
matches: vec!["GA401".into(), "GA402".into()],
|
||||
locale: "US".to_string(),
|
||||
locale: "US".to_owned(),
|
||||
rows: vec![
|
||||
KeyRow::new(
|
||||
0.8,
|
||||
|
||||
@@ -5,7 +5,7 @@ impl KeyLayout {
|
||||
pub fn gx502_layout() -> Self {
|
||||
Self {
|
||||
matches: vec!["GX502".into(), "GU502".into()],
|
||||
locale: "US".to_string(),
|
||||
locale: "US".to_owned(),
|
||||
rows: vec![
|
||||
KeyRow::new(
|
||||
0.8,
|
||||
|
||||
@@ -43,7 +43,7 @@ impl KeyLayout {
|
||||
|
||||
pub fn matches(&self, board_name: &str) -> bool {
|
||||
let board = board_name.to_ascii_uppercase();
|
||||
for tmp in self.matches.iter() {
|
||||
for tmp in &self.matches {
|
||||
if board.contains(tmp.as_str()) {
|
||||
return true;
|
||||
}
|
||||
@@ -91,7 +91,7 @@ impl KeyRow {
|
||||
Self { height, row }
|
||||
}
|
||||
|
||||
pub fn row(&self) -> Iter<Key> {
|
||||
pub fn row(&self) -> Iter<'_, Key> {
|
||||
self.row.iter()
|
||||
}
|
||||
|
||||
|
||||
@@ -43,8 +43,7 @@ impl ZonedColourArray {
|
||||
|
||||
pub fn rgb_for_zone(&mut self, zone: PerZone) -> &mut [u8] {
|
||||
match zone {
|
||||
PerZone::None => &mut self.0[9..=11],
|
||||
PerZone::KeyboardLeft => &mut self.0[9..=11],
|
||||
PerZone::None | PerZone::KeyboardLeft => &mut self.0[9..=11],
|
||||
PerZone::KeyboardCenterLeft => &mut self.0[12..=14],
|
||||
PerZone::KeyboardCenterRight => &mut self.0[15..=17],
|
||||
PerZone::KeyboardRight => &mut self.0[18..=20],
|
||||
|
||||
@@ -9,7 +9,7 @@ use serde_derive::{Deserialize, Serialize};
|
||||
// static mut RNDINDEX: usize = 0;
|
||||
static mut PRNDINDEX: usize = 0;
|
||||
|
||||
/// Pseudo random table ripped straight out of Room4Doom
|
||||
/// Pseudo random table ripped straight out of room4doom
|
||||
pub const RNDTABLE: [i32; 256] = [
|
||||
0, 8, 109, 220, 222, 241, 149, 107, 75, 248, 254, 140, 16, 66, 74, 21, 211, 47, 80, 242, 154,
|
||||
27, 205, 128, 161, 89, 77, 36, 95, 110, 85, 48, 212, 140, 211, 249, 22, 79, 200, 50, 28, 188,
|
||||
@@ -88,7 +88,7 @@ impl Sequences {
|
||||
}
|
||||
|
||||
pub fn next_state(&mut self, layout: &KeyLayout) {
|
||||
for effect in self.0.iter_mut() {
|
||||
for effect in &mut self.0 {
|
||||
effect.next_state(layout);
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,7 @@ impl Sequences {
|
||||
let mut keys = KeyColourArray::new();
|
||||
let mut zones = ZonedColourArray::new();
|
||||
let mut is_per_key = false;
|
||||
for effect in self.0.iter() {
|
||||
for effect in &self.0 {
|
||||
match effect.get_led_type() {
|
||||
LedType::Key(key) => {
|
||||
is_per_key = true;
|
||||
|
||||
@@ -36,14 +36,10 @@ impl From<&str> for AuraDevice {
|
||||
fn from(s: &str) -> Self {
|
||||
match s.to_lowercase().as_str() {
|
||||
"tuf" => AuraDevice::Tuf,
|
||||
"1866" => AuraDevice::X1866,
|
||||
"1869" => AuraDevice::X1869,
|
||||
"1854" => AuraDevice::X1854,
|
||||
"19b6" => AuraDevice::X19B6,
|
||||
"0x1866" => AuraDevice::X1866,
|
||||
"0x1869" => AuraDevice::X1869,
|
||||
"0x1854" => AuraDevice::X1854,
|
||||
"0x19b6" => AuraDevice::X19B6,
|
||||
"1866" | "0x1866" => AuraDevice::X1866,
|
||||
"1869" | "0x1869" => AuraDevice::X1869,
|
||||
"1854" | "0x1854" => AuraDevice::X1854,
|
||||
"19b6" | "0x19b6" => AuraDevice::X19B6,
|
||||
_ => AuraDevice::Unknown,
|
||||
}
|
||||
}
|
||||
@@ -108,9 +104,9 @@ impl From<AuraDev1866> for u32 {
|
||||
impl AuraDev1866 {
|
||||
pub fn to_bytes(control: &[Self]) -> [u8; 3] {
|
||||
let mut a: u32 = 0;
|
||||
control.iter().for_each(|n| {
|
||||
for n in control {
|
||||
a |= *n as u32;
|
||||
});
|
||||
}
|
||||
[
|
||||
((a & 0xff0000) >> 16) as u8,
|
||||
((a & 0xff00) >> 8) as u8,
|
||||
@@ -197,9 +193,9 @@ impl From<AuraDev19b6> for u32 {
|
||||
impl AuraDev19b6 {
|
||||
pub fn to_bytes(control: &[Self]) -> [u8; 3] {
|
||||
let mut a: u32 = 0;
|
||||
control.iter().for_each(|n| {
|
||||
for n in control {
|
||||
a |= *n as u32;
|
||||
});
|
||||
}
|
||||
[
|
||||
(a & 0xff) as u8,
|
||||
((a & 0xff00) >> 8) as u8,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
[package]
|
||||
name = "rog-control-center"
|
||||
license = "MPL-2.0"
|
||||
version.workspace = true
|
||||
authors = ["Luke D. Jones <luke@ljones.dev>"]
|
||||
edition = "2021"
|
||||
@@ -8,12 +9,11 @@ edition = "2021"
|
||||
mocking = []
|
||||
|
||||
[dependencies]
|
||||
egui = { git = "https://github.com/flukejones/egui" }
|
||||
eframe= { git = "https://github.com/flukejones/egui" }
|
||||
#eframe= { git = "https://github.com/emilk/egui", default-features = false, features = ["dark-light", "default_fonts", "wgpu"] }
|
||||
egui = { git = "https://github.com/flukejones/egui", branch = "wayland_dark_theme" }
|
||||
eframe = { git = "https://github.com/flukejones/egui", branch = "wayland_dark_theme" }
|
||||
|
||||
libappindicator = "0.7" # Tray icon
|
||||
gtk = "0.15"
|
||||
gtk = "0.15.5"
|
||||
|
||||
daemon = { path = "../daemon" }
|
||||
rog_anime = { path = "../rog-anime" }
|
||||
@@ -22,7 +22,6 @@ rog_aura = { path = "../rog-aura" }
|
||||
rog_profiles = { path = "../rog-profiles" }
|
||||
rog_platform = { path = "../rog-platform" }
|
||||
supergfxctl = { git = "https://gitlab.com/asus-linux/supergfxctl.git", default-features = false }
|
||||
#supergfxctl = { path = "../../supergfxctl", default-features = false }
|
||||
|
||||
log.workspace = true
|
||||
env_logger.workspace = true
|
||||
@@ -38,5 +37,5 @@ notify-rust.workspace = true
|
||||
|
||||
png_pong.workspace = true
|
||||
|
||||
nix = "^0.25"
|
||||
tempfile = "3.2.0"
|
||||
nix = "^0.26.1"
|
||||
tempfile = "3.3.0"
|
||||
|
||||
@@ -4,19 +4,20 @@ use std::{
|
||||
fs::{create_dir, OpenOptions},
|
||||
io::{Read, Write},
|
||||
};
|
||||
//use log::{error, info, warn};
|
||||
|
||||
use crate::{error::Error, notify::EnabledNotifications};
|
||||
use crate::{error::Error, update_and_notify::EnabledNotifications};
|
||||
|
||||
const CFG_DIR: &str = "rog";
|
||||
const CFG_FILE_NAME: &str = "rog-control-center.cfg";
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(default)]
|
||||
pub struct Config {
|
||||
pub run_in_background: bool,
|
||||
pub startup_in_background: bool,
|
||||
pub ac_command: String,
|
||||
pub bat_command: String,
|
||||
pub enable_notifications: bool,
|
||||
// This field must be last
|
||||
pub enabled_notifications: EnabledNotifications,
|
||||
}
|
||||
|
||||
@@ -27,6 +28,8 @@ impl Default for Config {
|
||||
startup_in_background: false,
|
||||
enable_notifications: true,
|
||||
enabled_notifications: EnabledNotifications::default(),
|
||||
ac_command: String::new(),
|
||||
bat_command: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,6 +70,9 @@ impl Config {
|
||||
} else if let Ok(data) = toml::from_str::<Config>(&buf) {
|
||||
info!("Loaded config file {path:?}");
|
||||
return Ok(data);
|
||||
} else if let Ok(data) = toml::from_str::<Config455>(&buf) {
|
||||
info!("Loaded old v4.5.5 config file {path:?}");
|
||||
return Ok(data.into());
|
||||
}
|
||||
}
|
||||
Err(Error::ConfigLoadFail)
|
||||
@@ -100,3 +106,24 @@ impl Config {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct Config455 {
|
||||
pub run_in_background: bool,
|
||||
pub startup_in_background: bool,
|
||||
pub enable_notifications: bool,
|
||||
pub enabled_notifications: EnabledNotifications,
|
||||
}
|
||||
|
||||
impl From<Config455> for Config {
|
||||
fn from(c: Config455) -> Self {
|
||||
Self {
|
||||
run_in_background: c.run_in_background,
|
||||
startup_in_background: c.startup_in_background,
|
||||
enable_notifications: c.enable_notifications,
|
||||
enabled_notifications: c.enabled_notifications,
|
||||
ac_command: String::new(),
|
||||
bat_command: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ pub enum Error {
|
||||
|
||||
impl fmt::Display for Error {
|
||||
// This trait requires `fmt` with this exact signature.
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Error::Io(err) => write!(f, "Failed to open: {}", err),
|
||||
Error::Nix(err) => write!(f, "Error: {}", err),
|
||||
|
||||
@@ -13,11 +13,11 @@ pub mod config;
|
||||
pub mod error;
|
||||
#[cfg(feature = "mocking")]
|
||||
pub mod mocking;
|
||||
pub mod notify;
|
||||
pub mod pages;
|
||||
pub mod startup_error;
|
||||
pub mod system_state;
|
||||
pub mod tray;
|
||||
pub mod update_and_notify;
|
||||
pub mod widgets;
|
||||
|
||||
#[cfg(feature = "mocking")]
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use eframe::{IconData, NativeOptions};
|
||||
use log::{error, info, LevelFilter};
|
||||
use log::{error, info};
|
||||
use rog_aura::layouts::KeyLayout;
|
||||
use rog_control_center::notify::EnabledNotifications;
|
||||
use rog_control_center::tray::init_tray;
|
||||
use rog_control_center::update_and_notify::EnabledNotifications;
|
||||
use rog_control_center::{
|
||||
config::Config, error::Result, get_ipc_file, notify::start_notifications, on_tmp_dir_exists,
|
||||
print_versions, startup_error::AppErrorShow, system_state::SystemState, RogApp,
|
||||
RogDbusClientBlocking, SHOWING_GUI, SHOW_GUI,
|
||||
config::Config, error::Result, get_ipc_file, on_tmp_dir_exists, print_versions,
|
||||
startup_error::AppErrorShow, system_state::SystemState, update_and_notify::start_notifications,
|
||||
RogApp, RogDbusClientBlocking, SHOWING_GUI, SHOW_GUI,
|
||||
};
|
||||
use rog_platform::supported::SupportedFunctions;
|
||||
use std::sync::Mutex;
|
||||
@@ -29,9 +29,9 @@ fn main() -> Result<()> {
|
||||
print_versions();
|
||||
let mut logger = env_logger::Builder::new();
|
||||
logger
|
||||
.parse_default_env()
|
||||
.target(env_logger::Target::Stdout)
|
||||
.format(|buf, record| writeln!(buf, "{}: {}", record.level(), record.args()))
|
||||
.filter(None, LevelFilter::Info)
|
||||
.init();
|
||||
|
||||
// start tokio
|
||||
@@ -118,7 +118,7 @@ fn main() -> Result<()> {
|
||||
Err(_) => on_tmp_dir_exists().unwrap(),
|
||||
};
|
||||
|
||||
let states = setup_page_state_and_notifs(layout, enabled_notifications, &supported)?;
|
||||
let states = setup_page_state_and_notifs(layout, enabled_notifications, &config, &supported)?;
|
||||
|
||||
init_tray(supported, states.clone());
|
||||
|
||||
@@ -153,6 +153,7 @@ fn main() -> Result<()> {
|
||||
fn setup_page_state_and_notifs(
|
||||
keyboard_layout: KeyLayout,
|
||||
enabled_notifications: Arc<Mutex<EnabledNotifications>>,
|
||||
config: &Config,
|
||||
supported: &SupportedFunctions,
|
||||
) -> Result<Arc<Mutex<SystemState>>> {
|
||||
let page_states = Arc::new(Mutex::new(SystemState::new(
|
||||
@@ -161,7 +162,7 @@ fn setup_page_state_and_notifs(
|
||||
supported,
|
||||
)?));
|
||||
|
||||
start_notifications(page_states.clone(), enabled_notifications)?;
|
||||
start_notifications(config, page_states.clone(), enabled_notifications)?;
|
||||
|
||||
Ok(page_states)
|
||||
}
|
||||
@@ -206,7 +207,7 @@ fn load_icon() -> IconData {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error!("Missing {APP_ICON_PATH}")
|
||||
error!("Missing {APP_ICON_PATH}");
|
||||
}
|
||||
|
||||
IconData {
|
||||
|
||||
@@ -22,7 +22,7 @@ impl RogApp {
|
||||
ui,
|
||||
);
|
||||
|
||||
fan_graphs(supported, &mut states.profiles, &mut states.fan_curves, &states.asus_dbus, &mut states.error, ui);
|
||||
fan_graphs(supported, &mut states.fan_curves, &states.asus_dbus, &mut states.error, ui);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ impl RogApp {
|
||||
supported: &SupportedFunctions,
|
||||
profiles: &mut ProfilesState,
|
||||
curves: &mut FanCurvesState,
|
||||
dbus: &RogDbusClientBlocking,
|
||||
dbus: &RogDbusClientBlocking<'_>,
|
||||
do_error: &mut Option<String>,
|
||||
ui: &mut Ui,
|
||||
) {
|
||||
@@ -62,7 +62,7 @@ impl RogApp {
|
||||
};
|
||||
|
||||
profiles.list.sort();
|
||||
for f in profiles.list.iter() {
|
||||
for f in &profiles.list {
|
||||
item(*f, curves, curves.enabled.contains(f));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -12,9 +12,10 @@ use supergfxctl::{
|
||||
zbus_proxy::DaemonProxyBlocking as GfxProxyBlocking,
|
||||
};
|
||||
|
||||
use crate::{error::Result, notify::EnabledNotifications, RogDbusClientBlocking};
|
||||
use crate::{error::Result, update_and_notify::EnabledNotifications, RogDbusClientBlocking};
|
||||
use log::error;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct BiosState {
|
||||
/// To be shared to a thread that checks notifications.
|
||||
/// It's a bit general in that it won't provide *what* was
|
||||
@@ -27,7 +28,7 @@ pub struct BiosState {
|
||||
}
|
||||
|
||||
impl BiosState {
|
||||
pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking) -> Result<Self> {
|
||||
pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking<'_>) -> Result<Self> {
|
||||
Ok(Self {
|
||||
post_sound: if supported.rog_bios_ctrl.post_sound {
|
||||
dbus.proxies().rog_bios().post_boot_sound()? != 0
|
||||
@@ -51,14 +52,14 @@ impl BiosState {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct ProfilesState {
|
||||
pub list: Vec<Profile>,
|
||||
pub current: Profile,
|
||||
}
|
||||
|
||||
impl ProfilesState {
|
||||
pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking) -> Result<Self> {
|
||||
pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking<'_>) -> Result<Self> {
|
||||
Ok(Self {
|
||||
list: if supported.platform_profile.platform_profile {
|
||||
let mut list = dbus.proxies().profile().profiles()?;
|
||||
@@ -76,7 +77,7 @@ impl ProfilesState {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct FanCurvesState {
|
||||
pub show_curve: Profile,
|
||||
pub show_graph: FanCurvePU,
|
||||
@@ -86,26 +87,25 @@ pub struct FanCurvesState {
|
||||
}
|
||||
|
||||
impl FanCurvesState {
|
||||
pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking) -> Result<Self> {
|
||||
pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking<'_>) -> Result<Self> {
|
||||
let profiles = if supported.platform_profile.platform_profile {
|
||||
dbus.proxies().profile().profiles()?
|
||||
} else {
|
||||
vec![Profile::Balanced, Profile::Quiet, Profile::Performance]
|
||||
};
|
||||
let enabled = if supported.platform_profile.fan_curves {
|
||||
HashSet::from_iter(
|
||||
dbus.proxies()
|
||||
.profile()
|
||||
.enabled_fan_profiles()?
|
||||
.iter()
|
||||
.cloned(),
|
||||
)
|
||||
dbus.proxies()
|
||||
.profile()
|
||||
.enabled_fan_profiles()?
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect::<HashSet<_>>()
|
||||
} else {
|
||||
HashSet::from([Profile::Balanced, Profile::Quiet, Profile::Performance])
|
||||
};
|
||||
|
||||
let mut curves: BTreeMap<Profile, FanCurveSet> = BTreeMap::new();
|
||||
profiles.iter().for_each(|p| {
|
||||
for p in &profiles {
|
||||
if supported.platform_profile.fan_curves {
|
||||
if let Ok(curve) = dbus.proxies().profile().fan_curve_data(*p) {
|
||||
curves.insert(*p, curve);
|
||||
@@ -118,7 +118,7 @@ impl FanCurvesState {
|
||||
curve.gpu.temp = [20, 30, 40, 50, 70, 80, 90, 100];
|
||||
curves.insert(*p, curve);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let show_curve = if supported.platform_profile.fan_curves {
|
||||
dbus.proxies().profile().active_profile()?
|
||||
@@ -136,7 +136,7 @@ impl FanCurvesState {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct AuraState {
|
||||
pub current_mode: AuraModeNum,
|
||||
pub modes: BTreeMap<AuraModeNum, AuraEffect>,
|
||||
@@ -149,7 +149,7 @@ pub struct AuraState {
|
||||
}
|
||||
|
||||
impl AuraState {
|
||||
pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking) -> Result<Self> {
|
||||
pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking<'_>) -> Result<Self> {
|
||||
Ok(Self {
|
||||
current_mode: if !supported.keyboard_led.stock_led_modes.is_empty() {
|
||||
dbus.proxies().led().led_mode().unwrap_or_default()
|
||||
@@ -189,7 +189,7 @@ impl AuraState {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct AnimeState {
|
||||
pub bright: u8,
|
||||
pub boot: bool,
|
||||
@@ -198,7 +198,7 @@ pub struct AnimeState {
|
||||
}
|
||||
|
||||
impl AnimeState {
|
||||
pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking) -> Result<Self> {
|
||||
pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking<'_>) -> Result<Self> {
|
||||
Ok(Self {
|
||||
boot: if supported.anime_ctrl.0 {
|
||||
dbus.proxies().anime().boot_enabled()?
|
||||
@@ -219,27 +219,39 @@ impl AnimeState {
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct GfxState {
|
||||
pub has_supergfx: bool,
|
||||
pub mode: GfxMode,
|
||||
pub power_status: GfxPower,
|
||||
}
|
||||
|
||||
impl GfxState {
|
||||
pub fn new(_supported: &SupportedFunctions, dbus: &GfxProxyBlocking) -> Result<Self> {
|
||||
pub fn new(_supported: &SupportedFunctions, dbus: &GfxProxyBlocking<'_>) -> Result<Self> {
|
||||
Ok(Self {
|
||||
mode: dbus.mode()?,
|
||||
power_status: dbus.power()?,
|
||||
has_supergfx: dbus.mode().is_ok(),
|
||||
mode: dbus.mode().unwrap_or(GfxMode::None),
|
||||
power_status: dbus.power().unwrap_or(GfxPower::Unknown),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
impl Default for GfxState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
has_supergfx: false,
|
||||
mode: GfxMode::None,
|
||||
power_status: GfxPower::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct PowerState {
|
||||
pub charge_limit: u8,
|
||||
pub ac_power: bool,
|
||||
}
|
||||
|
||||
impl PowerState {
|
||||
pub fn new(_supported: &SupportedFunctions, dbus: &RogDbusClientBlocking) -> Result<Self> {
|
||||
pub fn new(_supported: &SupportedFunctions, dbus: &RogDbusClientBlocking<'_>) -> Result<Self> {
|
||||
Ok(Self {
|
||||
charge_limit: dbus.proxies().charge().charge_control_end_threshold()?,
|
||||
ac_power: dbus.proxies().charge().mains_online()?,
|
||||
@@ -277,19 +289,62 @@ impl SystemState {
|
||||
enabled_notifications: Arc<Mutex<EnabledNotifications>>,
|
||||
supported: &SupportedFunctions,
|
||||
) -> Result<Self> {
|
||||
let (asus_dbus, conn) = RogDbusClientBlocking::new().unwrap();
|
||||
let gfx_dbus = GfxProxyBlocking::new(&conn).unwrap();
|
||||
let (asus_dbus, conn) = RogDbusClientBlocking::new()?;
|
||||
let mut error = None;
|
||||
let gfx_dbus = GfxProxyBlocking::new(&conn).expect("Couldn't connect to supergfxd");
|
||||
Ok(Self {
|
||||
keyboard_layout,
|
||||
enabled_notifications,
|
||||
power_state: PowerState::new(supported, &asus_dbus)?,
|
||||
bios: BiosState::new(supported, &asus_dbus)?,
|
||||
aura: AuraState::new(supported, &asus_dbus)?,
|
||||
anime: AnimeState::new(supported, &asus_dbus)?,
|
||||
profiles: ProfilesState::new(supported, &asus_dbus)?,
|
||||
fan_curves: FanCurvesState::new(supported, &asus_dbus)?,
|
||||
gfx_state: GfxState::new(supported, &gfx_dbus)?,
|
||||
error: None,
|
||||
power_state: PowerState::new(supported, &asus_dbus)
|
||||
.map_err(|e| {
|
||||
let e = format!("Could not get PowerState state: {e}");
|
||||
error!("{e}");
|
||||
error = Some(e);
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
bios: BiosState::new(supported, &asus_dbus)
|
||||
.map_err(|e| {
|
||||
let e = format!("Could not get BiosState state: {e}");
|
||||
error!("{e}");
|
||||
error = Some(e);
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
aura: AuraState::new(supported, &asus_dbus)
|
||||
.map_err(|e| {
|
||||
let e = format!("Could not get AuraState state: {e}");
|
||||
error!("{e}");
|
||||
error = Some(e);
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
anime: AnimeState::new(supported, &asus_dbus)
|
||||
.map_err(|e| {
|
||||
let e = format!("Could not get AanimeState state: {e}");
|
||||
error!("{e}");
|
||||
error = Some(e);
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
profiles: ProfilesState::new(supported, &asus_dbus)
|
||||
.map_err(|e| {
|
||||
let e = format!("Could not get ProfilesState state: {e}");
|
||||
error!("{e}");
|
||||
error = Some(e);
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
fan_curves: FanCurvesState::new(supported, &asus_dbus)
|
||||
.map_err(|e| {
|
||||
let e = format!("Could not get FanCurvesState state: {e}");
|
||||
error!("{e}");
|
||||
error = Some(e);
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
gfx_state: GfxState::new(supported, &gfx_dbus)
|
||||
.map_err(|e| {
|
||||
let e = format!("Could not get supergfxd state: {e}");
|
||||
error!("{e}");
|
||||
error = Some(e);
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
error,
|
||||
tray_should_update: true,
|
||||
app_should_update: true,
|
||||
asus_dbus,
|
||||
@@ -305,8 +360,8 @@ impl SystemState {
|
||||
|
||||
impl Default for SystemState {
|
||||
fn default() -> Self {
|
||||
let (asus_dbus, conn) = RogDbusClientBlocking::new().unwrap();
|
||||
let gfx_dbus = GfxProxyBlocking::new(&conn).unwrap();
|
||||
let (asus_dbus, conn) = RogDbusClientBlocking::new().expect("Couldn't connect to asusd");
|
||||
let gfx_dbus = GfxProxyBlocking::new(&conn).expect("Couldn't connect to supergfxd");
|
||||
|
||||
Self {
|
||||
keyboard_layout: KeyLayout::ga401_layout(),
|
||||
@@ -349,6 +404,7 @@ impl Default for SystemState {
|
||||
drag_delta: Default::default(),
|
||||
},
|
||||
gfx_state: GfxState {
|
||||
has_supergfx: false,
|
||||
mode: GfxMode::None,
|
||||
power_status: GfxPower::Unknown,
|
||||
},
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
use std::{
|
||||
io::Write,
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
mpsc::{channel, Receiver},
|
||||
Arc, Mutex,
|
||||
},
|
||||
@@ -21,7 +22,7 @@ use supergfxctl::{
|
||||
zbus_proxy::DaemonProxyBlocking as GfxProxyBlocking,
|
||||
};
|
||||
|
||||
use log::{debug, error, info, trace};
|
||||
use log::{debug, error, info, trace, warn};
|
||||
|
||||
const TRAY_APP_ICON: &str = "rog-control-center";
|
||||
const TRAY_LABEL: &str = "ROG Control Center";
|
||||
@@ -128,13 +129,18 @@ impl ROGTray {
|
||||
self.menu.show_all();
|
||||
}
|
||||
|
||||
fn add_radio_sub_menu(&mut self, header_label: &str, active_label: &str, sub_menu: RadioGroup) {
|
||||
fn add_radio_sub_menu(
|
||||
&mut self,
|
||||
header_label: &str,
|
||||
active_label: &str,
|
||||
sub_menu: &RadioGroup,
|
||||
) {
|
||||
let header_item = gtk::MenuItem::with_label(header_label);
|
||||
header_item.show_all();
|
||||
self.menu.add(&header_item);
|
||||
|
||||
let menu = gtk::Menu::new();
|
||||
for item in sub_menu.0.iter() {
|
||||
for item in &sub_menu.0 {
|
||||
if let Some(label) = item.label() {
|
||||
item.set_active(label == active_label);
|
||||
} else {
|
||||
@@ -197,7 +203,7 @@ impl ROGTray {
|
||||
}
|
||||
|
||||
fn _set_status(&mut self, status: AppIndicatorStatus) {
|
||||
self.tray.set_status(status)
|
||||
self.tray.set_status(status);
|
||||
}
|
||||
|
||||
fn menu_add_base(&mut self) {
|
||||
@@ -236,7 +242,10 @@ impl ROGTray {
|
||||
}
|
||||
|
||||
fn menu_add_gpu(&mut self, supported: &SupportedFunctions, current_mode: GfxMode) {
|
||||
let set_mux_off = Arc::new(AtomicBool::new(false));
|
||||
|
||||
let gfx_dbus = self.gfx_proxy.clone();
|
||||
let set_mux_off1 = set_mux_off.clone();
|
||||
let mut gpu_menu = RadioGroup::new("Integrated", move |_| {
|
||||
let mode = gfx_dbus
|
||||
.mode()
|
||||
@@ -254,9 +263,11 @@ impl ROGTray {
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
set_mux_off1.store(true, Ordering::Relaxed);
|
||||
});
|
||||
|
||||
let gfx_dbus = self.gfx_proxy.clone();
|
||||
let set_mux_off1 = set_mux_off.clone();
|
||||
gpu_menu.add("Hybrid", move |_| {
|
||||
let mode = gfx_dbus
|
||||
.mode()
|
||||
@@ -274,7 +285,33 @@ impl ROGTray {
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
set_mux_off1.store(true, Ordering::Relaxed);
|
||||
});
|
||||
if supported.rog_bios_ctrl.egpu_enable {
|
||||
let set_mux_off1 = set_mux_off.clone();
|
||||
let gfx_dbus = self.gfx_proxy.clone();
|
||||
gpu_menu.add("eGPU", move |_| {
|
||||
let mode = gfx_dbus
|
||||
.mode()
|
||||
.map_err(|e| {
|
||||
error!("ROGTray: mode: {e}");
|
||||
e
|
||||
})
|
||||
.unwrap_or(GfxMode::None);
|
||||
if mode != GfxMode::Egpu {
|
||||
gfx_dbus
|
||||
.set_mode(&GfxMode::Egpu)
|
||||
.map_err(|e| {
|
||||
error!("ROGTray: set_mode: {e}");
|
||||
e
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
set_mux_off1.store(true, Ordering::Relaxed);
|
||||
});
|
||||
}
|
||||
|
||||
let mut reboot_required = false;
|
||||
if supported.rog_bios_ctrl.gpu_mux {
|
||||
let gfx_dbus = self.bios_proxy.clone();
|
||||
gpu_menu.add("Ultimate (Reboot required)", move |_| {
|
||||
@@ -295,37 +332,97 @@ impl ROGTray {
|
||||
.ok();
|
||||
}
|
||||
});
|
||||
}
|
||||
if supported.rog_bios_ctrl.egpu_enable {
|
||||
let gfx_dbus = self.gfx_proxy.clone();
|
||||
gpu_menu.add("eGPU", move |_| {
|
||||
let mode = gfx_dbus
|
||||
.mode()
|
||||
|
||||
if set_mux_off.load(Ordering::Relaxed) {
|
||||
warn!("Selected non-dgpu mode, must set MUX to optimus");
|
||||
self.bios_proxy
|
||||
.set_gpu_mux_mode(GpuMode::Optimus)
|
||||
.map_err(|e| {
|
||||
error!("ROGTray: mode: {e}");
|
||||
error!("ROGTray: set_mode: {e}");
|
||||
e
|
||||
})
|
||||
.unwrap_or(GfxMode::None);
|
||||
if mode != GfxMode::Egpu {
|
||||
gfx_dbus
|
||||
.set_mode(&GfxMode::Egpu)
|
||||
.map_err(|e| {
|
||||
error!("ROGTray: set_mode: {e}");
|
||||
e
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
});
|
||||
.ok();
|
||||
}
|
||||
|
||||
if let Ok(mode) = self.bios_proxy.gpu_mux_mode() {
|
||||
let mode = match mode {
|
||||
GpuMode::Discrete => GfxMode::AsusMuxDiscreet,
|
||||
_ => GfxMode::Hybrid,
|
||||
};
|
||||
reboot_required = mode != current_mode;
|
||||
}
|
||||
}
|
||||
|
||||
let active = match current_mode {
|
||||
GfxMode::AsusMuxDiscreet => "Discreet".to_string(),
|
||||
GfxMode::AsusMuxDiscreet => "Discreet".to_owned(),
|
||||
_ => current_mode.to_string(),
|
||||
};
|
||||
|
||||
let reboot_required = if reboot_required {
|
||||
"(Reboot required)"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
|
||||
self.add_radio_sub_menu(
|
||||
&format!("GPU Mode: {current_mode}"),
|
||||
&format!("GPU Mode: {active} {reboot_required}"),
|
||||
active.as_str(),
|
||||
gpu_menu,
|
||||
&gpu_menu,
|
||||
);
|
||||
|
||||
debug!("ROGTray: appended gpu menu");
|
||||
}
|
||||
|
||||
fn menu_add_mux(&mut self, current_mode: GfxMode) {
|
||||
let gfx_dbus = self.bios_proxy.clone();
|
||||
|
||||
let mut reboot_required = false;
|
||||
if let Ok(mode) = gfx_dbus.gpu_mux_mode() {
|
||||
let mode = match mode {
|
||||
GpuMode::Discrete => GfxMode::AsusMuxDiscreet,
|
||||
_ => GfxMode::Hybrid,
|
||||
};
|
||||
reboot_required = mode != current_mode;
|
||||
}
|
||||
|
||||
let mut gpu_menu = RadioGroup::new("Optimus", move |_| {
|
||||
gfx_dbus
|
||||
.set_gpu_mux_mode(GpuMode::Optimus)
|
||||
.map_err(|e| {
|
||||
error!("ROGTray: set_mode: {e}");
|
||||
e
|
||||
})
|
||||
.ok();
|
||||
debug!("Setting GPU mode: {}", GpuMode::Optimus);
|
||||
});
|
||||
|
||||
let gfx_dbus = self.bios_proxy.clone();
|
||||
gpu_menu.add("Ultimate", move |_| {
|
||||
gfx_dbus
|
||||
.set_gpu_mux_mode(GpuMode::Discrete)
|
||||
.map_err(|e| {
|
||||
error!("ROGTray: set_mode: {e}");
|
||||
e
|
||||
})
|
||||
.ok();
|
||||
debug!("Setting GPU mode: {}", GpuMode::Discrete);
|
||||
});
|
||||
|
||||
let active = match current_mode {
|
||||
GfxMode::AsusMuxDiscreet => "Ultimate".to_owned(),
|
||||
GfxMode::Hybrid => "Optimus".to_owned(),
|
||||
_ => current_mode.to_string(),
|
||||
};
|
||||
debug!("Current active GPU mode: {}", active);
|
||||
let reboot_required = if reboot_required {
|
||||
"(Reboot required)"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
self.add_radio_sub_menu(
|
||||
&format!("GPU Mode: {active} {reboot_required}"),
|
||||
active.as_str(),
|
||||
&gpu_menu,
|
||||
);
|
||||
|
||||
debug!("ROGTray: appended gpu menu");
|
||||
@@ -346,6 +443,7 @@ impl ROGTray {
|
||||
fn rebuild_and_update(
|
||||
&mut self,
|
||||
supported: &SupportedFunctions,
|
||||
has_supergfx: bool,
|
||||
current_gfx_mode: GfxMode,
|
||||
charge_limit: u8,
|
||||
panel_od: bool,
|
||||
@@ -354,7 +452,11 @@ impl ROGTray {
|
||||
self.menu_add_base();
|
||||
self.menu_add_charge_limit(supported, charge_limit);
|
||||
self.menu_add_panel_od(supported, panel_od);
|
||||
self.menu_add_gpu(supported, current_gfx_mode);
|
||||
if has_supergfx {
|
||||
self.menu_add_gpu(supported, current_gfx_mode);
|
||||
} else if supported.rog_bios_ctrl.gpu_mux {
|
||||
self.menu_add_mux(current_gfx_mode);
|
||||
}
|
||||
self.menu_update();
|
||||
}
|
||||
}
|
||||
@@ -366,6 +468,12 @@ pub fn init_tray(
|
||||
let (send, recv) = channel();
|
||||
let _send = Arc::new(Mutex::new(send));
|
||||
|
||||
let has_supergfx = if let Ok(lock) = states.try_lock() {
|
||||
lock.gfx_state.has_supergfx
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
std::thread::spawn(move || {
|
||||
if gtk::init()
|
||||
.map_err(|e| {
|
||||
@@ -391,16 +499,26 @@ pub fn init_tray(
|
||||
return;
|
||||
}
|
||||
};
|
||||
tray.rebuild_and_update(&supported, GfxMode::Hybrid, 100, false);
|
||||
tray.rebuild_and_update(&supported, has_supergfx, GfxMode::Hybrid, 100, false);
|
||||
tray.set_icon(TRAY_APP_ICON);
|
||||
info!("Started ROGTray");
|
||||
|
||||
loop {
|
||||
if let Ok(mut lock) = states.lock() {
|
||||
if lock.tray_should_update {
|
||||
// Supergfx ends up adding some complexity to handle if it isn't available
|
||||
let current_gpu_mode = if lock.gfx_state.has_supergfx {
|
||||
lock.gfx_state.mode
|
||||
} else {
|
||||
match lock.bios.dedicated_gfx {
|
||||
GpuMode::Discrete => GfxMode::AsusMuxDiscreet,
|
||||
_ => GfxMode::Hybrid,
|
||||
}
|
||||
};
|
||||
tray.rebuild_and_update(
|
||||
&supported,
|
||||
lock.gfx_state.mode,
|
||||
has_supergfx,
|
||||
current_gpu_mode,
|
||||
lock.power_state.charge_limit,
|
||||
lock.bios.panel_overdrive,
|
||||
);
|
||||
@@ -408,12 +526,19 @@ pub fn init_tray(
|
||||
debug!("ROGTray: rebuilt menus due to state change");
|
||||
|
||||
match lock.gfx_state.power_status {
|
||||
GfxPower::Active => tray.set_icon("asus_notif_red"),
|
||||
GfxPower::Suspended => tray.set_icon("asus_notif_blue"),
|
||||
GfxPower::Off => tray.set_icon("asus_notif_green"),
|
||||
GfxPower::AsusDisabled => tray.set_icon("asus_notif_white"),
|
||||
GfxPower::AsusMuxDiscreet => tray.set_icon("asus_notif_red"),
|
||||
GfxPower::Unknown => tray.set_icon("gpu-integrated"),
|
||||
GfxPower::AsusMuxDiscreet | GfxPower::Active => {
|
||||
tray.set_icon("asus_notif_red");
|
||||
}
|
||||
GfxPower::Unknown => {
|
||||
if has_supergfx {
|
||||
tray.set_icon("gpu-integrated");
|
||||
} else {
|
||||
tray.set_icon("asus_notif_red");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
//! `update_and_notify` is responsible for both notifications *and* updating stored statuses
|
||||
//! about the system state. This is done through either direct, intoify, zbus notifications
|
||||
//! or similar methods.
|
||||
|
||||
use crate::{config::Config, error::Result, system_state::SystemState};
|
||||
use log::{error, info, trace};
|
||||
use log::{error, info, trace, warn};
|
||||
use notify_rust::{Hint, Notification, NotificationHandle, Urgency};
|
||||
use rog_dbus::{
|
||||
zbus_anime::AnimeProxy, zbus_led::LedProxy, zbus_platform::RogBiosProxy,
|
||||
@@ -12,12 +16,17 @@ use std::{
|
||||
fmt::Display,
|
||||
process::Command,
|
||||
sync::{Arc, Mutex},
|
||||
time::Duration,
|
||||
};
|
||||
use supergfxctl::{pci_device::GfxPower, zbus_proxy::DaemonProxy as SuperProxy};
|
||||
use tokio::time::sleep;
|
||||
use zbus::export::futures_util::{future, StreamExt};
|
||||
|
||||
const NOTIF_HEADER: &str = "ROG Control";
|
||||
|
||||
static mut POWER_AC_CMD: Option<Command> = None;
|
||||
static mut POWER_BAT_CMD: Option<Command> = None;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[serde(default)]
|
||||
pub struct EnabledNotifications {
|
||||
@@ -48,7 +57,7 @@ impl Default for EnabledNotifications {
|
||||
receive_notify_charge_control_end_threshold: true,
|
||||
receive_notify_mains_online: false,
|
||||
receive_notify_profile: true,
|
||||
receive_notify_led: false,
|
||||
receive_notify_led: true,
|
||||
receive_power_states: false,
|
||||
receive_notify_gfx: false,
|
||||
receive_notify_gfx_status: false,
|
||||
@@ -125,11 +134,36 @@ macro_rules! recv_notif {
|
||||
type SharedHandle = Arc<Mutex<Option<NotificationHandle>>>;
|
||||
|
||||
pub fn start_notifications(
|
||||
config: &Config,
|
||||
page_states: Arc<Mutex<SystemState>>,
|
||||
enabled_notifications: Arc<Mutex<EnabledNotifications>>,
|
||||
) -> Result<()> {
|
||||
let last_notification: SharedHandle = Arc::new(Mutex::new(None));
|
||||
|
||||
// Setup the AC/BAT commands that will run on poweer status change
|
||||
unsafe {
|
||||
let prog: Vec<&str> = config.ac_command.split_whitespace().collect();
|
||||
if prog.len() > 1 {
|
||||
let mut cmd = Command::new(prog[0]);
|
||||
|
||||
for arg in prog.iter().skip(1) {
|
||||
cmd.arg(*arg);
|
||||
}
|
||||
POWER_AC_CMD = Some(cmd);
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
let prog: Vec<&str> = config.bat_command.split_whitespace().collect();
|
||||
if prog.len() > 1 {
|
||||
let mut cmd = Command::new(prog[0]);
|
||||
|
||||
for arg in prog.iter().skip(1) {
|
||||
cmd.arg(*arg);
|
||||
}
|
||||
POWER_BAT_CMD = Some(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
// BIOS notif
|
||||
recv_notif!(
|
||||
RogBiosProxy,
|
||||
@@ -179,18 +213,6 @@ pub fn start_notifications(
|
||||
do_notification
|
||||
);
|
||||
|
||||
recv_notif!(
|
||||
RogBiosProxy,
|
||||
receive_notify_gpu_mux_mode,
|
||||
last_notification,
|
||||
enabled_notifications,
|
||||
page_states,
|
||||
(bios.dedicated_gfx),
|
||||
(mode),
|
||||
"Reboot required. BIOS GPU MUX mode set to",
|
||||
do_mux_notification
|
||||
);
|
||||
|
||||
// Charge notif
|
||||
recv_notif!(
|
||||
PowerProxy,
|
||||
@@ -271,104 +293,139 @@ pub fn start_notifications(
|
||||
};
|
||||
});
|
||||
|
||||
recv_notif!(
|
||||
SuperProxy,
|
||||
receive_notify_gfx,
|
||||
last_notification,
|
||||
enabled_notifications,
|
||||
page_states,
|
||||
(gfx_state.mode),
|
||||
(mode),
|
||||
"Gfx mode changed to",
|
||||
do_notification
|
||||
);
|
||||
|
||||
// recv_notif!(
|
||||
// SuperProxy,
|
||||
// receive_notify_action,
|
||||
// bios_notified,
|
||||
// last_gfx_action_notif,
|
||||
// enabled_notifications,
|
||||
// [action],
|
||||
// "Gfx mode change requires",
|
||||
// do_gfx_action_notif
|
||||
// );
|
||||
|
||||
let page_states1 = page_states.clone();
|
||||
let last_notification1 = last_notification.clone();
|
||||
tokio::spawn(async move {
|
||||
let conn = zbus::Connection::system()
|
||||
.await
|
||||
.map_err(|e| {
|
||||
error!("zbus signal: receive_notify_action: {e}");
|
||||
error!("zbus signal: receive_notify_gpu_mux_mode: {e}");
|
||||
e
|
||||
})
|
||||
.unwrap();
|
||||
let proxy = SuperProxy::new(&conn)
|
||||
let proxy = RogBiosProxy::new(&conn)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
error!("zbus signal: receive_notify_action: {e}");
|
||||
error!("zbus signal: receive_notify_gpu_mux_mode: {e}");
|
||||
e
|
||||
})
|
||||
.unwrap();
|
||||
if let Ok(mut p) = proxy.receive_notify_action().await {
|
||||
info!("Started zbus signal thread: receive_notify_action");
|
||||
if let Ok(mut p) = proxy.receive_notify_gpu_mux_mode().await {
|
||||
info!("Started zbus signal thread: receive_power_states");
|
||||
while let Some(e) = p.next().await {
|
||||
if let Ok(out) = e.args() {
|
||||
let action = out.action();
|
||||
do_gfx_action_notif("Gfx mode change requires", &format!("{action:?}",))
|
||||
.map_err(|e| {
|
||||
error!("zbus signal: do_gfx_action_notif: {e}");
|
||||
e
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
let notifs_enabled1 = enabled_notifications;
|
||||
let last_notif = last_notification;
|
||||
tokio::spawn(async move {
|
||||
let conn = zbus::Connection::system()
|
||||
.await
|
||||
.map_err(|e| {
|
||||
error!("zbus signal: receive_notify_gfx_status: {e}");
|
||||
e
|
||||
})
|
||||
.unwrap();
|
||||
let proxy = SuperProxy::new(&conn)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
error!("zbus signal: receive_notify_gfx_status: {e}");
|
||||
e
|
||||
})
|
||||
.unwrap();
|
||||
if let Ok(mut p) = proxy.receive_notify_gfx_status().await {
|
||||
info!("Started zbus signal thread: receive_notify_gfx_status");
|
||||
while let Some(e) = p.next().await {
|
||||
if let Ok(out) = e.args() {
|
||||
let status = out.status;
|
||||
if status != GfxPower::Unknown {
|
||||
if let Ok(config) = notifs_enabled1.lock() {
|
||||
if config.all_enabled && config.receive_notify_gfx_status {
|
||||
// Required check because status cycles through active/unknown/suspended
|
||||
if let Ok(ref mut lock) = last_notif.lock() {
|
||||
notify!(
|
||||
do_gpu_status_notif("dGPU status changed:", &status),
|
||||
lock
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Ok(mut lock) = page_states.lock() {
|
||||
lock.gfx_state.power_status = status;
|
||||
lock.set_notified();
|
||||
if let Ok(mut lock) = page_states1.lock() {
|
||||
lock.bios.dedicated_gfx = out.mode;
|
||||
lock.set_notified();
|
||||
}
|
||||
if let Ok(ref mut lock) = last_notification1.lock() {
|
||||
if let Some(notif) = lock.take() {
|
||||
notif.close();
|
||||
}
|
||||
}
|
||||
do_mux_notification("Reboot required. BIOS GPU MUX mode set to", &out.mode)
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
if let Ok(lock) = page_states.try_lock() {
|
||||
use supergfxctl::pci_device::Device;
|
||||
let dev = Device::find().unwrap_or_default();
|
||||
let mut found_dgpu = false; // just for logging
|
||||
for dev in dev {
|
||||
if dev.is_dgpu() {
|
||||
let notifs_enabled1 = enabled_notifications.clone();
|
||||
let last_notif = last_notification.clone();
|
||||
let page_states1 = page_states.clone();
|
||||
// Plain old thread is perfectly fine since most of this is potentially blocking
|
||||
tokio::spawn(async move {
|
||||
let mut last_status = GfxPower::Unknown;
|
||||
loop {
|
||||
if let Ok(status) = dev.get_runtime_status() {
|
||||
if status != GfxPower::Unknown && status != last_status {
|
||||
if let Ok(config) = notifs_enabled1.lock() {
|
||||
if config.all_enabled && config.receive_notify_gfx_status {
|
||||
// Required check because status cycles through active/unknown/suspended
|
||||
if let Ok(ref mut lock) = last_notif.lock() {
|
||||
notify!(
|
||||
do_gpu_status_notif(
|
||||
"dGPU status changed:",
|
||||
&status
|
||||
),
|
||||
lock
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Ok(mut lock) = page_states1.lock() {
|
||||
lock.gfx_state.power_status = status;
|
||||
lock.set_notified();
|
||||
}
|
||||
last_status = status;
|
||||
}
|
||||
}
|
||||
sleep(Duration::from_millis(500)).await;
|
||||
}
|
||||
});
|
||||
found_dgpu = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !found_dgpu {
|
||||
warn!("Did not find a dGPU on this system, dGPU status won't be avilable");
|
||||
}
|
||||
|
||||
if lock.gfx_state.has_supergfx {
|
||||
recv_notif!(
|
||||
SuperProxy,
|
||||
receive_notify_gfx,
|
||||
last_notification,
|
||||
enabled_notifications,
|
||||
page_states,
|
||||
(gfx_state.mode),
|
||||
(mode),
|
||||
"Gfx mode changed to",
|
||||
do_notification
|
||||
);
|
||||
|
||||
tokio::spawn(async move {
|
||||
let conn = zbus::Connection::system()
|
||||
.await
|
||||
.map_err(|e| {
|
||||
error!("zbus signal: receive_notify_action: {e}");
|
||||
e
|
||||
})
|
||||
.unwrap();
|
||||
let proxy = SuperProxy::new(&conn)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
error!("zbus signal: receive_notify_action: {e}");
|
||||
e
|
||||
})
|
||||
.unwrap();
|
||||
if let Ok(mut p) = proxy.receive_notify_action().await {
|
||||
info!("Started zbus signal thread: receive_notify_action");
|
||||
while let Some(e) = p.next().await {
|
||||
if let Ok(out) = e.args() {
|
||||
let action = out.action();
|
||||
do_gfx_action_notif(
|
||||
"Gfx mode change requires",
|
||||
&format!("{action:?}",),
|
||||
)
|
||||
.map_err(|e| {
|
||||
error!("zbus signal: do_gfx_action_notif: {e}");
|
||||
e
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -397,9 +454,23 @@ where
|
||||
|
||||
fn ac_power_notification(message: &str, on: &bool) -> Result<NotificationHandle> {
|
||||
let data = if *on {
|
||||
"plugged".to_string()
|
||||
unsafe {
|
||||
if let Some(cmd) = POWER_AC_CMD.as_mut() {
|
||||
if let Err(e) = cmd.spawn() {
|
||||
error!("AC power command error: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
"plugged".to_owned()
|
||||
} else {
|
||||
"unplugged".to_string()
|
||||
unsafe {
|
||||
if let Some(cmd) = POWER_BAT_CMD.as_mut() {
|
||||
if let Err(e) = cmd.spawn() {
|
||||
error!("Battery power command error: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
"unplugged".to_owned()
|
||||
};
|
||||
Ok(base_notification(message, &data).show()?)
|
||||
}
|
||||
@@ -417,13 +488,12 @@ fn do_thermal_notif(message: &str, profile: &Profile) -> Result<NotificationHand
|
||||
|
||||
fn do_gpu_status_notif(message: &str, data: &GfxPower) -> Result<NotificationHandle> {
|
||||
// eww
|
||||
let mut notif = base_notification(message, &<&str>::from(data).to_string());
|
||||
let mut notif = base_notification(message, &<&str>::from(data).to_owned());
|
||||
let icon = match data {
|
||||
GfxPower::Active => "asus_notif_red",
|
||||
GfxPower::Suspended => "asus_notif_blue",
|
||||
GfxPower::Off => "asus_notif_green",
|
||||
GfxPower::AsusDisabled => "asus_notif_white",
|
||||
GfxPower::AsusMuxDiscreet => "asus_notif_red",
|
||||
GfxPower::AsusMuxDiscreet | GfxPower::Active => "asus_notif_red",
|
||||
GfxPower::Unknown => "gpu-integrated",
|
||||
};
|
||||
notif.icon(icon);
|
||||
@@ -452,11 +522,25 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Actual GpuMode unused as data is never correct until switched by reboot
|
||||
fn do_mux_notification(message: &str, _: &GpuMode) -> Result<NotificationHandle> {
|
||||
let mut notif = base_notification(message, &"");
|
||||
/// Actual `GpuMode` unused as data is never correct until switched by reboot
|
||||
fn do_mux_notification(message: &str, m: &GpuMode) -> Result<()> {
|
||||
let mut notif = base_notification(message, &m.to_string());
|
||||
notif.action("gnome-session-quit", "Reboot");
|
||||
notif.urgency(Urgency::Critical);
|
||||
notif.icon("system-reboot-symbolic");
|
||||
notif.hint(Hint::Transient(true));
|
||||
Ok(notif.show()?)
|
||||
let handle = notif.show()?;
|
||||
|
||||
std::thread::spawn(|| {
|
||||
handle.wait_for_action(|id| {
|
||||
if id == "gnome-session-quit" {
|
||||
let mut cmd = Command::new("gnome-session-quit");
|
||||
cmd.arg("--reboot");
|
||||
cmd.spawn().ok();
|
||||
} else if id == "__closed" {
|
||||
// TODO: cancel the switching
|
||||
}
|
||||
})
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
@@ -12,7 +12,8 @@ pub fn app_settings(config: &mut Config, states: &mut SystemState, ui: &mut Ui)
|
||||
Default::default()
|
||||
};
|
||||
|
||||
if ui
|
||||
ui.label("Application settings");
|
||||
let app_changed = ui
|
||||
.checkbox(&mut config.run_in_background, "Run in Background")
|
||||
.clicked()
|
||||
|| ui
|
||||
@@ -23,11 +24,19 @@ pub fn app_settings(config: &mut Config, states: &mut SystemState, ui: &mut Ui)
|
||||
&mut enabled_notifications.all_enabled,
|
||||
"Enable Notifications",
|
||||
)
|
||||
.clicked()
|
||||
.clicked();
|
||||
|
||||
ui.label("Notification settings");
|
||||
let notif_changed = ui
|
||||
.checkbox(
|
||||
&mut enabled_notifications.receive_notify_gfx_status,
|
||||
"Enable dGPU status notification",
|
||||
)
|
||||
.clicked()
|
||||
|| ui
|
||||
.checkbox(
|
||||
&mut enabled_notifications.receive_notify_gfx_status,
|
||||
"Enable dGPU status notification",
|
||||
&mut enabled_notifications.receive_notify_led,
|
||||
"Enable LED mode change notification",
|
||||
)
|
||||
.clicked()
|
||||
|| ui
|
||||
@@ -71,8 +80,9 @@ pub fn app_settings(config: &mut Config, states: &mut SystemState, ui: &mut Ui)
|
||||
&mut enabled_notifications.receive_notify_post_boot_sound,
|
||||
"Enable BIOS post sound notification",
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
.clicked();
|
||||
|
||||
if app_changed || notif_changed {
|
||||
if let Ok(mut lock) = states.enabled_notifications.lock() {
|
||||
// Replace inner content before save
|
||||
*lock = enabled_notifications;
|
||||
|
||||
@@ -12,7 +12,7 @@ pub fn aura_power_group(supported: &SupportedFunctions, states: &mut SystemState
|
||||
|
||||
match supported.keyboard_led.prod_id {
|
||||
AuraDevice::X1854 | AuraDevice::X1869 | AuraDevice::X1866 => {
|
||||
aura_power1(supported, states, ui)
|
||||
aura_power1(supported, states, ui);
|
||||
}
|
||||
AuraDevice::X19B6 => aura_power2(supported, states, ui),
|
||||
AuraDevice::Tuf => aura_power1(supported, states, ui),
|
||||
|
||||
@@ -2,16 +2,12 @@ use egui::{plot::Points, Ui};
|
||||
use rog_platform::supported::SupportedFunctions;
|
||||
use rog_profiles::{FanCurvePU, Profile};
|
||||
|
||||
use crate::{
|
||||
system_state::{FanCurvesState, ProfilesState},
|
||||
RogDbusClientBlocking,
|
||||
};
|
||||
use crate::{system_state::FanCurvesState, RogDbusClientBlocking};
|
||||
|
||||
pub fn fan_graphs(
|
||||
supported: &SupportedFunctions,
|
||||
profiles: &mut ProfilesState,
|
||||
curves: &mut FanCurvesState,
|
||||
dbus: &RogDbusClientBlocking,
|
||||
dbus: &RogDbusClientBlocking<'_>,
|
||||
do_error: &mut Option<String>,
|
||||
ui: &mut Ui,
|
||||
) {
|
||||
@@ -36,14 +32,14 @@ pub fn fan_graphs(
|
||||
};
|
||||
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
for a in curves.curves.iter() {
|
||||
for a in &curves.curves {
|
||||
item(*a.0, ui);
|
||||
}
|
||||
});
|
||||
|
||||
let curve = curves.curves.get_mut(&curves.show_curve).unwrap();
|
||||
|
||||
use egui::plot::{Line, Plot, PlotPoints};
|
||||
use egui::plot::{Line, Plot};
|
||||
|
||||
let data = if curves.show_graph == FanCurvePU::CPU {
|
||||
&mut curve.cpu
|
||||
@@ -51,14 +47,40 @@ pub fn fan_graphs(
|
||||
&mut curve.gpu
|
||||
};
|
||||
|
||||
let points = data.temp.iter().enumerate().map(|(idx, x)| {
|
||||
let x = *x as f64;
|
||||
let y = ((data.pwm[idx] as u32) * 100 / 255) as f64;
|
||||
[x, y]
|
||||
});
|
||||
let mut points: Vec<[f64; 2]> = data
|
||||
.temp
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(idx, x)| {
|
||||
let x = *x as f64;
|
||||
let y = ((data.pwm[idx] as u32) * 100 / 255) as f64;
|
||||
[x, y]
|
||||
})
|
||||
.collect();
|
||||
|
||||
let line = Line::new(PlotPoints::from_iter(points.clone())).width(2.0);
|
||||
let points = Points::new(PlotPoints::from_iter(points)).radius(3.0);
|
||||
for i in 0..points.len() - 1 {
|
||||
if i > 0 && i < points.len() - 1 {
|
||||
if points[i][0] < points[i - 1][0] {
|
||||
points[i][0] = points[i - 1][0] + 1.0;
|
||||
data.temp[i] = points[i - 1][0] as u8;
|
||||
}
|
||||
if points[i][0] >= points[i + 1][0] {
|
||||
points[i + 1][0] = points[i][0] + 1.0;
|
||||
data.temp[i + 1] = points[i][0] as u8;
|
||||
}
|
||||
if points[i][1] < points[i - 1][1] {
|
||||
points[i][1] = points[i - 1][1] + 1.0;
|
||||
data.pwm[i] = (points[i - 1][1] * 255.0 / 100.0 + 1.0).floor() as u8;
|
||||
}
|
||||
if points[i][1] >= points[i + 1][1] {
|
||||
points[i + 1][1] = points[i][1] + 1.0;
|
||||
data.pwm[i + 1] = (points[i][1] * 255.0 / 100.0 + 1.0).floor() as u8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let line = Line::new(points.clone()).width(2.0);
|
||||
let points = Points::new(points).radius(3.0);
|
||||
|
||||
Plot::new("fan_curves")
|
||||
.view_aspect(1.666)
|
||||
@@ -85,7 +107,7 @@ pub fn fan_graphs(
|
||||
let mut idx = 0;
|
||||
|
||||
if let Some(point) = plot_ui.pointer_coordinate() {
|
||||
let mut x: i32 = 255;
|
||||
let mut x: i32 = point.x as i32;
|
||||
for (i, n) in data.temp.iter().enumerate() {
|
||||
let tmp = x.min((point.x as i32 - *n as i32).abs());
|
||||
if tmp < x {
|
||||
@@ -107,30 +129,47 @@ pub fn fan_graphs(
|
||||
}
|
||||
}
|
||||
plot_ui.line(line);
|
||||
plot_ui.points(points)
|
||||
plot_ui.points(points);
|
||||
});
|
||||
|
||||
let mut set = false;
|
||||
let mut clear = false;
|
||||
let mut reset = false;
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
|
||||
set = ui.add(egui::Button::new("Apply Fan-curve")).clicked();
|
||||
reset = ui.add(egui::Button::new("Reset Profile")).clicked();
|
||||
set = ui.add(egui::Button::new("Apply Profile")).clicked();
|
||||
clear = ui.add(egui::Button::new("Clear Profile Changes")).clicked();
|
||||
reset = ui.add(egui::Button::new("Factory Reset Profile")).clicked();
|
||||
});
|
||||
|
||||
if set {
|
||||
dbus.proxies()
|
||||
.profile()
|
||||
.set_fan_curve(profiles.current, data.clone())
|
||||
.set_fan_curve(curves.show_curve, data.clone())
|
||||
.map_err(|err| {
|
||||
*do_error = Some(err.to_string());
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
|
||||
if clear {
|
||||
if let Ok(curve) = dbus
|
||||
.proxies()
|
||||
.profile()
|
||||
.fan_curve_data(curves.show_curve)
|
||||
.map_err(|err| {
|
||||
*do_error = Some(err.to_string());
|
||||
})
|
||||
{
|
||||
if let Some(value) = curves.curves.get_mut(&curves.show_curve) {
|
||||
*value = curve;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if reset {
|
||||
dbus.proxies()
|
||||
.profile()
|
||||
.reset_profile_curves(profiles.current)
|
||||
.reset_profile_curves(curves.show_curve)
|
||||
.map_err(|err| {
|
||||
*do_error = Some(err.to_string());
|
||||
})
|
||||
|
||||
@@ -17,7 +17,7 @@ pub fn platform_profile(states: &mut SystemState, ui: &mut Ui) {
|
||||
};
|
||||
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
for a in states.profiles.list.iter() {
|
||||
for a in &states.profiles.list {
|
||||
item(*a, ui);
|
||||
}
|
||||
});
|
||||
@@ -46,7 +46,7 @@ pub fn rog_bios_group(supported: &SupportedFunctions, states: &mut SystemState,
|
||||
.asus_dbus
|
||||
.proxies()
|
||||
.charge()
|
||||
.set_charge_control_end_threshold(states.power_state.charge_limit as u8)
|
||||
.set_charge_control_end_threshold(states.power_state.charge_limit)
|
||||
.map_err(|err| {
|
||||
states.error = Some(err.to_string());
|
||||
})
|
||||
@@ -93,6 +93,13 @@ pub fn rog_bios_group(supported: &SupportedFunctions, states: &mut SystemState,
|
||||
|
||||
if supported.rog_bios_ctrl.gpu_mux {
|
||||
let mut changed = false;
|
||||
let mut dedicated_gfx = states.bios.dedicated_gfx;
|
||||
|
||||
let mut reboot_required = false;
|
||||
if let Ok(mode) = states.asus_dbus.proxies().rog_bios().gpu_mux_mode() {
|
||||
reboot_required = mode != states.bios.dedicated_gfx;
|
||||
}
|
||||
|
||||
ui.group(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.horizontal_wrapped(|ui| ui.label("GPU MUX mode"));
|
||||
@@ -100,19 +107,23 @@ pub fn rog_bios_group(supported: &SupportedFunctions, states: &mut SystemState,
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
changed = ui
|
||||
.selectable_value(
|
||||
&mut states.bios.dedicated_gfx,
|
||||
&mut dedicated_gfx,
|
||||
GpuMode::Discrete,
|
||||
"Dedicated (Ultimate)",
|
||||
)
|
||||
.clicked()
|
||||
|| ui
|
||||
.selectable_value(
|
||||
&mut states.bios.dedicated_gfx,
|
||||
&mut dedicated_gfx,
|
||||
GpuMode::Optimus,
|
||||
"Optimus (Hybrid)",
|
||||
)
|
||||
.clicked();
|
||||
});
|
||||
|
||||
if reboot_required {
|
||||
ui.horizontal_wrapped(|ui| ui.heading("REBOOT REQUIRED"));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -121,7 +132,7 @@ pub fn rog_bios_group(supported: &SupportedFunctions, states: &mut SystemState,
|
||||
.asus_dbus
|
||||
.proxies()
|
||||
.rog_bios()
|
||||
.set_gpu_mux_mode(states.bios.dedicated_gfx)
|
||||
.set_gpu_mux_mode(dedicated_gfx)
|
||||
.map_err(|err| {
|
||||
states.error = Some(err.to_string());
|
||||
})
|
||||
|
||||
@@ -81,7 +81,7 @@ impl<'a> RogDbusClientBlocking<'a> {
|
||||
Ok((RogDbusClientBlocking { proxies }, conn))
|
||||
}
|
||||
|
||||
pub fn proxies(&self) -> &DbusProxiesBlocking {
|
||||
pub fn proxies(&self) -> &DbusProxiesBlocking<'_> {
|
||||
&self.proxies
|
||||
}
|
||||
}
|
||||
@@ -150,7 +150,7 @@ impl<'a> RogDbusClient<'a> {
|
||||
Ok((RogDbusClient { proxies }, conn))
|
||||
}
|
||||
|
||||
pub fn proxies(&self) -> &DbusProxies {
|
||||
pub fn proxies(&self) -> &DbusProxies<'_> {
|
||||
&self.proxies
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
[package]
|
||||
name = "rog_platform"
|
||||
license = "MPL-2.0"
|
||||
version.workspace = true
|
||||
edition = "2021"
|
||||
|
||||
@@ -14,4 +15,4 @@ concat-idents.workspace = true
|
||||
udev.workspace = true
|
||||
inotify.workspace = true
|
||||
|
||||
rusb.workspace = true
|
||||
rusb.workspace = true
|
||||
|
||||
@@ -23,7 +23,7 @@ pub enum PlatformError {
|
||||
|
||||
impl fmt::Display for PlatformError {
|
||||
// This trait requires `fmt` with this exact signature.
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
PlatformError::ParseVendor => write!(f, "Parse gfx vendor error"),
|
||||
PlatformError::ParseNum => write!(f, "Parse number error"),
|
||||
|
||||
@@ -19,7 +19,7 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
pub(crate) fn to_device(sys_path: &Path) -> Result<Device> {
|
||||
Device::from_syspath(sys_path)
|
||||
.map_err(|e| PlatformError::Udev("Couldn't transform syspath to device".to_string(), e))
|
||||
.map_err(|e| PlatformError::Udev("Couldn't transform syspath to device".to_owned(), e))
|
||||
}
|
||||
|
||||
pub fn has_attr(device: &Device, attr_name: &str) -> bool {
|
||||
@@ -39,7 +39,7 @@ pub fn read_attr_bool(device: &Device, attr_name: &str) -> Result<bool> {
|
||||
}
|
||||
return Ok(true);
|
||||
}
|
||||
Err(PlatformError::AttrNotFound(attr_name.to_string()))
|
||||
Err(PlatformError::AttrNotFound(attr_name.to_owned()))
|
||||
}
|
||||
|
||||
pub fn write_attr_bool(device: &mut Device, attr: &str, value: bool) -> Result<()> {
|
||||
@@ -53,7 +53,7 @@ pub fn read_attr_u8(device: &Device, attr_name: &str) -> Result<u8> {
|
||||
let tmp = value.to_string_lossy();
|
||||
return tmp.parse::<u8>().map_err(|_| PlatformError::ParseNum);
|
||||
}
|
||||
Err(PlatformError::AttrNotFound(attr_name.to_string()))
|
||||
Err(PlatformError::AttrNotFound(attr_name.to_owned()))
|
||||
}
|
||||
|
||||
pub fn write_attr_u8(device: &mut Device, attr: &str, value: u8) -> Result<()> {
|
||||
@@ -71,7 +71,7 @@ pub fn read_attr_u8_array(device: &Device, attr_name: &str) -> Result<Vec<u8>> {
|
||||
.collect();
|
||||
return Ok(tmp);
|
||||
}
|
||||
Err(PlatformError::AttrNotFound(attr_name.to_string()))
|
||||
Err(PlatformError::AttrNotFound(attr_name.to_owned()))
|
||||
}
|
||||
|
||||
pub fn write_attr_u8_array(device: &mut Device, attr: &str, values: &[u8]) -> Result<()> {
|
||||
|
||||
@@ -11,12 +11,12 @@ use crate::{
|
||||
};
|
||||
|
||||
/// The "platform" device provides access to things like:
|
||||
/// - dgpu_disable
|
||||
/// - egpu_enable
|
||||
/// - panel_od
|
||||
/// - gpu_mux
|
||||
/// - keyboard_mode, set keyboard RGB mode and speed
|
||||
/// - keyboard_state, set keyboard power states
|
||||
/// - `dgpu_disable`
|
||||
/// - `egpu_enable`
|
||||
/// - `panel_od`
|
||||
/// - `gpu_mux`
|
||||
/// - `keyboard_mode`, set keyboard RGB mode and speed
|
||||
/// - `keyboard_state`, set keyboard power states
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Clone)]
|
||||
pub struct AsusPlatform {
|
||||
path: PathBuf,
|
||||
@@ -65,12 +65,13 @@ impl AsusPlatform {
|
||||
attr_u8!("platform_profile", pp_path);
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Type, Debug, PartialEq, Eq, Clone, Copy)]
|
||||
#[derive(Serialize, Deserialize, Default, Type, Debug, PartialEq, Eq, Clone, Copy)]
|
||||
pub enum GpuMode {
|
||||
Discrete,
|
||||
Optimus,
|
||||
Integrated,
|
||||
Egpu,
|
||||
#[default]
|
||||
Error,
|
||||
NotSupported,
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@ use crate::{
|
||||
};
|
||||
|
||||
/// The "platform" device provides access to things like:
|
||||
/// - dgpu_disable
|
||||
/// - egpu_enable
|
||||
/// - panel_od
|
||||
/// - gpu_mux
|
||||
/// - keyboard_mode, set keyboard RGB mode and speed
|
||||
/// - keyboard_state, set keyboard power states
|
||||
/// - `dgpu_disable`
|
||||
/// - `egpu_enable`
|
||||
/// - `panel_od`
|
||||
/// - `gpu_mux`
|
||||
/// - `keyboard_mode`, set keyboard RGB mode and speed
|
||||
/// - `keyboard_state`, set keyboard power states
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Clone)]
|
||||
pub struct AsusPower {
|
||||
mains: PathBuf,
|
||||
|
||||
@@ -11,7 +11,7 @@ impl USBRaw {
|
||||
for device in rusb::devices()?.iter() {
|
||||
let device_desc = device.device_descriptor()?;
|
||||
if device_desc.vendor_id() == 0x0b05 && device_desc.product_id() == id_product {
|
||||
let handle = Self::get_dev_handle(device)?;
|
||||
let handle = Self::get_dev_handle(&device)?;
|
||||
return Ok(Self(handle));
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ impl USBRaw {
|
||||
}
|
||||
|
||||
fn get_dev_handle(
|
||||
device: Device<rusb::GlobalContext>,
|
||||
device: &Device<rusb::GlobalContext>,
|
||||
) -> Result<DeviceHandle<rusb::GlobalContext>> {
|
||||
// We don't expect this ID to ever change
|
||||
let mut device = device.open()?;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
[package]
|
||||
name = "rog_profiles"
|
||||
license = "MPL-2.0"
|
||||
version.workspace = true
|
||||
authors = ["Luke D. Jones <luke@ljones.dev>"]
|
||||
edition = "2021"
|
||||
@@ -13,4 +14,4 @@ udev.workspace = true
|
||||
serde.workspace = true
|
||||
serde_derive.workspace = true
|
||||
|
||||
zbus = { workspace = true, optional = true }
|
||||
zbus = { workspace = true, optional = true }
|
||||
|
||||
@@ -72,6 +72,14 @@ impl Profile {
|
||||
file.write_all(<&str>::from(profile).as_bytes())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn from_throttle_thermal_policy(num: u8) -> Self {
|
||||
match num {
|
||||
1 => Self::Performance,
|
||||
2 => Self::Quiet,
|
||||
_ => Self::Balanced,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Profile {
|
||||
@@ -93,7 +101,6 @@ impl From<Profile> for &str {
|
||||
impl From<&str> for Profile {
|
||||
fn from(profile: &str) -> Profile {
|
||||
match profile.to_ascii_lowercase().trim() {
|
||||
"balanced" => Profile::Balanced,
|
||||
"performance" => Profile::Performance,
|
||||
"quiet" => Profile::Quiet,
|
||||
_ => Profile::Balanced,
|
||||
@@ -202,7 +209,7 @@ impl FanCurveProfiles {
|
||||
|
||||
/// Reset the stored (self) and device curve to the defaults of the platform.
|
||||
///
|
||||
/// Each platform_profile has a different default and the defualt can be read
|
||||
/// Each `platform_profile` has a different default and the defualt can be read
|
||||
/// only for the currently active profile.
|
||||
pub fn set_active_curve_to_defaults(
|
||||
&mut self,
|
||||
@@ -296,12 +303,12 @@ impl FanCurveProfiles {
|
||||
FanCurvePU::GPU => &self.balanced.gpu,
|
||||
},
|
||||
Profile::Performance => match pu {
|
||||
FanCurvePU::CPU => &self.balanced.cpu,
|
||||
FanCurvePU::GPU => &self.balanced.gpu,
|
||||
FanCurvePU::CPU => &self.performance.cpu,
|
||||
FanCurvePU::GPU => &self.performance.gpu,
|
||||
},
|
||||
Profile::Quiet => match pu {
|
||||
FanCurvePU::CPU => &self.balanced.cpu,
|
||||
FanCurvePU::GPU => &self.balanced.gpu,
|
||||
FanCurvePU::CPU => &self.quiet.cpu,
|
||||
FanCurvePU::GPU => &self.quiet.gpu,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
9
rust-toolchain
Normal file
9
rust-toolchain
Normal file
@@ -0,0 +1,9 @@
|
||||
# If you see this, run "rustup self update" to get rustup 1.23 or newer.
|
||||
|
||||
# NOTE: above comment is for older `rustup` (before TOML support was added),
|
||||
# which will treat the first line as the toolchain name, and therefore show it
|
||||
# to the user in the error, instead of "error: invalid channel name '[toolchain]'".
|
||||
|
||||
[toolchain]
|
||||
channel = "1.65.0"
|
||||
components = [ "rustfmt", "clippy" ]
|
||||
Reference in New Issue
Block a user