Merge pull request #873 from Kingtous/flutter_desktop

fix&opt: adjust conflict plugins & change implementation for window resize fit
This commit is contained in:
RustDesk 2022-06-27 10:43:49 +08:00 committed by GitHub
commit ce218f7abf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 97 additions and 254 deletions

View File

@ -7,7 +7,6 @@ import 'package:flutter_hbb/desktop/widgets/titlebar_widget.dart';
import 'package:flutter_hbb/models/model.dart';
import 'package:provider/provider.dart';
import 'package:tray_manager/tray_manager.dart';
import 'package:window_manager/window_manager.dart';
class DesktopHomePage extends StatefulWidget {
DesktopHomePage({Key? key}) : super(key: key);
@ -215,7 +214,7 @@ class _DesktopHomePageState extends State<DesktopHomePage> with TrayListener {
case "quit":
exit(0);
case "show":
windowManager.show();
// windowManager.show();
break;
default:
break;

View File

@ -12,11 +12,11 @@ import 'package:get/get.dart';
import 'package:get/route_manager.dart';
import 'package:provider/provider.dart';
import 'package:wakelock/wakelock.dart';
import 'package:window_manager/window_manager.dart';
// import 'package:window_manager/window_manager.dart';
import '../../common.dart';
import '../../mobile/widgets/dialog.dart';
import '../../mobile/widgets/gestures.dart';
import '../../mobile/widgets/overlay.dart';
import '../../models/model.dart';
@ -32,7 +32,7 @@ class RemotePage extends StatefulWidget {
}
class _RemotePageState extends State<RemotePage>
with WindowListener, AutomaticKeepAliveClientMixin {
with AutomaticKeepAliveClientMixin {
Timer? _interval;
Timer? _timer;
bool _showBar = !isWebDesktop;
@ -69,7 +69,7 @@ class _RemotePageState extends State<RemotePage>
_physicalFocusNode.requestFocus();
ffi.ffiModel.updateEventListener(widget.id);
ffi.listenToMouse(true);
WindowManager.instance.addListener(this);
// WindowManager.instance.addListener(this);
}
@override
@ -89,7 +89,7 @@ class _RemotePageState extends State<RemotePage>
if (!Platform.isLinux) {
Wakelock.disable();
}
WindowManager.instance.removeListener(this);
// WindowManager.instance.removeListener(this);
Get.delete<FFI>(tag: widget.id);
super.dispose();
}
@ -286,14 +286,7 @@ class _RemotePageState extends State<RemotePage>
OverlayEntry(builder: (context) {
return Container(
color: Colors.black,
child: isWebDesktop
? getBodyForDesktopWithListener(keyboard)
: SafeArea(
child: Container(
color: MyTheme.canvasColor,
child: _isPhysicalMouse
? getBodyForMobile()
: getBodyForMobileWithGesture())));
child: getBodyForDesktopWithListener(keyboard));
})
],
))),
@ -500,123 +493,6 @@ class _RemotePageState extends State<RemotePage>
/// DoubleFiner -> right click
/// HoldDrag -> left drag
Widget getBodyForMobileWithGesture() {
final touchMode = _ffi.ffiModel.touchMode;
return getMixinGestureDetector(
child: getBodyForMobile(),
onTapUp: (d) {
if (touchMode) {
_ffi.cursorModel.touch(
d.localPosition.dx, d.localPosition.dy, MouseButtons.left);
} else {
_ffi.tap(MouseButtons.left);
}
},
onDoubleTapDown: (d) {
if (touchMode) {
_ffi.cursorModel.move(d.localPosition.dx, d.localPosition.dy);
}
},
onDoubleTap: () {
_ffi.tap(MouseButtons.left);
_ffi.tap(MouseButtons.left);
},
onLongPressDown: (d) {
if (touchMode) {
_ffi.cursorModel.move(d.localPosition.dx, d.localPosition.dy);
}
},
onLongPress: () {
_ffi.tap(MouseButtons.right);
},
onDoubleFinerTap: (d) {
if (!touchMode) {
_ffi.tap(MouseButtons.right);
}
},
onHoldDragStart: (d) {
if (!touchMode) {
_ffi.sendMouse('down', MouseButtons.left);
}
},
onHoldDragUpdate: (d) {
if (!touchMode) {
_ffi.cursorModel.updatePan(d.delta.dx, d.delta.dy, touchMode);
}
},
onHoldDragEnd: (_) {
if (!touchMode) {
_ffi.sendMouse('up', MouseButtons.left);
}
},
onOneFingerPanStart: (d) {
if (touchMode) {
_ffi.cursorModel.move(d.localPosition.dx, d.localPosition.dy);
_ffi.sendMouse('down', MouseButtons.left);
}
},
onOneFingerPanUpdate: (d) {
_ffi.cursorModel.updatePan(d.delta.dx, d.delta.dy, touchMode);
},
onOneFingerPanEnd: (d) {
if (touchMode) {
_ffi.sendMouse('up', MouseButtons.left);
}
},
// scale + pan event
onTwoFingerScaleUpdate: (d) {
_ffi.canvasModel.updateScale(d.scale / _scale);
_scale = d.scale;
_ffi.canvasModel.panX(d.focalPointDelta.dx);
_ffi.canvasModel.panY(d.focalPointDelta.dy);
},
onTwoFingerScaleEnd: (d) {
_scale = 1;
_ffi.bind
.sessionPeerOption(id: widget.id, name: "view-style", value: "");
},
onThreeFingerVerticalDragUpdate: _ffi.ffiModel.isPeerAndroid
? null
: (d) {
_mouseScrollIntegral += d.delta.dy / 4;
if (_mouseScrollIntegral > 1) {
_ffi.scroll(1);
_mouseScrollIntegral = 0;
} else if (_mouseScrollIntegral < -1) {
_ffi.scroll(-1);
_mouseScrollIntegral = 0;
}
});
}
Widget getBodyForMobile() {
return Container(
color: MyTheme.canvasColor,
child: Stack(children: [
ImagePaint(id: widget.id),
CursorPaint(id: widget.id),
getHelpTools(),
SizedBox(
width: 0,
height: 0,
child: !_showEdit
? Container()
: TextFormField(
textInputAction: TextInputAction.newline,
autocorrect: false,
enableSuggestions: false,
autofocus: true,
focusNode: _mobileFocusNode,
maxLines: null,
initialValue: _value,
// trick way to make backspace work always
keyboardType: TextInputType.multiline,
onChanged: handleInput,
),
),
]));
}
Widget getBodyForDesktopWithListener(bool keyboard) {
var paints = <Widget>[
ImagePaint(
@ -630,8 +506,26 @@ class _RemotePageState extends State<RemotePage>
id: widget.id,
));
}
return Container(
color: MyTheme.canvasColor, child: Stack(children: paints));
paints.add(getHelpTools());
return MouseRegion(
onEnter: (evt) {
_ffi.bind.hostStopSystemKeyPropagate(stopped: false);
},
onExit: (evt) {
_ffi.bind.hostStopSystemKeyPropagate(stopped: true);
},
child: Container(
color: MyTheme.canvasColor,
child: LayoutBuilder(builder: (context, constraints) {
Future.delayed(Duration.zero, () {
Provider.of<CanvasModel>(context, listen: false)
.updateViewStyle();
});
return Stack(
children: paints,
);
}),
));
}
int lastMouseDownButtons = 0;

