Skip to content

Commit

Permalink
windows transparent title bar
Browse files Browse the repository at this point in the history
  • Loading branch information
ErBWs committed Feb 5, 2025
1 parent 0f1945f commit 1123362
Show file tree
Hide file tree
Showing 6 changed files with 268 additions and 222 deletions.
50 changes: 50 additions & 0 deletions lib/bean/appbar/desktop_title_bar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:kazumi/utils/storage.dart';

class DesktopTitleBar extends StatefulWidget {
const DesktopTitleBar({
super.key,
required this.child,
this.requireOffset = true,
});

final Widget child;
final bool requireOffset;

@override
State<StatefulWidget> createState() => _DesktopTitleBar();
}

class _DesktopTitleBar extends State<DesktopTitleBar> {
bool showWindowButton =
GStorage.setting.get(SettingBoxKey.showWindowButton, defaultValue: false);

EdgeInsets getInsets() {
if (!showWindowButton) {
return EdgeInsets.zero;
}
if (!widget.requireOffset) {
return EdgeInsets.zero;
}
if (Platform.isMacOS) {
return const EdgeInsets.only(top: 22);
} else if (Platform.isWindows) {
return const EdgeInsets.only(top: 32);
} else {
return EdgeInsets.zero;
}
}

@override
Widget build(BuildContext context) {
return SafeArea(
left: false,
top: true,
right: false,
bottom: false,
minimum: getInsets(),
child: widget.child,
);
}
}
7 changes: 3 additions & 4 deletions lib/bean/appbar/sys_app_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:kazumi/bean/appbar/desktop_title_bar.dart';
import 'package:kazumi/bean/dialog/dialog_helper.dart';
import 'package:kazumi/utils/storage.dart';
import 'package:kazumi/utils/utils.dart';
Expand Down Expand Up @@ -59,10 +60,8 @@ class SysAppBar extends StatelessWidget implements PreferredSizeWidget {
}
acs.add(const SizedBox(width: 8));
}
return SafeArea(
minimum: (Platform.isMacOS && needTopOffset && showWindowButton())
? const EdgeInsets.only(top: 22)
: EdgeInsets.zero,
return DesktopTitleBar(
requireOffset: needTopOffset,
child: GestureDetector(
// behavior: HitTestBehavior.translucent,
onPanStart: (_) =>
Expand Down
7 changes: 4 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ void main() async {
center: true,
// backgroundColor: Colors.white,
skipTaskbar: false,
titleBarStyle: (Platform.isMacOS || !showWindowButton)
? TitleBarStyle.hidden
: TitleBarStyle.normal,
titleBarStyle:
(Platform.isMacOS || Platform.isWindows || !showWindowButton)
? TitleBarStyle.hidden
: TitleBarStyle.normal,
windowButtonVisibility: showWindowButton,
title: 'Kazumi',
);
Expand Down
13 changes: 3 additions & 10 deletions lib/pages/player/player_item_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:kazumi/bean/appbar/desktop_title_bar.dart';
import 'package:kazumi/utils/utils.dart';
import 'package:kazumi/pages/video/video_controller.dart';
import 'package:kazumi/bean/dialog/dialog_helper.dart';
Expand Down Expand Up @@ -563,16 +564,8 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {
visible: !playerController.lockPanel,
child: SlideTransition(
position: topOffsetAnimation,
child: SafeArea(
left: false,
top: true,
right: false,
bottom: false,
minimum: (Platform.isMacOS &&
!videoPageController.isFullscreen &&
showWindowButton)
? const EdgeInsets.only(top: 22)
: EdgeInsets.zero,
child: DesktopTitleBar(
requireOffset: !videoPageController.isFullscreen,
child: MouseRegion(
cursor: (videoPageController.isFullscreen &&
!playerController.showVideoController)
Expand Down
Loading

0 comments on commit 1123362

Please sign in to comment.