From 07d133b08fc89cb09a3018c45a1969394f834222 Mon Sep 17 00:00:00 2001 From: Abdalrahman Mursi Date: Fri, 8 Dec 2023 20:55:04 +0200 Subject: [PATCH] 'macos_dev_names_include instead of macos-dev' --- parser/src/cfg/defcfg.rs | 16 +++++++--------- src/kanata/macos.rs | 2 +- src/kanata/mod.rs | 10 +++++----- src/oskbd/macos.rs | 12 ++++++------ 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/parser/src/cfg/defcfg.rs b/parser/src/cfg/defcfg.rs index 7295e3906..a35ddbd6d 100644 --- a/parser/src/cfg/defcfg.rs +++ b/parser/src/cfg/defcfg.rs @@ -40,7 +40,7 @@ pub struct CfgOptions { ))] pub windows_interception_mouse_hwid: Option<[u8; HWID_ARR_SZ]>, #[cfg(any(target_os = "macos", target_os = "unknown"))] - pub macos_dev: Vec, + pub macos_dev_names_include: Option>, } impl Default for CfgOptions { @@ -80,7 +80,7 @@ impl Default for CfgOptions { ))] windows_interception_mouse_hwid: None, #[cfg(any(target_os = "macos", target_os = "unknown"))] - macos_dev: vec![], + macos_dev_names_include: None, } } } @@ -242,16 +242,14 @@ pub fn parse_defcfg(expr: &[SExpr]) -> Result { cfg.windows_interception_mouse_hwid = Some(hwid_slice?); } } - "macos-dev" => { + "macos-dev-names-include" => { #[cfg(any(target_os = "macos", target_os = "unknown"))] { - cfg.macos_dev = parse_dev(val)?; - if cfg.macos_dev.is_empty() { - bail_expr!( - val, - "device list is empty, no devices will be intercepted" - ); + let dev_names = parse_dev(val)?; + if dev_names.is_empty() { + log::warn!("macos-dev-names-include is empty"); } + cfg.macos_dev_names_include = Some(dev_names); } } diff --git a/src/kanata/macos.rs b/src/kanata/macos.rs index 22423fff7..a9e97051f 100644 --- a/src/kanata/macos.rs +++ b/src/kanata/macos.rs @@ -14,7 +14,7 @@ impl Kanata { info!("entering the event loop"); let k = kanata.lock(); - let mut kb = match KbdIn::new(&k.kbd_in_paths) { + let mut kb = match KbdIn::new(k.include_names.clone()) { Ok(kbd_in) => kbd_in, Err(e) => bail!("failed to open keyboard device(s): {}", e), }; diff --git a/src/kanata/mod.rs b/src/kanata/mod.rs index 1759ab474..ff56cdc02 100644 --- a/src/kanata/mod.rs +++ b/src/kanata/mod.rs @@ -120,14 +120,14 @@ pub struct Kanata { time_remainder: u128, /// Is true if a live reload was requested by the user and false otherwise. live_reload_requested: bool, - #[cfg(any(target_os = "linux", target_os = "macos"))] - /// Linux/Macos input paths in the user configuration. + #[cfg(target_os = "linux")] + /// Linux input paths in the user configuration. pub kbd_in_paths: Vec, #[cfg(target_os = "linux")] /// Tracks the Linux user configuration to continue or abort if no devices are found. continue_if_no_devices: bool, - #[cfg(target_os = "linux")] - /// Tracks the Linux user configuration for device names (instead of paths) that should be + #[cfg(any(target_os = "linux", target_os = "macos"))] + /// Tracks the Linux/Macos user configuration for device names (instead of paths) that should be /// included for interception and processing by kanata. pub include_names: Option>, #[cfg(target_os = "linux")] @@ -325,7 +325,7 @@ impl Kanata { overrides: cfg.overrides, override_states: OverrideStates::new(), #[cfg(target_os = "macos")] - kbd_in_paths: cfg.items.macos_dev, + include_names: cfg.items.macos_dev_names_include, #[cfg(target_os = "linux")] kbd_in_paths: cfg.items.linux_dev, #[cfg(target_os = "linux")] diff --git a/src/oskbd/macos.rs b/src/oskbd/macos.rs index ad8c54cb3..8db707425 100644 --- a/src/oskbd/macos.rs +++ b/src/oskbd/macos.rs @@ -48,20 +48,20 @@ impl Drop for KbdIn { } impl KbdIn { - pub fn new(devices: &[String]) -> Result { + pub fn new(include_names: Option>) -> Result { if !driver_activated() { return Err(anyhow!( "Karabiner-VirtualHIDDevice driver is not activated." )); } - let registered_devices = if !devices.is_empty() { - validate_and_register_devices(devices) + let device_names = if include_names.is_some() { + validate_and_register_devices(include_names.unwrap()) } else { vec![] }; - if !registered_devices.is_empty() || register_device("") { + if !device_names.is_empty() || register_device("") { if grab() { Ok(Self {}) } else { @@ -85,8 +85,8 @@ impl KbdIn { } } -fn validate_and_register_devices(devices: &[String]) -> Vec { - devices +fn validate_and_register_devices(include_names: Vec) -> Vec { + include_names .iter() .filter_map(|dev| match device_matches(dev) { true => Some(dev.to_string()),