View File

@ -1,4 +1,3 @@
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:flutter/material.dart';
const sidebarColor = Color(0xFF0C6AF6);
@ -20,47 +19,51 @@ class DesktopTitleBar extends StatelessWidget {
colors: [backgroundStartColor, backgroundEndColor],
stops: [0.0, 1.0]),
),
child: WindowTitleBarBox(
child: SizedBox(
child: Row(
children: [
Expanded(
child: MoveWindow(
child: child,
)),
const WindowButtons()
],
),
),
child: Row(
children: [
Expanded(
child: child ?? Offstage(),)
// const WindowButtons()
],
),
);
}
}
final buttonColors = WindowButtonColors(
iconNormal: const Color(0xFF805306),
mouseOver: const Color(0xFFF6A00C),
mouseDown: const Color(0xFF805306),
iconMouseOver: const Color(0xFF805306),
iconMouseDown: const Color(0xFFFFD500));
final closeButtonColors = WindowButtonColors(
mouseOver: const Color(0xFFD32F2F),
mouseDown: const Color(0xFFB71C1C),
iconNormal: const Color(0xFF805306),
iconMouseOver: Colors.white);
class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
MinimizeWindowButton(colors: buttonColors),
MaximizeWindowButton(colors: buttonColors),
CloseWindowButton(colors: closeButtonColors),
],
);
}
}
// final buttonColors = WindowButtonColors(
// iconNormal: const Color(0xFF805306),
// mouseOver: const Color(0xFFF6A00C),
// mouseDown: const Color(0xFF805306),
// iconMouseOver: const Color(0xFF805306),
// iconMouseDown: const Color(0xFFFFD500));
//
// final closeButtonColors = WindowButtonColors(
// mouseOver: const Color(0xFFD32F2F),
// mouseDown: const Color(0xFFB71C1C),
// iconNormal: const Color(0xFF805306),
// iconMouseOver: Colors.white);
//
// class WindowButtons extends StatelessWidget {
// const WindowButtons({Key? key}) : super(key: key);
//
// @override
// Widget build(BuildContext context) {
// return Row(
// children: [
// MinimizeWindowButton(colors: buttonColors, onPressed: () {
// windowManager.minimize();
// },),
// MaximizeWindowButton(colors: buttonColors, onPressed: () async {
// if (await windowManager.isMaximized()) {
// windowManager.restore();
// } else {
// windowManager.maximize();
// }
// },),
// CloseWindowButton(colors: closeButtonColors, onPressed: () {
// windowManager.close();
// },),
// ],
// );
// }
// }

