Add unicode match support on MacOS
This commit is contained in:
parent
de296b77ea
commit
640fac5bf5
|
@ -18,11 +18,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
use std::os::raw::c_void;
|
use std::os::raw::{c_void, c_char};
|
||||||
use crate::bridge::macos::*;
|
use crate::bridge::macos::*;
|
||||||
use crate::event::{Event, KeyEvent, KeyModifier, ActionType};
|
use crate::event::{Event, KeyEvent, KeyModifier, ActionType};
|
||||||
use crate::event::KeyModifier::*;
|
use crate::event::KeyModifier::*;
|
||||||
use std::ffi::CString;
|
use std::ffi::{CString, CStr};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use log::{info, error};
|
use log::{info, error};
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
@ -94,14 +94,19 @@ extern fn keypress_callback(_self: *mut c_void, raw_buffer: *const u8, len: i32,
|
||||||
let _self = _self as *mut MacContext;
|
let _self = _self as *mut MacContext;
|
||||||
|
|
||||||
if is_modifier == 0 { // Char event
|
if is_modifier == 0 { // Char event
|
||||||
// Convert the received buffer to a character
|
// Convert the received buffer to a string
|
||||||
let buffer = std::slice::from_raw_parts(raw_buffer, len as usize);
|
let c_str = CStr::from_ptr(raw_buffer as (*const c_char));
|
||||||
let r = String::from_utf8_lossy(buffer).chars().nth(0);
|
let char_str = c_str.to_str();
|
||||||
|
|
||||||
// Send the char through the channel
|
// Send the char through the channel
|
||||||
if let Some(c) = r {
|
match char_str {
|
||||||
let event = Event::Key(KeyEvent::Char(c));
|
Ok(char_str) => {
|
||||||
(*_self).send_channel.send(event).unwrap();
|
let event = Event::Key(KeyEvent::Char(char_str.to_owned()));
|
||||||
|
(*_self).send_channel.send(event).unwrap();
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
error!("Unable to receive char: {}",e);
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}else{ // Modifier event
|
}else{ // Modifier event
|
||||||
let modifier: Option<KeyModifier> = match key_code {
|
let modifier: Option<KeyModifier> = match key_code {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user