fix(desktop): hide window controls in fullscreen

This commit is contained in:
zarzet committed 2026-10-25 21:27:03 +07:00
1 parent fe8b7c00dc
commit d281fa0029
4 files changed
+95 -53

No files matched your search

@@ -27,9 +27,8 @@ class KeyboardShortcutsPage extends ConsumerWidget {
showStore: showStore,
);
List<SingleActivator> keys(DesktopCommand command) => [
?desktopCommandShortcut(command, platform),
];
List<SingleActivator> keys(DesktopCommand command) =>
desktopCommandShortcuts(command, platform);
// Search and Settings also have their own command, listed in one row
// with the destination's number.
List<SingleActivator> tabKeys(ShellTab tab) => [
+15 -1
View File
@@ -144,6 +144,19 @@ const _destinationKeys = [
LogicalKeyboardKey.digit5,
];
/// Includes the native menu shortcut and any additional keyboard bindings.
List<SingleActivator> desktopCommandShortcuts(
DesktopCommand command, [
TargetPlatform? platform,
]) {
final target = platform ?? defaultTargetPlatform;
return [
?desktopCommandShortcut(command, target),
if (command == DesktopCommand.fullScreen && _usesCommandKey(target))
const SingleActivator(LogicalKeyboardKey.f11),
];
}
/// The shortcut that selects the [position]th (1-based) destination.
SingleActivator desktopDestinationShortcut(
int position, [
@@ -158,7 +171,8 @@ Map<ShortcutActivator, Intent> desktopShortcutBindings([
final target = platform ?? defaultTargetPlatform;
return {
for (final command in DesktopCommand.values)
?desktopCommandShortcut(command, target): DesktopCommandIntent(command),
for (final shortcut in desktopCommandShortcuts(command, target))
shortcut: DesktopCommandIntent(command),
for (var position = 1; position <= _destinationKeys.length; position++)
desktopDestinationShortcut(position, target): DesktopDestinationIntent(
position,
@@ -63,8 +63,8 @@ class DesktopWindowModeSetting extends StatelessWidget {
);
}
/// Keeps native replacement controls above the root navigator, including
/// Now Playing and modal routes. The mini player supplies its own controls.
/// Borderless window controls stay above pages and dialogs. Fullscreen keeps
/// the entire surface for content; the mini player supplies its own controls.
class DesktopWindowFrame extends StatelessWidget {
const DesktopWindowFrame({
super.key,
@@ -102,11 +102,8 @@ class DesktopWindowFrame extends StatelessWidget {
children: [
Column(
children: [
if (showControls && mode != DesktopWindowMode.windowed)
_WindowControls(
mode: mode,
onChooseMode: _chooseWindowMode,
)
if (showControls && mode == DesktopWindowMode.borderless)
_BorderlessWindowControls(onChooseMode: _chooseWindowMode)
else
const SizedBox.shrink(),
Expanded(child: child!),
@@ -144,21 +141,19 @@ class DesktopWindowFrame extends StatelessWidget {
}
}
class _WindowControls extends StatelessWidget {
const _WindowControls({required this.mode, required this.onChooseMode});
class _BorderlessWindowControls extends StatelessWidget {
const _BorderlessWindowControls({required this.onChooseMode});
final DesktopWindowMode mode;
final VoidCallback onChooseMode;
@override
Widget build(BuildContext context) {
final fullscreen = mode == DesktopWindowMode.fullscreen;
final title = SizedBox(
height: context.tokens.minTouchTarget,
child: Align(
alignment: AlignmentDirectional.centerStart,
child: Text(
desktopWindowModeLabel(context, mode),
desktopWindowModeLabel(context, DesktopWindowMode.borderless),
style: Theme.of(context).textTheme.labelLarge,
),
),
@@ -170,13 +165,11 @@ class _WindowControls extends StatelessWidget {
child: Row(
children: [
Expanded(
child: fullscreen
? title
: DesktopWindowDragArea(
frameless: true,
zoomOnDoubleClick: true,
child: title,
),
child: DesktopWindowDragArea(
frameless: true,
zoomOnDoubleClick: true,
child: title,
),
),
AppIconButton(
tooltip: context.l10n.desktopWindowMode,
@@ -186,35 +179,27 @@ class _WindowControls extends StatelessWidget {
AppIconButton(
tooltip: desktopTooltip(
context,
fullscreen
? context.l10n.desktopExitFullscreen
: context.l10n.desktopWindowed,
fullscreen
? DesktopCommand.fullScreen
: DesktopCommand.borderless,
),
icon: AppIcon(
fullscreen ? Icons.fullscreen_exit : Icons.filter_none,
context.l10n.desktopWindowed,
DesktopCommand.borderless,
),
icon: const AppIcon(Icons.filter_none),
onPressed: () => unawaited(leaveDesktopWindowMode()),
),
if (!fullscreen) ...[
AppIconButton(
tooltip: context.l10n.desktopMinimizeWindow,
icon: const AppIcon(Icons.minimize),
onPressed: minimizeDesktopWindow,
),
AppIconButton(
tooltip: context.l10n.desktopZoomWindow,
icon: const AppIcon(Icons.crop_square),
onPressed: zoomDesktopWindow,
),
AppIconButton(
tooltip: MaterialLocalizations.of(context).closeButtonTooltip,
icon: const AppIcon(Icons.close),
onPressed: closeDesktopWindow,
),
],
AppIconButton(
tooltip: context.l10n.desktopMinimizeWindow,
icon: const AppIcon(Icons.minimize),
onPressed: minimizeDesktopWindow,
),
AppIconButton(
tooltip: context.l10n.desktopZoomWindow,
icon: const AppIcon(Icons.crop_square),
onPressed: zoomDesktopWindow,
),
AppIconButton(
tooltip: MaterialLocalizations.of(context).closeButtonTooltip,
icon: const AppIcon(Icons.close),
onPressed: closeDesktopWindow,
),
],
),
),
+48 -4
View File
@@ -209,6 +209,12 @@ void main() {
(mac.trigger, mac.control, mac.meta),
(LogicalKeyboardKey.keyF, true, true),
);
final macF11 =
desktopShortcutBindings(TargetPlatform.macOS)[const SingleActivator(
LogicalKeyboardKey.f11,
)]
as DesktopCommandIntent;
expect(macF11.command, DesktopCommand.fullScreen);
});
Future<void> pumpApp(
@@ -309,11 +315,12 @@ void main() {
);
testWidgets(
'appearance choice applies fullscreen and offers an exit (Mornye: $mornye)',
'fullscreen fills the window and exits with F11 or Escape (Mornye: $mornye)',
(tester) async {
await pumpApp(
tester,
mornye: mornye,
shortcuts: true,
home: const Scaffold(body: DesktopWindowModeSetting()),
);
await tester.tap(find.text('Window mode'));
@@ -321,9 +328,17 @@ void main() {
await tester.tap(find.text('Full screen'));
await tester.pumpAndSettle();
expect(desktopWindowFullScreen.value, isTrue);
final exit = find.byTooltip(RegExp(r'^Exit full screen'));
expect(exit, findsOneWidget);
await tester.tap(exit);
expect(find.byTooltip(RegExp(r'^Exit full screen')), findsNothing);
expect(find.byTooltip('Window mode'), findsNothing);
expect(tester.getTopLeft(find.byType(Scaffold)), Offset.zero);
expect(tester.getSize(find.byType(Scaffold)), const Size(1000, 800));
await tester.sendKeyEvent(LogicalKeyboardKey.f11);
await tester.pumpAndSettle();
expect(desktopWindowMode.value, DesktopWindowMode.windowed);
await tester.sendKeyEvent(LogicalKeyboardKey.f11);
await tester.pumpAndSettle();
expect(desktopWindowFullScreen.value, isTrue);
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();
expect(desktopWindowMode.value, DesktopWindowMode.windowed);
},
@@ -359,6 +374,35 @@ void main() {
expect(desktopWindowMode.value, DesktopWindowMode.windowed);
});
testWidgets('macOS accepts F11 and Escape without fullscreen chrome', (
tester,
) async {
messenger.setMockMethodCallHandler(SystemChannels.menu, (_) async => null);
addTearDown(
() => messenger.setMockMethodCallHandler(SystemChannels.menu, null),
);
await pumpApp(
tester,
mornye: true,
shortcuts: true,
home: const Scaffold(body: Text('content')),
);
await tester.sendKeyEvent(LogicalKeyboardKey.f11);
await tester.pumpAndSettle();
expect(desktopWindowFullScreen.value, isTrue);
expect(find.text('Full screen'), findsNothing);
expect(tester.getTopLeft(find.byType(Scaffold)), Offset.zero);
await tester.sendKeyEvent(LogicalKeyboardKey.f11);
await tester.pumpAndSettle();
expect(desktopWindowMode.value, DesktopWindowMode.windowed);
await tester.sendKeyEvent(LogicalKeyboardKey.f11);
await tester.pumpAndSettle();
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();
expect(desktopWindowMode.value, DesktopWindowMode.windowed);
expect(tester.takeException(), isNull);
}, variant: TargetPlatformVariant.only(TargetPlatform.macOS));
testWidgets('fullscreen closes the mini player before changing mode', (
tester,
) async {