View File

@ -1,6 +1,5 @@
import 'dart:convert';
import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hbb/desktop/pages/desktop_home_page.dart';
import 'package:flutter_hbb/desktop/screen/desktop_file_transfer_screen.dart';
@ -9,7 +8,7 @@ import 'package:flutter_hbb/utils/multi_window_manager.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/route_manager.dart';
import 'package:provider/provider.dart';
import 'package:window_manager/window_manager.dart';
// import 'package:window_manager/window_manager.dart';
import 'common.dart';
import 'mobile/pages/home_page.dart';
@ -38,7 +37,6 @@ void runRustDeskApp(List<String> args) async {
return;
}
// main window
await windowManager.ensureInitialized();
if (args.isNotEmpty && args.first == 'multi_window') {
windowId = int.parse(args[1]);
final argument = args[2].isEmpty
@ -59,17 +57,11 @@ void runRustDeskApp(List<String> args) async {
break;
}
} else {
// await windowManager.ensureInitialized();
// disable tray
// initTray();
gFFI.serverModel.startService();
runApp(App());
doWhenWindowReady(() {
const initialSize = Size(1280, 720);
appWindow.minSize = initialSize;
appWindow.size = initialSize;
appWindow.alignment = Alignment.center;
appWindow.show();
});
}
}

View File

