diff --git a/docs/swhkd.1.scd b/docs/swhkd.1.scd index 8b3f3dc..2aa0837 100644 --- a/docs/swhkd.1.scd +++ b/docs/swhkd.1.scd @@ -38,9 +38,12 @@ More about the config file syntax in `swhkd(5)` *-d*, *--debug* Enable debug mode. -*-D, --device* +*-D, --device* Manually set the keyboard devices to use. Can occur multiple times. +*-I, --ignore-device* + Manually set the keyboard devices to ignore. Can occur multiple times. + # SIGNALS - Reload config file: `sudo pkill -HUP swhkd` diff --git a/swhkd/src/daemon.rs b/swhkd/src/daemon.rs index af75dd4..dc67d6d 100644 --- a/swhkd/src/daemon.rs +++ b/swhkd/src/daemon.rs @@ -143,16 +143,21 @@ async fn main() -> Result<(), Box> { }; } - let arg_devices: Vec<&str> = args.values_of("device").unwrap_or_default().collect(); + let arg_add_devices: Vec<&str> = args.values_of("device").unwrap_or_default().collect(); + let arg_ignore_devices: Vec<&str> = + args.values_of("ignore-device").unwrap_or_default().collect(); + + let to_add = |dev: &Device| arg_add_devices.contains(&dev.name().unwrap_or("[unknown]")); + let to_ignore = |dev: &Device| arg_ignore_devices.contains(&dev.name().unwrap_or("[unknown]")); let keyboard_devices: Vec<_> = { - if arg_devices.is_empty() { + if arg_add_devices.is_empty() { log::trace!("Attempting to find all keyboard file descriptors."); - evdev::enumerate().filter(|(_, dev)| check_device_is_keyboard(dev)).collect() - } else { evdev::enumerate() - .filter(|(_, dev)| arg_devices.contains(&dev.name().unwrap_or(""))) + .filter(|(_, dev)| !to_ignore(dev) && check_device_is_keyboard(dev)) .collect() + } else { + evdev::enumerate().filter(|(_, dev)| !to_ignore(dev) && to_add(dev)).collect() } }; @@ -308,8 +313,8 @@ async fn main() -> Result<(), Box> { }, Ok(device) => device }; - let name = device.name().unwrap_or("[unknown]"); - if arg_devices.contains(&name) || check_device_is_keyboard(&device) { + if !to_ignore(&device) && (to_add(&device) || check_device_is_keyboard(&device)) { + let name = device.name().unwrap_or("[unknown]"); log::info!("Device '{}' at '{}' added.", name, node); let _ = device.grab(); keyboard_states.insert(node.to_string(), KeyboardState::new()); @@ -490,14 +495,22 @@ pub fn set_command_line_args() -> Command<'static> { ) .arg(arg!(-d - -debug).required(false).help("Enable debug mode.")) .arg( - arg!(-D --device ) + arg!(-D --device ) .required(false) .takes_value(true) .multiple_occurrences(true) .help( - "Specific keyboard devices to use. Seperate multiple devices with semicolon.", + "Specific keyboard devices to use. Separate multiple devices with semicolon.", ), - ); + ) + .arg(arg!(-I --ignore-device ) + .required(false) + .takes_value(true) + .multiple_occurrences(true) + .help( + "Specific keyboard devices to ignore. Separate multiple devices with semicolon." + ) + ); app }