Skip to content

RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process

Files: limit transfer rows to top-level roots

Mele4541a62582c
diff --git a/src/files/app_listing.zig b/src/files/app_listing.zig
index d3c824f..b7118f9 100644
--- a/src/files/app_listing.zig
+++ b/src/files/app_listing.zig
@@ -367,22 +367,23 @@ pub fn sync(self: *App) void {
self.job_was_running = true;
const state_changed = self.job_state != progress.state;
const processed_changed = self.job_progress != progress.processed_items;
+ const measuring_changed = self.job_measuring != progress.measuring;
const bytes_changed = self.job_transferred_bytes != progress.transferred_bytes;
const tooltip_hovered = self.hoverKey() == std.math.maxInt(usize) - 2002;
// Active-file transitions only change progress presentation.
// They do not change the direct-child transfer rows for a
// directory transfer, so do not rebuild the entire listing.
- if (state_changed or
+ if (state_changed or measuring_changed or
((runner.kind == .copy or runner.kind == .move) and processed_changed))
{
self.transfer_rows_dirty = true;
}
- if (state_changed or
+ if (state_changed or measuring_changed or
((runner.kind == .copy or runner.kind == .move) and processed_changed))
{
self.transfer_tree_state.markDirty();
}
- if (state_changed) {
+ if (state_changed or measuring_changed) {
self.invalidate();
} else if (processed_changed or bytes_changed or file_path_changed or
(rate_changed and tooltip_hovered))
@@ -406,6 +407,7 @@ pub fn sync(self: *App) void {
self.job_progress = progress.processed_items;
self.job_state = progress.state;
self.job_transferred_bytes = progress.transferred_bytes;
+ self.job_measuring = progress.measuring;
}
const file_ops_active = self.job_state == .running or
diff --git a/src/files/app_transfer_tree.zig b/src/files/app_transfer_tree.zig
index 6c0975f..2e7a2ef 100644
--- a/src/files/app_transfer_tree.zig
+++ b/src/files/app_transfer_tree.zig
@@ -85,25 +85,19 @@ pub const State = struct {
return state == .skipped or state == .cancelled;
}
- /// A node is visible only when every directory ancestor is expanded.
+ /// The Transfers sidebar displays selected roots only.
pub fn nodeVisible(self: *const State, tree: *const projection.Tree, index: usize) bool {
- if (hiddenState(tree.nodes.items[index].state)) return false;
- var parent = tree.nodes.items[index].parent_index;
- while (parent) |parent_index| {
- const ancestor = tree.nodes.items[parent_index];
- if (hiddenState(ancestor.state) or ancestor.kind != .directory or
- !self.isExpanded(ancestor.path)) return false;
- parent = ancestor.parent_index;
- }
- return true;
+ _ = self;
+ const node = tree.nodes.items[index];
+ return node.parent_index == null and !hiddenState(node.state);
}
pub fn visibleCount(self: *const State, tree: *const projection.Tree) usize {
const profile_started = ui_profile.start();
- defer ui_profile.finish(profile_started, "tree_visible_count", tree.nodes.items.len);
+ defer ui_profile.finish(profile_started, "tree_visible_count", tree.roots.items.len);
var count: usize = 0;
- for (tree.nodes.items, 0..) |_, index| {
+ for (tree.roots.items) |index| {
if (self.nodeVisible(tree, index)) count += 1;
}
return count;
@@ -341,11 +335,11 @@ test "transfer tree hides skipped and cancelled entries" {
var state = State.init(allocator);
defer state.deinit();
- try state.toggleExpanded("/destination/source");
try std.testing.expect(state.nodeVisible(&tree, 0));
- try std.testing.expect(state.nodeVisible(&tree, 1));
+ try std.testing.expect(!state.nodeVisible(&tree, 1));
try std.testing.expect(!state.nodeVisible(&tree, 2));
try std.testing.expect(!state.nodeVisible(&tree, 3));
- try std.testing.expectEqual(@as(usize, 2), state.visibleCount(&tree));
+ try std.testing.expectEqual(@as(usize, 1), state.visibleCount(&tree));
+ try std.testing.expectEqual(@as(usize, 1), tree.roots.items.len);
}
diff --git a/src/files/transfer_tree.zig b/src/files/transfer_tree.zig
index ffb10ca..fa2cab5 100644
--- a/src/files/transfer_tree.zig
+++ b/src/files/transfer_tree.zig
@@ -19,6 +19,7 @@ pub const Node = struct {
pub const Tree = struct {
allocator: Allocator,
nodes: std.ArrayList(Node) = .empty,
+ roots: std.ArrayList(usize) = .empty,
pub fn deinit(self: *Tree) void {
for (self.nodes.items) |node| {
@@ -27,6 +28,7 @@ pub const Tree = struct {
self.allocator.free(node.name);
}
self.nodes.deinit(self.allocator);
+ self.roots.deinit(self.allocator);
}
};
@@ -118,6 +120,14 @@ pub fn build(allocator: Allocator, entries: []const ops.TransferEntry) !Tree {
node.parent_index = parent_index;
}
+ // Keep a compact index of selected top-level entries for sidebar UI.
+ // Descendants remain in nodes for complete subtree aggregation.
+ for (tree.nodes.items, 0..) |node, index| {
+ if (node.parent_index == null) {
+ try tree.roots.append(allocator, index);
+ }
+ }
+
return tree;
}