Skip to content

Commit 593d28d

Browse files
committed
[feat] add argument to ignore devices
--ignore-device takes the same format as --device and ignores the devices listed, separated by semicolon. If a device is listed both in the --device argument and --ignore-device argument, it is not added.
1 parent 34b9619 commit 593d28d

File tree

6 files changed

+134
-8
lines changed

6 files changed

+134
-8
lines changed

.vscode/launch.json

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "lldb",
9+
"request": "launch",
10+
"name": "Debug executable 'swhkd'",
11+
"cargo": {
12+
"args": [
13+
"build",
14+
"--bin=swhkd",
15+
"--package=Simple-Wayland-HotKey-Daemon"
16+
],
17+
"filter": {
18+
"name": "swhkd",
19+
"kind": "bin"
20+
}
21+
},
22+
"args": [],
23+
"cwd": "${workspaceFolder}"
24+
},
25+
{
26+
"type": "lldb",
27+
"request": "launch",
28+
"name": "Debug unit tests in executable 'swhkd'",
29+
"cargo": {
30+
"args": [
31+
"test",
32+
"--no-run",
33+
"--bin=swhkd",
34+
"--package=Simple-Wayland-HotKey-Daemon"
35+
],
36+
"filter": {
37+
"name": "swhkd",
38+
"kind": "bin"
39+
}
40+
},
41+
"args": [],
42+
"cwd": "${workspaceFolder}"
43+
},
44+
{
45+
"type": "lldb",
46+
"request": "launch",
47+
"name": "Debug executable 'swhks'",
48+
"cargo": {
49+
"args": [
50+
"build",
51+
"--bin=swhks",
52+
"--package=swhks"
53+
],
54+
"filter": {
55+
"name": "swhks",
56+
"kind": "bin"
57+
}
58+
},
59+
"args": [],
60+
"cwd": "${workspaceFolder}"
61+
},
62+
{
63+
"type": "lldb",
64+
"request": "launch",
65+
"name": "Debug unit tests in executable 'swhks'",
66+
"cargo": {
67+
"args": [
68+
"test",
69+
"--no-run",
70+
"--bin=swhks",
71+
"--package=swhks"
72+
],
73+
"filter": {
74+
"name": "swhks",
75+
"kind": "bin"
76+
}
77+
},
78+
"args": [],
79+
"cwd": "${workspaceFolder}"
80+
}
81+
]
82+
}

Notes.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Notes
2+
3+
Uinput docs: <https://kernel.org/doc/html/v4.12/input/uinput.html>
4+
Libevdev: <https://www.freedesktop.org/software/libevdev/doc/latest/>
5+
6+
Command to run swhkd
7+
```sh
8+
pkexec swhkd -d -D 'AT Translated Set 2 keyboard'
9+
```
10+
11+
Language guide: https://github.com/baskerville/sxhkd/blob/master/doc/sxhkd.1.asciidoc
12+
13+
Keyboard recognition: https://unix.stackexchange.com/questions/523108/getting-type-of-evdev-device
14+
15+
Parser discussion: <https://github.com/waycrate/swhkd/issues/168>
16+
17+
Run with minimal config
18+
```sh
19+
pkexec swhkd -d -c $PWD/test.conf
20+
```

myinstall.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set -xe
2+
3+
make
4+
sudo make install

swhkd/src/daemon.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,25 @@ async fn main() -> Result<(), Box<dyn Error>> {
143143
};
144144
}
145145

146-
let arg_devices: Vec<&str> = args.values_of("device").unwrap_or_default().collect();
146+
let arg_add_devices: Vec<&str> = args.values_of("device").unwrap_or_default().collect();
147+
let arg_ignore_devices: Vec<&str> =
148+
args.values_of("ignore-device").unwrap_or_default().collect();
147149

148150
let keyboard_devices: Vec<_> = {
149-
if arg_devices.is_empty() {
151+
if arg_add_devices.is_empty() {
150152
log::trace!("Attempting to find all keyboard file descriptors.");
151-
evdev::enumerate().filter(|(_, dev)| check_device_is_keyboard(dev)).collect()
153+
evdev::enumerate()
154+
.filter(|(_, dev)| {
155+
!arg_ignore_devices.contains(&dev.name().unwrap_or(""))
156+
&& check_device_is_keyboard(dev)
157+
})
158+
.collect()
152159
} else {
153160
evdev::enumerate()
154-
.filter(|(_, dev)| arg_devices.contains(&dev.name().unwrap_or("")))
161+
.filter(|(_, dev)| {
162+
!arg_ignore_devices.contains(&dev.name().unwrap_or(""))
163+
&& arg_add_devices.contains(&dev.name().unwrap_or(""))
164+
})
155165
.collect()
156166
}
157167
};
@@ -309,7 +319,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
309319
Ok(device) => device
310320
};
311321
let name = device.name().unwrap_or("[unknown]");
312-
if arg_devices.contains(&name) || check_device_is_keyboard(&device) {
322+
if !arg_ignore_devices.contains(&name) && (arg_add_devices.contains(&name) || check_device_is_keyboard(&device)) {
313323
log::info!("Device '{}' at '{}' added.", name, node);
314324
let _ = device.grab();
315325
keyboard_states.insert(node.to_string(), KeyboardState::new());
@@ -490,14 +500,22 @@ pub fn set_command_line_args() -> Command<'static> {
490500
)
491501
.arg(arg!(-d - -debug).required(false).help("Enable debug mode."))
492502
.arg(
493-
arg!(-D --device <DEVICE_NAME>)
503+
arg!(-D --device <DEVICE_NAMES>)
494504
.required(false)
495505
.takes_value(true)
496506
.multiple_occurrences(true)
497507
.help(
498508
"Specific keyboard devices to use. Seperate multiple devices with semicolon.",
499509
),
500-
);
510+
)
511+
.arg(arg!(-I --ignore-device <DEVICE_NAMES>)
512+
.required(false)
513+
.takes_value(true)
514+
.multiple_occurrences(true)
515+
.help(
516+
"Specific keyboard devices to ignore. Seperate multiple devices with semicolon."
517+
)
518+
);
501519
app
502520
}
503521

swhkd/src/uinput.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ pub fn get_all_switches() -> &'static [SwitchType] {
622622
SwitchType::SW_LID,
623623
SwitchType::SW_TABLET_MODE,
624624
SwitchType::SW_HEADPHONE_INSERT,
625-
SwitchType::SW_RFKILL_ALL,
625+
// SwitchType::SW_RFKILL_ALL,
626626
SwitchType::SW_MICROPHONE_INSERT,
627627
SwitchType::SW_DOCK,
628628
SwitchType::SW_LINEOUT_INSERT,

test.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
alt + ctrl + q
2+
qalculate-gtk

0 commit comments

Comments
 (0)