Skip to content

Commit

Permalink
fix(Device Hiding): use IMPORT{program} to query if device is manage …
Browse files Browse the repository at this point in the history
…by InputPlumber
  • Loading branch information
ShadowApex committed Feb 10, 2025
1 parent 0f74520 commit d694c26
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 32 deletions.
26 changes: 0 additions & 26 deletions rootfs/usr/lib/udev/hwdb.d/59-inputplumber.hwdb
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,3 @@ evdev:name:AT Translated Set 2 keyboard:dmi:*:svnAYANEO:*
evdev:name:AT Translated Set 2 keyboard:dmi:*:svnOrangePi:pnNEO-01:*
KEYBOARD_KEY_66=f15
KEYBOARD_KEY_67=f16

# List of virtual devices provided by inputplumber
# Sony Dualsense Edge
hid:b0003g0001v0000054Cp00000DF2
INPUTPLUMBER_VIRT=1

# Valve Steam Deck
hid:b0003g0103v000028DEp00001205
INPUTPLUMBER_VIRT=1

# Horipad Steam Controller
hid:b0003g0001v00000F0Dp000001AB
INPUTPLUMBER_VIRT=1

# XBox 360
input:b0003v045Ep028EeACED-e0,1,3,15,k130,131,133,134,136,137,13A,13B,13C,13D,13E,2C0,2C1,2C2,2C3,ra0,1,2,3,4,5,10,11,mlsf50,51,58,59,5A,60,w
INPUTPLUMBER_VIRT=1

# Xbox Series
input:b0003v045Ep0B12eACED-e0,1,3,15,kA7,130,131,133,134,136,137,13A,13B,13C,13D,13E,2C0,2C1,2C2,2C3,ra0,1,2,3,4,5,10,11,mlsf50,51,58,59,5A,60,w
INPUTPLUMBER_VIRT=1

# Xbox Elite 2
input:b0003v045Ep0B00eACED-e0,1,3,15,kA7,130,131,133,134,136,137,13A,13B,13C,13D,13E,2C0,2C1,2C2,2C3,2C4,2C5,2C6,2C7,ra0,1,2,3,4,5,10,11,mlsf50,51,58,59,5A,60,w
INPUTPLUMBER_VIRT=1

30 changes: 30 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ pub enum Commands {
#[command(subcommand)]
cmd: TargetsCommand,
},
/// Query input devices
Query {
/// Sysfs path to the device to query
sysfs_path: String,
#[arg(long, action)]
subsystem: Option<String>,
#[arg(long, action)]
udev: Option<bool>,
},
}

