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

View File

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

View File

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