Add the Windows menu, window cycling, edge snapping and size per kind
Phase 4 of docs/plans/floating-windows.md. A bar button lists the app's windows on every tab (show one, Show all, Minimise all, Close all). Alt+` and Alt+Shift+` bring the next or previous window to the front. Dropping a title at the left or right edge fills that half, at the top it maximises. A new window of a kind opens at the size that kind was last given.
This commit is contained in:
@@ -27,6 +27,9 @@ class WindowManager extends ChangeNotifier {
|
||||
final List<WindowEntry> _all = [];
|
||||
final Set<String> _hiddenGroups = {};
|
||||
final Map<String, Rect> _frames = {};
|
||||
|
||||
/// The size each kind's windows were last given, for its next new window.
|
||||
final Map<String, Size> _sizes = {};
|
||||
int _revision = 0;
|
||||
int _nextId = 0;
|
||||
|
||||
@@ -108,7 +111,9 @@ class WindowManager extends ChangeNotifier {
|
||||
frame:
|
||||
frame ??
|
||||
_frames[windowFrameKey(kind, serverKey, contentId)] ??
|
||||
spec.defaultFrame.shift(windowCascadeStep * siblings.toDouble()),
|
||||
(spec.defaultFrame.topLeft +
|
||||
windowCascadeStep * siblings.toDouble()) &
|
||||
(_sizes[kind] ?? spec.defaultFrame.size),
|
||||
data: data,
|
||||
);
|
||||
_change(() {
|
||||
@@ -176,8 +181,53 @@ class WindowManager extends ChangeNotifier {
|
||||
void setFrame(String id, Rect frame, {bool save = true}) =>
|
||||
_replace(id, (w) => w.copyWith(frame: frame), save: save);
|
||||
|
||||
/// Saves after a drag.
|
||||
void commit() => unawaited(save());
|
||||
/// Saves after a drag, and remembers the size for the kind's next window.
|
||||
void commit([String? id]) {
|
||||
final entry = id == null ? null : byId(id);
|
||||
if (entry != null && !entry.maximized) {
|
||||
_sizes[entry.kind] = entry.frame.size;
|
||||
}
|
||||
unawaited(save());
|
||||
}
|
||||
|
||||
/// Shows every window (un-minimised, every group shown).
|
||||
void showAll() {
|
||||
if (windows.every(isVisible)) return;
|
||||
_change(() {
|
||||
for (var i = 0; i < _all.length; i++) {
|
||||
final w = _all[i];
|
||||
if (!_here(w)) continue;
|
||||
_hiddenGroups.remove(w.groupId);
|
||||
if (w.minimized) _all[i] = w.copyWith(minimized: false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Minimises every window.
|
||||
void minimizeAll() {
|
||||
if (!windows.any(isVisible)) return;
|
||||
_change(() {
|
||||
for (var i = 0; i < _all.length; i++) {
|
||||
final w = _all[i];
|
||||
if (_here(w) && !w.minimized) _all[i] = w.copyWith(minimized: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Closes every window; each keeps its frame for its content.
|
||||
void closeAll() {
|
||||
final closing = windows;
|
||||
if (closing.isEmpty) return;
|
||||
_change(() {
|
||||
for (final entry in closing) {
|
||||
_all.remove(entry);
|
||||
_remember(entry);
|
||||
}
|
||||
});
|
||||
for (final entry in closing) {
|
||||
kinds[entry.kind]?.closed(entry);
|
||||
}
|
||||
}
|
||||
|
||||
void setMinimized(String id, bool minimized) =>
|
||||
_replace(id, (w) => w.copyWith(minimized: minimized));
|
||||
@@ -274,6 +324,9 @@ class WindowManager extends ChangeNotifier {
|
||||
_frames
|
||||
..clear()
|
||||
..addAll(record.frames);
|
||||
_sizes
|
||||
..clear()
|
||||
..addAll(record.sizes);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -281,6 +334,7 @@ class WindowManager extends ChangeNotifier {
|
||||
windows: List.unmodifiable(_all),
|
||||
hiddenGroups: Set.unmodifiable(_hiddenGroups),
|
||||
frames: Map.unmodifiable(_frames),
|
||||
sizes: Map.unmodifiable(_sizes),
|
||||
);
|
||||
|
||||
Future<void> save() async {
|
||||
|
||||
Reference in New Issue
Block a user