@ -891,9 +891,7 @@ class FFI {
/// Connect with the given [id]. Only transfer file if [isFileTransfer].
void connect(String id, {bool isFileTransfer = false}) {
if (isFileTransfer) {
setByName('connect_file_transfer', id);
} else {
if (!isFileTransfer) {
chatModel.resetClientMode();
canvasModel.id = id;
imageModel._id = id;

View File

@ -1,7 +1,7 @@
#include "my_application.h"
#include <flutter_linux/flutter_linux.h>
#include <bitsdojo_window_linux/bitsdojo_window_plugin.h>
// #include <bitsdojo_window_linux/bitsdojo_window_plugin.h>
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#endif
@ -48,8 +48,8 @@ static void my_application_activate(GApplication* application) {
gtk_window_set_title(window, "rustdesk");
}
auto bdw = bitsdojo_window_from(window); // <--- add this line
bdw->setCustomFrame(true); // <-- add this line
// auto bdw = bitsdojo_window_from(window); // <--- add this line
// bdw->setCustomFrame(true); // <-- add this line
gtk_window_set_default_size(window, 1280, 720); // <-- comment this line
gtk_widget_show(GTK_WIDGET(window));

View File

@ -1,8 +1,8 @@
import Cocoa
import FlutterMacOS
import bitsdojo_window_macos
// import bitsdojo_window_macos
class MainFlutterWindow: BitsdojoWindow {
class MainFlutterWindow: NSWindow {
override func awakeFromNib() {
if (!rustdesk_core_main()){
print("Rustdesk core returns false, exiting without launching Flutter app")
@ -18,7 +18,7 @@ class MainFlutterWindow: BitsdojoWindow {
super.awakeFromNib()
}
override func bitsdojo_window_configure() -> UInt {
return BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP
}
// override func bitsdojo_window_configure() -> UInt {
// return BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP
// }
}

View File

@ -21,6 +21,8 @@ void wire_rustdesk_core_main(int64_t port_);
void wire_start_global_event_stream(int64_t port_);
void wire_host_stop_system_key_propagate(int64_t port_, bool stopped);
void wire_session_connect(int64_t port_, struct wire_uint_8_list *id, bool is_file_transfer);
void wire_get_session_remember(int64_t port_, struct wire_uint_8_list *id);
@ -170,6 +172,7 @@ static int64_t dummy_method_to_enforce_bundling(void) {
int64_t dummy_var = 0;
dummy_var ^= ((int64_t) (void*) wire_rustdesk_core_main);
dummy_var ^= ((int64_t) (void*) wire_start_global_event_stream);
dummy_var ^= ((int64_t) (void*) wire_host_stop_system_key_propagate);
dummy_var ^= ((int64_t) (void*) wire_session_connect);
dummy_var ^= ((int64_t) (void*) wire_get_session_remember);
dummy_var ^= ((int64_t) (void*) wire_get_session_toggle_option);

View File

@ -36,41 +36,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.8.2"
bitsdojo_window:
dependency: "direct main"
description:
name: bitsdojo_window
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.2"
bitsdojo_window_linux:
dependency: transitive
description:
name: bitsdojo_window_linux
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.2"
bitsdojo_window_macos:
dependency: transitive
description:
name: bitsdojo_window_macos
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.2"
bitsdojo_window_platform_interface:
dependency: transitive
description:
name: bitsdojo_window_platform_interface
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.2"
bitsdojo_window_windows:
dependency: transitive
description:
name: bitsdojo_window_windows
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.2"
boolean_selector:
dependency: transitive
description:
@ -221,11 +186,9 @@ packages:
desktop_multi_window:
dependency: "direct main"
description:
path: "."
ref: "704718b2853723b615675e048f1f385cbfb209a6"
resolved-ref: "704718b2853723b615675e048f1f385cbfb209a6"
url: "https://github.com/Kingtous/rustdesk_desktop_multi_window"
source: git
path: "../../rustdesk_desktop_multi_window"
relative: true
source: path
version: "0.0.1"
device_info_plus:
dependency: "direct main"
@ -785,13 +748,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.1.0"
screen_retriever:
dependency: transitive
description:
name: screen_retriever
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.2"
settings_ui:
dependency: "direct main"
description:
@ -1105,13 +1061,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.6.1"
window_manager:
dependency: "direct main"
description:
name: window_manager
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.5"
xdg_directories:
dependency: transitive
description:

View File

@ -58,12 +58,12 @@ dependencies:
url: https://github.com/SoLongAndThanksForAllThePizza/flutter_rust_bridge
ref: master
path: frb_dart
window_manager: ^0.2.5
# window_manager: ^0.2.5
desktop_multi_window:
git:
url: https://github.com/Kingtous/rustdesk_desktop_multi_window
ref: 704718b2853723b615675e048f1f385cbfb209a6
bitsdojo_window: ^0.1.2
ref: c7d97cb6615f2def34f8bad4def01af9e0077beb
# bitsdojo_window: ^0.1.2
freezed_annotation: ^2.0.3
tray_manager: 0.1.7
get: ^4.6.5

View File

@ -5,11 +5,11 @@
#include "flutter_window.h"
#include "utils.h"
#include <bitsdojo_window_windows/bitsdojo_window_plugin.h>
// #include <bitsdojo_window_windows/bitsdojo_window_plugin.h>
typedef bool (*FUNC_RUSTDESK_CORE_MAIN)(void);
auto bdw = bitsdojo_window_configure(BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP);
// auto bdw = bitsdojo_window_configure(BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP);
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t *command_line, _In_ int show_command)
{

View File

@ -69,6 +69,11 @@ pub fn start_global_event_stream(s: StreamSink<String>) -> ResultType<()> {
Ok(())
}
pub fn host_stop_system_key_propagate(stopped: bool) {
#[cfg(windows)]
crate::platform::windows::stop_system_key_propagate(stopped);
}
pub fn session_connect(
events2ui: StreamSink<EventToUI>,
id: String,