mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-06-12 05:13:09 +08:00
flutter_desktop: adjust window
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
1719b4735d
commit
03439831a7
@ -179,3 +179,25 @@ class RemoteCursorMovedState {
|
|||||||
|
|
||||||
static RxBool find(String id) => Get.find<RxBool>(tag: tag(id));
|
static RxBool find(String id) => Get.find<RxBool>(tag: tag(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class RemoteCountState {
|
||||||
|
static String tag() => 'remote_count_';
|
||||||
|
|
||||||
|
static void init() {
|
||||||
|
final key = tag();
|
||||||
|
if (!Get.isRegistered(tag: key)) {
|
||||||
|
// Server side, default true
|
||||||
|
final RxInt state = 1.obs;
|
||||||
|
Get.put(state, tag: key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void delete() {
|
||||||
|
final key = tag();
|
||||||
|
if (Get.isRegistered(tag: key)) {
|
||||||
|
Get.delete(tag: key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static RxInt find() => Get.find<RxInt>(tag: tag());
|
||||||
|
}
|
||||||
|
@ -9,6 +9,8 @@ import 'package:flutter_hbb/desktop/widgets/tabbar_widget.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart';
|
||||||
|
|
||||||
|
import '../../common/shared_state.dart';
|
||||||
|
|
||||||
class DesktopTabPage extends StatefulWidget {
|
class DesktopTabPage extends StatefulWidget {
|
||||||
const DesktopTabPage({Key? key}) : super(key: key);
|
const DesktopTabPage({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@ -40,6 +42,7 @@ class _DesktopTabPageState extends State<DesktopTabPage> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
Get.put<DesktopTabController>(tabController);
|
Get.put<DesktopTabController>(tabController);
|
||||||
|
RemoteCountState.init();
|
||||||
tabController.add(TabInfo(
|
tabController.add(TabInfo(
|
||||||
key: kTabLabelHomePage,
|
key: kTabLabelHomePage,
|
||||||
label: kTabLabelHomePage,
|
label: kTabLabelHomePage,
|
||||||
|
@ -28,11 +28,13 @@ class RemotePage extends StatefulWidget {
|
|||||||
const RemotePage({
|
const RemotePage({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.id,
|
required this.id,
|
||||||
|
required this.windowId,
|
||||||
required this.tabBarHeight,
|
required this.tabBarHeight,
|
||||||
required this.windowBorderWidth,
|
required this.windowBorderWidth,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final String id;
|
final String id;
|
||||||
|
final int windowId;
|
||||||
final double tabBarHeight;
|
final double tabBarHeight;
|
||||||
final double windowBorderWidth;
|
final double windowBorderWidth;
|
||||||
|
|
||||||
@ -239,6 +241,7 @@ class _RemotePageState extends State<RemotePage>
|
|||||||
paints.add(QualityMonitor(_ffi.qualityMonitorModel));
|
paints.add(QualityMonitor(_ffi.qualityMonitorModel));
|
||||||
paints.add(RemoteMenubar(
|
paints.add(RemoteMenubar(
|
||||||
id: widget.id,
|
id: widget.id,
|
||||||
|
windowId: widget.windowId,
|
||||||
ffi: _ffi,
|
ffi: _ffi,
|
||||||
onEnterOrLeaveImageSetter: (func) => _onEnterOrLeaveImage4Menubar = func,
|
onEnterOrLeaveImageSetter: (func) => _onEnterOrLeaveImage4Menubar = func,
|
||||||
onEnterOrLeaveImageCleaner: () => _onEnterOrLeaveImage4Menubar = null,
|
onEnterOrLeaveImageCleaner: () => _onEnterOrLeaveImage4Menubar = null,
|
||||||
|
@ -32,6 +32,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
|||||||
var connectionMap = RxList<Widget>.empty(growable: true);
|
var connectionMap = RxList<Widget>.empty(growable: true);
|
||||||
|
|
||||||
_ConnectionTabPageState(Map<String, dynamic> params) {
|
_ConnectionTabPageState(Map<String, dynamic> params) {
|
||||||
|
RemoteCountState.init();
|
||||||
final RxBool fullscreen = Get.find(tag: 'fullscreen');
|
final RxBool fullscreen = Get.find(tag: 'fullscreen');
|
||||||
final peerId = params['id'];
|
final peerId = params['id'];
|
||||||
if (peerId != null) {
|
if (peerId != null) {
|
||||||
@ -45,10 +46,12 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
|||||||
page: Obx(() => RemotePage(
|
page: Obx(() => RemotePage(
|
||||||
key: ValueKey(peerId),
|
key: ValueKey(peerId),
|
||||||
id: peerId,
|
id: peerId,
|
||||||
|
windowId: windowId(),
|
||||||
tabBarHeight:
|
tabBarHeight:
|
||||||
fullscreen.isTrue ? 0 : kDesktopRemoteTabBarHeight,
|
fullscreen.isTrue ? 0 : kDesktopRemoteTabBarHeight,
|
||||||
windowBorderWidth: fullscreen.isTrue ? 0 : kWindowBorderWidth,
|
windowBorderWidth: fullscreen.isTrue ? 0 : kWindowBorderWidth,
|
||||||
))));
|
))));
|
||||||
|
_update_remote_count();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,6 +82,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
|||||||
page: Obx(() => RemotePage(
|
page: Obx(() => RemotePage(
|
||||||
key: ValueKey(id),
|
key: ValueKey(id),
|
||||||
id: id,
|
id: id,
|
||||||
|
windowId: windowId(),
|
||||||
tabBarHeight:
|
tabBarHeight:
|
||||||
fullscreen.isTrue ? 0 : kDesktopRemoteTabBarHeight,
|
fullscreen.isTrue ? 0 : kDesktopRemoteTabBarHeight,
|
||||||
windowBorderWidth: fullscreen.isTrue ? 0 : kWindowBorderWidth,
|
windowBorderWidth: fullscreen.isTrue ? 0 : kWindowBorderWidth,
|
||||||
@ -86,6 +90,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
|||||||
} else if (call.method == "onDestroy") {
|
} else if (call.method == "onDestroy") {
|
||||||
tabController.clear();
|
tabController.clear();
|
||||||
}
|
}
|
||||||
|
_update_remote_count();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,6 +166,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
|||||||
WindowController.fromWindowId(windowId()).hide();
|
WindowController.fromWindowId(windowId()).hide();
|
||||||
}
|
}
|
||||||
ConnectionTypeState.delete(id);
|
ConnectionTypeState.delete(id);
|
||||||
|
_update_remote_count();
|
||||||
}
|
}
|
||||||
|
|
||||||
int windowId() {
|
int windowId() {
|
||||||
@ -178,7 +184,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> handleWindowCloseButton() async {
|
Future<bool> handleWindowCloseButton() async {
|
||||||
final connLength = tabController.state.value.tabs.length;
|
final connLength = tabController.length;
|
||||||
if (connLength < 1) {
|
if (connLength < 1) {
|
||||||
return true;
|
return true;
|
||||||
} else if (connLength == 1) {
|
} else if (connLength == 1) {
|
||||||
@ -189,8 +195,12 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
|||||||
final res = await closeConfirmDialog();
|
final res = await closeConfirmDialog();
|
||||||
if (res) {
|
if (res) {
|
||||||
tabController.clear();
|
tabController.clear();
|
||||||
|
_update_remote_count();
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_update_remote_count() =>
|
||||||
|
RemoteCountState.find().value = tabController.length;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import 'package:flutter_hbb/models/chat_model.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:rxdart/rxdart.dart' as rxdart;
|
import 'package:rxdart/rxdart.dart' as rxdart;
|
||||||
|
import 'package:desktop_multi_window/desktop_multi_window.dart';
|
||||||
|
|
||||||
import '../../common.dart';
|
import '../../common.dart';
|
||||||
import '../../mobile/widgets/dialog.dart';
|
import '../../mobile/widgets/dialog.dart';
|
||||||
@ -26,6 +27,7 @@ class _MenubarTheme {
|
|||||||
|
|
||||||
class RemoteMenubar extends StatefulWidget {
|
class RemoteMenubar extends StatefulWidget {
|
||||||
final String id;
|
final String id;
|
||||||
|
final int windowId;
|
||||||
final FFI ffi;
|
final FFI ffi;
|
||||||
final Function(Function(bool)) onEnterOrLeaveImageSetter;
|
final Function(Function(bool)) onEnterOrLeaveImageSetter;
|
||||||
final Function() onEnterOrLeaveImageCleaner;
|
final Function() onEnterOrLeaveImageCleaner;
|
||||||
@ -33,6 +35,7 @@ class RemoteMenubar extends StatefulWidget {
|
|||||||
const RemoteMenubar({
|
const RemoteMenubar({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.id,
|
required this.id,
|
||||||
|
required this.windowId,
|
||||||
required this.ffi,
|
required this.ffi,
|
||||||
required this.onEnterOrLeaveImageSetter,
|
required this.onEnterOrLeaveImageSetter,
|
||||||
required this.onEnterOrLeaveImageCleaner,
|
required this.onEnterOrLeaveImageCleaner,
|
||||||
@ -306,25 +309,29 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
|||||||
return {'supportedHwcodec': supportedHwcodec};
|
return {'supportedHwcodec': supportedHwcodec};
|
||||||
}(), builder: (context, snapshot) {
|
}(), builder: (context, snapshot) {
|
||||||
if (snapshot.hasData) {
|
if (snapshot.hasData) {
|
||||||
return mod_menu.PopupMenuButton(
|
return Obx(() {
|
||||||
padding: EdgeInsets.zero,
|
final remoteCount = RemoteCountState.find().value;
|
||||||
icon: const Icon(
|
return mod_menu.PopupMenuButton(
|
||||||
Icons.tv,
|
padding: EdgeInsets.zero,
|
||||||
color: _MenubarTheme.commonColor,
|
icon: const Icon(
|
||||||
),
|
Icons.tv,
|
||||||
tooltip: translate('Display Settings'),
|
color: _MenubarTheme.commonColor,
|
||||||
position: mod_menu.PopupMenuPosition.under,
|
),
|
||||||
itemBuilder: (BuildContext context) => _getDisplayMenu(snapshot.data!)
|
tooltip: translate('Display Settings'),
|
||||||
.map((entry) => entry.build(
|
position: mod_menu.PopupMenuPosition.under,
|
||||||
context,
|
itemBuilder: (BuildContext context) =>
|
||||||
const MenuConfig(
|
_getDisplayMenu(snapshot.data!, remoteCount)
|
||||||
commonColor: _MenubarTheme.commonColor,
|
.map((entry) => entry.build(
|
||||||
height: _MenubarTheme.height,
|
context,
|
||||||
dividerHeight: _MenubarTheme.dividerHeight,
|
const MenuConfig(
|
||||||
)))
|
commonColor: _MenubarTheme.commonColor,
|
||||||
.expand((i) => i)
|
height: _MenubarTheme.height,
|
||||||
.toList(),
|
dividerHeight: _MenubarTheme.dividerHeight,
|
||||||
);
|
)))
|
||||||
|
.expand((i) => i)
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
return const Offstage();
|
return const Offstage();
|
||||||
}
|
}
|
||||||
@ -586,7 +593,15 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
|||||||
return displayMenu;
|
return displayMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MenuEntryBase<String>> _getDisplayMenu(dynamic futureData) {
|
bool _isWindowCanBeAdjusted(int remoteCount) {
|
||||||
|
final RxBool fullscreen = Get.find(tag: 'fullscreen');
|
||||||
|
return remoteCount == 1 &&
|
||||||
|
fullscreen.isFalse &&
|
||||||
|
widget.ffi.canvasModel.scale > 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<MenuEntryBase<String>> _getDisplayMenu(
|
||||||
|
dynamic futureData, int remoteCount) {
|
||||||
const EdgeInsets padding = EdgeInsets.only(left: 18.0, right: 8.0);
|
const EdgeInsets padding = EdgeInsets.only(left: 18.0, right: 8.0);
|
||||||
final displayMenu = [
|
final displayMenu = [
|
||||||
MenuEntryRadios<String>(
|
MenuEntryRadios<String>(
|
||||||
@ -739,6 +754,42 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
|||||||
MenuEntryDivider<String>(),
|
MenuEntryDivider<String>(),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (_isWindowCanBeAdjusted(remoteCount)) {
|
||||||
|
displayMenu.insert(
|
||||||
|
0,
|
||||||
|
MenuEntryDivider<String>(),
|
||||||
|
);
|
||||||
|
displayMenu.insert(
|
||||||
|
0,
|
||||||
|
MenuEntryButton<String>(
|
||||||
|
childBuilder: (TextStyle? style) => Container(
|
||||||
|
alignment: AlignmentDirectional.center,
|
||||||
|
height: _MenubarTheme.height,
|
||||||
|
child: Text(
|
||||||
|
translate('Adjust Window'),
|
||||||
|
style: style,
|
||||||
|
)),
|
||||||
|
proc: () {
|
||||||
|
() async {
|
||||||
|
final wndRect =
|
||||||
|
await WindowController.fromWindowId(widget.windowId)
|
||||||
|
.getFrame();
|
||||||
|
final canvasModel = widget.ffi.canvasModel;
|
||||||
|
final width =
|
||||||
|
canvasModel.size.width + canvasModel.windowBorderWidth * 2;
|
||||||
|
final height = canvasModel.size.height +
|
||||||
|
canvasModel.tabBarHeight +
|
||||||
|
canvasModel.windowBorderWidth * 2;
|
||||||
|
await WindowController.fromWindowId(widget.windowId).setFrame(
|
||||||
|
Rect.fromLTWH(wndRect.left, wndRect.top, width, height));
|
||||||
|
}();
|
||||||
|
},
|
||||||
|
padding: padding,
|
||||||
|
dismissOnClicked: true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Show Codec Preference
|
/// Show Codec Preference
|
||||||
if (bind.mainHasHwcodec()) {
|
if (bind.mainHasHwcodec()) {
|
||||||
final List<bool> codecs = [];
|
final List<bool> codecs = [];
|
||||||
|
@ -69,6 +69,8 @@ class DesktopTabController {
|
|||||||
|
|
||||||
DesktopTabController({required this.tabType});
|
DesktopTabController({required this.tabType});
|
||||||
|
|
||||||
|
int get length => state.value.tabs.length;
|
||||||
|
|
||||||
void add(TabInfo tab, {bool authorized = false}) {
|
void add(TabInfo tab, {bool authorized = false}) {
|
||||||
if (!isDesktop) return;
|
if (!isDesktop) return;
|
||||||
final index = state.value.tabs.indexWhere((e) => e.key == tab.key);
|
final index = state.value.tabs.indexWhere((e) => e.key == tab.key);
|
||||||
|
Loading…
Reference in New Issue
Block a user