fix physical keyboard on mobile does not work

This commit is contained in:
csf 2023-02-09 23:14:24 +09:00
parent 2a0c9699e8
commit 58f6748134
3 changed files with 44 additions and 33 deletions

View File

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hbb/models/state_model.dart';
import '../../common.dart';
import '../../models/input_model.dart';
class RawKeyFocusScope extends StatelessWidget {
@ -19,6 +20,13 @@ class RawKeyFocusScope extends StatelessWidget {
@override
Widget build(BuildContext context) {
final FocusOnKeyCallback? onKey;
if (isAndroid) {
onKey = inputModel.handleRawKeyEvent;
} else {
onKey = stateGlobal.grabKeyboard ? inputModel.handleRawKeyEvent : null;
}
return FocusScope(
autofocus: true,
child: Focus(
@ -26,8 +34,7 @@ class RawKeyFocusScope extends StatelessWidget {
canRequestFocus: true,
focusNode: focusNode,
onFocusChange: onFocusChange,
onKey:
stateGlobal.grabKeyboard ? inputModel.handleRawKeyEvent : null,
onKey: onKey,
child: child));
}
}

View File

@ -581,9 +581,10 @@ class _RemotePageState extends State<RemotePage> {
child: Text(translate('Reset canvas')), value: 'reset_canvas'));
}
if (perms['keyboard'] != false) {
more.add(PopupMenuItem<String>(
child: Text(translate('Physical Keyboard Input Mode')),
value: 'input-mode'));
// * Currently mobile does not enable map mode
// more.add(PopupMenuItem<String>(
// child: Text(translate('Physical Keyboard Input Mode')),
// value: 'input-mode'));
if (pi.platform == kPeerPlatformLinux || pi.sasEnabled) {
more.add(PopupMenuItem<String>(
child: Text('${translate('Insert')} Ctrl + Alt + Del'),
@ -638,8 +639,9 @@ class _RemotePageState extends State<RemotePage> {
);
if (value == 'cad') {
bind.sessionCtrlAltDel(id: widget.id);
} else if (value == 'input-mode') {
changePhysicalKeyboardInputMode();
// * Currently mobile does not enable map mode
// } else if (value == 'input-mode') {
// changePhysicalKeyboardInputMode();
} else if (value == 'lock') {
bind.sessionLockScreen(id: widget.id);
} else if (value == 'block-input') {
@ -701,26 +703,26 @@ class _RemotePageState extends State<RemotePage> {
}));
}
void changePhysicalKeyboardInputMode() async {
var current = await bind.sessionGetKeyboardMode(id: widget.id) ?? "legacy";
gFFI.dialogManager.show((setState, close) {
void setMode(String? v) async {
await bind.sessionPeerOption(
id: widget.id, name: "keyboard-mode", value: v ?? "");
setState(() => current = v ?? '');
Future.delayed(Duration(milliseconds: 300), close);
}
return CustomAlertDialog(
title: Text(translate('Physical Keyboard Input Mode')),
content: Column(mainAxisSize: MainAxisSize.min, children: [
getRadio('Legacy mode', 'legacy', current, setMode,
contentPadding: EdgeInsets.zero),
getRadio('Map mode', 'map', current, setMode,
contentPadding: EdgeInsets.zero),
]));
}, clickMaskDismiss: true);
}
// * Currently mobile does not enable map mode
// void changePhysicalKeyboardInputMode() async {
// var current = await bind.sessionGetKeyboardMode(id: widget.id) ?? "legacy";
// gFFI.dialogManager.show((setState, close) {
// void setMode(String? v) async {
// await bind.sessionSetKeyboardMode(id: widget.id, value: v ?? "");
// setState(() => current = v ?? '');
// Future.delayed(Duration(milliseconds: 300), close);
// }
//
// return CustomAlertDialog(
// title: Text(translate('Physical Keyboard Input Mode')),
// content: Column(mainAxisSize: MainAxisSize.min, children: [
// getRadio('Legacy mode', 'legacy', current, setMode,
// contentPadding: EdgeInsets.zero),
// getRadio('Map mode', 'map', current, setMode,
// contentPadding: EdgeInsets.zero),
// ]));
// }, clickMaskDismiss: true);
// }
Widget getHelpTools() {
final keyboard = isKeyboardShown();

View File

@ -58,9 +58,12 @@ class InputModel {
InputModel(this.parent);
KeyEventResult handleRawKeyEvent(FocusNode data, RawKeyEvent e) {
// * Currently mobile does not enable map mode
if (isDesktop) {
bind.sessionGetKeyboardMode(id: id).then((result) {
keyboardMode = result.toString();
});
}
final key = e.logicalKey;
if (e is RawKeyDownEvent) {
@ -93,10 +96,9 @@ class InputModel {
}
}
if (keyboardMode == 'map') {
// * Currently mobile does not enable map mode
if (isDesktop && keyboardMode == 'map') {
mapKeyboardMode(e);
} else if (keyboardMode == 'translate') {
legacyKeyboardMode(e);
} else {
legacyKeyboardMode(e);
}