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);
|
||||
|
||||
Reference in New Issue
Block a user