win, translate mode, check dead code
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
cf121bdf47
commit
6e54cd2e6b
@ -1382,25 +1382,23 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
text: translate('Ratio'),
|
||||
optionsGetter: () {
|
||||
List<MenuEntryRadioOption> list = [];
|
||||
List<String> modes = ["legacy"];
|
||||
List<KeyboardModeMenu> modes = [
|
||||
KeyboardModeMenu(key: 'legacy', menu: 'Legacy mode'),
|
||||
KeyboardModeMenu(key: 'map', menu: 'Map mode'),
|
||||
KeyboardModeMenu(key: 'translate', menu: 'Translate mode'),
|
||||
];
|
||||
|
||||
if (bind.sessionIsKeyboardModeSupported(id: widget.id, mode: "map")) {
|
||||
modes.add("map");
|
||||
}
|
||||
|
||||
for (String mode in modes) {
|
||||
if (mode == "legacy") {
|
||||
for (KeyboardModeMenu mode in modes) {
|
||||
if (bind.sessionIsKeyboardModeSupported(
|
||||
id: widget.id, mode: mode.key)) {
|
||||
list.add(MenuEntryRadioOption(
|
||||
text: translate('Legacy mode'), value: 'legacy'));
|
||||
} else if (mode == "map") {
|
||||
list.add(MenuEntryRadioOption(
|
||||
text: translate('Map mode'), value: 'map'));
|
||||
text: translate(mode.menu), value: mode.key));
|
||||
}
|
||||
}
|
||||
return list;
|
||||
},
|
||||
curOptionGetter: () async {
|
||||
return await bind.sessionGetKeyboardMode(id: widget.id) ?? "legacy";
|
||||
return await bind.sessionGetKeyboardMode(id: widget.id) ?? 'legacy';
|
||||
},
|
||||
optionSetter: (String oldValue, String newValue) async {
|
||||
await bind.sessionSetKeyboardMode(id: widget.id, value: newValue);
|
||||
@ -1689,3 +1687,10 @@ class _DraggableShowHideState extends State<_DraggableShowHide> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class KeyboardModeMenu {
|
||||
final String key;
|
||||
final String menu;
|
||||
|
||||
KeyboardModeMenu({required this.key, required this.menu});
|
||||
}
|
||||
|
@ -671,8 +671,8 @@ pub fn is_keyboard_mode_supported(keyboard_mode: &KeyboardMode, version_number:
|
||||
match keyboard_mode {
|
||||
KeyboardMode::Legacy => true,
|
||||
KeyboardMode::Map => version_number >= hbb_common::get_version_number("1.2.0"),
|
||||
KeyboardMode::Translate => false,
|
||||
KeyboardMode::Auto => false,
|
||||
KeyboardMode::Translate => version_number >= hbb_common::get_version_number("1.2.0"),
|
||||
KeyboardMode::Auto => version_number >= hbb_common::get_version_number("1.2.0"),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -387,7 +387,10 @@ pub fn event_to_key_events(event: &Event, lock_modes: Option<i32>) -> Vec<KeyEve
|
||||
}
|
||||
}
|
||||
|
||||
println!("REMOVE ME ========================= key_events {:?}", &key_events);
|
||||
println!(
|
||||
"REMOVE ME ========================= key_events {:?}",
|
||||
&key_events
|
||||
);
|
||||
|
||||
key_events
|
||||
}
|
||||
@ -396,8 +399,7 @@ pub fn event_type_to_event(event_type: EventType) -> Event {
|
||||
Event {
|
||||
event_type,
|
||||
time: SystemTime::now(),
|
||||
name: None,
|
||||
unicode: Vec::new(),
|
||||
unicode: None,
|
||||
code: 0,
|
||||
scan_code: 0,
|
||||
}
|
||||
@ -571,7 +573,8 @@ pub fn legacy_keyboard_mode(event: &Event, mut key_event: KeyEvent) -> Vec<KeyEv
|
||||
if let Some(k) = control_key {
|
||||
key_event.set_control_key(k);
|
||||
} else {
|
||||
let mut chr = match event.name {
|
||||
let name = event.unicode.as_ref().and_then(|unicode|unicode.name.clone());
|
||||
let mut chr = match &name {
|
||||
Some(ref s) => {
|
||||
if s.len() <= 2 {
|
||||
// exclude chinese characters
|
||||
@ -717,51 +720,25 @@ pub fn map_keyboard_mode(event: &Event, mut key_event: KeyEvent) -> Option<KeyEv
|
||||
Some(key_event)
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
fn is_modifier_code(scan_code: u32) -> bool {
|
||||
match scan_code {
|
||||
// Alt | AltGr | ControlLeft | ControlRight | ShiftLeft | ShiftRight | MetaLeft | MetaRight
|
||||
0x38 | 0xE038 | 0x1D | 0xE01D | 0x2A | 0x36 | 0xE05B | 0xE05C => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn is_modifier_code(key_code: u32) -> bool {
|
||||
match scan_code {
|
||||
64 | 108 | 37 | 105 | 50 | 62 | 133 | 134 => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn is_modifier_code(key_code: u32) -> bool {
|
||||
match scan_code {
|
||||
0x3A | 0x3D | 0x3B | 0x3E | 0x38 | 0x3C | 0x37 | 0x36 => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn translate_keyboard_mode(event: &Event, key_event: KeyEvent) -> Vec<KeyEvent> {
|
||||
#[cfg(target_os = "windows")]
|
||||
let is_modifier = is_modifier_code(event.scan_code);
|
||||
#[cfg(target_os = "linux")]
|
||||
let is_modifier = is_modifier_code(event.key_code);
|
||||
#[cfg(target_os = "macos")]
|
||||
let is_modifier = is_modifier_code(event.key_code);
|
||||
|
||||
let mut events: Vec<KeyEvent> = Vec::new();
|
||||
if is_modifier {
|
||||
match &event.unicode {
|
||||
Some(unicode_info) => {
|
||||
if !unicode_info.is_dead {
|
||||
for code in &unicode_info.unicode {
|
||||
let mut evt = key_event.clone();
|
||||
evt.set_unicode(*code as _);
|
||||
events.push(evt);
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
if events.is_empty() {
|
||||
if let Some(evt) = map_keyboard_mode(event, key_event) {
|
||||
events.push(evt);
|
||||
}
|
||||
return events;
|
||||
}
|
||||
|
||||
for unicode in &event.unicode {
|
||||
let mut evt = key_event.clone();
|
||||
evt.set_unicode(*unicode as _);
|
||||
events.push(evt);
|
||||
}
|
||||
events
|
||||
}
|
||||
|
@ -423,7 +423,7 @@ impl<T: InvokeUiSession> Session<T> {
|
||||
|
||||
pub fn handle_flutter_key_event(
|
||||
&self,
|
||||
name: &str,
|
||||
_name: &str,
|
||||
keycode: i32,
|
||||
scancode: i32,
|
||||
lock_modes: i32,
|
||||
@ -448,8 +448,7 @@ impl<T: InvokeUiSession> Session<T> {
|
||||
};
|
||||
let event = Event {
|
||||
time: std::time::SystemTime::now(),
|
||||
name: Option::Some(name.to_owned()),
|
||||
unicode: Vec::new(),
|
||||
unicode: None,
|
||||
code: keycode as _,
|
||||
scan_code: scancode as _,
|
||||
event_type: event_type,
|
||||
|
Loading…
Reference in New Issue
Block a user