Skip to content

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

WIP: prepare sidebar accordion foundation

Mel7a67578cbc77
diff --git a/src/files/app_places.zig b/src/files/app_places.zig
index e524871..620c111 100644
--- a/src/files/app_places.zig
+++ b/src/files/app_places.zig
@@ -182,10 +182,12 @@ pub fn deviceAt(self: *App, index: usize) ?*const volumes_mod.Volume {
};
}
-/// Height DEVICES adds below Places, heading included.
+/// Height DISKS adds below Places, heading included. Keep an empty card
+/// visible so the sidebar's section structure does not jump when devices
+/// are connected or removed.
pub fn deviceBlock(self: *App) i32 {
const count: i32 = @intCast(self.device_list.items.len);
- return if (count == 0) 0 else 44 + count * self.placeStep();
+ return if (count == 0) 64 else 44 + count * self.placeStep();
}
/// The eject button at a mounted device row's right edge.
diff --git a/src/files/app_sidebar_paint.zig b/src/files/app_sidebar_paint.zig
index dd1d6bd..0400ac9 100644
--- a/src/files/app_sidebar_paint.zig
+++ b/src/files/app_sidebar_paint.zig
@@ -23,12 +23,26 @@ const drawText = @import("app_draw.zig").drawText;
const fontMetrics = @import("app_draw.zig").fontMetrics;
const deviceLabel = App.deviceLabel;
+/// A quiet surface separating the sidebar's four functional sections.
+fn drawSidebarCard(cr: *c.cairo_t, x: f64, y: f64, w: f64, h: f64) void {
+ if (w <= 0 or h <= 0) return;
+ roundedRect(cr, x, y, w, h, 9);
+ setSource(cr, withAlpha(ui_theme.global.app_item_hover, 0.18));
+ c.cairo_fill_preserve(cr);
+ setSource(cr, withAlpha(ui_theme.global.sidebarForeground(), 0.08));
+ c.cairo_set_line_width(cr, 1);
+ c.cairo_stroke(cr);
+}
+
/// 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) return;
setSource(cr, ui_theme.global.sidebarForeground());
- drawText(cr, tr("DEVICES"), 24, @floatFromInt(self.placeY(self.deviceBase()) - 12), shell_ui.headingSize(), true);
+ drawText(cr, tr("DISKS"), 24, @floatFromInt(self.placeY(self.deviceBase()) - 12), shell_ui.headingSize(), true);
+ 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;
+ }
const hovered = self.hoverKey();
for (self.device_list.items, 0..) |*volume, k| {
const index = self.deviceBase() + k;
@@ -148,6 +162,41 @@ pub fn renderSidebar(self: *App, cr: *c.cairo_t) void {
c.cairo_set_operator(cr, c.CAIRO_OPERATOR_SOURCE);
c.cairo_paint(cr);
c.cairo_set_operator(cr, c.CAIRO_OPERATOR_OVER);
+
+ // Keep the existing functional sections, but give each its own visual
+ // surface. Places includes built-in locations and pins; disks are
+ // separated from navigation; torrents and file operations share
+ // Transfers; Git remains contextual to an open repository.
+ const pin_count = self.pins.items.items.len;
+ const pin_bottom = self.pinRowY(pin_count);
+ drawSidebarCard(
+ cr,
+ 8,
+ @floatFromInt(self.contentTop() + 4),
+ @max(0, content_width - 16),
+ @floatFromInt(@max(0, pin_bottom + 16 - self.contentTop() - 4)),
+ );
+ const disks_y = pin_bottom + 24;
+ drawSidebarCard(
+ cr,
+ 8,
+ @floatFromInt(disks_y),
+ @max(0, content_width - 16),
+ @floatFromInt(self.deviceBlock() + 8),
+ );
+ const transfers_y = pin_bottom + 32 + self.deviceBlock();
+ drawSidebarCard(
+ cr,
+ 8,
+ @floatFromInt(transfers_y),
+ @max(0, content_width - 16),
+ @floatFromInt(self.torrentSidebarHeight() + self.fileOpsSidebarHeight() + 4),
+ );
+ if (self.repository() != null) {
+ const git_card = self.gitCard();
+ drawSidebarCard(cr, git_card.x - 2, git_card.y - 4, git_card.w + 4, git_card.h + 8);
+ }
+
self.renderTorrentSidebar(cr);
self.renderFileOpsSidebar(cr);
self.renderGitSidebar(cr, content_width);
diff --git a/src/files/app_sidebar_tests.zig b/src/files/app_sidebar_tests.zig
index bac8b2f..5cf6738 100644
--- a/src/files/app_sidebar_tests.zig
+++ b/src/files/app_sidebar_tests.zig
@@ -233,7 +233,7 @@ test "pins sit after Projects, take drops by gap and keep the rows in drawn orde
try std.testing.expectEqual(places_bottom + 2 * step, app.placeY(App.pin_base + 1));
}
-test "Sidebar lists devices under Places; only mounted ones eject" {
+test "Sidebar separates Disks from Places; only mounted volumes eject" {
var app = try testApp();
defer app.deinit();
app.h = 1000;
@@ -249,7 +249,7 @@ test "Sidebar lists devices under Places; only mounted ones eject" {
const step = app.placeStep();
try std.testing.expectEqual(last_place_y + 44 + step, app.placeY(mounted));
try std.testing.expectEqual(app.placeY(mounted) + step, app.placeY(unmounted));
- try std.testing.expectEqual(extent + 44 + 2 * step, app.sidebarExtent());
+ try std.testing.expectEqual(extent + 44 + 2 * step - 64, app.sidebarExtent());
const row_y: f64 = @floatFromInt(app.placeY(mounted) + 10);
try std.testing.expectEqual(@as(?usize, mounted), app.placeAt(70, row_y));