feat(commands): add touchpad inhibition handling and status display

New Features
- Implement touchpad enable/disable commands via /sys/class/input/inhibited.
- Add permission adjustments for touchpad inhibition files.
- Show touchpad status in `lapctl status`.

Enhancements
- Update install rules to manage touchpad inhibition permissions.
- Expose new `touchpad` command module.

Bug Fixes
- Resolve missing permission errors for touchpad devices.
- Handle missing /sys/class/input directory gracefully.
This commit is contained in:
sankalp committed 2026-03-16 22:26:22 +05:45
1 parent 1bb54facaf
commit 42b3fb47fd
4 files changed
+85

No files matched your search

+4
View File
@@ -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 {
+1
View File
@@ -5,3 +5,4 @@ pub mod inhibit;
pub mod install_rules;
pub mod power;
pub mod status;
pub mod touchpad;
+26
View File
@@ -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());
}
}
}
}
+54
View File
@@ -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),
}
}
}
}
}