pub async fn main_cli(args: Args) -> Result<(), Box<dyn Error>> {
Expand All @@ -65,6 +74,27 @@ pub async fn main_cli(args: Args) -> Result<(), Box<dyn Error>> {
Commands::Device { id: number, cmd } => handle_device(connection, cmd, number).await?,
Commands::Devices { cmd } => handle_devices(connection, cmd).await?,
Commands::Targets { cmd } => handle_targets(connection, cmd).await?,
Commands::Query {
udev,
sysfs_path,
subsystem,
} => {
// example:
// inputplumber query /devices/pci0000:00/0000:00:08.3/0000:c3:00.4/usb7/7-1/7-1:1.0/input/input83/event11

// Check to see if the device is virtual
let is_virtual =
sysfs_path.contains("devices/virtual") || sysfs_path.contains("vhci_hcd");

if !is_virtual {
return Ok(());
}

// Bluetooth devices are virtual, so ensure ensure the device is not bluetooth

//println!("Found option: {udev:?}");
println!("INPUTPLUMBER_VIRT=1")
}
}

Ok(())
Expand Down
26 changes: 20 additions & 6 deletions src/udev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,34 @@ pub async fn block_joysticks() -> Result<(), Box<dyn Error>> {
"/usr/bin/chmod"
};

const IP_CMD: &str = "/home/william/Projects/InputPlumber/target/debug/inputplumber";

let rule = format!(
r#"# Hide all evdev devices that are not InputPlumber virtual devices
ACTION=="add|change", SUBSYSTEM=="input", KERNEL=="js[0-9]*|event[0-9]*", ENV{{ID_INPUT_JOYSTICK}}=="1", ENV{{INPUTPLUMBER_VIRT}}!="1", MODE:="0000", GROUP:="root", RUN:="{chmod_cmd} 000 %p"
r#"# InputPlumber device hiding rules
# Managed by InputPlumber, this file will be autoremoved during configuration changes.
# Query InputPlumber to see if the given device is being managed by InputPlumber.
# If it is, add the INPUTPLUMBER_VIRT property to the device.
ACTION=="add|change", KERNEL=="hidraw[0-9]*|js[0-9]*|event[0-9]*", IMPORT{{program}}="{IP_CMD} query %p"
# Create symlinks for all virtual InputPlumber devices
ACTION=="add|change", KERNEL=="hidraw[0-9]*|js[0-9]*|event[0-9]*", ENV{{INPUTPLUMBER_VIRT}}=="1", SYMLINK+="inputplumber/by-targets/%k", GOTO="inputplumber_end"
# Hide all evdev gamepads that are not InputPlumber virtual devices
ACTION=="add|change", KERNEL=="js[0-9]*|event[0-9]*", ENV{{ID_INPUT_JOYSTICK}}=="1", ENV{{INPUTPLUMBER_VIRT}}!="1", SYMLINK+="inputplumber/by-hidden/%k", MODE:="0000", GROUP:="root", RUN:="{chmod_cmd} 000 %p"
# Hide all Horipad Steam Controller hidraw devices
ACTION=="add|change", SUBSYSTEM=="hidraw", KERNEL=="hidraw[0-9]*", ATTR{{idVendor}}=="0F0D", ATTR{{idProduct}}=="0196", ENV{{INPUTPLUMBER_VIRT}}!="1", MODE:="0000", GROUP:="root", RUN:="{chmod_cmd} 000 %p"
ACTION=="add|change", SUBSYSTEM=="hidraw", KERNEL=="hidraw[0-9]*", ATTR{{idVendor}}=="0F0D", ATTR{{idProduct}}=="01AB", ENV{{INPUTPLUMBER_VIRT}}!="1", MODE:="0000", GROUP:="root", RUN:="{chmod_cmd} 000 %p"
ACTION=="add|change", SUBSYSTEM=="hidraw", KERNEL=="hidraw[0-9]*", ATTR{{idVendor}}=="0F0D", ATTR{{idProduct}}=="0196", ENV{{INPUTPLUMBER_VIRT}}!="1", SYMLINK+="inputplumber/by-hidden/%k", MODE:="0000", GROUP:="root", RUN:="{chmod_cmd} 000 %p"
ACTION=="add|change", SUBSYSTEM=="hidraw", KERNEL=="hidraw[0-9]*", ATTR{{idVendor}}=="0F0D", ATTR{{idProduct}}=="01AB", ENV{{INPUTPLUMBER_VIRT}}!="1", SYMLINK+="inputplumber/by-hidden/%k", MODE:="0000", GROUP:="root", RUN:="{chmod_cmd} 000 %p"
# Hide all PlayStation hidraw devices
ACTION=="add|change", SUBSYSTEMS=="hid", DRIVERS=="playstation", GOTO="playstation_start"
GOTO="playstation_end"
LABEL="playstation_start"
ACTION=="add|change", SUBSYSTEM=="hidraw", KERNEL=="hidraw[0-9]*", ENV{{INPUTPLUMBER_VIRT}}!="1", MODE:="0000", GROUP:="root", RUN:="{chmod_cmd} 000 %p"
ACTION=="add|change", SUBSYSTEM=="hidraw", KERNEL=="hidraw[0-9]*", ENV{{INPUTPLUMBER_VIRT}}!="1", SYMLINK+="inputplumber/by-hidden/%k", MODE:="0000", GROUP:="root", RUN:="{chmod_cmd} 000 %p"
LABEL="playstation_end"
LABEL="inputplumber_end"
"#
);

Expand Down Expand Up @@ -88,7 +102,7 @@ pub async fn hide_device(path: &str) -> Result<(), Box<dyn Error>> {
{match_rule}, GOTO="inputplumber_valid"
GOTO="inputplumber_end"
LABEL="inputplumber_valid"
ACTION=="add|change", KERNEL=="hidraw[0-9]*|js[0-9]*|event[0-9]*", SUBSYSTEM=="{subsystem}", MODE:="0000", GROUP:="root", RUN:="{chmod_cmd} 000 {path}", SYMLINK+="inputplumber/%k"
ACTION=="add|change", KERNEL=="hidraw[0-9]*|js[0-9]*|event[0-9]*", SUBSYSTEM=="{subsystem}", MODE:="0000", GROUP:="root", RUN:="{chmod_cmd} 000 {path}", SYMLINK+="inputplumber/by-hidden/%k"
LABEL="inputplumber_end"
"#
);
Expand Down

0 comments on commit d694c26

Please sign in to comment.