Skip to content

Commit fc5d709

Browse files
malpernclaude
andauthored
fix(macos): don't intercept all devices when include/exclude list has no matches (#1986)
## Summary - When `macos-dev-names-include` or `macos-dev-names-exclude` is configured but no connected devices match, kanata was falling back to `register_device("")` which intercepts **all** devices - This caused kanata to grab the wrong keyboard (e.g., the internal MacBook keyboard when an external keyboard was specified but not connected) - Now kanata only falls back to the catch-all registration when no device filter is configured at all — when a filter is present but nothing matches, kanata exits with an error Fixes #1479 ## Test plan - [x] Configured `macos-dev-names-include` with a nonexistent device name — kanata now errors out instead of grabbing all devices - [x] Configured `macos-dev-names-include` with a real connected device — kanata correctly grabs only that device and remapping works - [x] No include/exclude list — default behavior unchanged (grabs all devices) ## Possible follow-up Linux has `linux-continue-if-no-devs-found` which lets kanata wait for devices instead of exiting. A cross-platform `continue-if-no-devs-found` option could be added to support the multi-instance use case where kanata should stay running and pick up the device when it connects. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3bda1ec commit fc5d709

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/oskbd/macos.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ impl KbdIn {
7979

8080
// Based on the definition of include and exclude names, they should never be used together.
8181
// Kanata config parser should probably enforce this.
82+
let has_device_filter = include_names.is_some() || exclude_names.is_some();
8283
let device_names = if let Some(included_names) = include_names {
8384
validate_and_register_devices(included_names)
8485
} else if let Some(excluded_names) = exclude_names {
@@ -104,7 +105,10 @@ impl KbdIn {
104105
vec![]
105106
};
106107

107-
if !device_names.is_empty() || register_device("") {
108+
// When an include/exclude list is configured but no devices matched,
109+
// do NOT fall back to registering all devices. Only use the catch-all
110+
// register_device("") when no device filter was specified at all.
111+
if !device_names.is_empty() || (!has_device_filter && register_device("")) {
108112
if grab() {
109113
Ok(Self { grabbed: true })
110114
} else {

0 commit comments

Comments
 (0)