Merge pull request #877 from SoLongAndThanksForAllThePizza/flutter_desktop

feat: implemented remote control on desktop
This commit is contained in:
RustDesk 2022-06-27 16:53:57 +08:00 committed by GitHub
commit 6c4f5dc007
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 37 deletions

View File

@ -256,28 +256,28 @@ class _RemotePageState extends State<RemotePage>
child: getRawPointerAndKeyBody( child: getRawPointerAndKeyBody(
keyboard, keyboard,
Scaffold( Scaffold(
// resizeToAvoidBottomInset: true, // resizeToAvoidBottomInset: true,
floatingActionButton: !showActionButton floatingActionButton: !showActionButton
? null ? null
: FloatingActionButton( : FloatingActionButton(
mini: !hideKeyboard, mini: !hideKeyboard,
child: Icon(hideKeyboard child: Icon(hideKeyboard
? Icons.expand_more ? Icons.expand_more
: Icons.expand_less), : Icons.expand_less),
backgroundColor: MyTheme.accent, backgroundColor: MyTheme.accent,
onPressed: () { onPressed: () {
setState(() { setState(() {
if (hideKeyboard) { if (hideKeyboard) {
_showEdit = false; _showEdit = false;
_ffi.invokeMethod( _ffi.invokeMethod(
"enable_soft_keyboard", false); "enable_soft_keyboard", false);
_mobileFocusNode.unfocus(); _mobileFocusNode.unfocus();
_physicalFocusNode.requestFocus(); _physicalFocusNode.requestFocus();
} else { } else {
_showBar = !_showBar; _showBar = !_showBar;
} }
}); });
}), }),
bottomNavigationBar: _showBar && pi.displays.length > 0 bottomNavigationBar: _showBar && pi.displays.length > 0
? getBottomAppBar(keyboard) ? getBottomAppBar(keyboard)
: null, : null,

View File

@ -425,18 +425,35 @@ class CanvasModel with ChangeNotifier {
final size = MediaQueryData.fromWindow(ui.window).size; final size = MediaQueryData.fromWindow(ui.window).size;
final s1 = size.width / (parent.target?.ffiModel.display.width ?? 720); final s1 = size.width / (parent.target?.ffiModel.display.width ?? 720);
final s2 = size.height / (parent.target?.ffiModel.display.height ?? 1280); final s2 = size.height / (parent.target?.ffiModel.display.height ?? 1280);
if (s == 'shrink') { // Closure to perform shrink operation.
final shrinkOp = () {
final s = s1 < s2 ? s1 : s2; final s = s1 < s2 ? s1 : s2;
if (s < 1) { if (s < 1) {
_scale = s; _scale = s;
} }
} else if (s == 'stretch') { };
// Closure to perform stretch operation.
final stretchOp = () {
final s = s1 > s2 ? s1 : s2; final s = s1 > s2 ? s1 : s2;
if (s > 1) { if (s > 1) {
_scale = s; _scale = s;
} }
};
// Closure to perform default operation(set the scale to 1.0).
final defaultOp = () {
_scale = 1.0;
};
if (s == 'shrink') {
shrinkOp();
} else if (s == 'stretch') {
stretchOp();
} else { } else {
_scale = 1; // On desktop, shrink is the default behavior.
if (isDesktop) {
shrinkOp();
} else {
defaultOp();
}
} }
_x = (size.width - getDisplayWidth() * _scale) / 2; _x = (size.width - getDisplayWidth() * _scale) / 2;
_y = (size.height - getDisplayHeight() * _scale) / 2; _y = (size.height - getDisplayHeight() * _scale) / 2;
@ -459,21 +476,24 @@ class CanvasModel with ChangeNotifier {
} }
void moveDesktopMouse(double x, double y) { void moveDesktopMouse(double x, double y) {
final size = MediaQueryData.fromWindow(ui.window).size; // On mobile platforms, move the canvas with the cursor.
final dw = getDisplayWidth() * _scale; if (!isDesktop) {
final dh = getDisplayHeight() * _scale; final size = MediaQueryData.fromWindow(ui.window).size;
var dxOffset = 0; final dw = getDisplayWidth() * _scale;
var dyOffset = 0; final dh = getDisplayHeight() * _scale;
if (dw > size.width) { var dxOffset = 0;
dxOffset = (x - dw * (x / size.width) - _x).toInt(); var dyOffset = 0;
} if (dw > size.width) {
if (dh > size.height) { dxOffset = (x - dw * (x / size.width) - _x).toInt();
dyOffset = (y - dh * (y / size.height) - _y).toInt(); }
} if (dh > size.height) {
_x += dxOffset; dyOffset = (y - dh * (y / size.height) - _y).toInt();
_y += dyOffset; }
if (dxOffset != 0 || dyOffset != 0) { _x += dxOffset;
notifyListeners(); _y += dyOffset;
if (dxOffset != 0 || dyOffset != 0) {
notifyListeners();
}
} }
parent.target?.cursorModel.moveLocal(x, y); parent.target?.cursorModel.moveLocal(x, y);
} }
@ -714,6 +734,7 @@ class CursorModel with ChangeNotifier {
} }
} }
/// Update the cursor position.
void updateCursorPosition(Map<String, dynamic> evt) { void updateCursorPosition(Map<String, dynamic> evt) {
_x = double.parse(evt['x']); _x = double.parse(evt['x']);
_y = double.parse(evt['y']); _y = double.parse(evt['y']);