Skip to content

Commit

Permalink
'macos_dev_names_include instead of macos-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdalrahman Mursi committed Dec 8, 2023
1 parent 42d1429 commit 07d133b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
16 changes: 7 additions & 9 deletions parser/src/cfg/defcfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
pub macos_dev_names_include: Option<Vec<String>>,
}

impl Default for CfgOptions {
Expand Down Expand Up @@ -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,
}
}
}
Expand Down Expand Up @@ -242,16 +242,14 @@ pub fn parse_defcfg(expr: &[SExpr]) -> Result<CfgOptions> {
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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/kanata/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
Expand Down
10 changes: 5 additions & 5 deletions src/kanata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
#[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<Vec<String>>,
#[cfg(target_os = "linux")]
Expand Down Expand Up @@ -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")]
Expand Down
12 changes: 6 additions & 6 deletions src/oskbd/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ impl Drop for KbdIn {
}

impl KbdIn {
pub fn new(devices: &[String]) -> Result<Self, anyhow::Error> {
pub fn new(include_names: Option<Vec<String>>) -> Result<Self, anyhow::Error> {
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 {
Expand All @@ -85,8 +85,8 @@ impl KbdIn {
}
}

fn validate_and_register_devices(devices: &[String]) -> Vec<String> {
devices
fn validate_and_register_devices(include_names: Vec<String>) -> Vec<String> {
include_names
.iter()
.filter_map(|dev| match device_matches(dev) {
true => Some(dev.to_string()),
Expand Down

0 comments on commit 07d133b

Please sign in to comment.