Skip to content

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

Show per-file transfer progress rings

Melfe228baa06cb
diff --git a/src/files/app.zig b/src/files/app.zig
index 478533e..b3d0cc3 100644
--- a/src/files/app.zig
+++ b/src/files/app.zig
@@ -279,6 +279,8 @@ pub const App = struct {
job_cut_revision: ?usize = null,
job_progress: usize = std.math.maxInt(usize),
job_transferred_bytes: u64 = 0,
+ job_current_file_path: [4096]u8 = undefined,
+ job_current_file_path_len: usize = 0,
job_rate_sample_bytes: u64 = 0,
job_rate_sample_at: i64 = 0,
job_bytes_per_second: u64 = 0,
diff --git a/src/files/app_items.zig b/src/files/app_items.zig
index cc14dc8..b6d532d 100644
--- a/src/files/app_items.zig
+++ b/src/files/app_items.zig
@@ -28,6 +28,7 @@ const itemType = App.itemType;
pub fn renderFileItems(self: *App, cr: *c.cairo_t, viewport_h: i32) void {
const accent = ui_theme.shellPalette().accent;
+ const job_progress = if (self.job_runner) |runner| runner.pollProgress() else null;
const cols = self.columns();
const cell = self.cellWidth();
const first = @divTrunc(self.scroll_y, self.rowHeight()) * cols;
@@ -69,6 +70,26 @@ pub fn renderFileItems(self: *App, cr: *c.cairo_t, viewport_h: i32) void {
if (cut) c.cairo_push_group(cr);
const icon = self.itemIconRect(index);
self.drawItemIcon(cr, item, icon.x, icon.y, icon.w);
+ if (job_progress) |progress| {
+ if ((progress.state == .running or progress.state == .paused) and
+ progress.current_file_path_len > 0 and
+ progress.current_file_size > 0 and
+ std.mem.eql(u8, progress.current_file_path[0..progress.current_file_path_len], item.path))
+ {
+ const fraction = @min(
+ 1.0,
+ @as(f64, @floatFromInt(progress.current_file_bytes)) /
+ @as(f64, @floatFromInt(progress.current_file_size)),
+ );
+ const ring_size = @min(26.0, icon.w);
+ shell_ui.drawProgressRing(cr, .{
+ .x = icon.x + (icon.w - ring_size) / 2,
+ .y = icon.y + (icon.w - ring_size) / 2,
+ .w = ring_size,
+ .h = ring_size,
+ }, fraction, accent);
+ }
+ }
if (item.is_dir and !item.is_symlink) {
if (self.job_runner) |runner| {
if (runner.progressForPath(item.path)) |progress| {
diff --git a/src/files/app_listing.zig b/src/files/app_listing.zig
index 4f30333..1620070 100644
--- a/src/files/app_listing.zig
+++ b/src/files/app_listing.zig
@@ -134,6 +134,8 @@ fn damageJobProgress(
self: *App,
damage_surfaces: bool,
damage_tooltip: bool,
+ previous_file_path: []const u8,
+ current_file_path: []const u8,
) void {
if (damage_surfaces) {
if (self.transfer_view.active) {
@@ -158,8 +160,14 @@ fn damageJobProgress(
var index = first;
while (index < last) : (index += 1) {
const item = self.items.items[@intCast(index)];
- if (!item.is_dir or item.is_symlink) continue;
- if (runner.progressForPath(item.path) == null) continue;
+ const parent_folder = item.is_dir and !item.is_symlink and
+ runner.progressForPath(item.path) != null;
+ const active_file =
+ (current_file_path.len > 0 and std.mem.eql(u8, item.path, current_file_path)) or
+ (previous_file_path.len > 0 and
+ !std.mem.eql(u8, previous_file_path, current_file_path) and
+ std.mem.eql(u8, item.path, previous_file_path));
+ if (!parent_folder and !active_file) continue;
const icon = self.itemIconRect(index);
const ring_size = @min(26.0, icon.w);
@@ -240,6 +248,12 @@ pub fn sync(self: *App) void {
}
if (self.job_runner) |runner| {
const progress = runner.pollProgress();
+ const current_file_path = if (progress.state == .running or progress.state == .paused)
+ progress.current_file_path[0..progress.current_file_path_len]
+ else
+ "";
+ const previous_file_path = self.job_current_file_path[0..self.job_current_file_path_len];
+ const file_path_changed = !std.mem.eql(u8, previous_file_path, current_file_path);
const sample_at = nowMs();
var rate_changed = false;
if (progress.state == .running or progress.state == .paused or progress.state == .waiting_conflict) {
@@ -301,10 +315,23 @@ pub fn sync(self: *App) void {
const tooltip_hovered = self.hoverKey() == std.math.maxInt(usize) - 2002;
if (structure_changed) {
self.invalidate();
- } else if (bytes_changed or
+ } else if (bytes_changed or file_path_changed or
(rate_changed and tooltip_hovered))
{
- damageJobProgress(self, bytes_changed, tooltip_hovered);
+ damageJobProgress(
+ self,
+ bytes_changed or file_path_changed,
+ tooltip_hovered,
+ previous_file_path,
+ current_file_path,
+ );
+ }
+ }
+ if (file_path_changed) {
+ self.job_current_file_path_len = 0;
+ if (current_file_path.len <= self.job_current_file_path.len) {
+ @memcpy(self.job_current_file_path[0..current_file_path.len], current_file_path);
+ self.job_current_file_path_len = current_file_path.len;
}
}
self.job_progress = progress.processed_items;