diff --git a/src/commands/install_rules.rs b/src/commands/install_rules.rs index e2b9adb..46c7c45 100644 --- a/src/commands/install_rules.rs +++ b/src/commands/install_rules.rs @@ -27,6 +27,9 @@ ACTION=="add", SUBSYSTEM=="powercap", RUN+="/bin/sh -c 'chmod a+w /sys/class/pow # AMD HWMon Power Capping ACTION=="add", SUBSYSTEM=="hwmon", RUN+="/bin/sh -c 'find /sys/class/hwmon -name \"power1_cap\" -exec chmod a+w {} + 2>/dev/null'" + +# Input Device Inhibition (Touchpad) +ACTION=="add", SUBSYSTEM=="input", RUN+="/bin/sh -c 'find /sys/class/input -name \"inhibited\" -exec chmod a+w {} + 2>/dev/null'" "#; pub fn execute() { @@ -58,6 +61,7 @@ pub fn execute() { "chmod a+w /sys/devices/platform/asus-nb-wmi/throttle_thermal_policy 2>/dev/null", "chmod a+w /sys/class/powercap/intel-rapl:0/constraint_*_power_limit_uw 2>/dev/null", "find /sys/class/hwmon -name \"power1_cap\" -exec chmod a+w {} + 2>/dev/null", + "find /sys/class/input -name \"inhibited\" -exec chmod a+w {} + 2>/dev/null", ]; for cmd in commands { diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 70c780a..dd4aa25 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -5,3 +5,4 @@ pub mod inhibit; pub mod install_rules; pub mod power; pub mod status; +pub mod touchpad; diff --git a/src/commands/status.rs b/src/commands/status.rs index c3f1860..e5f692a 100644 --- a/src/commands/status.rs +++ b/src/commands/status.rs @@ -153,4 +153,30 @@ pub fn execute() { if !tdp_found { println!("CPU TDP Limit: Hardware Managed"); } + + // Touchpad Status + let sys_class_input = Path::new("/sys/class/input"); + if sys_class_input.exists() + && let Ok(entries) = fs::read_dir(sys_class_input) + { + for entry in entries.flatten() { + let path = entry.path(); + let name_path = path.join("name"); + let inhibited_path = path.join("inhibited"); + + if name_path.exists() + && inhibited_path.exists() + && let Ok(name) = fs::read_to_string(&name_path) + && name.to_lowercase().contains("touchpad") + && let Ok(val) = fs::read_to_string(&inhibited_path) + { + let status = if val.trim() == "1" { + "Disabled" + } else { + "Enabled" + }; + println!("Touchpad: {} ({})", status, name.trim()); + } + } + } } diff --git a/src/commands/touchpad.rs b/src/commands/touchpad.rs new file mode 100644 index 0000000..931fdbe --- /dev/null +++ b/src/commands/touchpad.rs @@ -0,0 +1,54 @@ +use crate::cli::TouchpadCommands; +use log::{error, info}; +use std::fs; +use std::path::Path; + +pub fn execute(command: &TouchpadCommands) { + let sys_class_input = Path::new("/sys/class/input"); + if !sys_class_input.exists() { + error!("Could not find /sys/class/input. Is this a Linux system?"); + return; + } + + let mut found_touchpads = Vec::new(); + + if let Ok(entries) = fs::read_dir(sys_class_input) { + for entry in entries.flatten() { + let path = entry.path(); + let name_path = path.join("name"); + let inhibited_path = path.join("inhibited"); + + if name_path.exists() + && inhibited_path.exists() + && let Ok(name) = fs::read_to_string(&name_path) + && name.to_lowercase().contains("touchpad") + { + found_touchpads.push((name.trim().to_string(), inhibited_path)); + } + } + } + + if found_touchpads.is_empty() { + error!("No touchpad devices found with 'inhibited' support in /sys/class/input."); + return; + } + + match command { + TouchpadCommands::Enable => { + for (name, path) in found_touchpads { + match fs::write(&path, "0") { + Ok(_) => info!("Enabled touchpad: {}", name), + Err(e) => error!("Failed to enable touchpad {}: {}", name, e), + } + } + } + TouchpadCommands::Disable => { + for (name, path) in found_touchpads { + match fs::write(&path, "1") { + Ok(_) => info!("Disabled touchpad: {}", name), + Err(e) => error!("Failed to disable touchpad {}: {}", name, e), + } + } + } + } +}