From 673991d7d5f96b54bd19a2874157981a877826b7 Mon Sep 17 00:00:00 2001 From: csf Date: Thu, 24 Feb 2022 15:59:03 +0800 Subject: [PATCH] update touch mode --- lib/home_page.dart | 30 +++++++-------- lib/remote_page.dart | 72 ++++++++++++++--------------------- lib/widgets/gesture_help.dart | 21 ++++++---- 3 files changed, 57 insertions(+), 66 deletions(-) diff --git a/lib/home_page.dart b/lib/home_page.dart index 988859087..f29e18a66 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -54,25 +54,25 @@ class _HomePageState extends State { this._menuPos = RelativeRect.fromLTRB(x, y, x, y); }, onTap: () { + List> items = []; + items.add(PopupMenuItem( + child: Text(translate('ID Server')), + value: 'id_server')); + if (isAndroid){ + items.add( + PopupMenuItem( + child: Text(translate('Share My Screen')), + value: 'server') + ); + } + items.add(PopupMenuItem( + child: Text(translate('About') + ' RustDesk'), + value: 'about')); () async { var value = await showMenu( context: context, position: this._menuPos, - items: [ - PopupMenuItem( - child: Text(translate('ID Server')), - value: 'id_server'), - // TODO test - isAndroid - ? PopupMenuItem( - child: Text(translate('Share My Screen')), - value: 'server') - : PopupMenuItem( - child: SizedBox.shrink(), value: ''), - PopupMenuItem( - child: Text(translate('About') + ' RustDesk'), - value: 'about'), - ], + items: items, elevation: 8, ); if (value == 'id_server') { diff --git a/lib/remote_page.dart b/lib/remote_page.dart index 981828597..30979be49 100644 --- a/lib/remote_page.dart +++ b/lib/remote_page.dart @@ -29,7 +29,6 @@ class _RemotePageState extends State { double _bottom = 0; String _value = ''; double _scale = 1; - bool _mouseTools = false; var _more = true; var _fn = false; @@ -204,7 +203,6 @@ class _RemotePageState extends State { void openKeyboard() { // destroy first, so that our _value trick can work _value = initText; - resetMouse(); setState(() => _showEdit = false); _timer?.cancel(); _timer = Timer(Duration(milliseconds: 30), () { @@ -220,10 +218,6 @@ class _RemotePageState extends State { }); } - void resetMouse() { - _mouseTools = false; - } - @override Widget build(BuildContext context) { final pi = Provider.of(context).pi; @@ -300,29 +294,11 @@ class _RemotePageState extends State { color: Colors.white, icon: Icon(Icons.keyboard), onPressed: openKeyboard), - Container( - color: _mouseTools ? Colors.blue[500] : null, - child: IconButton( - color: Colors.white, - icon: Icon(Icons.mouse), - onPressed: () { - setState(() { - _mouseTools = !_mouseTools; - resetTool(); - }); - }, - )), IconButton( color: Colors.white, - icon: Icon(Icons.help), - onPressed: () { - setState(() => _showEdit = false); - showModalBottomSheet( - backgroundColor: MyTheme.grayBg, - context: context, - builder: (context) => - GestureHelp(initTouchMode: _touchMode)); - }, + icon: Icon( + _touchMode ? Icons.touch_app : Icons.mouse), + onPressed: changeTouchMode, ) ]) + [ @@ -518,18 +494,6 @@ class _RemotePageState extends State { more.add(PopupMenuItem( child: Text(translate('Paste')), value: 'paste')); } - more.add(PopupMenuItem( - child: Row( - children: ([ - Container(width: 100.0, child: Text(translate('Touch mode'))), - Padding(padding: EdgeInsets.symmetric(horizontal: 16.0)), - Icon( - _touchMode - ? Icons.check_box_outlined - : Icons.check_box_outline_blank, - color: MyTheme.accent) - ])), - value: 'touch_mode')); more.add(PopupMenuItem( child: Text(translate('Reset canvas')), value: 'reset_canvas')); } @@ -580,23 +544,43 @@ class _RemotePageState extends State { } else { showSetOSPassword(context, true); } - } else if (value == 'touch_mode') { - _touchMode = !_touchMode; - final v = _touchMode ? 'Y' : ''; - FFI.setByName('peer_option', '{"name": "touch-mode", "value": "$v"}'); } else if (value == 'reset_canvas') { FFI.cursorModel.reset(); } }(); } + void changeTouchMode() { + setState(() => _showEdit = false); + showModalBottomSheet( + backgroundColor: MyTheme.grayBg, + isScrollControlled: true, + context: context, + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.vertical(top: Radius.circular(5))), + builder: (context) => DraggableScrollableSheet( + expand: false, + builder: (context, scrollController) { + return SingleChildScrollView( + padding: EdgeInsets.symmetric(vertical: 10), + child: GestureHelp( + touchMode: _touchMode, + onTouchModeChange: (t) { + setState(() => _touchMode = t); + final v = _touchMode ? 'Y' : ''; + FFI.setByName('peer_option', + '{"name": "touch-mode", "value": "$v"}'); + })); + })); + } + void close() { msgbox('', 'Close', 'Are you sure to close the connection?', context); } Widget getHelpTools() { final keyboard = isKeyboardShown(); - if (!_mouseTools && !keyboard) { + if (!keyboard) { return SizedBox(); } final size = MediaQuery.of(context).size; diff --git a/lib/widgets/gesture_help.dart b/lib/widgets/gesture_help.dart index 7dd23c0ed..05ae537f3 100644 --- a/lib/widgets/gesture_help.dart +++ b/lib/widgets/gesture_help.dart @@ -32,9 +32,12 @@ class GestureIcons { IconData(0xe691, fontFamily: _family); } +typedef OnTouchModeChange = void Function(bool); + class GestureHelp extends StatefulWidget { - GestureHelp({Key? key,this.initTouchMode = false}) : super(key: key); - final initTouchMode; + GestureHelp({Key? key,required this.touchMode,required this.onTouchModeChange}) : super(key: key); + final bool touchMode; + final OnTouchModeChange onTouchModeChange; @override State createState() => _GestureHelpState(); } @@ -45,7 +48,7 @@ class _GestureHelpState extends State { @override void initState() { - _touchMode = widget.initTouchMode; + _touchMode = widget.touchMode; _selectedIndex = _touchMode ? 1 : 0; super.initState(); } @@ -61,20 +64,24 @@ class _GestureHelpState extends State { children: [ ToggleSwitch( initialLabelIndex: _selectedIndex, + inactiveBgColor: MyTheme.darkGray, totalSwitches: 2, minWidth: 130, fontSize: 15, iconSize: 20, labels: ["触摸板模式", "触屏模式"], icons: [ - GestureIcons.icon_mouse, - GestureIcons.icon_Tablet_Touch + Icons.mouse, + Icons.touch_app ], onToggle: (index) { debugPrint(index.toString()); setState(() { - _touchMode = index == 0 ? false : true; - _selectedIndex = index ?? 0; + if (_selectedIndex != index){ + _selectedIndex = index ?? 0; + _touchMode = index == 0 ? false : true; + widget.onTouchModeChange(_touchMode); + } }); }, ),