update touch mode

This commit is contained in:
csf 2022-02-24 15:59:03 +08:00
parent 0de614bdb3
commit 673991d7d5
3 changed files with 57 additions and 66 deletions

View File

@ -54,25 +54,25 @@ class _HomePageState extends State<HomePage> {
this._menuPos = RelativeRect.fromLTRB(x, y, x, y); this._menuPos = RelativeRect.fromLTRB(x, y, x, y);
}, },
onTap: () { onTap: () {
List<PopupMenuItem<String>> items = [];
items.add(PopupMenuItem<String>(
child: Text(translate('ID Server')),
value: 'id_server'));
if (isAndroid){
items.add(
PopupMenuItem<String>(
child: Text(translate('Share My Screen')),
value: 'server')
);
}
items.add(PopupMenuItem<String>(
child: Text(translate('About') + ' RustDesk'),
value: 'about'));
() async { () async {
var value = await showMenu<dynamic>( var value = await showMenu<dynamic>(
context: context, context: context,
position: this._menuPos, position: this._menuPos,
items: [ items: items,
PopupMenuItem<String>(
child: Text(translate('ID Server')),
value: 'id_server'),
// TODO test
isAndroid
? PopupMenuItem<dynamic>(
child: Text(translate('Share My Screen')),
value: 'server')
: PopupMenuItem<dynamic>(
child: SizedBox.shrink(), value: ''),
PopupMenuItem<String>(
child: Text(translate('About') + ' RustDesk'),
value: 'about'),
],
elevation: 8, elevation: 8,
); );
if (value == 'id_server') { if (value == 'id_server') {

View File

@ -29,7 +29,6 @@ class _RemotePageState extends State<RemotePage> {
double _bottom = 0; double _bottom = 0;
String _value = ''; String _value = '';
double _scale = 1; double _scale = 1;
bool _mouseTools = false;
var _more = true; var _more = true;
var _fn = false; var _fn = false;
@ -204,7 +203,6 @@ class _RemotePageState extends State<RemotePage> {
void openKeyboard() { void openKeyboard() {
// destroy first, so that our _value trick can work // destroy first, so that our _value trick can work
_value = initText; _value = initText;
resetMouse();
setState(() => _showEdit = false); setState(() => _showEdit = false);
_timer?.cancel(); _timer?.cancel();
_timer = Timer(Duration(milliseconds: 30), () { _timer = Timer(Duration(milliseconds: 30), () {
@ -220,10 +218,6 @@ class _RemotePageState extends State<RemotePage> {
}); });
} }
void resetMouse() {
_mouseTools = false;
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final pi = Provider.of<FfiModel>(context).pi; final pi = Provider.of<FfiModel>(context).pi;
@ -300,29 +294,11 @@ class _RemotePageState extends State<RemotePage> {
color: Colors.white, color: Colors.white,
icon: Icon(Icons.keyboard), icon: Icon(Icons.keyboard),
onPressed: openKeyboard), onPressed: openKeyboard),
Container(
color: _mouseTools ? Colors.blue[500] : null,
child: IconButton(
color: Colors.white,
icon: Icon(Icons.mouse),
onPressed: () {
setState(() {
_mouseTools = !_mouseTools;
resetTool();
});
},
)),
IconButton( IconButton(
color: Colors.white, color: Colors.white,
icon: Icon(Icons.help), icon: Icon(
onPressed: () { _touchMode ? Icons.touch_app : Icons.mouse),
setState(() => _showEdit = false); onPressed: changeTouchMode,
showModalBottomSheet(
backgroundColor: MyTheme.grayBg,
context: context,
builder: (context) =>
GestureHelp(initTouchMode: _touchMode));
},
) )
]) + ]) +
<Widget>[ <Widget>[
@ -518,18 +494,6 @@ class _RemotePageState extends State<RemotePage> {
more.add(PopupMenuItem<String>( more.add(PopupMenuItem<String>(
child: Text(translate('Paste')), value: 'paste')); child: Text(translate('Paste')), value: 'paste'));
} }
more.add(PopupMenuItem<String>(
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<String>( more.add(PopupMenuItem<String>(
child: Text(translate('Reset canvas')), value: 'reset_canvas')); child: Text(translate('Reset canvas')), value: 'reset_canvas'));
} }
@ -580,23 +544,43 @@ class _RemotePageState extends State<RemotePage> {
} else { } else {
showSetOSPassword(context, true); 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') { } else if (value == 'reset_canvas') {
FFI.cursorModel.reset(); 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() { void close() {
msgbox('', 'Close', 'Are you sure to close the connection?', context); msgbox('', 'Close', 'Are you sure to close the connection?', context);
} }
Widget getHelpTools() { Widget getHelpTools() {
final keyboard = isKeyboardShown(); final keyboard = isKeyboardShown();
if (!_mouseTools && !keyboard) { if (!keyboard) {
return SizedBox(); return SizedBox();
} }
final size = MediaQuery.of(context).size; final size = MediaQuery.of(context).size;

View File

@ -32,9 +32,12 @@ class GestureIcons {
IconData(0xe691, fontFamily: _family); IconData(0xe691, fontFamily: _family);
} }
typedef OnTouchModeChange = void Function(bool);
class GestureHelp extends StatefulWidget { class GestureHelp extends StatefulWidget {
GestureHelp({Key? key,this.initTouchMode = false}) : super(key: key); GestureHelp({Key? key,required this.touchMode,required this.onTouchModeChange}) : super(key: key);
final initTouchMode; final bool touchMode;
final OnTouchModeChange onTouchModeChange;
@override @override
State<StatefulWidget> createState() => _GestureHelpState(); State<StatefulWidget> createState() => _GestureHelpState();
} }
@ -45,7 +48,7 @@ class _GestureHelpState extends State<GestureHelp> {
@override @override
void initState() { void initState() {
_touchMode = widget.initTouchMode; _touchMode = widget.touchMode;
_selectedIndex = _touchMode ? 1 : 0; _selectedIndex = _touchMode ? 1 : 0;
super.initState(); super.initState();
} }
@ -61,20 +64,24 @@ class _GestureHelpState extends State<GestureHelp> {
children: <Widget>[ children: <Widget>[
ToggleSwitch( ToggleSwitch(
initialLabelIndex: _selectedIndex, initialLabelIndex: _selectedIndex,
inactiveBgColor: MyTheme.darkGray,
totalSwitches: 2, totalSwitches: 2,
minWidth: 130, minWidth: 130,
fontSize: 15, fontSize: 15,
iconSize: 20, iconSize: 20,
labels: ["触摸板模式", "触屏模式"], labels: ["触摸板模式", "触屏模式"],
icons: [ icons: [
GestureIcons.icon_mouse, Icons.mouse,
GestureIcons.icon_Tablet_Touch Icons.touch_app
], ],
onToggle: (index) { onToggle: (index) {
debugPrint(index.toString()); debugPrint(index.toString());
setState(() { setState(() {
_touchMode = index == 0 ? false : true; if (_selectedIndex != index){
_selectedIndex = index ?? 0; _selectedIndex = index ?? 0;
_touchMode = index == 0 ? false : true;
widget.onTouchModeChange(_touchMode);
}
}); });
}, },
), ),