Skip to content

Commit

Permalink
macos: Use array for chars in create_string_for_key function and poin…
Browse files Browse the repository at this point in the history
…ters to it
  • Loading branch information
pentamassiv committed Sep 10, 2024
1 parent e10f56f commit d6f71a6
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/macos/macos_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,8 +800,7 @@ fn create_string_for_key(keycode: u16, modifier: u32) -> Option<CFStringRef> {
let keyboard_layout = unsafe { CFDataGetBytePtr(layout_data) };

let mut keys_down: UInt32 = 0;
// let mut chars: *mut c_void;//[UniChar; 4];
let mut chars: u16 = 0;
let mut chars: [UniChar; 1] = [0];
let mut real_length = 0;
let status = unsafe {
UCKeyTranslate(
Expand All @@ -812,9 +811,9 @@ fn create_string_for_key(keycode: u16, modifier: u32) -> Option<CFStringRef> {
LMGetKbdType() as u32,
kUCKeyTranslateNoDeadKeysBit,
&mut keys_down,
8, // sizeof(chars) / sizeof(chars[0]),
chars.len() as CFIndex,
&mut real_length,
&mut chars,
chars.as_mut_ptr(),
)
};

Expand All @@ -823,7 +822,13 @@ fn create_string_for_key(keycode: u16, modifier: u32) -> Option<CFStringRef> {
return None;
}

unsafe { Some(CFStringCreateWithCharacters(kCFAllocatorDefault, &chars, 1)) }
unsafe {
Some(CFStringCreateWithCharacters(
kCFAllocatorDefault,
chars.as_ptr(),
1,
))
}
}

#[link(name = "ApplicationServices", kind = "framework")]
Expand Down Expand Up @@ -875,4 +880,4 @@ impl Drop for Enigo {
}
debug!("released all held keys");
}
}
}

0 comments on commit d6f71a6

Please sign in to comment.