Skip to content

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

Hide empty Drives and Transfers sidebar cards

Meld2136801ab90
diff --git a/src/files/app_sidebar_paint.zig b/src/files/app_sidebar_paint.zig
index 1ac8a04..a537076 100644
--- a/src/files/app_sidebar_paint.zig
+++ b/src/files/app_sidebar_paint.zig
@@ -146,11 +146,14 @@ pub fn sidebarLayout(self: *App) app_model.SidebarLayout {
const transfers_body = torrent_height +
(if (file_ops_height > 0) @as(i32, app_model.SidebarLayout.gap) + file_ops_height else 0) +
(if (transfer_tree_height > 0) @as(i32, app_model.SidebarLayout.gap) + transfer_tree_height else 0);
+ const transfers_visible = torrent_height > 0 or
+ file_ops_height > 0 or
+ transfer_tree_height > 0;
return app_model.SidebarLayout.init(
top,
.{ places_body, disks_body, git_body, transfers_body },
- .{ true, true, self.repository() != null, torrent_height > 0 or file_ops_height > 0 or transfer_tree_height > 0 },
+ .{ true, self.device_list.items.len > 0, self.repository() != null, transfers_visible },
self.sidebar_expanded,
);
}
@@ -223,10 +226,7 @@ pub fn sidebarBodyY(self: *App, section: app_model.SidebarSection, x: f64, y: f6
/// DEVICES: a heading and one row per volume, dimmed while unmounted, with
/// an eject button on the mounted ones.
pub fn renderDevices(self: *App, cr: *c.cairo_t, content_width: f64) void {
- if (self.device_list.items.len == 0) {
- drawText(cr, tr("No removable volumes"), 32, @floatFromInt(self.placeY(self.deviceBase()) + 20), shell_ui.statusSize(), false);
- return;
- }
+ if (self.device_list.items.len == 0) return;
const hovered = self.hoverKey();
const disks_card = self.sidebarLayout().cards[@intFromEnum(app_model.SidebarSection.disks)];
const metrics = fontMetrics(cr, shell_ui.textSize());
@@ -351,7 +351,7 @@ pub fn renderSidebar(self: *App, cr: *c.cairo_t) void {
const layout = self.sidebarLayout();
const section_names = [_][]const u8{
tr("PLACES"),
- tr("DISKS"),
+ tr("DRIVES"),
"GIT",
tr("TRANSFERS"),
};
diff --git a/src/files/app_sidebar_tests.zig b/src/files/app_sidebar_tests.zig
index 385f8c1..ac35d60 100644
--- a/src/files/app_sidebar_tests.zig
+++ b/src/files/app_sidebar_tests.zig
@@ -70,6 +70,10 @@ test "sidebar header clicks independently toggle sections" {
defer app.deinit();
app.w = 800;
app.h = 1000;
+ const volumes = [_]volumes_mod.Volume{
+ .{ .id = "/b/sdb1", .label = "STICK", .mount = null, .size = 1 << 30, .kind = .stick },
+ };
+ app.device_list.items = &volumes;
try std.testing.expect(app.sidebar_expanded[0]);
try std.testing.expect(!app.sidebar_expanded[1]);
@@ -103,6 +107,26 @@ test "sidebar header clicks independently toggle sections" {
try std.testing.expectEqual(@as(?app_model.SidebarSection, null), app.sidebarHeaderAt(-1, selected_y));
}
+test "sidebar hides Drives and Transfers cards when they have no content" {
+ var app = try testApp();
+ defer app.deinit();
+ app.w = 800;
+ app.h = 1000;
+
+ var layout = app.sidebarLayout();
+ try std.testing.expect(layout.cards[@intFromEnum(app_model.SidebarSection.places)].visible);
+ try std.testing.expect(!layout.cards[@intFromEnum(app_model.SidebarSection.disks)].visible);
+ try std.testing.expect(!layout.cards[@intFromEnum(app_model.SidebarSection.transfers)].visible);
+
+ const volumes = [_]volumes_mod.Volume{
+ .{ .id = "/b/sdb1", .label = "STICK", .mount = null, .size = 1 << 30, .kind = .stick },
+ };
+ app.device_list.items = &volumes;
+ layout = app.sidebarLayout();
+ try std.testing.expect(layout.cards[@intFromEnum(app_model.SidebarSection.disks)].visible);
+ try std.testing.expect(!layout.cards[@intFromEnum(app_model.SidebarSection.transfers)].visible);
+}
+
test "collapsing sidebar section while scrolled clamps the scroll offset" {
var app = try testApp();
defer app.deinit();
@@ -181,6 +205,10 @@ test "adjacent collapsed sidebar headers invalidate their shared transition area
defer app.deinit();
app.w = 800;
app.h = 1000;
+ const volumes = [_]volumes_mod.Volume{
+ .{ .id = "/b/sdb1", .label = "STICK", .mount = null, .size = 1 << 30, .kind = .stick },
+ };
+ app.device_list.items = &volumes;
app.sidebar_expanded[0] = false;
const first = app.hoverBounds(940).?;
@@ -202,6 +230,10 @@ test "adjacent collapsed sidebar headers invalidate their shared transition area
test "sidebar body geometry rejects hidden areas and translates legacy section coordinates" {
var app = try testApp();
defer app.deinit();
+ const volumes = [_]volumes_mod.Volume{
+ .{ .id = "/b/sdb1", .label = "STICK", .mount = null, .size = 1 << 30, .kind = .stick },
+ };
+ app.device_list.items = &volumes;
const places = app.sidebarLayout().cards[@intFromEnum(app_model.SidebarSection.places)];
const places_y = @as(f64, @floatFromInt(places.y + places.header_height)) + 5;
@@ -461,13 +493,13 @@ test "Sidebar separates Disks from Places; only mounted volumes eject" {
var app = try testApp();
defer app.deinit();
app.h = 1000;
- const extent = app.sidebarExtent();
- const last_place_y = app.placeY(App.pin_base - 1);
const volumes = [_]volumes_mod.Volume{
.{ .id = "/b/sdb1", .label = "STICK", .mount = "/run/media/user/STICK", .size = 1 << 30, .kind = .stick },
.{ .id = "/b/sda1", .label = "", .mount = null, .size = 500 << 30, .kind = .drive },
};
app.device_list.items = &volumes;
+ const extent = app.sidebarExtent();
+ const last_place_y = app.placeY(App.pin_base - 1);
const mounted = app.deviceBase();
const unmounted = mounted + 1;
const step = app.placeStep();