mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-25 21:49:04 +08:00
touch mode and reset canvas
This commit is contained in:
parent
3310205fd1
commit
5696c8ce97
@ -299,6 +299,7 @@ class CanvasModel with ChangeNotifier {
|
||||
_x = 0;
|
||||
_y = 0;
|
||||
_scale = 1.0;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@ -341,8 +342,40 @@ class CursorModel with ChangeNotifier {
|
||||
return h - thresh;
|
||||
}
|
||||
|
||||
void updatePan(double dx, double dy) {
|
||||
void touch(double x, double y, bool right) {
|
||||
final scale = FFI.canvasModel.scale;
|
||||
final xoffset = FFI.canvasModel.x;
|
||||
final yoffset = FFI.canvasModel.y;
|
||||
_x = (x - xoffset) / scale + _displayOriginX;
|
||||
_y = (y - yoffset) / scale + _displayOriginY;
|
||||
FFI.moveMouse(_x, _y);
|
||||
FFI.tap(right);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
_x = _displayOriginX;
|
||||
_y = _displayOriginY;
|
||||
FFI.moveMouse(_x, _y);
|
||||
FFI.canvasModel.clear();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void updatePan(double dx, double dy, bool touchMode, bool drag) {
|
||||
if (FFI.imageModel.image == null) return;
|
||||
if (touchMode) {
|
||||
if (drag) {
|
||||
final scale = FFI.canvasModel.scale;
|
||||
_x += dx / scale;
|
||||
_y += dy / scale;
|
||||
FFI.moveMouse(_x, _y);
|
||||
notifyListeners();
|
||||
} else {
|
||||
FFI.canvasModel.panX(dx);
|
||||
FFI.canvasModel.panY(dy);
|
||||
}
|
||||
return;
|
||||
}
|
||||
final scale = FFI.canvasModel.scale;
|
||||
dx /= scale;
|
||||
dy /= scale;
|
||||
@ -750,6 +783,8 @@ final langs = <String, Map<String, String>>{
|
||||
'Paste': '粘贴',
|
||||
'Are you sure to close the connection?': '是否确认关闭连接?',
|
||||
'Download new version': '下载新版本',
|
||||
'Touch mode': '触屏模式',
|
||||
'Reset canvas': '重置画布',
|
||||
},
|
||||
'en': <String, String>{}
|
||||
};
|
||||
|
@ -40,6 +40,7 @@ class _RemotePageState extends State<RemotePage> {
|
||||
final FocusNode _focusNode = FocusNode();
|
||||
var _showKeyboard = false;
|
||||
var _reconnects = 1;
|
||||
var _touchMode = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -53,6 +54,7 @@ class _RemotePageState extends State<RemotePage> {
|
||||
});
|
||||
Wakelock.enable();
|
||||
loadingCancelCallback = () => _interval.cancel();
|
||||
_touchMode = FFI.getByName('peer_option', "touch-mode") != '';
|
||||
}
|
||||
|
||||
@override
|
||||
@ -306,14 +308,22 @@ class _RemotePageState extends State<RemotePage> {
|
||||
)
|
||||
: null,
|
||||
body: FlutterEasyLoading(
|
||||
child: Container(
|
||||
color: Colors.black,
|
||||
child: SafeArea(
|
||||
child: GestureDetector(
|
||||
onLongPress: () {
|
||||
if (_drag || _scroll) return;
|
||||
FFI.tap(true);
|
||||
},
|
||||
onTap: () {
|
||||
onTapUp: (details) {
|
||||
if (_drag || _scroll) return;
|
||||
if (_touchMode) {
|
||||
FFI.cursorModel.touch(details.localPosition.dx,
|
||||
details.localPosition.dy, _right);
|
||||
} else {
|
||||
FFI.tap(_right);
|
||||
}
|
||||
},
|
||||
onScaleStart: (details) {
|
||||
_scale = 1;
|
||||
@ -331,7 +341,8 @@ class _RemotePageState extends State<RemotePage> {
|
||||
var y = details.focalPoint.dy;
|
||||
var dx = x - _xOffset;
|
||||
var dy = y - _yOffset;
|
||||
FFI.cursorModel.updatePan(dx, dy);
|
||||
FFI.cursorModel
|
||||
.updatePan(dx, dy, _touchMode, _drag);
|
||||
_xOffset = x;
|
||||
_yOffset = y;
|
||||
} else {
|
||||
@ -356,9 +367,6 @@ class _RemotePageState extends State<RemotePage> {
|
||||
}
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.black,
|
||||
child: SafeArea(
|
||||
child: Container(
|
||||
color: MyTheme.canvasColor,
|
||||
child: Stack(children: [
|
||||
@ -388,6 +396,92 @@ class _RemotePageState extends State<RemotePage> {
|
||||
);
|
||||
}
|
||||
|
||||
void showActions(BuildContext context) {
|
||||
final size = MediaQuery.of(context).size;
|
||||
final x = 120.0;
|
||||
final y = size.height;
|
||||
final more = <PopupMenuItem<String>>[];
|
||||
if (FFI.ffiModel.pi.version.isNotEmpty) {
|
||||
more.add(PopupMenuItem<String>(
|
||||
child: Text(translate('Refresh')), value: 'refresh'));
|
||||
}
|
||||
if (FFI.ffiModel.permissions['keyboard'] != false &&
|
||||
FFI.ffiModel.permissions['clipboard'] != false) {
|
||||
more.add(PopupMenuItem<String>(
|
||||
child: Text(translate('Paste')), value: 'paste'));
|
||||
}
|
||||
more.add(PopupMenuItem<String>(
|
||||
child: Row(
|
||||
children: ([
|
||||
Container(width: 100.0, child: Text(translate('OS Password'))),
|
||||
TextButton(
|
||||
style: flatButtonStyle,
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
showSetOSPassword(context, false);
|
||||
},
|
||||
child: Icon(Icons.edit, color: MyTheme.accent),
|
||||
)
|
||||
])),
|
||||
value: 'enter_os_password'));
|
||||
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>(
|
||||
child: Text(translate('Reset canvas')), value: 'reset_canvas'));
|
||||
() async {
|
||||
var value = await showMenu(
|
||||
context: context,
|
||||
position: RelativeRect.fromLTRB(x, y, x, y),
|
||||
items: [
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Insert') + ' Ctrl + Alt + Del'),
|
||||
value: 'cad'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Insert Lock')), value: 'lock'),
|
||||
] +
|
||||
more,
|
||||
elevation: 8,
|
||||
);
|
||||
if (value == 'cad') {
|
||||
FFI.setByName('ctrl_alt_del');
|
||||
} else if (value == 'lock') {
|
||||
FFI.setByName('lock_screen');
|
||||
} else if (value == 'refresh') {
|
||||
FFI.setByName('refresh');
|
||||
} else if (value == 'paste') {
|
||||
() async {
|
||||
ClipboardData data = await Clipboard.getData(Clipboard.kTextPlain);
|
||||
if (data.text != null) {
|
||||
FFI.setByName('input_string', '${data.text}');
|
||||
}
|
||||
}();
|
||||
} else if (value == 'enter_os_password') {
|
||||
var password = FFI.getByName('peer_option', "os-password");
|
||||
if (password != "") {
|
||||
FFI.setByName('input_os_password', password);
|
||||
} 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 close() {
|
||||
msgbox('', 'Close', 'Are you sure to close the connection?', context);
|
||||
}
|
||||
@ -806,72 +900,6 @@ void showOptions(BuildContext context) {
|
||||
}, () async => true, true, 0);
|
||||
}
|
||||
|
||||
void showActions(BuildContext context) {
|
||||
final size = MediaQuery.of(context).size;
|
||||
final x = 120.0;
|
||||
final y = size.height;
|
||||
final more = <PopupMenuItem<String>>[];
|
||||
if (FFI.ffiModel.pi.version.isNotEmpty) {
|
||||
more.add(PopupMenuItem<String>(
|
||||
child: Text(translate('Refresh')), value: 'refresh'));
|
||||
}
|
||||
if (FFI.ffiModel.permissions['keyboard'] != false &&
|
||||
FFI.ffiModel.permissions['clipboard'] != false) {
|
||||
more.add(
|
||||
PopupMenuItem<String>(child: Text(translate('Paste')), value: 'paste'));
|
||||
}
|
||||
more.add(PopupMenuItem<String>(
|
||||
child: Row(
|
||||
children: ([
|
||||
Text(translate('OS Password')),
|
||||
TextButton(
|
||||
style: flatButtonStyle,
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
showSetOSPassword(context, false);
|
||||
},
|
||||
child: Icon(Icons.edit),
|
||||
)
|
||||
])),
|
||||
value: 'enter_os_password'));
|
||||
() async {
|
||||
var value = await showMenu(
|
||||
context: context,
|
||||
position: RelativeRect.fromLTRB(x, y, x, y),
|
||||
items: [
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Insert') + ' Ctrl + Alt + Del'),
|
||||
value: 'cad'),
|
||||
PopupMenuItem<String>(
|
||||
child: Text(translate('Insert Lock')), value: 'lock'),
|
||||
] +
|
||||
more,
|
||||
elevation: 8,
|
||||
);
|
||||
if (value == 'cad') {
|
||||
FFI.setByName('ctrl_alt_del');
|
||||
} else if (value == 'lock') {
|
||||
FFI.setByName('lock_screen');
|
||||
} else if (value == 'refresh') {
|
||||
FFI.setByName('refresh');
|
||||
} else if (value == 'paste') {
|
||||
() async {
|
||||
ClipboardData data = await Clipboard.getData(Clipboard.kTextPlain);
|
||||
if (data.text != null) {
|
||||
FFI.setByName('input_string', '${data.text}');
|
||||
}
|
||||
}();
|
||||
} else if (value == 'enter_os_password') {
|
||||
var password = FFI.getByName('peer_option', "os-password");
|
||||
if (password != "") {
|
||||
FFI.setByName('input_os_password', password);
|
||||
} else {
|
||||
showSetOSPassword(context, true);
|
||||
}
|
||||
}
|
||||
}();
|
||||
}
|
||||
|
||||
void showSetOSPassword(BuildContext context, bool login) {
|
||||
final controller = TextEditingController();
|
||||
var password = FFI.getByName('peer_option', "os-password");
|
||||
|
Loading…
Reference in New Issue
Block a user