double click toggle maximize
This commit is contained in:
parent
c01b9d5d7d
commit
06844f2f4f
@ -289,57 +289,48 @@ class DesktopTab extends StatelessWidget {
|
|||||||
Widget _buildBar() {
|
Widget _buildBar() {
|
||||||
return Row(
|
return Row(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Row(
|
||||||
child: Row(
|
children: [
|
||||||
children: [
|
Offstage(
|
||||||
Offstage(
|
offstage: !Platform.isMacOS,
|
||||||
offstage: !Platform.isMacOS,
|
child: const SizedBox(
|
||||||
child: const SizedBox(
|
width: 78,
|
||||||
width: 78,
|
)),
|
||||||
)),
|
GestureDetector(
|
||||||
Row(children: [
|
onDoubleTap: () =>
|
||||||
Offstage(
|
showMaximize ? toggleMaximize(isMainWindow) : null,
|
||||||
offstage: !showLogo,
|
onPanStart: (_) => startDragging(isMainWindow),
|
||||||
child: SvgPicture.asset(
|
child: Row(children: [
|
||||||
'assets/logo.svg',
|
Offstage(
|
||||||
width: 16,
|
offstage: !showLogo,
|
||||||
height: 16,
|
child: SvgPicture.asset(
|
||||||
)),
|
'assets/logo.svg',
|
||||||
Offstage(
|
width: 16,
|
||||||
offstage: !showTitle,
|
height: 16,
|
||||||
child: const Text(
|
)),
|
||||||
"RustDesk",
|
Offstage(
|
||||||
style: TextStyle(fontSize: 13),
|
offstage: !showTitle,
|
||||||
).marginOnly(left: 2))
|
child: const Text(
|
||||||
]).marginOnly(
|
"RustDesk",
|
||||||
left: 5,
|
style: TextStyle(fontSize: 13),
|
||||||
right: 10,
|
).marginOnly(left: 2))
|
||||||
),
|
]).marginOnly(
|
||||||
Expanded(
|
left: 5,
|
||||||
child: GestureDetector(
|
right: 10,
|
||||||
onPanStart: (_) {
|
)),
|
||||||
if (isMainWindow) {
|
_ListView(
|
||||||
windowManager.startDragging();
|
controller: controller,
|
||||||
} else {
|
onTabClose: onTabClose,
|
||||||
WindowController.fromWindowId(windowId!)
|
tabBuilder: tabBuilder,
|
||||||
.startDragging();
|
labelGetter: labelGetter,
|
||||||
}
|
),
|
||||||
},
|
],
|
||||||
child: _ListView(
|
|
||||||
controller: controller,
|
|
||||||
onTabClose: onTabClose,
|
|
||||||
tabBuilder: tabBuilder,
|
|
||||||
labelGetter: labelGetter,
|
|
||||||
)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
Offstage(offstage: tail == null, child: tail),
|
|
||||||
WindowActionPanel(
|
WindowActionPanel(
|
||||||
mainTab: isMainWindow,
|
isMainWindow: isMainWindow,
|
||||||
tabType: tabType,
|
tabType: tabType,
|
||||||
state: state,
|
state: state,
|
||||||
|
tail: tail,
|
||||||
showMinimize: showMinimize,
|
showMinimize: showMinimize,
|
||||||
showMaximize: showMaximize,
|
showMaximize: showMaximize,
|
||||||
showClose: showClose,
|
showClose: showClose,
|
||||||
@ -351,20 +342,22 @@ class DesktopTab extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class WindowActionPanel extends StatefulWidget {
|
class WindowActionPanel extends StatefulWidget {
|
||||||
final bool mainTab;
|
final bool isMainWindow;
|
||||||
final DesktopTabType tabType;
|
final DesktopTabType tabType;
|
||||||
final Rx<DesktopTabState> state;
|
final Rx<DesktopTabState> state;
|
||||||
|
|
||||||
final bool showMinimize;
|
final bool showMinimize;
|
||||||
final bool showMaximize;
|
final bool showMaximize;
|
||||||
final bool showClose;
|
final bool showClose;
|
||||||
|
final Widget? tail;
|
||||||
final Future<bool> Function()? onClose;
|
final Future<bool> Function()? onClose;
|
||||||
|
|
||||||
const WindowActionPanel(
|
const WindowActionPanel(
|
||||||
{Key? key,
|
{Key? key,
|
||||||
required this.mainTab,
|
required this.isMainWindow,
|
||||||
required this.tabType,
|
required this.tabType,
|
||||||
required this.state,
|
required this.state,
|
||||||
|
this.tail,
|
||||||
this.showMinimize = true,
|
this.showMinimize = true,
|
||||||
this.showMaximize = true,
|
this.showMaximize = true,
|
||||||
this.showClose = true,
|
this.showClose = true,
|
||||||
@ -387,7 +380,7 @@ class WindowActionPanelState extends State<WindowActionPanel>
|
|||||||
DesktopMultiWindow.addListener(this);
|
DesktopMultiWindow.addListener(this);
|
||||||
windowManager.addListener(this);
|
windowManager.addListener(this);
|
||||||
|
|
||||||
if (widget.mainTab) {
|
if (widget.isMainWindow) {
|
||||||
windowManager.isMaximized().then((maximized) {
|
windowManager.isMaximized().then((maximized) {
|
||||||
if (isMaximized != maximized) {
|
if (isMaximized != maximized) {
|
||||||
WidgetsBinding.instance.addPostFrameCallback(
|
WidgetsBinding.instance.addPostFrameCallback(
|
||||||
@ -430,23 +423,24 @@ class WindowActionPanelState extends State<WindowActionPanel>
|
|||||||
super.onWindowUnmaximize();
|
super.onWindowUnmaximize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void onWindowClose() {
|
|
||||||
debugPrint("onWindowClose : is Main : ${widget.mainTab}");
|
|
||||||
super.onWindowClose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Row(
|
return Expanded(
|
||||||
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: GestureDetector(
|
||||||
|
onDoubleTap: widget.showMaximize ? _toggleMaximize : null,
|
||||||
|
onPanStart: (_) => startDragging(widget.isMainWindow),
|
||||||
|
)),
|
||||||
|
Offstage(offstage: widget.tail == null, child: widget.tail),
|
||||||
Offstage(
|
Offstage(
|
||||||
offstage: !widget.showMinimize,
|
offstage: !widget.showMinimize,
|
||||||
child: ActionIcon(
|
child: ActionIcon(
|
||||||
message: 'Minimize',
|
message: 'Minimize',
|
||||||
icon: IconFont.min,
|
icon: IconFont.min,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (widget.mainTab) {
|
if (widget.isMainWindow) {
|
||||||
windowManager.minimize();
|
windowManager.minimize();
|
||||||
} else {
|
} else {
|
||||||
WindowController.fromWindowId(windowId!).minimize();
|
WindowController.fromWindowId(windowId!).minimize();
|
||||||
@ -459,24 +453,7 @@ class WindowActionPanelState extends State<WindowActionPanel>
|
|||||||
child: ActionIcon(
|
child: ActionIcon(
|
||||||
message: isMaximized ? "Restore" : "Maximize",
|
message: isMaximized ? "Restore" : "Maximize",
|
||||||
icon: isMaximized ? IconFont.restore : IconFont.max,
|
icon: isMaximized ? IconFont.restore : IconFont.max,
|
||||||
onTap: () {
|
onTap: _toggleMaximize,
|
||||||
if (widget.mainTab) {
|
|
||||||
if (isMaximized) {
|
|
||||||
windowManager.unmaximize();
|
|
||||||
} else {
|
|
||||||
windowManager.maximize();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
final wc = WindowController.fromWindowId(windowId!);
|
|
||||||
if (isMaximized) {
|
|
||||||
wc.unmaximize();
|
|
||||||
} else {
|
|
||||||
wc.maximize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// setState for sub window, wc.unmaximize/maximize() will not invoke onWindowMaximize/Unmaximize
|
|
||||||
setState(() => isMaximized = !isMaximized);
|
|
||||||
},
|
|
||||||
isClose: false,
|
isClose: false,
|
||||||
)),
|
)),
|
||||||
Offstage(
|
Offstage(
|
||||||
@ -487,7 +464,7 @@ class WindowActionPanelState extends State<WindowActionPanel>
|
|||||||
onTap: () async {
|
onTap: () async {
|
||||||
final res = await widget.onClose?.call() ?? true;
|
final res = await widget.onClose?.call() ?? true;
|
||||||
if (res) {
|
if (res) {
|
||||||
if (widget.mainTab) {
|
if (widget.isMainWindow) {
|
||||||
windowManager.close();
|
windowManager.close();
|
||||||
} else {
|
} else {
|
||||||
// only hide for multi window, not close
|
// only hide for multi window, not close
|
||||||
@ -500,7 +477,47 @@ class WindowActionPanelState extends State<WindowActionPanel>
|
|||||||
isClose: true,
|
isClose: true,
|
||||||
)),
|
)),
|
||||||
],
|
],
|
||||||
);
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _toggleMaximize() {
|
||||||
|
toggleMaximize(widget.isMainWindow).then((maximize) {
|
||||||
|
if (isMaximized != maximize) {
|
||||||
|
// setState for sub window, wc.unmaximize/maximize() will not invoke onWindowMaximize/Unmaximize
|
||||||
|
setState(() => isMaximized = !isMaximized);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void startDragging(bool isMainWindow) {
|
||||||
|
if (isMainWindow) {
|
||||||
|
windowManager.startDragging();
|
||||||
|
} else {
|
||||||
|
WindowController.fromWindowId(windowId!).startDragging();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// return true -> window will be maximize
|
||||||
|
/// return false -> window will be unmaximize
|
||||||
|
Future<bool> toggleMaximize(bool isMainWindow) async {
|
||||||
|
if (isMainWindow) {
|
||||||
|
if (await windowManager.isMaximized()) {
|
||||||
|
windowManager.unmaximize();
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
windowManager.maximize();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
final wc = WindowController.fromWindowId(windowId!);
|
||||||
|
if (await wc.isMaximized()) {
|
||||||
|
wc.unmaximize();
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
wc.maximize();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user