fix wayland map mode
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
af32998af6
commit
f56adbb56e
@ -117,44 +117,41 @@ class InputModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void mapKeyboardMode(RawKeyEvent e) {
|
void mapKeyboardMode(RawKeyEvent e) {
|
||||||
int scanCode;
|
int positionCode = -1;
|
||||||
int keyCode;
|
int platformCode = -1;
|
||||||
bool down;
|
bool down;
|
||||||
|
|
||||||
if (e.data is RawKeyEventDataMacOs) {
|
if (e.data is RawKeyEventDataMacOs) {
|
||||||
RawKeyEventDataMacOs newData = e.data as RawKeyEventDataMacOs;
|
RawKeyEventDataMacOs newData = e.data as RawKeyEventDataMacOs;
|
||||||
scanCode = newData.keyCode;
|
positionCode = newData.keyCode;
|
||||||
keyCode = newData.keyCode;
|
platformCode = newData.keyCode;
|
||||||
} else if (e.data is RawKeyEventDataWindows) {
|
} else if (e.data is RawKeyEventDataWindows) {
|
||||||
RawKeyEventDataWindows newData = e.data as RawKeyEventDataWindows;
|
RawKeyEventDataWindows newData = e.data as RawKeyEventDataWindows;
|
||||||
scanCode = newData.scanCode;
|
positionCode = newData.scanCode;
|
||||||
keyCode = newData.keyCode;
|
platformCode = newData.keyCode;
|
||||||
} else if (e.data is RawKeyEventDataLinux) {
|
} else if (e.data is RawKeyEventDataLinux) {
|
||||||
RawKeyEventDataLinux newData = e.data as RawKeyEventDataLinux;
|
RawKeyEventDataLinux newData = e.data as RawKeyEventDataLinux;
|
||||||
// scanCode and keyCode of RawKeyEventDataLinux are incorrect.
|
// scanCode and keyCode of RawKeyEventDataLinux are incorrect.
|
||||||
// 1. scanCode means keycode
|
// 1. scanCode means keycode
|
||||||
// 2. keyCode means keysym
|
// 2. keyCode means keysym
|
||||||
scanCode = 0;
|
positionCode = newData.scanCode;
|
||||||
keyCode = newData.scanCode;
|
platformCode = newData.keyCode;
|
||||||
} else if (e.data is RawKeyEventDataAndroid) {
|
} else if (e.data is RawKeyEventDataAndroid) {
|
||||||
RawKeyEventDataAndroid newData = e.data as RawKeyEventDataAndroid;
|
RawKeyEventDataAndroid newData = e.data as RawKeyEventDataAndroid;
|
||||||
scanCode = newData.scanCode + 8;
|
positionCode = newData.scanCode + 8;
|
||||||
keyCode = newData.keyCode;
|
platformCode = newData.keyCode;
|
||||||
} else {
|
} else {}
|
||||||
scanCode = -1;
|
|
||||||
keyCode = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e is RawKeyDownEvent) {
|
if (e is RawKeyDownEvent) {
|
||||||
down = true;
|
down = true;
|
||||||
} else {
|
} else {
|
||||||
down = false;
|
down = false;
|
||||||
}
|
}
|
||||||
inputRawKey(e.character ?? '', keyCode, scanCode, down);
|
inputRawKey(e.character ?? '', platformCode, positionCode, down);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send raw Key Event
|
/// Send raw Key Event
|
||||||
void inputRawKey(String name, int keyCode, int scanCode, bool down) {
|
void inputRawKey(String name, int platformCode, int positionCode, bool down) {
|
||||||
const capslock = 1;
|
const capslock = 1;
|
||||||
const numlock = 2;
|
const numlock = 2;
|
||||||
const scrolllock = 3;
|
const scrolllock = 3;
|
||||||
@ -174,8 +171,8 @@ class InputModel {
|
|||||||
bind.sessionHandleFlutterKeyEvent(
|
bind.sessionHandleFlutterKeyEvent(
|
||||||
id: id,
|
id: id,
|
||||||
name: name,
|
name: name,
|
||||||
keycode: keyCode,
|
platformCode: platformCode,
|
||||||
scancode: scanCode,
|
positionCode: positionCode,
|
||||||
lockModes: lockModes,
|
lockModes: lockModes,
|
||||||
downOrUp: down);
|
downOrUp: down);
|
||||||
}
|
}
|
||||||
|
@ -332,13 +332,13 @@ pub fn session_switch_display(id: String, value: i32) {
|
|||||||
pub fn session_handle_flutter_key_event(
|
pub fn session_handle_flutter_key_event(
|
||||||
id: String,
|
id: String,
|
||||||
name: String,
|
name: String,
|
||||||
keycode: i32,
|
platform_code: i32,
|
||||||
scancode: i32,
|
position_code: i32,
|
||||||
lock_modes: i32,
|
lock_modes: i32,
|
||||||
down_or_up: bool,
|
down_or_up: bool,
|
||||||
) {
|
) {
|
||||||
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
|
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
|
||||||
session.handle_flutter_key_event(&name, keycode, scancode, lock_modes, down_or_up);
|
session.handle_flutter_key_event(&name, platform_code, position_code, lock_modes, down_or_up);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -529,19 +529,19 @@ impl<T: InvokeUiSession> Session<T> {
|
|||||||
pub fn handle_flutter_key_event(
|
pub fn handle_flutter_key_event(
|
||||||
&self,
|
&self,
|
||||||
_name: &str,
|
_name: &str,
|
||||||
keycode: i32,
|
platform_code: i32,
|
||||||
scancode: i32,
|
position_code: i32,
|
||||||
lock_modes: i32,
|
lock_modes: i32,
|
||||||
down_or_up: bool,
|
down_or_up: bool,
|
||||||
) {
|
) {
|
||||||
if scancode < 0 || keycode < 0 {
|
if position_code < 0 || platform_code < 0 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let keycode: KeyCode = keycode as _;
|
let platform_code: KeyCode = platform_code as _;
|
||||||
let scancode: u32 = scancode as _;
|
let position_code: u32 = position_code as _;
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
let key = rdev::key_from_code(keycode) as rdev::Key;
|
let key = rdev::key_from_code(position_code) as rdev::Key;
|
||||||
// Windows requires special handling
|
// Windows requires special handling
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let key = rdev::get_win_key(keycode, scancode);
|
let key = rdev::get_win_key(keycode, scancode);
|
||||||
@ -554,8 +554,8 @@ impl<T: InvokeUiSession> Session<T> {
|
|||||||
let event = Event {
|
let event = Event {
|
||||||
time: SystemTime::now(),
|
time: SystemTime::now(),
|
||||||
unicode: None,
|
unicode: None,
|
||||||
platform_code: keycode as _,
|
platform_code: platform_code as _,
|
||||||
position_code: scancode as _,
|
position_code: position_code as _,
|
||||||
event_type: event_type,
|
event_type: event_type,
|
||||||
};
|
};
|
||||||
keyboard::client::process_event(&event, Some(lock_modes));
|
keyboard::client::process_event(&event, Some(lock_modes));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user