flutter_desktop: update custom cursor lib & menubar margin & better callback for pinning menubar

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2022-09-13 19:10:55 -07:00
parent f4bc27f969
commit c5a78ce107
4 changed files with 54 additions and 27 deletions

View File

@ -18,6 +18,8 @@ import '../../models/model.dart';
import '../../models/platform_model.dart'; import '../../models/platform_model.dart';
import '../../common/shared_state.dart'; import '../../common/shared_state.dart';
bool _isCustomCursorInited = false;
class RemotePage extends StatefulWidget { class RemotePage extends StatefulWidget {
const RemotePage({ const RemotePage({
Key? key, Key? key,
@ -45,7 +47,7 @@ class _RemotePageState extends State<RemotePage>
var _isPhysicalMouse = false; var _isPhysicalMouse = false;
var _imageFocused = false; var _imageFocused = false;
final _onEnterOrLeaveImage = <Function(bool)>[]; Function(bool)? _onEnterOrLeaveImage4Menubar;
late FFI _ffi; late FFI _ffi;
@ -95,6 +97,14 @@ class _RemotePageState extends State<RemotePage>
_ffi.qualityMonitorModel.checkShowQualityMonitor(widget.id); _ffi.qualityMonitorModel.checkShowQualityMonitor(widget.id);
_showRemoteCursor.value = bind.sessionGetToggleOptionSync( _showRemoteCursor.value = bind.sessionGetToggleOptionSync(
id: widget.id, arg: 'show-remote-cursor'); id: widget.id, arg: 'show-remote-cursor');
if (!_isCustomCursorInited) {
customCursorController.registerNeedUpdateCursorCallback(
(String? lastKey, String? currentKey) async {
return lastKey == null || lastKey != currentKey;
});
_isCustomCursorInited = true;
}
} }
@override @override
@ -327,16 +337,24 @@ class _RemotePageState extends State<RemotePage>
_rawKeyFocusNode.requestFocus(); _rawKeyFocusNode.requestFocus();
} }
_cursorOverImage.value = true; _cursorOverImage.value = true;
for (var f in _onEnterOrLeaveImage) { if (_onEnterOrLeaveImage4Menubar != null) {
f(true); try {
_onEnterOrLeaveImage4Menubar!(true);
} catch (e) {
//
}
} }
_ffi.enterOrLeave(true); _ffi.enterOrLeave(true);
} }
void leaveView(PointerExitEvent evt) { void leaveView(PointerExitEvent evt) {
_cursorOverImage.value = false; _cursorOverImage.value = false;
for (var f in _onEnterOrLeaveImage) { if (_onEnterOrLeaveImage4Menubar != null) {
f(false); try {
_onEnterOrLeaveImage4Menubar!(false);
} catch (e) {
//
}
} }
_ffi.enterOrLeave(false); _ffi.enterOrLeave(false);
} }
@ -381,7 +399,8 @@ class _RemotePageState extends State<RemotePage>
paints.add(RemoteMenubar( paints.add(RemoteMenubar(
id: widget.id, id: widget.id,
ffi: _ffi, ffi: _ffi,
onEnterOrLeaveImage: _onEnterOrLeaveImage, onEnterOrLeaveImageSetter: (func) => _onEnterOrLeaveImage4Menubar = func,
onEnterOrLeaveImageCleaner: () => _onEnterOrLeaveImage4Menubar = null,
)); ));
return Stack( return Stack(
children: paints, children: paints,

View File

@ -98,7 +98,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
controller: tabController, controller: tabController,
showTabBar: fullscreen.isFalse, showTabBar: fullscreen.isFalse,
onWindowCloseButton: handleWindowCloseButton, onWindowCloseButton: handleWindowCloseButton,
tail: AddButton().paddingOnly(left: 10), tail: const AddButton().paddingOnly(left: 10),
pageViewBuilder: (pageView) { pageViewBuilder: (pageView) {
WindowController.fromWindowId(windowId()) WindowController.fromWindowId(windowId())
.setFullscreen(fullscreen.isTrue); .setFullscreen(fullscreen.isTrue);

View File

@ -26,13 +26,15 @@ class _MenubarTheme {
class RemoteMenubar extends StatefulWidget { class RemoteMenubar extends StatefulWidget {
final String id; final String id;
final FFI ffi; final FFI ffi;
final List<Function(bool)> onEnterOrLeaveImage; final Function(Function(bool)) onEnterOrLeaveImageSetter;
final Function() onEnterOrLeaveImageCleaner;
const RemoteMenubar({ const RemoteMenubar({
Key? key, Key? key,
required this.id, required this.id,
required this.ffi, required this.ffi,
required this.onEnterOrLeaveImage, required this.onEnterOrLeaveImageSetter,
required this.onEnterOrLeaveImageCleaner,
}) : super(key: key); }) : super(key: key);
@override @override
@ -52,10 +54,10 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
} }
@override @override
void initState() { initState() {
super.initState(); super.initState();
widget.onEnterOrLeaveImage.add((enter) { widget.onEnterOrLeaveImageSetter((enter) {
if (enter) { if (enter) {
_rxHideReplay.add(0); _rxHideReplay.add(0);
_isCursorOverImage = true; _isCursorOverImage = true;
@ -74,6 +76,13 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
}); });
} }
@override
dispose() {
super.dispose();
widget.onEnterOrLeaveImageCleaner();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Align( return Align(
@ -85,21 +94,20 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
Widget _buildShowHide(BuildContext context) { Widget _buildShowHide(BuildContext context) {
return Obx(() => Tooltip( return Obx(() => Tooltip(
message: translate(_show.value ? "Hide Menubar" : "Show Menubar"), message: translate(_show.value ? "Hide Menubar" : "Show Menubar"),
child: SizedBox( child: SizedBox(
width: 100, width: 100,
height: 5, height: 13,
child: TextButton( child: TextButton(
onHover: (bool v) { onHover: (bool v) {
_hideColor.value = v ? Colors.white60 : Colors.white24; _hideColor.value = v ? Colors.white60 : Colors.white24;
}, },
onPressed: () { onPressed: () {
_show.value = !_show.value; _show.value = !_show.value;
}, },
child: Obx(() => Container( child: Obx(() => Container(
color: _hideColor.value, color: _hideColor.value,
)))), ).marginOnly(bottom: 8.0))))));
));
} }
Widget _buildMenubar(BuildContext context) { Widget _buildMenubar(BuildContext context) {

View File

@ -71,7 +71,7 @@ dependencies:
flutter_custom_cursor: flutter_custom_cursor:
git: git:
url: https://github.com/Kingtous/rustdesk_flutter_custom_cursor url: https://github.com/Kingtous/rustdesk_flutter_custom_cursor
ref: 9021e21de36c84edf01d5034f38eda580463163b ref: 47179378523c993092f70d95f93d53f40af01f02
get: ^4.6.5 get: ^4.6.5
visibility_detector: ^0.3.3 visibility_detector: ^0.3.3
contextmenu: ^3.0.0 contextmenu: ^3.0.0