Chat: a phone layout tiles floating chats; a wide one floats them again
At phone width (Quick switch or Chat stack) floating windows are hidden, so a floating chat could not be opened from the list, the stack or the peek. The phone now holds each floating chat as an ordinary pane while the server set keeps it floating; widening floats it again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,8 @@ mixin _ChatScreenFloat on State<ChatScreen>, _ChatScreenWorkspace {
|
||||
void _bindWindows() {
|
||||
final windows = widget.windows;
|
||||
if (windows == null) return;
|
||||
_workspace.showOutside = windows.show;
|
||||
_workspace.showOutside = _showOutside;
|
||||
windows.manager.addListener(_windowsChanged);
|
||||
windows.tiling = _tiling = ChatTiling(
|
||||
holds: _workspace.holdsSession,
|
||||
dock: _dockSession,
|
||||
@@ -35,9 +36,99 @@ mixin _ChatScreenFloat on State<ChatScreen>, _ChatScreenWorkspace {
|
||||
if (windows != null && identical(windows.tiling, _tiling)) {
|
||||
windows.tiling = null;
|
||||
}
|
||||
windows?.manager.removeListener(_windowsChanged);
|
||||
_workspace.showOutside = null;
|
||||
}
|
||||
|
||||
/// A chat out in a window comes to the top on a wide layout. A phone
|
||||
/// ignores floating: the chat leaves its (hidden) window and opens as a
|
||||
/// pane, still floating in the server's set.
|
||||
bool _showOutside(String sessionId) {
|
||||
final windows = widget.windows;
|
||||
if (windows == null) return false;
|
||||
if (!_phoneIgnoresFloat) return windows.show(sessionId);
|
||||
_holdForPhone(windows, sessionId);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Takes [sessionId] out of its window, to be tiled on this phone layout.
|
||||
void _holdForPhone(ChatWindows windows, String sessionId) {
|
||||
final window = windows.windows
|
||||
.where((window) => window.contentId == sessionId)
|
||||
.firstOrNull;
|
||||
if (window == null) return;
|
||||
_phoneDocked.add(sessionId);
|
||||
windows.manager.close(window.id);
|
||||
}
|
||||
|
||||
/// Whether the last build was a phone's layout, which tiles floating chats.
|
||||
bool? _builtPhoneFloat;
|
||||
bool _followingFloat = false;
|
||||
|
||||
/// Called from build: a change between a phone and a wide layout moves
|
||||
/// the floating chats between panes and windows after the frame.
|
||||
void _trackFloatLayout() {
|
||||
if (widget.windows == null) return;
|
||||
final phone = _phoneIgnoresFloat;
|
||||
if (phone == _builtPhoneFloat) return;
|
||||
_builtPhoneFloat = phone;
|
||||
_followFloatLayoutSoon();
|
||||
}
|
||||
|
||||
void _windowsChanged() {
|
||||
if (_builtPhoneFloat == true &&
|
||||
(widget.windows?.windows.isNotEmpty ?? false)) {
|
||||
_followFloatLayoutSoon();
|
||||
}
|
||||
}
|
||||
|
||||
void _followFloatLayoutSoon() {
|
||||
if (_followingFloat) return;
|
||||
_followingFloat = true;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_followingFloat = false;
|
||||
if (mounted) _followFloatLayout();
|
||||
});
|
||||
}
|
||||
|
||||
/// On a phone every floating chat becomes a pane (the chat on screen
|
||||
/// stays); on a wide layout the chats held that way float again.
|
||||
void _followFloatLayout() {
|
||||
final windows = widget.windows;
|
||||
if (windows == null) return;
|
||||
final phone = _phoneIgnoresFloat;
|
||||
final ids = phone
|
||||
? windows.floatingSessionIds.toList()
|
||||
: _phoneDocked.toList();
|
||||
if (ids.isEmpty) return;
|
||||
// One write for the whole move: the chats stay floating in the set.
|
||||
_applyingServerWorkspace = true;
|
||||
try {
|
||||
if (phone) {
|
||||
final active = _workspace.activePaneId;
|
||||
for (final id in ids) {
|
||||
_holdForPhone(windows, id);
|
||||
_workspace.dock(id);
|
||||
}
|
||||
if (active != null) _workspace.activate(active);
|
||||
} else {
|
||||
for (final id in ids) {
|
||||
final pane = _workspace.panes
|
||||
.where((pane) => pane.sessionId == id)
|
||||
.firstOrNull;
|
||||
if (pane == null) continue;
|
||||
_workspace.detach(pane.id);
|
||||
windows.float(id);
|
||||
}
|
||||
_phoneDocked.clear();
|
||||
}
|
||||
} finally {
|
||||
_applyingServerWorkspace = false;
|
||||
}
|
||||
_syncOpenWorkspace();
|
||||
if (!phone && _workspace.paneCount == 0) _back();
|
||||
}
|
||||
|
||||
/// Panes float only on a wide layout, beside the chat list.
|
||||
bool get _floatsHere =>
|
||||
widget.windows != null && !_pageOpen && showsListBesideDetail(context);
|
||||
|
||||
@@ -113,9 +113,18 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
ChatWorkspaceBinding? _workspaceBinding;
|
||||
String? _workspaceScope;
|
||||
|
||||
/// Chats that float in windows on a wide layout, held as ordinary panes
|
||||
/// while the layout is a phone's (see `_ChatScreenFloat`). They stay
|
||||
/// floating in the server's set, so a wide layout floats them again.
|
||||
final Set<String> _phoneDocked = {};
|
||||
|
||||
/// Whether this layout ignores floating: a phone's, where windows are
|
||||
/// hidden and the chats are navigated one at a time.
|
||||
bool get _phoneIgnoresFloat =>
|
||||
mounted && widget.windows != null && !showsListBesideDetail(context);
|
||||
|
||||
Iterable<ChatOpenWorkspaceEntry> _serverWorkspaceEntries() sync* {
|
||||
final floating =
|
||||
widget.windows?.floatingSessionIds.toSet() ?? const <String>{};
|
||||
final floating = {...?widget.windows?.floatingSessionIds, ..._phoneDocked};
|
||||
for (final pane in _workspace.panes) {
|
||||
yield ChatOpenWorkspaceEntry(
|
||||
pane.sessionId,
|
||||
@@ -231,9 +240,24 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
]);
|
||||
}
|
||||
_applyingServerWorkspace = true;
|
||||
final phone = _phoneIgnoresFloat;
|
||||
try {
|
||||
final windows = widget.windows;
|
||||
if (windows != null) {
|
||||
for (final entry in snapshot.entries) {
|
||||
if (!entry.floating) _phoneDocked.remove(entry.sessionId);
|
||||
}
|
||||
if (windows != null && phone) {
|
||||
// A phone tiles the floating chats too; they float again when the
|
||||
// layout is wide.
|
||||
for (final entry in snapshot.entries.where((e) => e.floating)) {
|
||||
_phoneDocked.add(entry.sessionId);
|
||||
final window = windows.windows
|
||||
.where((window) => window.contentId == entry.sessionId)
|
||||
.firstOrNull;
|
||||
if (window != null) windows.manager.close(window.id);
|
||||
}
|
||||
}
|
||||
if (windows != null && !phone) {
|
||||
final entriesBySession = {
|
||||
for (final entry in snapshot.entries) entry.sessionId: entry,
|
||||
};
|
||||
@@ -259,7 +283,7 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
}
|
||||
_workspace.reconcileSessions(
|
||||
snapshot.entries
|
||||
.where((entry) => !entry.floating)
|
||||
.where((entry) => phone || !entry.floating)
|
||||
.map((entry) => entry.sessionId),
|
||||
);
|
||||
if (keepInitial) {
|
||||
@@ -364,6 +388,8 @@ mixin _ChatScreenWorkspace on State<ChatScreen> {
|
||||
'${_workspace.activePaneId}:${_workspace.panes.map((p) => '${p.id}=${p.sessionId}').join(',')}';
|
||||
if (_workspaceSignature == signature) return;
|
||||
_workspaceSignature = signature;
|
||||
// A phone-held floating chat the operator closed is no longer open.
|
||||
_phoneDocked.removeWhere((id) => !_workspace.holdsSession(id));
|
||||
_syncOpenWorkspace();
|
||||
_touchActiveChat();
|
||||
void update() {
|
||||
|
||||
@@ -550,6 +550,7 @@ class _ChatScreenState extends State<ChatScreen>
|
||||
(_) => _publishWorkspaceRoute(),
|
||||
);
|
||||
}
|
||||
_trackFloatLayout();
|
||||
_offeredNext = selected != null && _nextAfter(selected) != null;
|
||||
// A phone opens a chat as a real Navigator page with stock Back. A wide
|
||||
// window keeps the destination rail and the chat list beside the open
|
||||
|
||||
Reference in New Issue
Block a user