Skip to content

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

Format transfer tooltip sizes with human-readable units

Mel9d3cdd039f4e
diff --git a/src/files/app_sidebar_paint.zig b/src/files/app_sidebar_paint.zig
index 62cbaf4..6ad79a6 100644
--- a/src/files/app_sidebar_paint.zig
+++ b/src/files/app_sidebar_paint.zig
@@ -608,11 +608,19 @@ pub fn renderFileOpsTip(self: *App, cr: *c.cairo_t) void {
var speed_buf: [96]u8 = undefined;
var bytes_buf: [96]u8 = undefined;
- const speed = i18n.fmt(&speed_buf, tr("{rate} KiB/s"), .{
- .rate = @divTrunc(self.job_bytes_per_second, 1024),
+ var speed_size_buf: [32]u8 = undefined;
+ var bytes_size_buf: [32]u8 = undefined;
+ const speed = i18n.fmt(&speed_buf, tr("{rate}/s"), .{
+ .rate = @import("app_draw.zig").formatSize(
+ @intCast(@min(self.job_bytes_per_second, @as(u64, std.math.maxInt(i64)))),
+ &speed_size_buf,
+ ),
}) catch "";
const transferred = i18n.fmt(&bytes_buf, tr("{value} transferred"), .{
- .value = @divTrunc(self.job_transferred_bytes, 1024),
+ .value = @import("app_draw.zig").formatSize(
+ @intCast(@min(self.job_transferred_bytes, @as(u64, std.math.maxInt(i64)))),
+ &bytes_size_buf,
+ ),
}) catch "";
const details = [_][]const u8{ speed, transferred };
transferTip.render(cr, self.w, self.h, self.mouse_x, self.mouse_y, tr("File transfer"), &details);
diff --git a/src/files/app_torrent_rows.zig b/src/files/app_torrent_rows.zig
index 82c00c3..5632228 100644
--- a/src/files/app_torrent_rows.zig
+++ b/src/files/app_torrent_rows.zig
@@ -157,9 +157,14 @@ pub fn renderTorrentTip(self: *App, cr: *c.cairo_t) void {
var peers_buf: [160]u8 = undefined;
var known_buf: [96]u8 = undefined;
var eta_buf: [96]u8 = undefined;
+ var download_size_buf: [32]u8 = undefined;
+ var upload_size_buf: [32]u8 = undefined;
const progress = if (t.pending) @as(i32, 0) else std.math.clamp(t.progress, 0, 1000000);
const state = std.fmt.bufPrint(&progress_buf, "{s} · {d}.{d}%", .{ if (self.torrents.fd < 0) tr("Disconnected") else inlineStatus(t), @divTrunc(progress, 10000), @mod(@divTrunc(progress, 1000), 10) }) catch "";
- const rates = i18n.fmt(&rate_buf, tr("↓ {rate} KiB/s ↑ {rate2} KiB/s"), .{ .rate = @divTrunc(t.download_rate, 1024), .rate2 = @divTrunc(t.upload_rate, 1024) }) catch "";
+ const rates = i18n.fmt(&rate_buf, tr("↓ {rate}/s ↑ {rate2}/s"), .{
+ .rate = draw.formatSize(t.download_rate, &download_size_buf),
+ .rate2 = draw.formatSize(t.upload_rate, &upload_size_buf),
+ }) catch "";
const connected = i18n.fmt(&peers_buf, tr("Connected peers: {peers} · Seeds: {seeds}"), .{ .peers = t.peers, .seeds = t.seeds }) catch "";
const known = i18n.fmt(&known_buf, tr("Known peers: {value}"), .{ .value = t.known_peers }) catch "";
const eta = if (@import("torrents.zig").etaSeconds(t)) |seconds|
diff --git a/src/files/app_torrents.zig b/src/files/app_torrents.zig
index 62a9139..5a04a71 100644
--- a/src/files/app_torrents.zig
+++ b/src/files/app_torrents.zig
@@ -934,11 +934,13 @@ pub fn renderTorrentSidebarTip(self: *App, cr: *c.cairo_t) void {
var download_buf: [96]u8 = undefined;
var upload_buf: [96]u8 = undefined;
- const download = i18n.fmt(&download_buf, tr("Download: {rate} KiB/s"), .{
- .rate = @divTrunc(t.download_rate, 1024),
+ var download_size_buf: [32]u8 = undefined;
+ var upload_size_buf: [32]u8 = undefined;
+ const download = i18n.fmt(&download_buf, tr("Download: {rate}/s"), .{
+ .rate = draw.formatSize(t.download_rate, &download_size_buf),
}) catch "";
- const upload = i18n.fmt(&upload_buf, tr("Upload: {rate} KiB/s"), .{
- .rate = @divTrunc(t.upload_rate, 1024),
+ const upload = i18n.fmt(&upload_buf, tr("Upload: {rate}/s"), .{
+ .rate = draw.formatSize(t.upload_rate, &upload_size_buf),
}) catch "";
const details = [_][]const u8{ download, upload };
transferTip.render(cr, self.w, self.h, self.mouse_x, self.mouse_y, t.name, &details);