a99f7014f5
Phase 1.3 and 1.4 of docs/plans/floating-windows.md. Windows are plain children of the terminal stage's stack in the shell page, outside every destination, so popups opened from one are above all of them. Each window has its own page navigator: pushed pages open inside the window, and popup routes go to the root navigator. One WindowFrame chrome (move, resize, minimise, maximise, close), a focus scope per window, a ScaffoldMessenger per window. No feature uses it yet. The capture fixture opens probe windows with ?windows=N, and window_layering_test.dart covers every popup type from a window over Chat and over another destination.
109 lines
3.3 KiB
Dart
109 lines
3.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'window_focus.dart';
|
|
import 'window_layer.dart';
|
|
import 'window_manager.dart';
|
|
|
|
/// The app's floating windows, drawn in the shell page above the
|
|
/// destinations and the terminal panel: plain children of one stack, in the
|
|
/// manager's order (the last pressed, focused or opened on top).
|
|
///
|
|
/// Because the windows are part of the shell page rather than an overlay
|
|
/// above it, every popup opened from one (a sheet, dialog, menu or dropdown
|
|
/// on the root navigator; a tooltip in the page's overlay) is drawn above
|
|
/// all of them. A window is built whatever destination shows, so its
|
|
/// tickers, focus and semantics never depend on a hidden tab.
|
|
///
|
|
/// The host fills its parent and takes no input between windows.
|
|
class WindowHost extends StatefulWidget {
|
|
const WindowHost({super.key, required this.manager});
|
|
|
|
final WindowManager manager;
|
|
|
|
@override
|
|
State<WindowHost> createState() => _WindowHostState();
|
|
}
|
|
|
|
class _WindowHostState extends State<WindowHost> {
|
|
final WindowFocus _focus = WindowFocus();
|
|
Set<String> _visible = const {};
|
|
String? _active;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
widget.manager.addListener(_changed);
|
|
WidgetsBinding.instance.addPostFrameCallback((_) => _changed());
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(covariant WindowHost oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
if (oldWidget.manager != widget.manager) {
|
|
oldWidget.manager.removeListener(_changed);
|
|
widget.manager.addListener(_changed);
|
|
_changed();
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
widget.manager.removeListener(_changed);
|
|
_focus.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
/// Moves the keyboard with the windows: a window that shows or comes to
|
|
/// the top takes it; when the window that had it hides, the next one down
|
|
/// takes it, and after the last one it returns to where it was.
|
|
void _changed() {
|
|
if (!mounted) return;
|
|
final manager = widget.manager;
|
|
final visible = {
|
|
for (final w in manager.windows)
|
|
if (manager.isVisible(w)) w.id,
|
|
};
|
|
final active = manager.active?.id;
|
|
final focused = _focus.focused;
|
|
if (_visible.isEmpty && visible.isNotEmpty) _focus.remember();
|
|
if (active == null) {
|
|
if (_visible.isNotEmpty) _focus.release();
|
|
} else if (active != _active || !_visible.contains(active)) {
|
|
_focus.focusSoon(active);
|
|
} else if (focused != null && !visible.contains(focused)) {
|
|
_focus.focusSoon(active);
|
|
}
|
|
_visible = visible;
|
|
_active = active;
|
|
setState(() {});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final manager = widget.manager;
|
|
final windows = manager.windows;
|
|
_focus.retain({for (final w in windows) w.id});
|
|
return LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
final bounds = constraints.biggest;
|
|
return Stack(
|
|
fit: StackFit.expand,
|
|
children: [
|
|
for (final entry in windows)
|
|
if (manager.kinds[entry.kind] case final kind?)
|
|
WindowLayer(
|
|
key: ValueKey(entry.id),
|
|
manager: manager,
|
|
kind: kind,
|
|
entry: entry,
|
|
visible: manager.isVisible(entry),
|
|
bounds: bounds,
|
|
focus: _focus,
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|