Add windows support to unicode matches
This commit is contained in:
parent
a19b90e50a
commit
de296b77ea
|
@ -250,7 +250,7 @@ LRESULT CALLBACK window_procedure(HWND window, unsigned int msg, WPARAM wp, LPAR
|
|||
// We need to call the callback in two different ways based on the type of key
|
||||
// The only modifier we use that has a result > 0 is the BACKSPACE, so we have to consider it.
|
||||
if (result >= 1 && raw->data.keyboard.VKey != VK_BACK) {
|
||||
keypress_callback(manager_instance, reinterpret_cast<int32_t*>(buffer.data()), buffer.size(), 0, raw->data.keyboard.VKey, is_key_down);
|
||||
keypress_callback(manager_instance, reinterpret_cast<uint16_t*>(buffer.data()), buffer.size(), 0, raw->data.keyboard.VKey, is_key_down);
|
||||
}else{
|
||||
keypress_callback(manager_instance, nullptr, 0, 1, raw->data.keyboard.VKey, is_key_down);
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ extern "C" int32_t initialize(void * self, wchar_t * ico_path, wchar_t * bmp_pat
|
|||
* Called when a new keypress is made, the first argument is an int array,
|
||||
* while the second is the size of the array.
|
||||
*/
|
||||
typedef void (*KeypressCallback)(void * self, int32_t *buffer, int32_t len, int32_t is_modifier, int32_t key_code, int32_t is_key_down);
|
||||
typedef void (*KeypressCallback)(void * self, uint16_t *buffer, int32_t len, int32_t is_modifier, int32_t key_code, int32_t is_key_down);
|
||||
extern KeypressCallback keypress_callback;
|
||||
|
||||
/*
|
||||
|
|
|
@ -49,7 +49,7 @@ extern {
|
|||
pub fn set_clipboard(payload: *const u16) -> i32;
|
||||
|
||||
// KEYBOARD
|
||||
pub fn register_keypress_callback(cb: extern fn(_self: *mut c_void, *const i32,
|
||||
pub fn register_keypress_callback(cb: extern fn(_self: *mut c_void, *const u16,
|
||||
i32, i32, i32, i32));
|
||||
|
||||
pub fn eventloop();
|
||||
|
|
|
@ -23,8 +23,8 @@ use crate::event::{Event, KeyEvent, KeyModifier, ActionType};
|
|||
use crate::event::KeyModifier::*;
|
||||
use std::ffi::c_void;
|
||||
use std::{fs};
|
||||
use widestring::U16CString;
|
||||
use log::{info};
|
||||
use widestring::{U16CString, U16CStr};
|
||||
use log::{info, error};
|
||||
|
||||
const BMP_BINARY : &[u8] = include_bytes!("../res/win/espanso.bmp");
|
||||
const ICO_BINARY : &[u8] = include_bytes!("../res/win/espanso.ico");
|
||||
|
@ -102,20 +102,31 @@ impl super::Context for WindowsContext {
|
|||
|
||||
// Native bridge code
|
||||
|
||||
extern fn keypress_callback(_self: *mut c_void, raw_buffer: *const i32, len: i32,
|
||||
extern fn keypress_callback(_self: *mut c_void, raw_buffer: *const u16, len: i32,
|
||||
is_modifier: i32, key_code: i32, is_key_down: i32) {
|
||||
unsafe {
|
||||
let _self = _self as *mut WindowsContext;
|
||||
if is_key_down != 0 { // KEY DOWN 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 r = std::char::from_u32(buffer[0] as u32);
|
||||
let c_string = U16CStr::from_slice_with_nul(buffer);
|
||||
|
||||
// Send the char through the channel
|
||||
if let Some(c) = r {
|
||||
let event = Event::Key(KeyEvent::Char(c));
|
||||
(*_self).send_channel.send(event).unwrap();
|
||||
if let Ok(c_string) = c_string {
|
||||
let string = c_string.to_string();
|
||||
|
||||
// Send the char through the channel
|
||||
match string {
|
||||
Ok(string) => {
|
||||
let event = Event::Key(KeyEvent::Char(string));
|
||||
(*_self).send_channel.send(event).unwrap();
|
||||
},
|
||||
Err(e) => {
|
||||
error!("Unable to receive char: {}",e);
|
||||
},
|
||||
}
|
||||
}else{
|
||||
error!("unable to decode widechar");
|
||||
}
|
||||
}
|
||||
}else{ // KEY UP event
|
||||
|
|
Loading…
Reference in New Issue
Block a user