Merge pull request #3921 from fufesou/fix/wayland_map_mode
fix wayland map mode
This commit is contained in:
commit
8b78510ea7
@ -117,44 +117,41 @@ class InputModel {
|
||||
}
|
||||
|
||||
void mapKeyboardMode(RawKeyEvent e) {
|
||||
int scanCode;
|
||||
int keyCode;
|
||||
int positionCode = -1;
|
||||
int platformCode = -1;
|
||||
bool down;
|
||||
|
||||
if (e.data is RawKeyEventDataMacOs) {
|
||||
RawKeyEventDataMacOs newData = e.data as RawKeyEventDataMacOs;
|
||||
scanCode = newData.keyCode;
|
||||
keyCode = newData.keyCode;
|
||||
positionCode = newData.keyCode;
|
||||
platformCode = newData.keyCode;
|
||||
} else if (e.data is RawKeyEventDataWindows) {
|
||||
RawKeyEventDataWindows newData = e.data as RawKeyEventDataWindows;
|
||||
scanCode = newData.scanCode;
|
||||
keyCode = newData.keyCode;
|
||||
positionCode = newData.scanCode;
|
||||
platformCode = newData.keyCode;
|
||||
} else if (e.data is RawKeyEventDataLinux) {
|
||||
RawKeyEventDataLinux newData = e.data as RawKeyEventDataLinux;
|
||||
// scanCode and keyCode of RawKeyEventDataLinux are incorrect.
|
||||
// 1. scanCode means keycode
|
||||
// 2. keyCode means keysym
|
||||
scanCode = 0;
|
||||
keyCode = newData.scanCode;
|
||||
positionCode = newData.scanCode;
|
||||
platformCode = newData.keyCode;
|
||||
} else if (e.data is RawKeyEventDataAndroid) {
|
||||
RawKeyEventDataAndroid newData = e.data as RawKeyEventDataAndroid;
|
||||
scanCode = newData.scanCode + 8;
|
||||
keyCode = newData.keyCode;
|
||||
} else {
|
||||
scanCode = -1;
|
||||
keyCode = -1;
|
||||
}
|
||||
positionCode = newData.scanCode + 8;
|
||||
platformCode = newData.keyCode;
|
||||
} else {}
|
||||
|
||||
if (e is RawKeyDownEvent) {
|
||||
down = true;
|
||||
} else {
|
||||
down = false;
|
||||
}
|
||||
inputRawKey(e.character ?? '', keyCode, scanCode, down);
|
||||
inputRawKey(e.character ?? '', platformCode, positionCode, down);
|
||||
}
|
||||
|
||||
/// 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 numlock = 2;
|
||||
const scrolllock = 3;
|
||||
@ -174,8 +171,8 @@ class InputModel {
|
||||
bind.sessionHandleFlutterKeyEvent(
|
||||
id: id,
|
||||
name: name,
|
||||
keycode: keyCode,
|
||||
scancode: scanCode,
|
||||
platformCode: platformCode,
|
||||
positionCode: positionCode,
|
||||
lockModes: lockModes,
|
||||
downOrUp: down);
|
||||
}
|
||||
|
@ -332,13 +332,13 @@ pub fn session_switch_display(id: String, value: i32) {
|
||||
pub fn session_handle_flutter_key_event(
|
||||
id: String,
|
||||
name: String,
|
||||
keycode: i32,
|
||||
scancode: i32,
|
||||
platform_code: i32,
|
||||
position_code: i32,
|
||||
lock_modes: i32,
|
||||
down_or_up: bool,
|
||||
) {
|
||||
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(
|
||||
&self,
|
||||
_name: &str,
|
||||
keycode: i32,
|
||||
scancode: i32,
|
||||
platform_code: i32,
|
||||
position_code: i32,
|
||||
lock_modes: i32,
|
||||
down_or_up: bool,
|
||||
) {
|
||||
if scancode < 0 || keycode < 0 {
|
||||
if position_code < 0 || platform_code < 0 {
|
||||
return;
|
||||
}
|
||||
let keycode: KeyCode = keycode as _;
|
||||
let scancode: u32 = scancode as _;
|
||||
let platform_code: KeyCode = platform_code as _;
|
||||
let position_code: u32 = position_code as _;
|
||||
|
||||
#[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
|
||||
#[cfg(target_os = "windows")]
|
||||
let key = rdev::get_win_key(keycode, scancode);
|
||||
@ -554,8 +554,8 @@ impl<T: InvokeUiSession> Session<T> {
|
||||
let event = Event {
|
||||
time: SystemTime::now(),
|
||||
unicode: None,
|
||||
platform_code: keycode as _,
|
||||
position_code: scancode as _,
|
||||
platform_code: platform_code as _,
|
||||
position_code: position_code as _,
|
||||
event_type: event_type,
|
||||
};
|
||||
keyboard::client::process_event(&event, Some(lock_modes));
|
||||
|
Loading…
x
Reference in New Issue
Block a user