Skip to content

Commit

Permalink
macOS: Try getting the layout again
Browse files Browse the repository at this point in the history
  • Loading branch information
pentamassiv committed Apr 18, 2024
1 parent c60f3b6 commit c717b81
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/macos/macos_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const kCFStringEncodingUTF8: u32 = 0x0800_0100;
extern "C" {
fn TISCopyCurrentKeyboardInputSource() -> TISInputSourceRef;
fn TISCopyCurrentKeyboardLayoutInputSource() -> TISInputSourceRef;
fn TISCopyCurrentASCIICapableKeyboardLayoutInputSource()-> TISInputSourceRef;

#[allow(non_upper_case_globals)]
static kTISPropertyUnicodeKeyLayoutData: CFStringRef;
Expand Down Expand Up @@ -848,6 +849,14 @@ fn create_string_for_key(keycode: u16, modifier: u32) -> CFStringRef {
};
debug_assert!(!layout_data.is_null());
}
if layout_data.is_null() {
debug!("TISGetInputSourceProperty(current_keyboard, kTISPropertyUnicodeKeyLayoutData) returned NULL again");
current_keyboard = unsafe { TISCopyCurrentASCIICapableKeyboardLayoutInputSource() };
layout_data = unsafe {
TISGetInputSourceProperty(current_keyboard, kTISPropertyUnicodeKeyLayoutData)
};
debug_assert!(!layout_data.is_null());
}
let keyboard_layout = unsafe { CFDataGetBytePtr(layout_data) };

let mut keys_down: UInt32 = 0;
Expand Down

0 comments on commit c717b81

Please sign in to comment.