From 0d1a720f036c18969caa87c16391b73a5c6291e3 Mon Sep 17 00:00:00 2001 From: lollipopkit Date: Tue, 19 Dec 2023 11:00:00 +0800 Subject: [PATCH] new: `custom titlebar` on linux/win --- lib/main.dart | 5 +-- lib/view/widget/appbar.dart | 63 ++++++++++++++++++++++--------------- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 1c4aa158..d84a4568 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -128,7 +128,10 @@ void _setupLogger() { Future _initDesktopWindow() async { if (!isDesktop) return; + await windowManager.ensureInitialized(); + await CustomAppBar.updateTitlebarHeight(); + const windowOptions = WindowOptions( size: Size(400, 777), center: true, @@ -136,9 +139,7 @@ Future _initDesktopWindow() async { skipTaskbar: false, titleBarStyle: TitleBarStyle.hidden, ); - windowManager.waitUntilReadyToShow(windowOptions, () async { - if (isMacOS) await CustomAppBar.updateTitlebarHeight(); await windowManager.show(); await windowManager.focus(); }); diff --git a/lib/view/widget/appbar.dart b/lib/view/widget/appbar.dart index cd1d34c9..37eb7221 100644 --- a/lib/view/widget/appbar.dart +++ b/lib/view/widget/appbar.dart @@ -40,31 +40,42 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget { Positioned( right: 0, top: 0, - child: Row( - children: [ - const SizedBox(width: 8), - IconButton( - icon: const Icon(Icons.minimize), - onPressed: () => windowManager.minimize(), - ), - const SizedBox(width: 8), - IconButton( - icon: const Icon(Icons.crop_square), - onPressed: () async { - if (await windowManager.isMaximized()) { - windowManager.unmaximize(); - } else { - windowManager.maximize(); - } - }, - ), - const SizedBox(width: 8), - IconButton( - icon: const Icon(Icons.close), - onPressed: () => windowManager.close(), - ), - const SizedBox(width: 8), - ], + child: GestureDetector( + onVerticalDragStart: (_) { + windowManager.startDragging(); + }, + onHorizontalDragStart: (_) { + windowManager.startDragging(); + }, + child: Row( + mainAxisSize: MainAxisSize.max, + children: [ + const SizedBox(width: 8), + IconButton( + icon: Transform.translate( + offset: const Offset(0, -3.5), + child: const Icon(Icons.minimize, size: 13), + ), + onPressed: () => windowManager.minimize(), + ), + const SizedBox(width: 8), + IconButton( + icon: const Icon(Icons.crop_square, size: 13), + onPressed: () async { + if (await windowManager.isMaximized()) { + windowManager.unmaximize(); + } else { + windowManager.maximize(); + } + }, + ), + const SizedBox(width: 8), + IconButton( + icon: const Icon(Icons.close, size: 14), + onPressed: () => windowManager.close(), + ), + ], + ), ), ), ], @@ -78,7 +89,7 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget { break; // Draw a titlebar on Linux case 'linux' || 'windows': - _titlebarHeight = 27; + _titlebarHeight = 37; _drawTitlebar = true; break; default: