Improve fullscreen

This commit is contained in:
2025-03-03 19:28:20 +08:00
parent 9fe49217dc
commit 4af15b9139
2 changed files with 98 additions and 69 deletions

View File

@@ -6,13 +6,27 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:venera/foundation/app.dart'; import 'package:venera/foundation/app.dart';
import 'package:venera/foundation/comic_source/comic_source.dart'; import 'package:venera/foundation/comic_source/comic_source.dart';
import 'package:venera/foundation/global_state.dart';
import 'package:window_manager/window_manager.dart'; import 'package:window_manager/window_manager.dart';
const _kTitleBarHeight = 36.0; const _kTitleBarHeight = 36.0;
void toggleWindowFrame() { class WindowFrameController extends InheritedWidget {
GlobalState.find<_WindowFrameState>().toggleWindowFrame(); /// Whether the window frame is hidden.
final bool isWindowFrameHidden;
/// Sets the visibility of the window frame.
final void Function(bool) setWindowFrame;
const WindowFrameController._create({
required this.isWindowFrameHidden,
required this.setWindowFrame,
required super.child,
});
@override
bool updateShouldNotify(covariant InheritedWidget oldWidget) {
return false;
}
} }
class WindowFrame extends StatefulWidget { class WindowFrame extends StatefulWidget {
@@ -22,95 +36,105 @@ class WindowFrame extends StatefulWidget {
@override @override
State<WindowFrame> createState() => _WindowFrameState(); State<WindowFrame> createState() => _WindowFrameState();
static WindowFrameController of(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType<WindowFrameController>()!;
}
} }
class _WindowFrameState extends AutomaticGlobalState<WindowFrame> { class _WindowFrameState extends State<WindowFrame> {
bool isHideWindowFrame = false; bool isWindowFrameHidden = false;
bool useDarkTheme = false; bool useDarkTheme = false;
void toggleWindowFrame() { void setWindowFrame(bool show) {
isHideWindowFrame = !isHideWindowFrame; setState(() {
isWindowFrameHidden = !show;
});
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (App.isMobile) return widget.child; if (App.isMobile) return widget.child;
if (isHideWindowFrame) return widget.child;
var body = Stack( Widget body = Stack(
children: [ children: [
Positioned.fill( Positioned.fill(
child: MediaQuery( child: MediaQuery(
data: MediaQuery.of(context).copyWith( data: MediaQuery.of(context).copyWith(
padding: const EdgeInsets.only(top: _kTitleBarHeight)), padding: isWindowFrameHidden
? null
: const EdgeInsets.only(top: _kTitleBarHeight),
),
child: widget.child, child: widget.child,
), ),
), ),
Positioned( if (!isWindowFrameHidden)
top: 0, Positioned(
left: 0, top: 0,
right: 0, left: 0,
child: Material( right: 0,
color: Colors.transparent, child: Material(
child: Theme( color: Colors.transparent,
data: Theme.of(context).copyWith( child: Theme(
brightness: useDarkTheme ? Brightness.dark : null, data: Theme.of(context).copyWith(
), brightness: useDarkTheme ? Brightness.dark : null,
child: Builder(builder: (context) { ),
return SizedBox( child: Builder(builder: (context) {
height: _kTitleBarHeight, return SizedBox(
child: Row( height: _kTitleBarHeight,
children: [ child: Row(
if (App.isMacOS) children: [
const DragToMoveArea( if (App.isMacOS)
child: SizedBox( const DragToMoveArea(
height: double.infinity, child: SizedBox(
width: 16, height: double.infinity,
), width: 16,
).paddingRight(52)
else
const SizedBox(width: 12),
Expanded(
child: DragToMoveArea(
child: Text(
'Venera',
style: TextStyle(
fontSize: 13,
color: (useDarkTheme ||
context.brightness == Brightness.dark)
? Colors.white
: Colors.black,
), ),
) ).paddingRight(52)
.toAlign(Alignment.centerLeft) else
.paddingLeft(4 + (App.isMacOS ? 25 : 0)), const SizedBox(width: 12),
Expanded(
child: DragToMoveArea(
child: Text(
'Venera',
style: TextStyle(
fontSize: 13,
color: (useDarkTheme ||
context.brightness == Brightness.dark)
? Colors.white
: Colors.black,
),
)
.toAlign(Alignment.centerLeft)
.paddingLeft(4 + (App.isMacOS ? 25 : 0)),
),
), ),
), if (kDebugMode)
if (kDebugMode) const TextButton(
const TextButton( onPressed: debug,
onPressed: debug, child: Text('Debug'),
child: Text('Debug'), ),
), if (!App.isMacOS) const WindowButtons()
if (!App.isMacOS) const WindowButtons() ],
], ),
), );
); }),
}), ),
), ),
), )
)
], ],
); );
if (App.isLinux) { if (App.isLinux) {
return VirtualWindowFrame(child: body); body = VirtualWindowFrame(child: body);
} else {
return body;
} }
}
@override return WindowFrameController._create(
Object? get key => 'WindowFrame'; isWindowFrameHidden: isWindowFrameHidden,
setWindowFrame: setWindowFrame,
child: body,
);
}
} }
class WindowButtons extends StatefulWidget { class WindowButtons extends StatefulWidget {

View File

@@ -222,6 +222,9 @@ class _ReaderState extends State<Reader>
} }
void onKeyEvent(KeyEvent event) { void onKeyEvent(KeyEvent event) {
if (event.logicalKey == LogicalKeyboardKey.f12 && event is KeyUpEvent) {
fullscreen();
}
_imageViewController?.handleKeyEvent(event); _imageViewController?.handleKeyEvent(event);
} }
@@ -496,10 +499,12 @@ abstract mixin class _ReaderLocation {
mixin class _ReaderWindow { mixin class _ReaderWindow {
bool isFullscreen = false; bool isFullscreen = false;
void fullscreen() { void fullscreen() async {
windowManager.setFullScreen(!isFullscreen); await windowManager.hide();
await windowManager.setFullScreen(!isFullscreen);
await windowManager.show();
isFullscreen = !isFullscreen; isFullscreen = !isFullscreen;
toggleWindowFrame(); WindowFrame.of(App.rootContext).setWindowFrame(!isFullscreen);
} }
} }