Merge pull request #1202 from fufesou/flutter_desktop_remote_menus

Flutter desktop remote menus
This commit is contained in:
RustDesk 2022-08-08 09:33:47 +08:00 committed by GitHub
commit d173fd9cec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 106 additions and 95 deletions

View File

@ -58,6 +58,8 @@ class _ConnectionPageState extends State<ConnectionPage> {
@override
Widget build(BuildContext context) {
Provider.of<FfiModel>(context);
if (_idController.text.isEmpty) _idController.text = gFFI.getId();
return Container(
decoration: BoxDecoration(color: isDarkTheme() ? null : MyTheme.grayBg),

View File

@ -236,15 +236,49 @@ class _RemotePageState extends State<RemotePage>
_ffi.inputKey(label, down: down, press: press ?? false);
}
Widget buildBody(FfiModel ffiModel) {
final hasDisplays = ffiModel.pi.displays.length > 0;
final hideKeyboard = isKeyboardShown() && _showEdit;
final showActionButton = !_showBar || hideKeyboard;
final keyboard = ffiModel.permissions['keyboard'] != false;
return Scaffold(
// resizeToAvoidBottomInset: true,
floatingActionButton: !showActionButton
? null
: FloatingActionButton(
mini: !hideKeyboard,
child:
Icon(hideKeyboard ? Icons.expand_more : Icons.expand_less),
backgroundColor: MyTheme.accent,
onPressed: () {
setState(() {
if (hideKeyboard) {
_showEdit = false;
_ffi.invokeMethod("enable_soft_keyboard", false);
_mobileFocusNode.unfocus();
_physicalFocusNode.requestFocus();
} else {
_showBar = !_showBar;
}
});
}),
bottomNavigationBar: _showBar && hasDisplays ? getBottomAppBar() : null,
body: Overlay(
initialEntries: [
OverlayEntry(builder: (context) {
return Container(
color: Colors.black,
child: getBodyForDesktopWithListener(keyboard));
})
],
));
}
@override
Widget build(BuildContext context) {
super.build(context);
Provider.of<CanvasModel>(context, listen: false).tabBarHeight =
super.widget.tabBarHeight;
final pi = Provider.of<FfiModel>(context).pi;
final hideKeyboard = isKeyboardShown() && _showEdit;
final showActionButton = !_showBar || hideKeyboard;
final keyboard = _ffi.ffiModel.permissions['keyboard'] != false;
return WillPopScope(
onWillPop: () async {
clientClose();
@ -257,47 +291,11 @@ class _RemotePageState extends State<RemotePage>
ChangeNotifierProvider.value(value: _ffi.cursorModel),
ChangeNotifierProvider.value(value: _ffi.canvasModel),
],
child: getRawPointerAndKeyBody(
keyboard,
Scaffold(
// resizeToAvoidBottomInset: true,
floatingActionButton: !showActionButton
? null
: FloatingActionButton(
mini: !hideKeyboard,
child: Icon(hideKeyboard
? Icons.expand_more
: Icons.expand_less),
backgroundColor: MyTheme.accent,
onPressed: () {
setState(() {
if (hideKeyboard) {
_showEdit = false;
_ffi.invokeMethod(
"enable_soft_keyboard", false);
_mobileFocusNode.unfocus();
_physicalFocusNode.requestFocus();
} else {
_showBar = !_showBar;
}
});
}),
bottomNavigationBar: _showBar && pi.displays.length > 0
? getBottomAppBar(keyboard)
: null,
body: Overlay(
initialEntries: [
OverlayEntry(builder: (context) {
return Container(
color: Colors.black,
child: getBodyForDesktopWithListener(keyboard));
})
],
))),
));
child: getRawPointerAndKeyBody(Consumer<FfiModel>(
builder: (context, ffiModel, _child) => buildBody(ffiModel)))));
}
Widget getRawPointerAndKeyBody(bool keyboard, Widget child) {
Widget getRawPointerAndKeyBody(Widget child) {
return Listener(
onPointerHover: (e) {
if (e.kind != ui.PointerDeviceKind.mouse) return;
@ -352,8 +350,11 @@ class _RemotePageState extends State<RemotePage>
'{"id": "${widget.id}", "type": "wheel", "x": "$dx", "y": "$dy"}');
}
},
child: MouseRegion(
cursor: keyboard ? SystemMouseCursors.none : MouseCursor.defer,
child: Consumer<FfiModel>(
builder: (context, FfiModel, _child) => MouseRegion(
cursor: FfiModel.permissions['keyboard'] != false
? SystemMouseCursors.none
: MouseCursor.defer,
child: FocusScope(
autofocus: true,
child: Focus(
@ -397,10 +398,10 @@ class _RemotePageState extends State<RemotePage>
}
return KeyEventResult.handled;
},
child: child))));
child: child)))));
}
Widget getBottomAppBar(bool keyboard) {
Widget? getBottomAppBar() {
return BottomAppBar(
elevation: 10,
color: MyTheme.accent,
@ -515,6 +516,7 @@ class _RemotePageState extends State<RemotePage>
));
}
paints.add(getHelpTools());
return MouseRegion(
onEnter: (evt) {
bind.hostStopSystemKeyPropagate(stopped: false);
@ -878,7 +880,14 @@ class ImagePainter extends CustomPainter {
void paint(Canvas canvas, Size size) {
if (image == null) return;
canvas.scale(scale, scale);
canvas.drawImage(image!, new Offset(x, y), new Paint());
// https://github.com/flutter/flutter/issues/76187#issuecomment-784628161
var paint = new Paint();
if (scale > 1.00001) {
paint.filterQuality = FilterQuality.high;
} else if (scale < 0.99999) {
paint.filterQuality = FilterQuality.medium;
}
canvas.drawImage(image!, new Offset(x, y), paint);
}
@override