diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..7afc549 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,82 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Debug executable 'swhkd'", + "cargo": { + "args": [ + "build", + "--bin=swhkd", + "--package=Simple-Wayland-HotKey-Daemon" + ], + "filter": { + "name": "swhkd", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in executable 'swhkd'", + "cargo": { + "args": [ + "test", + "--no-run", + "--bin=swhkd", + "--package=Simple-Wayland-HotKey-Daemon" + ], + "filter": { + "name": "swhkd", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug executable 'swhks'", + "cargo": { + "args": [ + "build", + "--bin=swhks", + "--package=swhks" + ], + "filter": { + "name": "swhks", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug unit tests in executable 'swhks'", + "cargo": { + "args": [ + "test", + "--no-run", + "--bin=swhks", + "--package=swhks" + ], + "filter": { + "name": "swhks", + "kind": "bin" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/Notes.md b/Notes.md new file mode 100644 index 0000000..00a4105 --- /dev/null +++ b/Notes.md @@ -0,0 +1,20 @@ +# Notes + +Uinput docs: +Libevdev: + +Command to run swhkd +```sh +pkexec swhkd -d -D 'AT Translated Set 2 keyboard' +``` + +Language guide: https://github.com/baskerville/sxhkd/blob/master/doc/sxhkd.1.asciidoc + +Keyboard recognition: https://unix.stackexchange.com/questions/523108/getting-type-of-evdev-device + +Parser discussion: + +Run with minimal config +```sh +pkexec swhkd -d -c $PWD/test.conf +``` diff --git a/myinstall.sh b/myinstall.sh new file mode 100755 index 0000000..fd2f86a --- /dev/null +++ b/myinstall.sh @@ -0,0 +1,4 @@ +set -xe + +make +sudo make install \ No newline at end of file diff --git a/swhkd/src/daemon.rs b/swhkd/src/daemon.rs index af75dd4..da41a88 100644 --- a/swhkd/src/daemon.rs +++ b/swhkd/src/daemon.rs @@ -143,15 +143,25 @@ 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 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() + evdev::enumerate() + .filter(|(_, dev)| { + !arg_ignore_devices.contains(&dev.name().unwrap_or("")) + && check_device_is_keyboard(dev) + }) + .collect() } else { evdev::enumerate() - .filter(|(_, dev)| arg_devices.contains(&dev.name().unwrap_or(""))) + .filter(|(_, dev)| { + !arg_ignore_devices.contains(&dev.name().unwrap_or("")) + && arg_add_devices.contains(&dev.name().unwrap_or("")) + }) .collect() } }; @@ -309,7 +319,7 @@ 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 !arg_ignore_devices.contains(&name) && (arg_add_devices.contains(&name) || check_device_is_keyboard(&device)) { log::info!("Device '{}' at '{}' added.", name, node); let _ = device.grab(); keyboard_states.insert(node.to_string(), KeyboardState::new()); @@ -490,14 +500,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.", ), - ); + ) + .arg(arg!(-I --ignore-device ) + .required(false) + .takes_value(true) + .multiple_occurrences(true) + .help( + "Specific keyboard devices to ignore. Seperate multiple devices with semicolon." + ) + ); app } diff --git a/swhkd/src/uinput.rs b/swhkd/src/uinput.rs index f0684ae..e02ade3 100644 --- a/swhkd/src/uinput.rs +++ b/swhkd/src/uinput.rs @@ -622,7 +622,7 @@ pub fn get_all_switches() -> &'static [SwitchType] { SwitchType::SW_LID, SwitchType::SW_TABLET_MODE, SwitchType::SW_HEADPHONE_INSERT, - SwitchType::SW_RFKILL_ALL, + // SwitchType::SW_RFKILL_ALL, SwitchType::SW_MICROPHONE_INSERT, SwitchType::SW_DOCK, SwitchType::SW_LINEOUT_INSERT, diff --git a/test.conf b/test.conf new file mode 100644 index 0000000..fa75722 --- /dev/null +++ b/test.conf @@ -0,0 +1,2 @@ +alt + ctrl + q + qalculate-gtk \ No newline at end of file