Float several chats and keep them working on every tab

Floating chats were stuck on other destinations: the hidden Chat tab
muted the window's hide animation, so the window stayed painted but took
no input. The reveal now uses its own ticker, each floating pane's focus
scope hangs from a FloatingFocusRoot above the destination stack, and the
windows show over every destination like the terminal.

Any number of chats can float; the shortcut, a window's X and the menu
show or hide them together. Each pane keeps its own frame (also while
docked), saved in record version 2; version 1 records still load. Drags
read the live frame so fast pointer events no longer lose movement.
This commit is contained in:
2026-11-10 15:26:38 +00:00
parent 827d9bd3b5
commit cdd54c113c
25 changed files with 962 additions and 419 deletions
@@ -6,20 +6,46 @@ import 'package:flutter/foundation.dart';
import 'chat_float_store.dart';
import 'chat_workspace_controller.dart';
/// The floating chat window's frame. A drag moves it every pointer event
/// without saving; [commit] marks the end of the drag.
class ChatFloatFrame extends ChangeNotifier {
ChatFloatFrame([this._rect = chatFloatDefaultRect]);
Rect _rect;
Rect get rect => _rect;
/// The floating chat windows' frames, by pane id. A drag moves a window every
/// pointer event without saving; [commit] marks the end of the drag. A pane
/// keeps its frame while it is docked, so floating it again puts the window
/// back where it was.
class ChatFloatFrames extends ChangeNotifier {
ChatFloatFrames([Map<String, Rect> frames = const {}])
: _frames = {...frames};
final Map<String, Rect> _frames;
int _commits = 0;
Map<String, Rect> get frames => Map.unmodifiable(_frames);
/// Advances when a move or resize ends (the binding saves then).
int get commits => _commits;
void move(Rect rect) {
if (rect == _rect) return;
_rect = rect;
/// [paneId]'s frame; a window without one opens at the default frame,
/// stepped down and right by [index] so stacked windows stay visible.
Rect rectFor(String paneId, {int index = 0}) =>
_frames[paneId] ??
chatFloatDefaultRect.shift(Offset(32, 32) * index.toDouble());
/// Gives [paneId] its opening frame ([rectFor] at [index]) unless it has
/// one, so the window stays put when other windows come and go.
void place(String paneId, {required int index}) {
if (_frames.containsKey(paneId)) return;
move(paneId, rectFor(paneId, index: index));
}
void move(String paneId, Rect rect) {
if (_frames[paneId] == rect) return;
_frames[paneId] = rect;
notifyListeners();
}
/// Replaces every frame (a restore).
void restore(Map<String, Rect> frames) {
if (mapEquals(frames, _frames)) return;
_frames
..clear()
..addAll(frames);
notifyListeners();
}
@@ -29,21 +55,21 @@ class ChatFloatFrame extends ChangeNotifier {
}
}
/// Saves which chat floats, whether it shows and the window's frame, and
/// Saves which chats float, whether they show and their windows' frames, and
/// restores them once the workspace layout itself has been restored.
class ChatFloatBinding {
ChatFloatBinding({
required this.controller,
required this.frame,
required this.frames,
required this.store,
this.debounce = const Duration(milliseconds: 250),
}) {
controller.addListener(_changed);
frame.addListener(_frameChanged);
frames.addListener(_framesChanged);
}
final ChatWorkspaceController controller;
final ChatFloatFrame frame;
final ChatFloatFrames frames;
final ChatFloatStore store;
final Duration debounce;
ChatFloatRecord? _saved;
@@ -53,11 +79,22 @@ class ChatFloatBinding {
Timer? _timer;
Future<void> _writes = Future.value();
ChatFloatRecord get _current => ChatFloatRecord(
pane: controller.floatingPane,
shown: controller.floatShown,
rect: frame.rect,
);
/// Frames of panes still open somewhere (tiled or floating); a closed
/// pane's frame is dropped.
ChatFloatRecord get _current {
final open = {
for (final pane in controller.panes) pane.id,
for (final pane in controller.floatingPanes) pane.id,
};
return ChatFloatRecord(
panes: controller.floatingPanes,
shown: controller.floatShown,
frames: {
for (final MapEntry(:key, :value) in frames.frames.entries)
if (open.contains(key)) key: value,
},
);
}
/// Call after the workspace layout restored, so a saved float can tell
/// whether its chat is already open in the tiling.
@@ -66,25 +103,24 @@ class ChatFloatBinding {
try {
record = await store.read();
} on Object {
// Unavailable preferences leave the default frame and no float.
// Unavailable preferences leave the default frames and no float.
}
if (_disposed) return;
if (record != null) {
_saved = record;
_commits = frame.commits;
frame.move(record.rect);
final pane = record.pane;
if (pane != null && controller.floatingPane == null) {
controller.restoreFloat(pane, shown: record.shown);
_commits = frames.commits;
frames.restore(record.frames);
if (record.panes.isNotEmpty && controller.floatingPanes.isEmpty) {
controller.restoreFloats(record.panes, shown: record.shown);
}
}
_loading = false;
_changed();
}
void _frameChanged() {
if (frame.commits == _commits) return;
_commits = frame.commits;
void _framesChanged() {
if (frames.commits == _commits) return;
_commits = frames.commits;
_changed();
}
@@ -113,7 +149,7 @@ class ChatFloatBinding {
void dispose() {
if (_disposed) return;
controller.removeListener(_changed);
frame.removeListener(_frameChanged);
frames.removeListener(_framesChanged);
unawaited(flush());
_disposed = true;
}