mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
Improve fullscreen
This commit is contained in:
@@ -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,30 +36,39 @@ 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,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (!isWindowFrameHidden)
|
||||||
Positioned(
|
Positioned(
|
||||||
top: 0,
|
top: 0,
|
||||||
left: 0,
|
left: 0,
|
||||||
@@ -103,14 +126,15 @@ class _WindowFrameState extends AutomaticGlobalState<WindowFrame> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
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 {
|
||||||
|
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user