Skip to content

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

Trash and Nix build fixes

oxydizer5687125c1af4
diff --git a/nix/package.nix b/nix/package.nix
index 206ce1d..da63210 100644
--- a/nix/package.nix
+++ b/nix/package.nix
@@ -76,9 +76,11 @@ let
# Only this fixed-output fetch may access the network; the build gets the
# verified package cache and runs offline. Using nixpkgs' zig.fetchDeps
# rather than our own derivation was suggested by SpaceboyRoss.
+ # Update this hash whenever the .dependencies in build.zig.zon change (CI's
+ # "hash mismatch" error prints the new value as "got").
zigDeps = zig_0_17.fetchDeps {
inherit pname version src;
- hash = "sha256-R5Eg4CG+DW/pgg1zU+4Y2Ov1LCY3ReJordmBQGxkiyc=";
+ hash = "sha256-wWUzaz1grmsPxv5Uth3P8KgEY/XaDXNRrniF8c4IeGc=";
};
in
stdenv.mkDerivation {
diff --git a/po/rediwm.pot b/po/rediwm.pot
index ab78e76..4a216df 100644
--- a/po/rediwm.pot
+++ b/po/rediwm.pot
@@ -423,6 +423,10 @@ msgstr ""
msgid "At critical battery level"
msgstr ""
+#: src/files/trash_properties.zig
+msgid "At least {size}"
+msgstr ""
+
#: src/control_center/sections/printers.zig
msgid "Attached USB printers"
msgstr ""
@@ -827,6 +831,10 @@ msgstr ""
msgid "Calculate size"
msgstr ""
+#: src/files/trash_properties.zig
+msgid "Calculating…"
+msgstr ""
+
#: src/calculator/app.zig
msgid "Calculator"
msgstr ""
@@ -1573,7 +1581,7 @@ msgstr ""
msgid "Could not read Wi-Fi networks"
msgstr ""
-#: src/files/app_dialogs.zig
+#: src/desktop/app_actions.zig
msgid "Could not read file properties"
msgstr ""
@@ -1995,6 +2003,10 @@ msgstr ""
msgid "Delete {name}?"
msgstr ""
+#: src/files/trash_properties.zig
+msgid "Deleted files and folders"
+msgstr ""
+
#: src/session/power_capabilities.zig
msgid "Denied by policy"
msgstr ""
@@ -7745,6 +7757,12 @@ msgid_plural "{count} have no Trash information"
msgstr[0] ""
msgstr[1] ""
+#: src/files/trash_properties.zig
+msgid "{count} item"
+msgid_plural "{count} items"
+msgstr[0] ""
+msgstr[1] ""
+
#: src/files/app_paint.zig
msgid "{count} item selected · {size}"
msgid_plural "{count} items selected · {size}"
diff --git a/src/desktop/AGENTS.md b/src/desktop/AGENTS.md
index fcd58ae..2faf70c 100644
--- a/src/desktop/AGENTS.md
+++ b/src/desktop/AGENTS.md
@@ -24,3 +24,10 @@ Desktop keyboard focus and compositor drop targets are in the root
file whose own Name/Icon are never shown. Allow Launching is `chmod u+x`.
* Launches go through `app_scope.place` like every other user app: the worker
hands pids over with `Worker.takeStarted`.
+* The Trash icon's Properties is Files' window, not a desktop popup:
+ `files/trash_properties.zig`, held in `App.trash_card` (`edit ==
+ .trash_properties`) and routed like the delete dialog (paint, `promptRect`,
+ pointer, keys; `closeTrashCard` on every way out). Its count runs on its own
+ thread (`files/trash_totals.zig`) and writes the worker's `wake_main`; `tick`
+ polls it. Other Properties still use the small popup. Open reuses
+ `openSelected`, so the Trash icon must stay selected under the window.
diff --git a/src/desktop/app.zig b/src/desktop/app.zig
index c9e25bd..df3fabc 100644
--- a/src/desktop/app.zig
+++ b/src/desktop/app.zig
@@ -7,6 +7,7 @@ const damage_mod = @import("damage.zig");
pub const Damage = damage_mod.Damage;
const rename = @import("rename.zig");
const deletion = @import("../delete_dialog.zig");
+const trash_properties = @import("../files/trash_properties.zig");
const Host = @import("host.zig").Host;
const host_mod = @import("host.zig");
const Menu = @import("menu.zig").Menu;
@@ -78,9 +79,11 @@ pub const App = struct {
menu_icon: ?usize = null,
menu_x: i32 = 0,
menu_y: i32 = 0,
- edit: enum { none, rename, folder, file, trash, properties, add_app, open_with } = .none,
+ edit: enum { none, rename, folder, file, trash, trash_properties, properties, add_app, open_with } = .none,
folder_token: u64 = 0,
deletion: deletion.State = .{},
+ /// The Trash's Properties window, the one Files shows too.
+ trash_card: ?trash_properties.State = null,
catalog: []const @import("dotdesktop.zig").parser.AppEntry = &.{},
applications: ?@import("../files/open_with.zig").State = null,
picker_theme: @import("../icon_theme.zig").Config = .{ .theme_name = "", .base_dirs = &.{} },
@@ -152,6 +155,7 @@ pub const App = struct {
}
pub fn deinit(self: *App) void {
self.closePicker();
+ self.closeTrashCard();
self.deletion.deinit();
self.rename_editor.deinit();
if (self.wallpaper) |im| a.free(im.pixels);
@@ -293,6 +297,9 @@ pub const App = struct {
pub const pickerAction = app_actions.pickerAction;
pub const beginEdit = app_actions.beginEdit;
pub const deleteAction = app_actions.deleteAction;
+ pub const beginTrashProperties = app_actions.beginTrashProperties;
+ pub const trashPropertiesAction = app_actions.trashPropertiesAction;
+ pub const closeTrashCard = app_actions.closeTrashCard;
pub const finishEdit = app_actions.finishEdit;
pub const choiceEntry = app_actions.choiceEntry;
@@ -319,6 +326,7 @@ pub const App = struct {
}
pub fn tick(self: *App) bool {
const now = nowMs();
+ if (self.trash_card) |*card| if (card.poll()) self.invalidate();
const error_len = self.worker.takeError(&self.notice);
if (error_len > 0) {
if (self.edit == .folder) self.edit = .none;
diff --git a/src/desktop/app_actions.zig b/src/desktop/app_actions.zig
index 9fabb1d..be14e99 100644
--- a/src/desktop/app_actions.zig
+++ b/src/desktop/app_actions.zig
@@ -7,6 +7,7 @@ const grid = @import("grid.zig");
const watcher = @import("watcher.zig");
const rename = @import("rename.zig");
const deletion = @import("../delete_dialog.zig");
+const trash_properties = @import("../files/trash_properties.zig");
const a = std.heap.c_allocator;
pub fn copy(self: *App, cut: bool) void {
@@ -39,7 +40,7 @@ pub fn menuBuiltin(self: *const App) watcher.Builtin {
pub fn menuLabels(self: *App) []const []const u8 {
const icon_labels = [_]i18n.Message{ i18n.msg("Open"), i18n.msg("Open With…"), i18n.msg("Cut"), i18n.msg("Copy"), i18n.msg("Rename"), i18n.msg("Move to Trash"), i18n.msg("Properties"), i18n.msg("Allow Launching") };
const desktop_labels = [_]i18n.Message{ i18n.msg("New Folder"), i18n.msg("New File"), i18n.msg("Add Application…"), i18n.msg("Paste"), i18n.msg("Refresh"), i18n.msg("Change Wallpaper"), i18n.msg("Desktop Settings") };
- const trash_labels = [_]i18n.Message{ i18n.msg("Open"), i18n.msg("Empty Trash…") };
+ const trash_labels = [_]i18n.Message{ i18n.msg("Open"), i18n.msg("Empty Trash…"), i18n.msg("Properties") };
const messages: []const i18n.Message = switch (self.menuBuiltin()) {
.home => icon_labels[0..1],
.trash => &trash_labels,
@@ -51,7 +52,7 @@ pub fn menuLabels(self: *App) []const []const u8 {
pub fn menuIcon(self: *App, row: usize) @import("ui").layout.IconId {
const IconId = @import("ui").layout.IconId;
- if (self.menuBuiltin() != .none) return if (row == 0) .chevron_right else .trash;
+ if (self.menuBuiltin() != .none) return ([_]IconId{ .chevron_right, .trash, .view_list })[row];
return if (self.menu_icon != null)
([_]IconId{ .chevron_right, .grid, .cut, .copy, .edit, .trash, .view_list, .checkmark })[row]
else
@@ -76,7 +77,7 @@ pub fn menuAction(self: *App, row: usize) void {
self.deletion.deinit();
self.deletion = .{ .permanent = true, .empty_trash = true };
self.edit = .trash;
- }
+ } else if (builtin == .trash and row == 2) self.beginTrashProperties();
return;
}
if (self.menu_icon != null) {
@@ -141,6 +142,7 @@ pub fn pickerAction(self: *App, action: @import("../files/open_with.zig").Action
pub fn beginEdit(self: *App, kind: @FieldType(App, "edit")) void {
self.deletion.deinit();
self.closePicker();
+ self.closeTrashCard();
self.edit = kind;
if (kind == .folder) {
const path = std.fmt.allocPrint(a, "{s}/{s}", .{ self.worker.dir, i18n.tr("New Folder") }) catch {
@@ -187,6 +189,43 @@ pub fn beginEdit(self: *App, kind: @FieldType(App, "edit")) void {
if (kind == .file) self.edit_text.appendSlice(a, i18n.tr("New File")) catch {};
}
+/// Opens the Trash's Properties window for the Trash icon the menu belongs to.
+pub fn beginTrashProperties(self: *App) void {
+ const index = self.menu_icon orelse return;
+ if (index >= self.icons.items.len or self.icons.items[index].item.builtin != .trash) return;
+ self.deletion.deinit();
+ self.closePicker();
+ self.closeTrashCard();
+ self.trash_card = trash_properties.State.init(self.icons.items[index].item.path, self.worker.wake_main) catch {
+ self.notify("{s}", .{i18n.tr("Could not read file properties")});
+ return;
+ };
+ self.edit = .trash_properties;
+ self.invalidate();
+}
+
+pub fn closeTrashCard(self: *App) void {
+ if (self.trash_card) |*card| card.deinit();
+ self.trash_card = null;
+}
+
+pub fn trashPropertiesAction(self: *App, action: trash_properties.Action) void {
+ switch (action) {
+ .none => {},
+ .close => {
+ self.closeTrashCard();
+ self.edit = .none;
+ },
+ // The Trash icon stays selected under the window, as Open from its menu expects.
+ .open => {
+ self.closeTrashCard();
+ self.edit = .none;
+ self.openSelected();
+ },
+ }
+ self.invalidate();
+}
+
pub fn deleteAction(self: *App, action: deletion.Action) void {
switch (action) {
.cancel => {
diff --git a/src/desktop/app_keyboard.zig b/src/desktop/app_keyboard.zig
index 7aef172..9c53b7e 100644
--- a/src/desktop/app_keyboard.zig
+++ b/src/desktop/app_keyboard.zig
@@ -15,6 +15,7 @@ pub fn keyboardLeft(self: *App, refocusing: bool) void {
if (!refocusing) {
self.menu = false;
self.deletion.deinit();
+ self.closeTrashCard();
self.closePicker();
self.edit = .none;
}
@@ -25,7 +26,7 @@ pub fn keyboardLeft(self: *App, refocusing: bool) void {
/// menu, list and icon navigation otherwise. The delete dialog, Return,
/// Escape and Ctrl shortcuts fire once.
pub fn keyRepeats(self: *const App, sym: u32, utf8: []const u8) bool {
- if (self.edit == .trash or self.edit == .folder or self.ctrl) return false;
+ if (self.edit == .trash or self.edit == .trash_properties or self.edit == .folder or self.ctrl) return false;
const vertical = sym == c.XKB_KEY_Up or sym == c.XKB_KEY_Down;
if (self.menu) return vertical;
const typing = switch (sym) {
@@ -44,6 +45,10 @@ pub fn key(self: *App, sym: u32, utf8: []const u8) void {
self.deleteAction(self.deletion.key(sym));
return;
}
+ if (self.edit == .trash_properties) {
+ if (self.trash_card) |*card| self.trashPropertiesAction(card.key(sym));
+ return;
+ }
if (self.edit == .add_app) {
if (self.applications) |*picker| {
// Preserve application search from the desktop's original chooser.
diff --git a/src/desktop/app_paint.zig b/src/desktop/app_paint.zig
index 1e0bc04..5657ff5 100644
--- a/src/desktop/app_paint.zig
+++ b/src/desktop/app_paint.zig
@@ -160,6 +160,11 @@ pub fn promptRect(self: *App) ?grid.Rect {
const g = self.deletion.geometry(self.geometry.w, self.geometry.h - self.geometry.bottom);
return .{ .x = @intFromFloat(@floor(g.x)), .y = @intFromFloat(@floor(g.y)), .w = @intFromFloat(@ceil(g.width)), .h = @intFromFloat(@ceil(g.height)) };
}
+ if (self.edit == .trash_properties) {
+ const card = self.trash_card orelse return null;
+ const g = card.geometry(self.geometry.w, self.geometry.h - self.geometry.bottom);
+ return .{ .x = @intFromFloat(@floor(g.box.x)), .y = @intFromFloat(@floor(g.box.y)), .w = @intFromFloat(@ceil(g.box.w)), .h = @intFromFloat(@ceil(g.box.h)) };
+ }
if (self.edit == .add_app) {
if (self.applications) |*picker| {
const r = picker.geometry(self.geometry.w, self.geometry.h - self.geometry.bottom).box;
@@ -248,6 +253,15 @@ pub fn paintOverlay(self: *App, cr: *c.cairo_t, now: i64) void {
self.deletion.drawWindow(cr, self.geometry.w, self.geometry.h - self.geometry.bottom, self.x, self.y, null)
else
self.deletion.draw(cr, self.geometry.w, self.geometry.h - self.geometry.bottom, self.x, self.y, null);
+ } else if (self.edit == .trash_properties) {
+ if (self.trash_card) |*card| {
+ const w = self.geometry.w;
+ const h = self.geometry.h - self.geometry.bottom;
+ if (self.separate_overlays)
+ card.drawWindow(cr, w, h, self.x, self.y, null, self.picker_theme, self.worker.io)
+ else
+ card.draw(cr, w, h, self.x, self.y, null, self.picker_theme, self.worker.io);
+ }
} else if (self.edit != .none and self.edit != .rename and self.edit != .folder) {
const x = @divTrunc(self.geometry.w - 420, 2);
const y = @divTrunc(self.geometry.h - 120, 2);
diff --git a/src/desktop/app_pointer.zig b/src/desktop/app_pointer.zig
index 51c4051..d6c7123 100644
--- a/src/desktop/app_pointer.zig
+++ b/src/desktop/app_pointer.zig
@@ -29,6 +29,17 @@ pub fn pointerMotion(self: *App, x: f64, y: f64) void {
self.y = y;
return;
}
+ if (self.edit == .trash_properties) {
+ if (self.trash_card) |*card| {
+ const w = self.geometry.w;
+ const h = self.geometry.h - self.geometry.bottom;
+ const old_hit = card.hit(w, h, self.x, self.y);
+ if (card.motion(w, h, x, y) or old_hit != card.hit(w, h, x, y)) self.invalidate();
+ }
+ self.x = x;
+ self.y = y;
+ return;
+ }
if (self.edit == .trash) {
if (self.deletion.motion(self.geometry.w, self.geometry.h - self.geometry.bottom, x, y)) self.invalidate();
const g = self.deletion.geometry(self.geometry.w, self.geometry.h - self.geometry.bottom);
@@ -82,6 +93,7 @@ pub fn pointerMotion(self: *App, x: f64, y: f64) void {
pub fn leave(self: *App) void {
self.deletion.placement.grab = null;
+ if (self.trash_card) |*card| card.placement.grab = null;
if (self.applications) |*picker| picker.placement.grab = null;
if (self.hover != null) {
self.damageIcon(self.hover.?);
@@ -100,7 +112,7 @@ pub fn deselect(self: *App) void {
pub fn button(self: *App, button_code: u32, pressed: bool) void {
const was_menu = self.menu;
- const was_delete_dialog = self.edit == .trash;
+ const was_delete_dialog = self.edit == .trash or self.edit == .trash_properties;
const was_renaming = self.edit == .rename;
const menu_hit = was_menu and self.menu_layout.hit(self.x, self.y) != null;
if (pressed) self.endLaunch();
@@ -127,6 +139,15 @@ pub fn pointerButton(self: *App, button_code: u32, pressed: bool) void {
}
return;
}
+ if (self.edit == .trash_properties) {
+ if (button_code == 272) if (self.trash_card) |*card| {
+ const w = self.geometry.w;
+ const h = self.geometry.h - self.geometry.bottom;
+ if (card.pointerButton(w, h, self.x, self.y, pressed)) return;
+ if (pressed) self.trashPropertiesAction(card.click(w, h, self.x, self.y));
+ };
+ return;
+ }
if (self.edit == .trash and button_code == 272 and self.deletion.pointerButton(self.geometry.w, self.geometry.h - self.geometry.bottom, self.x, self.y, pressed)) return;
if (self.renameGeometry()) |g| {
if (button_code != 272) return;
diff --git a/src/desktop/app_tests.zig b/src/desktop/app_tests.zig
index 69e904f..fc17668 100644
--- a/src/desktop/app_tests.zig
+++ b/src/desktop/app_tests.zig
@@ -107,11 +107,13 @@ test "desktop motion keeps menu highlights and moving selections live" {
try std.testing.expectEqual(@as(usize, 1), app.menuLabels().len);
try std.testing.expectEqualStrings("Open", app.menuLabels()[0]);
app.menu_icon = 1;
- try std.testing.expectEqual(@as(usize, 2), app.menuLabels().len);
+ try std.testing.expectEqual(@as(usize, 3), app.menuLabels().len);
try std.testing.expectEqualStrings("Open", app.menuLabels()[0]);
try std.testing.expectEqualStrings("Empty Trash…", app.menuLabels()[1]);
try std.testing.expectEqual(@import("ui").layout.IconId.trash, app.menuIcon(1));
try std.testing.expectEqual(@as(?[]const u8, null), app.menuHint(1));
+ try std.testing.expectEqualStrings("Properties", app.menuLabels()[2]);
+ try std.testing.expectEqual(@import("ui").layout.IconId.view_list, app.menuIcon(2));
// Opening and cancelling must not enqueue work (the worker is undefined).
app.menuAction(1);
try std.testing.expect(app.edit == .trash);
diff --git a/src/files/AGENTS.md b/src/files/AGENTS.md
index 6d9f03f..9c9c0e9 100644
--- a/src/files/AGENTS.md
+++ b/src/files/AGENTS.md
@@ -99,7 +99,16 @@ and headless fixtures. The pinned library is compiled only into Files/tests.
metadata (`trash_restorable`, worked out when the menu opens, not per paint;
`context_menu.Row.disabled`). Delete inside the Trash uses the shared delete
dialog with `in_trash`: permanent, no checkbox.
-* Tests: `trash_tests.zig`, `app_trash_tests.zig`, `tests/files_trash.py`
+* **Trash Properties** (sidebar row, and the desktop's Trash icon) is
+ `trash_properties.zig`, one window for both hosts: `properties_card.zig`
+ (the identity row and fields shared with file Properties, so they cannot
+ drift) minus permissions, with the icon looked up like the sidebar's (a pack's
+ `user-trash`, else the `trash_can` glyph). Items are the top-level entries of
+ `Trash/files`, the size every payload byte under them (`trash_totals.zig`:
+ links never followed, metadata excluded); the count is a thread per open
+ window that writes the host's wake fd, and `partial` reads "At least".
+* Tests: `trash_tests.zig`, `app_trash_tests.zig`, `trash_totals_tests.zig`,
+ `trash_properties_tests.zig`, `tests/files_trash.py`
(keyboard driven, filesystem as ground truth, fake `gio`).
## Git
diff --git a/src/files/app.zig b/src/files/app.zig
index 2717cd4..f9206a5 100644
--- a/src/files/app.zig
+++ b/src/files/app.zig
@@ -543,6 +543,8 @@ pub const App = struct {
pub const openProperties = app_dialogs.openProperties;
pub const openSelectedProperties = app_dialogs.openSelectedProperties;
pub const propertiesAction = app_dialogs.propertiesAction;
+ pub const openTrashProperties = app_dialogs.openTrashProperties;
+ pub const trashPropertiesAction = app_dialogs.trashPropertiesAction;
pub const canOpenWith = app_dialogs.canOpenWith;
pub const openWithDialog = app_dialogs.openWithDialog;
pub const openWithAction = app_dialogs.openWithAction;
@@ -599,6 +601,7 @@ pub const App = struct {
pub const viewTop = app_layout.viewTop;
pub const compactList = app_layout.compactList;
pub const itemInset = app_layout.itemInset;
+ pub const itemLeftInset = app_layout.itemLeftInset;
pub const rowHeight = app_layout.rowHeight;
pub const cardHeight = app_layout.cardHeight;
pub const listBaseline = app_layout.listBaseline;
diff --git a/src/files/app_dialogs.zig b/src/files/app_dialogs.zig
index 411b3b7..feee12e 100644
--- a/src/files/app_dialogs.zig
+++ b/src/files/app_dialogs.zig
@@ -11,6 +11,7 @@ const icons = @import("../icon_cache.zig");
const deletion = @import("../delete_dialog.zig");
const open_with = @import("open_with.zig");
const properties = @import("properties.zig");
+const trash_properties = @import("trash_properties.zig");
const ViewItem = @import("app_model.zig").ViewItem;
const Dialog = @import("app_model.zig").Dialog;
@@ -21,6 +22,7 @@ pub fn closeDialog(self: *App) void {
dlg.deletion.deinit();
if (dlg.applications) |*apps| apps.deinit();
if (dlg.properties) |*props| props.deinit();
+ if (dlg.trash_properties) |*props| props.deinit();
dlg.edit.text.deinit(self.allocator);
if (dlg.target_path) |tp| self.allocator.free(tp);
if (dlg.conflict_name) |cn| self.allocator.free(cn);
@@ -76,6 +78,34 @@ pub fn propertiesAction(self: *App, action: properties.Action) void {
}
}
+/// Properties of the Trash itself (the sidebar's Trash row), not of an item in it.
+pub fn openTrashProperties(self: *App) void {
+ const path = self.trash_dir orelse {
+ self.setStatusNotice(tr("Could not read file properties"), true);
+ return;
+ };
+ const state = trash_properties.State.init(path, self.worker.wake_main) catch {
+ self.setStatusNotice(tr("Could not read file properties"), true);
+ return;
+ };
+ self.closeDialog();
+ self.dialog = .{ .kind = .trash_properties, .title = tr("Properties"), .trash_properties = state };
+ self.invalidate();
+}
+
+pub fn trashPropertiesAction(self: *App, action: trash_properties.Action) void {
+ switch (action) {
+ .none => self.invalidate(),
+ .close => self.closeDialog(),
+ .open => {
+ const path = self.allocator.dupe(u8, self.dialog.?.trash_properties.?.path) catch return;
+ defer self.allocator.free(path);
+ self.closeDialog();
+ self.navigate(path);
+ },
+ }
+}
+
pub fn canOpenWith(self: *const App) bool {
if (self.history.archive_len > 0) return false;
if (self.chooser != null) return false;
@@ -278,7 +308,7 @@ pub fn confirmDialog(self: *App) void {
.torrent_source, .torrent_destination => self.confirmTorrent(),
.terminal_close => self.terminalConfirmClose(),
.open_with => self.openWithAction(.open),
- .properties => {},
+ .properties, .trash_properties => {},
.new_folder => {
const name = std.mem.trim(u8, dlg.edit.text.items, " \t\r\n");
ops_mod.createFolder(self.allocator, self.history.current, name) catch |err| {
@@ -367,6 +397,10 @@ pub fn handleDialogKey(self: *App, sym: u32, utf8: []const u8) void {
self.propertiesAction(action);
return;
}
+ if (dlg.kind == .trash_properties) {
+ self.trashPropertiesAction(self.dialog.?.trash_properties.?.key(sym));
+ return;
+ }
if (dlg.kind == .open_with) {
const action = self.dialog.?.applications.?.key(sym, self.shift, self.w, self.h);
self.openWithAction(action);
diff --git a/src/files/app_hover.zig b/src/files/app_hover.zig
index 58552c4..d808dc6 100644
--- a/src/files/app_hover.zig
+++ b/src/files/app_hover.zig
@@ -23,7 +23,7 @@ pub fn hoverBounds(self: *App, key: usize) ?header.Rect {
const index = key - 1000;
if (index >= self.items.items.len or self.items.items[index].text().len > 8) return null; // May show a full-name tooltip.
const i: i32 = @intCast(index);
- return .{ .x = @floatFromInt(self.sidebarWidth() + 19 + @mod(i, self.columns()) * self.cellWidth()), .y = @floatFromInt(self.viewTop() + self.itemInset() - 1 + @divTrunc(i, self.columns()) * self.rowHeight() - self.scroll_y), .w = @floatFromInt(self.cellWidth() - 18), .h = @floatFromInt(self.cardHeight() + 2) };
+ return .{ .x = @floatFromInt(self.sidebarWidth() + self.itemLeftInset() - 1 + @mod(i, self.columns()) * self.cellWidth()), .y = @floatFromInt(self.viewTop() + self.itemInset() - 1 + @divTrunc(i, self.columns()) * self.rowHeight() - self.scroll_y), .w = @floatFromInt(self.cellWidth() - 18), .h = @floatFromInt(self.cardHeight() + 2) };
}
if (self.chooser != null and key >= 500 and key < 513) {
if (key > 500) return self.chooserRect(key - 501);
@@ -130,7 +130,7 @@ pub fn navHighlight(self: *App, frame: hover_glide.Frame) header.Rect {
pub fn itemHighlight(self: *App, frame: hover_glide.Frame) header.Rect {
const cell: f64 = @floatFromInt(self.cellWidth());
return .{
- .x = @as(f64, @floatFromInt(self.sidebarWidth() + 20)) + frame.col * cell,
+ .x = @as(f64, @floatFromInt(self.sidebarWidth() + self.itemLeftInset())) + frame.col * cell,
.y = @as(f64, @floatFromInt(self.viewTop() + self.itemInset() - self.scroll_y)) + frame.row * @as(f64, @floatFromInt(self.rowHeight())),
.w = cell - 20,
.h = @floatFromInt(self.cardHeight()),
diff --git a/src/files/app_items.zig b/src/files/app_items.zig
index f5a8231..b215247 100644
--- a/src/files/app_items.zig
+++ b/src/files/app_items.zig
@@ -43,7 +43,7 @@ pub fn renderFileItems(self: *App, cr: *c.cairo_t, viewport_h: i32) void {
const idx: usize = @intCast(index);
const item = self.items.items[idx];
const baseline = self.listBaseline();
- const x: f64 = @floatFromInt(self.sidebarWidth() + 20 + @mod(index, cols) * cell);
+ const x: f64 = @floatFromInt(self.sidebarWidth() + self.itemLeftInset() + @mod(index, cols) * cell);
const y: f64 = @floatFromInt(self.viewTop() + self.itemInset() + @divTrunc(index, cols) * self.rowHeight() - self.scroll_y);
const width: f64 = @floatFromInt(cell - 20);
// Items sit on the list itself; only selection and keyboard focus
@@ -167,7 +167,7 @@ pub fn renderFilenameTip(self: *App, cr: *c.cairo_t) void {
// Anchor to the item, so motion within it does not require a repaint.
const row = @divTrunc(@as(i32, @intCast(index)), self.columns());
const y = std.math.clamp(@as(f64, @floatFromInt(self.viewTop() + self.itemInset() + row * self.rowHeight() - self.scroll_y + self.cardHeight())), 4, @max(4, @as(f64, @floatFromInt(self.h - self.footerHeight())) - height));
- const x: f64 = @floatFromInt(@min(self.sidebarWidth() + 20, self.w - @as(i32, @intFromFloat(width)) - 12));
+ const x: f64 = @floatFromInt(@min(self.sidebarWidth() + self.itemLeftInset(), self.w - @as(i32, @intFromFloat(width)) - 12));
roundedRect(cr, x, y, width, height, 4);
setSource(cr, ui_theme.global.app_divider);
c.cairo_fill(cr);
@@ -180,8 +180,8 @@ pub fn itemIconRect(self: *App, index: i32) header.Rect {
const cols = self.columns();
const size: f64 = if (self.list_view) 24 else GridCard.icon_size;
return .{
- .x = @as(f64, @floatFromInt(self.sidebarWidth() + 20 + @mod(index, cols) * self.cellWidth())) + (if (self.list_view) @as(f64, 12) else GridCard.padding_x) - self.horizontalOffset(),
- .y = @as(f64, @floatFromInt(self.viewTop() + self.itemInset() + @divTrunc(index, cols) * self.rowHeight() - self.scroll_y)) + (if (self.compactList()) @as(f64, 3) else if (self.list_view) @as(f64, 6) else GridCard.padding_top),
+ .x = @as(f64, @floatFromInt(self.sidebarWidth() + self.itemLeftInset() + @mod(index, cols) * self.cellWidth())) + (if (self.list_view) @as(f64, 12) else GridCard.padding_x) - self.horizontalOffset(),
+ .y = @as(f64, @floatFromInt(self.viewTop() + self.itemInset() + @divTrunc(index, cols) * self.rowHeight() - self.scroll_y)) + (if (self.list_view) @as(f64, @floatFromInt(self.cardHeight() - 24)) / 2 else GridCard.padding_top),
.w = size,
.h = size,
};
diff --git a/src/files/app_keyboard.zig b/src/files/app_keyboard.zig
index d2d5af6..ff54e81 100644
--- a/src/files/app_keyboard.zig
+++ b/src/files/app_keyboard.zig
@@ -24,7 +24,7 @@ pub fn keyRepeats(self: *const App, sym: u32, utf8: []const u8) bool {
c.XKB_KEY_BackSpace, c.XKB_KEY_Delete, c.XKB_KEY_Left, c.XKB_KEY_Right => true,
else => false,
}, utf8);
- if (self.dialog) |dlg| return if (dlg.kind == .open_with) vertical else dlg.kind != .properties and dlg.kind != .trash_confirm and dlg.kind != .conflict and dlg.kind != .terminal_close and typing;
+ if (self.dialog) |dlg| return if (dlg.kind == .open_with) vertical else dlg.kind != .properties and dlg.kind != .trash_properties and dlg.kind != .trash_confirm and dlg.kind != .conflict and dlg.kind != .terminal_close and typing;
if (self.menu != null) return vertical;
if (self.focus == .search or self.focus == .location_bar or self.focus == .filename) return typing;
return vertical or sym == c.XKB_KEY_Left or sym == c.XKB_KEY_Right or
diff --git a/src/files/app_layout.zig b/src/files/app_layout.zig
index fd0048f..edaeda4 100644
--- a/src/files/app_layout.zig
+++ b/src/files/app_layout.zig
@@ -125,17 +125,22 @@ pub fn itemInset(self: *App) i32 {
return if (self.compactList()) 0 else 20;
}
+/// Outer left margin of the file rows; grid cards keep their wider gutter.
+pub fn itemLeftInset(self: *App) i32 {
+ return if (self.list_view and !self.transfer_view.active) 10 else 20;
+}
+
pub fn rowHeight(self: *App) i32 {
- return if (self.compactList()) 32 else if (self.list_view or self.transfer_view.active) 38 else GridCard.height + 8;
+ return if (self.compactList() or (self.list_view and !self.transfer_view.active)) 32 else if (self.list_view or self.transfer_view.active) 38 else GridCard.height + 8;
}
pub fn cardHeight(self: *App) i32 {
- return if (self.compactList()) 30 else if (self.list_view or self.transfer_view.active) 36 else GridCard.height;
+ return if (self.compactList() or (self.list_view and !self.transfer_view.active)) 30 else if (self.list_view or self.transfer_view.active) 36 else GridCard.height;
}
/// Text baseline of a list row, from the row's top.
pub fn listBaseline(self: *App) f64 {
- return if (self.compactList()) 21 else 24;
+ return if (self.compactList() or (self.list_view and !self.transfer_view.active)) 21 else 24;
}
pub fn sidebarTargetWidth(self: *App) i32 {
@@ -214,11 +219,11 @@ pub fn scrollbarGutter(self: *const App) i32 {
}
pub fn columns(self: *App) i32 {
- return if (self.list_view or self.transfer_view.active) 1 else @max(1, @divTrunc(self.w - self.sidebarWidth() - 20 - self.scrollbarGutter(), 210));
+ return if (self.list_view or self.transfer_view.active) 1 else @max(1, @divTrunc(self.w - self.sidebarWidth() - self.itemLeftInset() - self.scrollbarGutter(), 210));
}
pub fn cellWidth(self: *App) i32 {
- return @divTrunc(self.w - self.sidebarWidth() - 20 - self.scrollbarGutter(), self.columns());
+ return @divTrunc(self.w - self.sidebarWidth() - self.itemLeftInset() - self.scrollbarGutter(), self.columns());
}
pub fn contentHeight(self: *App) i32 {
@@ -228,7 +233,7 @@ pub fn contentHeight(self: *App) i32 {
pub fn itemAt(self: *App, x: f64, y: f64) ?usize {
if (self.transfer_view.active) return null;
- const gx = @as(i32, @intFromFloat(x)) - self.sidebarWidth() - 20;
+ const gx = @as(i32, @intFromFloat(x)) - self.sidebarWidth() - self.itemLeftInset();
if (y < @as(f64, @floatFromInt(self.viewTop())) or y >= @as(f64, @floatFromInt(self.contentBottom()))) return null;
const gy = @as(i32, @intFromFloat(y)) - self.viewTop() - self.itemInset() + self.scroll_y;
if (gx < 0 or gy < 0) return null;
@@ -310,7 +315,7 @@ pub fn listWidths(self: *App) [5]f64 {
pub fn listColumn(self: *App, column: usize) header.Rect {
const widths = self.listWidths();
- var x: f64 = @as(f64, @floatFromInt(self.sidebarWidth() + 20)) - self.horizontalOffset();
+ var x: f64 = @as(f64, @floatFromInt(self.sidebarWidth() + self.itemLeftInset())) - self.horizontalOffset();
for (widths[0..column]) |width| x += width;
return .{ .x = x, .y = @floatFromInt(self.contentTop()), .w = widths[column], .h = 30 };
}
@@ -351,7 +356,7 @@ pub fn sizeButtonRect(self: *App, idx: usize) ?header.Rect {
const cols = self.columns();
const cell = self.cellWidth();
const i: i32 = @intCast(idx);
- const x: f64 = @floatFromInt(self.sidebarWidth() + 20 + @mod(i, cols) * cell);
+ const x: f64 = @floatFromInt(self.sidebarWidth() + self.itemLeftInset() + @mod(i, cols) * cell);
const y: f64 = @floatFromInt(self.viewTop() + self.itemInset() + @divTrunc(i, cols) * self.rowHeight() - self.scroll_y);
if (self.list_view) {
const sz = self.listColumn(1);
diff --git a/src/files/app_listing.zig b/src/files/app_listing.zig
index 982ce5c..62626f8 100644
--- a/src/files/app_listing.zig
+++ b/src/files/app_listing.zig
@@ -135,6 +135,7 @@ pub fn sync(self: *App) void {
self.setStatusNotice(notice, false);
}
self.syncFolderSizes();
+ if (self.dialog) |*dlg| if (dlg.trash_properties) |*props| if (props.poll()) self.invalidate();
_ = c.pthread_mutex_lock(&self.worker.mutex);
const animation_settings = self.worker.animation_settings;
const new_theme = self.worker.theme;
diff --git a/src/files/app_menu.zig b/src/files/app_menu.zig
index be49440..abdcf11 100644
--- a/src/files/app_menu.zig
+++ b/src/files/app_menu.zig
@@ -344,7 +344,12 @@ pub fn runMenu(self: *App, row: usize) void {
},
.properties => {
var buf: [4096]u8 = undefined;
- if (self.placePath(self.menu_place, &buf)) |path| self.openProperties(path, null);
+ // The Trash (built-in row 1) is not a folder with permissions: it has its own window.
+ const trash_row = switch (self.rowKind(self.menu_place)) {
+ .builtin => |index| index == 1,
+ else => false,
+ };
+ if (trash_row) self.openTrashProperties() else if (self.placePath(self.menu_place, &buf)) |path| self.openProperties(path, null);
},
.mount => self.activateDevice(self.menu_place - self.deviceBase()),
.eject => self.ejectDevice(self.menu_place - self.deviceBase()),
diff --git a/src/files/app_model.zig b/src/files/app_model.zig
index a535b6d..54907d9 100644
--- a/src/files/app_model.zig
+++ b/src/files/app_model.zig
@@ -12,6 +12,7 @@ const header = @import("header.zig");
const IconId = @import("ui").layout.IconId;
const open_with = @import("open_with.zig");
const properties = @import("properties.zig");
+const trash_properties = @import("trash_properties.zig");
const Editor = @import("editor.zig").Editor;
pub const DeviceOp = struct { id: []u8, unmount: bool, open: bool, navigation: u32 };
@@ -202,6 +203,7 @@ pub const DialogKind = enum {
conflict,
open_with,
properties,
+ trash_properties,
};
pub const Dialog = struct {
@@ -213,6 +215,7 @@ pub const Dialog = struct {
deletion: deletion.State = .{},
applications: ?open_with.State = null,
properties: ?properties.State = null,
+ trash_properties: ?trash_properties.State = null,
};
pub const RenameCard = struct { panel: header.Rect, field: header.Rect, confirm: header.Rect, cancel: header.Rect };
diff --git a/src/files/app_paint.zig b/src/files/app_paint.zig
index fed34cd..6af8586 100644
--- a/src/files/app_paint.zig
+++ b/src/files/app_paint.zig
@@ -468,6 +468,10 @@ pub fn renderDialog(self: *App, cr: *c.cairo_t) void {
self.dialog.?.properties.?.draw(cr, self.w, self.h, self.mouse_x, self.mouse_y, self.theme_cfg, self.io);
return;
}
+ if (dlg.kind == .trash_properties) {
+ self.dialog.?.trash_properties.?.draw(cr, self.w, self.h, self.mouse_x, self.mouse_y, ui_theme.global.app_toolbar, self.theme_cfg, self.io);
+ return;
+ }
if (dlg.kind == .open_with) {
self.dialog.?.applications.?.draw(cr, self.w, self.h, self.mouse_x, self.mouse_y, self.theme_cfg, self.io);
return;
diff --git a/src/files/app_pointer.zig b/src/files/app_pointer.zig
index 0a64fb4..18289e5 100644
--- a/src/files/app_pointer.zig
+++ b/src/files/app_pointer.zig
@@ -24,6 +24,7 @@ pub fn hoverKey(self: *App) usize {
const y = self.mouse_y;
if (self.dialog) |dlg| {
if (dlg.kind == .properties) return dlg.properties.?.hit(self.w, self.h, x, y);
+ if (dlg.kind == .trash_properties) return @intFromEnum(dlg.trash_properties.?.hit(self.w, self.h, x, y));
if (dlg.kind == .open_with) return dlg.applications.?.hit(self.w, self.h, x, y);
if (dlg.kind == .trash_confirm) return @intFromEnum(dlg.deletion.geometry(self.w, self.h).target(x, y));
const dw: f64 = @min(440, @as(f64, @floatFromInt(self.w)) - 24);
@@ -115,6 +116,7 @@ pub fn handleMotion(self: *App, x: f64, y: f64) void {
if (self.dialog) |*dlg| {
const moved = switch (dlg.kind) {
.properties => dlg.properties.?.motion(self.w, self.h, x, y),
+ .trash_properties => dlg.trash_properties.?.motion(self.w, self.h, x, y),
.open_with => dlg.applications.?.motion(self.w, self.h, x, y),
.trash_confirm => dlg.deletion.motion(self.w, self.h, x, y),
else => false,
@@ -182,6 +184,7 @@ pub fn cancelDrag(self: *App) void {
if (self.dialog) |*dlg| {
dlg.deletion.placement.grab = null;
if (dlg.properties) |*props| props.placement.grab = null;
+ if (dlg.trash_properties) |*props| props.placement.grab = null;
if (dlg.applications) |*apps| apps.placement.grab = null;
}
self.column_resize = null;
@@ -212,7 +215,7 @@ pub fn updateSelectionBand(self: *App) void {
const cols = self.columns();
for (self.items.items, 0..) |*item, i| {
const index: i32 = @intCast(i);
- const x: f64 = @floatFromInt(self.sidebarWidth() + 20 + @mod(index, cols) * self.cellWidth());
+ const x: f64 = @floatFromInt(self.sidebarWidth() + self.itemLeftInset() + @mod(index, cols) * self.cellWidth());
const y: f64 = @floatFromInt(self.viewTop() + self.itemInset() + @divTrunc(index, cols) * self.rowHeight());
const hit = rect.x < x + @as(f64, @floatFromInt(self.cellWidth() - 20)) and rect.x + rect.w > x and
rect.y < y + @as(f64, @floatFromInt(self.cardHeight())) and rect.y + rect.h > y;
@@ -284,6 +287,7 @@ pub fn handleButton(self: *App, button: u32, pressed: bool) void {
if (self.dialog) |*dlg| {
const consumed = switch (dlg.kind) {
.properties => dlg.properties.?.pointerButton(self.w, self.h, self.mouse_x, self.mouse_y, pressed),
+ .trash_properties => dlg.trash_properties.?.pointerButton(self.w, self.h, self.mouse_x, self.mouse_y, pressed),
.open_with => dlg.applications.?.pointerButton(self.w, self.h, self.mouse_x, self.mouse_y, pressed),
.trash_confirm => dlg.deletion.pointerButton(self.w, self.h, self.mouse_x, self.mouse_y, pressed),
else => false,
@@ -356,6 +360,11 @@ pub fn handleButton(self: *App, button: u32, pressed: bool) void {
self.propertiesAction(action);
return;
}
+ if (dlg.kind == .trash_properties) {
+ const action = self.dialog.?.trash_properties.?.click(self.w, self.h, x, y);
+ self.trashPropertiesAction(action);
+ return;
+ }
if (dlg.kind == .open_with) {
const action = self.dialog.?.applications.?.click(self.w, self.h, x, y);
self.openWithAction(action);
diff --git a/src/files/properties.zig b/src/files/properties.zig
index a3901b8..5eb4632 100644
--- a/src/files/properties.zig
+++ b/src/files/properties.zig
@@ -13,6 +13,7 @@ const button = @import("ui").widgets.button;
const checkbox = @import("ui").widgets.checkbox;
const icons = @import("../icon_cache.zig");
const icon_theme = @import("../icon_theme.zig");
+const card = @import("properties_card.zig");
const Rect = ui.Rect;
const centeredTextX = @import("ui").paint.centeredTextX;
@@ -38,7 +39,7 @@ pub const Geometry = struct {
return .{
.box = .{ .x = (@as(f32, @floatFromInt(w)) - width) / 2, .y = (@as(f32, @floatFromInt(h)) - height) / 2, .w = width, .h = height },
.close = frame.closeBox(width),
- .open = .{ .x = width - 48, .y = 67 + contentShift() - scroll, .w = 28, .h = 28 },
+ .open = card.openBox(width, scroll - contentShift()),
.scroll = scroll,
};
}
@@ -209,17 +210,14 @@ pub const State = struct {
button.paint(r, g.close, .{ .icon = .close, .variant = .chrome, .label = tr("Close") }, .{ .focused = self.keyboard_focus and self.focus == 0, .pointer = if (hover == 1) .hover else .idle });
r.clip = .{ .x = 12, .y = 49 + contentShift(), .w = g.box.w - 24, .h = g.box.h - 59 - contentShift() };
const s = g.scroll - contentShift();
- r.fillRect(24, 66 - s, 64, 64, .{ .color = theme.global.app_toolbar, .radius = 9, .border_width = 1, .border_color = theme.global.app_item_border });
const preview = self.preview orelse icons.get(cfg, io, if (self.isDirectory()) "folder" else "text-x-generic", @intFromFloat(44 * ui.scaleOf(cr)));
- if (preview) |im| r.drawImageCover(34, 76 - s, 44, 44, 0, .{ .pixels = im.pixels, .width = @intCast(im.size), .height = @intCast(im.size) }) else r.drawIcon(34, 76 - s, 44, 44, .{ .id = .view_list, .color = palette.fg });
- r.drawText(108, 68 - s, g.box.w - 162, 26, .{ .content = std.fs.path.basename(self.path), .font_size = ui.textSize(), .weight = 600, .color = palette.fg });
- r.drawText(108, 99 - s, g.box.w - 132, 24, .{ .content = self.description, .font_size = ui.textSize(), .color = palette.fg });
- var accent_palette = palette;
- accent_palette.fg = palette.accent;
- r.palette = accent_palette;
- button.paint(r, g.open, .{ .icon = .open, .variant = .ghost, .label = tr("Open") }, .{ .focused = self.keyboard_focus and self.focus == 1, .pointer = if (hover == 2) .hover else .idle });
- r.palette = palette;
- r.fillRect(24, 146 - s, g.box.w - 48, 1, .{ .color = theme.global.app_divider });
+ card.paintIdentity(r, g.box.w, s, .{
+ .image = if (preview) |im| .{ .pixels = im.pixels, .width = @intCast(im.size), .height = @intCast(im.size) } else null,
+ .glyph = .view_list,
+ .name = std.fs.path.basename(self.path),
+ .kind = self.description,
+ });
+ card.paintOpen(r, g.box.w, s, tr("Open"), self.keyboard_focus and self.focus == 1, hover == 2);
var size_buf: [128]u8 = undefined;
var short_buf: [32]u8 = undefined;
const byte_count: u64 = @intCast(@max(0, self.stat.st_size));
@@ -228,11 +226,7 @@ pub const State = struct {
var modified_buf: [64]u8 = undefined;
const values = [_][]const u8{ size, date(self.created, &created_buf), date(self.stat.st_mtim.tv_sec, &modified_buf), std.fs.path.dirname(self.path) orelse "/", self.owner, self.group };
const labels = [_][]const u8{ tr("Size"), tr("Created"), tr("Modified"), tr("Location"), tr("Owner"), tr("Group") };
- for (labels, values, 0..) |label, value, i| {
- const y = 157 + @as(f32, @floatFromInt(i)) * 26 - s;
- r.drawText(24, y, 120, 24, .{ .content = label, .font_size = ui.textSize(), .color = palette.fg });
- r.drawText(162, y, g.box.w - 186, 24, .{ .content = value, .font_size = ui.textSize(), .color = palette.fg });
- }
+ card.paintFields(r, g.box.w, s, &labels, &values);
r.fillRect(24, 322 - s, g.box.w - 48, 1, .{ .color = theme.global.app_divider });
r.drawText(24, 334 - s, 160, 28, .{ .content = tr("Permissions"), .font_size = ui.headingSize(), .weight = 600, .color = palette.fg });
var mode_buf: [8]u8 = undefined;
diff --git a/src/files/properties_card.zig b/src/files/properties_card.zig
new file mode 100644
index 0000000..1381f1f
--- /dev/null
+++ b/src/files/properties_card.zig
@@ -0,0 +1,63 @@
+//! The body shared by every Properties window: an identity row (preview tile,
+//! name, kind, Open) and the label/value fields under it. File Properties
+//! (`properties.zig`) and the Trash's (`trash_properties.zig`, also shown by the
+//! desktop) both draw with these, so the two cannot drift apart.
+//!
+//! `s` is how far the content is scrolled, less the title bar's extra height:
+//! a row at `y` is drawn at `y - s`. The renderer's palette is the body's
+//! (`fg` for text, `accent` for Open); call these with it set.
+const std = @import("std");
+const ui = @import("ui");
+const theme = ui.theme;
+const button = ui.widgets.button;
+const Renderer = ui.paint.Renderer;
+const Rect = ui.cairo.Rect;
+
+pub const fields_y: f32 = 157;
+pub const field_step: f32 = 26;
+
+pub fn openBox(width: f32, s: f32) Rect {
+ return .{ .x = width - 48, .y = 67 - s, .w = 28, .h = 28 };
+}
+
+/// Where the content ends once it holds `count` fields.
+pub fn fieldsBottom(count: usize) f32 {
+ return fields_y + @as(f32, @floatFromInt(count)) * field_step;
+}
+
+pub const Identity = struct {
+ /// Raster of the thing described, drawn 44 px wide in its tile.
+ image: ?ui.paint.Image = null,
+ /// Vector glyph for when there is no raster.
+ glyph: ui.layout.IconId,
+ name: []const u8,
+ kind: []const u8,
+};
+
+pub fn paintIdentity(r: *Renderer, width: f32, s: f32, id: Identity) void {
+ const t = r.palette orelse theme.global;
+ r.fillRect(24, 66 - s, 64, 64, .{ .color = theme.global.app_toolbar, .radius = 9, .border_width = 1, .border_color = theme.global.app_item_border });
+ if (id.image) |im| r.drawImageCover(34, 76 - s, 44, 44, 0, im) else r.drawIcon(34, 76 - s, 44, 44, .{ .id = id.glyph, .color = t.fg });
+ r.drawText(108, 68 - s, width - 162, 26, .{ .content = id.name, .font_size = t.font_size, .weight = 600, .color = t.fg });
+ r.drawText(108, 99 - s, width - 132, 24, .{ .content = id.kind, .font_size = t.font_size, .color = t.fg });
+}
+
+pub fn paintOpen(r: *Renderer, width: f32, s: f32, label: []const u8, focused: bool, hovered: bool) void {
+ const body = r.palette orelse theme.global;
+ var accent = body;
+ accent.fg = body.accent;
+ r.palette = accent;
+ button.paint(r, openBox(width, s), .{ .icon = .open, .variant = .ghost, .label = label }, .{ .focused = focused, .pointer = if (hovered) .hover else .idle });
+ r.palette = body;
+}
+
+/// The rule under the identity row, then one label and value per line.
+pub fn paintFields(r: *Renderer, width: f32, s: f32, labels: []const []const u8, values: []const []const u8) void {
+ const t = r.palette orelse theme.global;
+ r.fillRect(24, 146 - s, width - 48, 1, .{ .color = theme.global.app_divider });
+ for (labels, values, 0..) |label, value, i| {
+ const y = fields_y + @as(f32, @floatFromInt(i)) * field_step - s;
+ r.drawText(24, y, 120, 24, .{ .content = label, .font_size = t.font_size, .color = t.fg });
+ r.drawText(162, y, width - 186, 24, .{ .content = value, .font_size = t.font_size, .color = t.fg });
+ }
+}
diff --git a/src/files/trash_properties.zig b/src/files/trash_properties.zig
new file mode 100644
index 0000000..fba5b5a
--- /dev/null
+++ b/src/files/trash_properties.zig
@@ -0,0 +1,199 @@
+//! Properties window of the Trash itself, shown by Files (sidebar Trash) and
+//! by the desktop's Trash icon. It is the file Properties window
+//! (`properties.zig`) with the Trash's own facts in place of an inode's: its
+//! icon, how many items it holds and how much they weigh, and no permissions.
+//! The items and size come from `trash_totals.zig` on a thread that lives as
+//! long as the window; until it answers the rows read "Calculating…".
+const std = @import("std");
+const i18n = @import("i18n");
+const tr = i18n.tr;
+const c = @import("c.zig").api;
+const icons = @import("../icon_cache.zig");
+const icon_theme = @import("../icon_theme.zig");
+const ui = @import("ui");
+const shell_ui = ui.cairo;
+const theme = ui.theme;
+const chrome = ui.window_chrome;
+const dialog = ui.widgets.dialog;
+const button = ui.widgets.button;
+const card = @import("properties_card.zig");
+const totals = @import("trash_totals.zig");
+const formatSize = @import("app_draw.zig").formatSize;
+const Rect = shell_ui.Rect;
+const a = std.heap.c_allocator;
+
+pub const Action = enum { none, close, open };
+pub const Target = enum { none, close, open };
+
+const field_count = 3;
+
+fn contentShift() f32 {
+ return @max(0, @as(f32, @floatFromInt((chrome.Metrics{}).titlebarHeight())) - 49);
+}
+
+fn cardHeight() f32 {
+ return card.fieldsBottom(field_count) + 22 + contentShift();
+}
+
+pub const Geometry = struct {
+ box: Rect,
+ close: Rect,
+ open: Rect,
+
+ pub fn init(w: i32, h: i32) Geometry {
+ const width: f32 = @min(440, @as(f32, @floatFromInt(w)) - 24);
+ const height: f32 = @min(cardHeight(), @as(f32, @floatFromInt(h)) - 16);
+ return .{
+ .box = .{ .x = (@as(f32, @floatFromInt(w)) - width) / 2, .y = (@as(f32, @floatFromInt(h)) - height) / 2, .w = width, .h = height },
+ .close = dialog.closeBox(width),
+ .open = card.openBox(width, -contentShift()),
+ };
+ }
+};
+
+fn contains(rect: Rect, x: f32, y: f32) bool {
+ return x >= rect.x and y >= rect.y and x < rect.x + rect.w and y < rect.y + rect.h;
+}
+
+pub const State = struct {
+ placement: dialog.Placement = .{},
+ /// The Trash's `files` directory, shown as its location.
+ path: []const u8 = "",
+ task: ?*totals.Task = null,
+ totals: ?totals.Summary = null,
+ focus: Target = .close,
+ keyboard_focus: bool = false,
+
+ /// Starts counting at once. `wake_fd` is the host's event fd: it is
+ /// written when the totals arrive, after which the host calls `poll`.
+ pub fn init(path: []const u8, wake_fd: c_int) !State {
+ const owned = try a.dupe(u8, path);
+ errdefer a.free(owned);
+ return .{ .path = owned, .task = try totals.Task.start(path, wake_fd) };
+ }
+
+ pub fn deinit(self: *State) void {
+ if (self.task) |task| task.destroy();
+ a.free(self.path);
+ self.* = .{};
+ }
+
+ /// Takes the totals if they have arrived; true means repaint.
+ pub fn poll(self: *State) bool {
+ const task = self.task orelse return false;
+ const done = task.poll() orelse return false;
+ self.totals = done;
+ task.destroy();
+ self.task = null;
+ return true;
+ }
+
+ pub fn geometry(self: *const State, w: i32, h: i32) Geometry {
+ var g = Geometry.init(w, h);
+ g.box = self.placement.box(g.box, w, h);
+ return g;
+ }
+
+ pub fn pointerButton(self: *State, w: i32, h: i32, x: f64, y: f64, pressed: bool) bool {
+ return self.placement.button(Geometry.init(w, h).box, w, h, x, y, pressed);
+ }
+
+ pub fn motion(self: *State, w: i32, h: i32, x: f64, y: f64) bool {
+ return self.placement.motion(Geometry.init(w, h).box, w, h, x, y);
+ }
+
+ pub fn hit(self: *const State, w: i32, h: i32, x: f64, y: f64) Target {
+ const g = self.geometry(w, h);
+ const px: f32 = @floatCast(x - g.box.x);
+ const py: f32 = @floatCast(y - g.box.y);
+ if (contains(g.close, px, py)) return .close;
+ if (py < 49 + contentShift() or py >= g.box.h - 8) return .none;
+ if (contains(g.open, px, py)) return .open;
+ return .none;
+ }
+
+ pub fn click(self: *State, w: i32, h: i32, x: f64, y: f64) Action {
+ const target = self.hit(w, h, x, y);
+ if (target == .none) return .none;
+ self.keyboard_focus = false;
+ self.focus = target;
+ return self.activate();
+ }
+
+ fn activate(self: *const State) Action {
+ return if (self.focus == .open) .open else .close;
+ }
+
+ pub fn key(self: *State, sym: u32) Action {
+ if (sym == c.XKB_KEY_Escape) return .close;
+ if (sym == c.XKB_KEY_Tab or sym == c.XKB_KEY_ISO_Left_Tab) {
+ self.keyboard_focus = true;
+ self.focus = if (self.focus == .close) .open else .close;
+ } else if (sym == c.XKB_KEY_Return or sym == c.XKB_KEY_KP_Enter or sym == c.XKB_KEY_space) return self.activate();
+ return .none;
+ }
+
+ /// Dims the host window behind the card, then draws it.
+ pub fn draw(self: *const State, ctx: anytype, w: i32, h: i32, mx: f64, my: f64, background: ?[4]f32, cfg: icon_theme.Config, io: std.Io) void {
+ const cr: *c.cairo_t = @ptrCast(ctx);
+ c.cairo_save(cr);
+ defer c.cairo_restore(cr);
+ shell_ui.setSource(cr, dialog.backdropColor());
+ c.cairo_paint(cr);
+ self.drawWindow(ctx, w, h, mx, my, background, cfg, io);
+ }
+
+ /// Floating compositor prompts have no app-sized backdrop to dim.
+ pub fn drawWindow(self: *const State, ctx: anytype, w: i32, h: i32, mx: f64, my: f64, background: ?[4]f32, cfg: icon_theme.Config, io: std.Io) void {
+ const cr: *c.cairo_t = @ptrCast(ctx);
+ c.cairo_save(cr);
+ defer c.cairo_restore(cr);
+ const g = self.geometry(w, h);
+ var layer = shell_ui.Layer.begin(cr, g.box) orelse return;
+ defer layer.finish();
+ const r = &layer.renderer;
+ var palette = theme.shellPalette();
+ palette.font_size = shell_ui.textSize();
+ palette.button_font_size = shell_ui.textSize();
+ r.palette = palette;
+ dialog.paintWindowFrame(r, layer.local(), background);
+ dialog.paintWindowTitle(r, layer.local(), tr("Properties"), .trash_can, null);
+ const hover = self.hit(w, h, mx, my);
+ button.paint(r, g.close, .{ .icon = .close, .variant = .chrome, .label = tr("Close") }, .{ .focused = self.keyboard_focus and self.focus == .close, .pointer = if (hover == .close) .hover else .idle });
+ // The body is the app surface: it takes the app's foreground, not the dark chrome's.
+ palette.fg = theme.global.forApp().window_fg;
+ r.palette = palette;
+ r.clip = .{ .x = 12, .y = 49 + contentShift(), .w = g.box.w - 24, .h = g.box.h - 59 - contentShift() };
+ const s = -contentShift();
+ // The same artwork the desktop and sidebar show: a pack's, else the glyph.
+ const art = icons.getPack(cfg, io, "user-trash", @intFromFloat(44 * shell_ui.scaleOf(cr)));
+ card.paintIdentity(r, g.box.w, s, .{
+ .image = if (art) |im| .{ .pixels = im.pixels, .width = @intCast(im.size), .height = @intCast(im.size) } else null,
+ .glyph = .trash_can,
+ .name = tr("Trash"),
+ .kind = tr("Deleted files and folders"),
+ });
+ card.paintOpen(r, g.box.w, s, tr("Open"), self.keyboard_focus and self.focus == .open, hover == .open);
+ var items_buf: [64]u8 = undefined;
+ var size_buf: [128]u8 = undefined;
+ var short_buf: [32]u8 = undefined;
+ var items: []const u8 = tr("Calculating…");
+ var size: []const u8 = items;
+ if (self.totals) |t| {
+ items = i18n.fmt(&items_buf, i18n.trn("{count} item", "{count} items", t.items), .{ .count = t.items }) catch "—";
+ const short = formatSize(t.bytes, &short_buf);
+ const bytes: u64 = @intCast(@max(0, t.bytes));
+ size = (if (t.partial)
+ i18n.fmt(&size_buf, tr("At least {size}"), .{ .size = short })
+ else
+ i18n.fmt(&size_buf, i18n.trn("{size} ({bytes} byte)", "{size} ({bytes} bytes)", bytes), .{ .size = short, .bytes = bytes })) catch "—";
+ }
+ const labels = [field_count][]const u8{ tr("Items"), tr("Size"), tr("Location") };
+ const values = [field_count][]const u8{ items, size, self.path };
+ card.paintFields(r, g.box.w, s, &labels, &values);
+ }
+};
+
+test {
+ _ = @import("trash_properties_tests.zig");
+}
diff --git a/src/files/trash_properties_tests.zig b/src/files/trash_properties_tests.zig
new file mode 100644
index 0000000..7dda0c6
--- /dev/null
+++ b/src/files/trash_properties_tests.zig
@@ -0,0 +1,93 @@
+const std = @import("std");
+const c = @import("c.zig").api;
+const icon_theme = @import("../icon_theme.zig");
+const trash_properties = @import("trash_properties.zig");
+const State = trash_properties.State;
+
+fn writeFile(dir_fd: c_int, name: [*:0]const u8, content: []const u8) !void {
+ const fd = c.openat(dir_fd, name, c.O_WRONLY | c.O_CREAT | c.O_CLOEXEC, @as(c.mode_t, 0o600));
+ if (fd < 0) return error.CreateFailed;
+ defer _ = c.close(fd);
+ if (c.write(fd, content.ptr, content.len) != @as(isize, @intCast(content.len))) return error.WriteFailed;
+}
+
+fn waitForTotals(state: *State) !void {
+ var tries: usize = 0;
+ while (!state.poll()) : (tries += 1) {
+ if (tries > 500) return error.TotalsNeverArrived;
+ _ = c.usleep(10_000);
+ }
+}
+
+test "keys and clicks reach Close and Open" {
+ var state = try State.init("/nonexistent-rediwm-trash", -1);
+ defer state.deinit();
+ try std.testing.expectEqual(trash_properties.Action.none, state.key(c.XKB_KEY_a));
+ try std.testing.expectEqual(trash_properties.Action.close, state.key(c.XKB_KEY_Escape));
+ // Close has the focus first, so Enter closes without a Tab.
+ try std.testing.expectEqual(trash_properties.Action.close, state.key(c.XKB_KEY_Return));
+ try std.testing.expectEqual(trash_properties.Action.none, state.key(c.XKB_KEY_Tab));
+ try std.testing.expect(state.keyboard_focus and state.focus == .open);
+ try std.testing.expectEqual(trash_properties.Action.open, state.key(c.XKB_KEY_Return));
+ try std.testing.expectEqual(trash_properties.Action.none, state.key(c.XKB_KEY_ISO_Left_Tab));
+ try std.testing.expectEqual(trash_properties.Action.close, state.key(c.XKB_KEY_space));
+
+ const g = state.geometry(800, 600);
+ try std.testing.expectEqual(trash_properties.Action.close, state.click(800, 600, g.box.x + g.close.x + 3, g.box.y + g.close.y + 3));
+ try std.testing.expectEqual(trash_properties.Action.open, state.click(800, 600, g.box.x + g.open.x + 3, g.box.y + g.open.y + 3));
+ // Text and empty space are not buttons.
+ try std.testing.expectEqual(trash_properties.Action.none, state.click(800, 600, g.box.x + 40, g.box.y + g.box.h - 20));
+ try std.testing.expectEqual(trash_properties.Action.none, state.click(800, 600, 2, 2));
+}
+
+test "the window counts the Trash and draws a pack's trash artwork" {
+ var template = "/tmp/rediwm-trash-card-XXXXXX".* ++ [_]u8{0};
+ const root = c.mkdtemp(&template) orelse return error.TempFailed;
+ const root_fd = c.open(root, c.O_RDONLY | c.O_DIRECTORY | c.O_CLOEXEC);
+ try std.testing.expect(root_fd >= 0);
+ defer _ = c.rmdir(root);
+ defer _ = c.close(root_fd);
+ // The pack: icons/user-trash.svg, a solid green square.
+ try std.testing.expectEqual(@as(c_int, 0), c.mkdirat(root_fd, "icons", 0o700));
+ defer _ = c.unlinkat(root_fd, "icons", c.AT_REMOVEDIR);
+ try writeFile(root_fd, "icons/user-trash.svg", "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\"><rect width=\"48\" height=\"48\" fill=\"#00ff00\"/></svg>");
+ defer _ = c.unlinkat(root_fd, "icons/user-trash.svg", 0);
+ // The Trash itself: two entries, one of them a folder.
+ try std.testing.expectEqual(@as(c_int, 0), c.mkdirat(root_fd, "files", 0o700));
+ defer _ = c.unlinkat(root_fd, "files", c.AT_REMOVEDIR);
+ try writeFile(root_fd, "files/note.txt", "hello");
+ defer _ = c.unlinkat(root_fd, "files/note.txt", 0);
+ try std.testing.expectEqual(@as(c_int, 0), c.mkdirat(root_fd, "files/dir", 0o700));
+ defer _ = c.unlinkat(root_fd, "files/dir", c.AT_REMOVEDIR);
+ try writeFile(root_fd, "files/dir/data", "0123456789");
+ defer _ = c.unlinkat(root_fd, "files/dir/data", 0);
+
+ var files_path: [128]u8 = undefined;
+ const files = try std.fmt.bufPrint(&files_path, "{s}/files", .{std.mem.span(root)});
+ var state = try State.init(files, -1);
+ defer state.deinit();
+ try std.testing.expect(state.totals == null);
+ try waitForTotals(&state);
+ try std.testing.expectEqual(@as(u64, 2), state.totals.?.items);
+ try std.testing.expectEqual(@as(i64, 15), state.totals.?.bytes);
+ try std.testing.expect(!state.totals.?.partial);
+
+ const w = 640;
+ const h = 480;
+ const surface = c.cairo_image_surface_create(c.CAIRO_FORMAT_ARGB32, w, h).?;
+ defer c.cairo_surface_destroy(surface);
+ const cr = c.cairo_create(surface).?;
+ defer c.cairo_destroy(cr);
+ const cfg: icon_theme.Config = .{ .theme_name = "", .override_root = std.mem.span(root), .base_dirs = &.{} };
+ state.draw(cr, w, h, 0, 0, null, cfg, std.testing.io);
+ c.cairo_surface_flush(surface);
+
+ // Centre of the icon tile: the pack's artwork, not the built-in glyph.
+ const g = state.geometry(w, h);
+ const x: usize = @intFromFloat(g.box.x + 24 + 32);
+ const y: usize = @intFromFloat(g.box.y + 66 + @max(0, @as(f32, @floatFromInt((@import("ui").window_chrome.Metrics{}).titlebarHeight())) - 49) + 32);
+ const pixels: [*]const u32 = @ptrCast(@alignCast(c.cairo_image_surface_get_data(surface)));
+ const stride: usize = @intCast(@divExact(c.cairo_image_surface_get_stride(surface), 4));
+ const pixel = pixels[y * stride + x];
+ try std.testing.expectEqual(@as(u32, 0xff00ff00), pixel);
+}
diff --git a/src/files/trash_totals.zig b/src/files/trash_totals.zig
new file mode 100644
index 0000000..077294a
--- /dev/null
+++ b/src/files/trash_totals.zig
@@ -0,0 +1,120 @@
+//! What the Trash holds, counted off the UI thread. Files and the desktop's
+//! Trash icon show the same totals in the same Properties window
+//! (`trash_properties.zig`), so there is one walker.
+//!
+//! Items are the top-level entries of `Trash/files` (what the Trash view lists
+//! and Empty Trash removes); the size is every payload byte below them. Links
+//! are counted, never followed, and directory or `.trashinfo` metadata is not
+//! included.
+const std = @import("std");
+const c = @import("c.zig").api;
+
+const a = std.heap.c_allocator;
+
+pub const Summary = struct {
+ items: u64 = 0,
+ bytes: i64 = 0,
+ /// Something could not be read or the walk was cancelled: `bytes` is a
+ /// lower bound.
+ partial: bool = false,
+};
+
+pub fn collect(path: []const u8, stop: *const std.atomic.Value(bool)) Summary {
+ var result: Summary = .{};
+ const z = a.dupeSentinel(u8, path, 0) catch {
+ result.partial = true;
+ return result;
+ };
+ defer a.free(z);
+ const fd = c.open(z, c.O_RDONLY | c.O_DIRECTORY | c.O_NOFOLLOW | c.O_CLOEXEC);
+ if (fd < 0) {
+ result.partial = true;
+ return result;
+ }
+ walk(fd, 0, stop, &result);
+ return result;
+}
+
+// Owns fd. Never follows links, counts top-level deleted entries, and sums
+// payload sizes recursively (excluding directory and .trashinfo metadata).
+fn walk(fd: c_int, depth: usize, stop: *const std.atomic.Value(bool), result: *Summary) void {
+ const dir = c.fdopendir(fd) orelse {
+ _ = c.close(fd);
+ result.partial = true;
+ return;
+ };
+ defer _ = c.closedir(dir);
+ while (!stop.load(.acquire)) {
+ std.c._errno().* = 0;
+ const entry = c.readdir(dir) orelse {
+ if (std.c._errno().* != 0) result.partial = true;
+ return;
+ };
+ const name: [*:0]const u8 = @ptrCast(&entry.*.d_name);
+ if (std.mem.eql(u8, std.mem.span(name), ".") or std.mem.eql(u8, std.mem.span(name), "..")) continue;
+ if (depth == 0) result.items += 1;
+ var st: c.struct_stat = undefined;
+ if (c.fstatat(fd, name, &st, c.AT_SYMLINK_NOFOLLOW) != 0) {
+ result.partial = true;
+ continue;
+ }
+ if (st.st_mode & c.S_IFMT == c.S_IFDIR) {
+ if (depth >= 128) {
+ result.partial = true;
+ continue;
+ }
+ const child = c.openat(fd, name, c.O_RDONLY | c.O_DIRECTORY | c.O_NOFOLLOW | c.O_CLOEXEC);
+ if (child < 0) result.partial = true else walk(child, depth + 1, stop, result);
+ } else result.bytes +|= @max(0, st.st_size);
+ }
+ result.partial = true;
+}
+
+/// One count on its own thread, for as long as a Properties window is open.
+/// The host polls from its loop; the thread writes to `wake_fd` (the host's
+/// existing eventfd) when it finishes, so nothing ticks while idle.
+pub const Task = struct {
+ path: [:0]u8,
+ wake_fd: c_int,
+ stop: std.atomic.Value(bool) = .init(false),
+ finished: std.atomic.Value(bool) = .init(false),
+ result: Summary = .{},
+ thread: std.Thread = undefined,
+
+ pub fn start(path: []const u8, wake_fd: c_int) !*Task {
+ const self = try a.create(Task);
+ errdefer a.destroy(self);
+ self.* = .{ .path = try a.dupeSentinel(u8, path, 0), .wake_fd = wake_fd };
+ errdefer a.free(self.path);
+ self.thread = try std.Thread.spawn(.{}, run, .{self});
+ return self;
+ }
+
+ fn run(self: *Task) void {
+ self.result = collect(self.path, &self.stop);
+ self.finished.store(true, .release);
+ if (self.wake_fd >= 0) {
+ const one: u64 = 1;
+ _ = c.write(self.wake_fd, &one, @sizeOf(u64));
+ }
+ }
+
+ /// The totals once the walk is over.
+ pub fn poll(self: *const Task) ?Summary {
+ if (!self.finished.load(.acquire)) return null;
+ return self.result;
+ }
+
+ /// Cancels a walk in progress and waits for the thread, so the wake fd
+ /// may be closed afterwards.
+ pub fn destroy(self: *Task) void {
+ self.stop.store(true, .release);
+ self.thread.join();
+ a.free(self.path);
+ a.destroy(self);
+ }
+};
+
+test {
+ _ = @import("trash_totals_tests.zig");
+}
diff --git a/src/files/trash_totals_tests.zig b/src/files/trash_totals_tests.zig
new file mode 100644
index 0000000..f74c3ba
--- /dev/null
+++ b/src/files/trash_totals_tests.zig
@@ -0,0 +1,65 @@
+const std = @import("std");
+const c = @import("c.zig").api;
+const totals = @import("trash_totals.zig");
+const collect = totals.collect;
+
+test "Trash totals include nested payloads without following symlinks" {
+ var template = "/tmp/rediwm-trash-totals-XXXXXX".* ++ [_]u8{0};
+ const root = c.mkdtemp(&template) orelse return error.TempFailed;
+ defer _ = c.rmdir(root);
+ const fd = c.open(root, c.O_RDONLY | c.O_DIRECTORY | c.O_CLOEXEC);
+ try std.testing.expect(fd >= 0);
+ defer _ = c.close(fd);
+ const stop: std.atomic.Value(bool) = .init(false);
+ const empty = collect(std.mem.span(root), &stop);
+ try std.testing.expectEqual(@as(u64, 0), empty.items);
+ try std.testing.expectEqual(@as(i64, 0), empty.bytes);
+ try std.testing.expect(!empty.partial);
+ try std.testing.expectEqual(@as(c_int, 0), c.mkdirat(fd, "folder", 0o700));
+ defer _ = c.unlinkat(fd, "folder", c.AT_REMOVEDIR);
+ const file = c.openat(fd, "folder/data", c.O_WRONLY | c.O_CREAT | c.O_CLOEXEC, @as(c.mode_t, 0o600));
+ try std.testing.expect(file >= 0);
+ defer _ = c.unlinkat(fd, "folder/data", 0);
+ try std.testing.expectEqual(@as(isize, 7), c.write(file, "payload", 7));
+ _ = c.close(file);
+ // A loop would recurse forever if links were followed.
+ try std.testing.expectEqual(@as(c_int, 0), c.symlinkat(".", fd, "loop"));
+ defer _ = c.unlinkat(fd, "loop", 0);
+ const summary = collect(std.mem.span(root), &stop);
+ try std.testing.expectEqual(@as(u64, 2), summary.items);
+ try std.testing.expectEqual(@as(i64, 8), summary.bytes);
+ try std.testing.expect(!summary.partial);
+ const cancelled: std.atomic.Value(bool) = .init(true);
+ try std.testing.expect(collect(std.mem.span(root), &cancelled).partial);
+}
+
+test "a counting task hands over its totals and wakes the host once" {
+ var template = "/tmp/rediwm-trash-task-XXXXXX".* ++ [_]u8{0};
+ const root = c.mkdtemp(&template) orelse return error.TempFailed;
+ defer _ = c.rmdir(root);
+ const fd = c.open(root, c.O_RDONLY | c.O_DIRECTORY | c.O_CLOEXEC);
+ try std.testing.expect(fd >= 0);
+ defer _ = c.close(fd);
+ const file = c.openat(fd, "gone.txt", c.O_WRONLY | c.O_CREAT | c.O_CLOEXEC, @as(c.mode_t, 0o600));
+ try std.testing.expect(file >= 0);
+ defer _ = c.unlinkat(fd, "gone.txt", 0);
+ try std.testing.expectEqual(@as(isize, 5), c.write(file, "hello", 5));
+ _ = c.close(file);
+
+ const wake = c.eventfd(0, c.EFD_CLOEXEC | c.EFD_NONBLOCK);
+ try std.testing.expect(wake >= 0);
+ defer _ = c.close(wake);
+ const task = try totals.Task.start(std.mem.span(root), wake);
+ defer task.destroy();
+ var poll_fd = c.struct_pollfd{ .fd = wake, .events = c.POLLIN, .revents = 0 };
+ try std.testing.expectEqual(@as(c_int, 1), c.poll(&poll_fd, 1, 5000));
+ const summary = task.poll().?;
+ try std.testing.expectEqual(@as(u64, 1), summary.items);
+ try std.testing.expectEqual(@as(i64, 5), summary.bytes);
+ try std.testing.expect(!summary.partial);
+}
+
+test "destroying a task right away is safe" {
+ const task = try totals.Task.start("/nonexistent-rediwm-trash", -1);
+ task.destroy();
+}
diff --git a/tests/desktop_icons.py b/tests/desktop_icons.py
index d0dc2bc..0036d6b 100644
--- a/tests/desktop_icons.py
+++ b/tests/desktop_icons.py
@@ -472,27 +472,46 @@ def run():
for window in action('windows')['Windows']:
if window['app_id']=='rediwm-files': action('close_window', {'id': window['id']})
wait_for(lambda: not action('windows')['Windows'], 'Files did not close')
- click(152,60,273);click(200,82)
+ click(48,60,273);click(200,82)
wait_for(lambda: files_marker.exists() and files_marker.read_text()==str(home), 'Home context-menu click did not open Home')
close_files()
files_marker.unlink()
- click(152,172,273);click(200,194)
+ click(48,172,273);click(200,194)
wait_for(lambda: files_marker.exists() and files_marker.read_text()==str(trash_dir), 'Trash context-menu click did not open Trash')
close_files()
real_files.unlink()
files_marker.unlink()
- click(152,60,273);key(108);key(28)
+ click(48,60,273);key(108);key(28)
wait_for(lambda: files_marker.exists() and files_marker.read_text()==str(home), 'Home menu should only offer Open')
files_marker.unlink()
- click(152,172,273);key(108);key(108);key(28)
- wait_for(lambda: files_marker.exists() and files_marker.read_text()==str(trash_dir), 'Trash menu should wrap from Empty Trash to Open')
+ click(48,172,273);key(108);key(108);key(108);key(28)
+ wait_for(lambda: files_marker.exists() and files_marker.read_text()==str(trash_dir), 'Trash menu should wrap from Properties to Open')
+ files_marker.unlink()
+ # Properties is the Files window for the Trash itself: items and size, no permissions.
+ card=(430,230,850,450)
+ def trash_properties(name):
+ click(48,172,273);key(108);key(108);key(28)
+ time.sleep(.5)
+ return capture(name)
+ before_properties = capture('before-trash-properties')
+ empty_properties = trash_properties('trash-properties-empty')
+ assert difference(before_properties, empty_properties).crop(card).getbbox(), 'Trash Properties did not appear'
+ key(1)
+ assert not difference(before_properties, capture('trash-properties-closed')).crop(card).getbbox(), 'Escape left Trash Properties showing'
+ (trash_dir/'report.txt').write_text('x'*1234)
+ full_properties = trash_properties('trash-properties-full')
+ assert difference(empty_properties, full_properties).crop(card).getbbox(), 'Trash Properties ignored what is in the Trash'
+ key(15);key(28) # Tab reaches Open: Files shows the Trash and the window closes.
+ wait_for(lambda: files_marker.exists() and files_marker.read_text()==str(trash_dir), 'Open in Trash Properties did not open the Trash')
+ assert not difference(before_properties, capture('trash-properties-opened')).crop(card).getbbox(), 'Open left Trash Properties showing'
+ (trash_dir/'report.txt').unlink()
trashed_file=trash_dir/'empty-trash.txt';trashed_file.write_text('fixture')
- click(152,172,273);key(108);key(28)
+ click(48,172,273);key(108);key(28)
time.sleep(.2)
assert trashed_file.exists(), 'Desktop emptied Trash before confirmation'
key(1)
assert trashed_file.exists(), 'Cancelling Empty Trash deleted contents'
- click(152,172,273);click(200,224)
+ click(48,172,273);click(200,224)
time.sleep(.2)
assert trashed_file.exists(), 'Clicking Empty Trash bypassed confirmation'
key(15);key(28) # Tab reaches confirmation, without a deletion-mode checkbox.
diff --git a/tests/files_controls.py b/tests/files_controls.py
index 5816c22..3a65189 100644
--- a/tests/files_controls.py
+++ b/tests/files_controls.py
@@ -460,7 +460,7 @@ def run():
# Switching to list changes hit testing as well as painting.
click(727, 80)
- click(300, 220) # Second 44px row below the pinned header
+ click(300, 210) # Second 32px row below the pinned header
key(28)
opened("alpha-file.txt")
@@ -620,7 +620,7 @@ def run():
image = git_shot()
# List cell ends at width-34; Git defaults to 164px.
x = image.width - offset
- return [image.getpixel((x, 170 + row * 38)) for row in range(3)]
+ return [image.getpixel((x, 170 + row * 32)) for row in range(3)]
def changed_badges():
modified, deleted, added = badges()
@@ -629,8 +629,8 @@ def run():
# Both line-count colours appear beside M: staged and working
# changes combine into +28 -3, rather than double counting.
def count_pixels(image, row=0):
- return image.crop((image.width - 160, 158 + row * 38,
- image.width - 40, 182 + row * 38)).tobytes()
+ return image.crop((image.width - 160, 158 + row * 32,
+ image.width - 40, 182 + row * 32)).tobytes()
raw = count_pixels(git_shot())
pixels = zip(raw[0::3], raw[1::3], raw[2::3])
assert any(g > r + 40 and g > b + 25 for r, g, b in pixels), "added-line count missing"
@@ -662,8 +662,8 @@ def run():
# nested file is the fourth row, labelled with its path from the folder.
def nested_row():
image = git_shot()
- badge = image.getpixel((image.width - 190, 170 + 3 * 38))
- return badge[1] > badge[0] + 12, image.crop((250, 170 + 3 * 38 - 12, 700, 170 + 3 * 38 + 12)).tobytes()
+ badge = image.getpixel((image.width - 190, 170 + 3 * 32))
+ return badge[1] > badge[0] + 12, image.crop((250, 170 + 3 * 32 - 12, 700, 170 + 3 * 32 + 12)).tobytes()
assert nested_row()[0], "nested changed file was not listed flat"
with_path = nested_row()[1]
def toggle_full_paths():
@@ -693,7 +693,7 @@ def run():
click(checkbox_x, 82)
wait_for(lambda: prefs.read_bytes()[4] == 1, "Git View checkbox did not turn back on")
wait_for(changed_badges, "Git badges did not return with Git View on")
- click(300, 215) # Deleted beta.txt is retained but cannot open.
+ click(300, 200) # Deleted beta.txt is retained but cannot open.
key(28)
assert not marker.exists(), "deleted tracked file was opened"
key(46, ctrl=True)
diff --git a/tests/files_trash.py b/tests/files_trash.py
index 151e26e..a930f2c 100644
--- a/tests/files_trash.py
+++ b/tests/files_trash.py
@@ -271,6 +271,37 @@ def run():
ipc.type_text("made")
key(ENTER)
wait_for(lambda: (plain / "made").is_dir(), "New Folder no longer works outside the Trash")
+
+ # The sidebar's Trash row has its own Properties window (items, size, Open, Close),
+ # not the permissions sheet of its folder: Tab never reaches a permission cell, so
+ # Enter after two Tabs closes the window instead of changing the folder's mode.
+ put("late.txt", home / "late.txt", "twelve chars")
+ mode = files.stat().st_mode
+ geometry = next(iter(windows()))
+ row = (geometry["x"] + 75, geometry["y"] + 221) # sidebar: Home, Trash, Recent
+
+ def trash_properties():
+ ipc.click_at(*row, 0x111)
+ time.sleep(.3)
+ for _ in range(3): # Open, Open in New Window, Empty Trash…, Properties
+ key(DOWN)
+ key(ENTER)
+ time.sleep(.6)
+
+ trash_properties()
+ key(TAB)
+ key(TAB)
+ key(ENTER)
+ time.sleep(.4)
+ assert files.stat().st_mode == mode, "Trash Properties offered permissions to change"
+ trash_properties()
+ key(ESC)
+ time.sleep(.3)
+ assert windows()[0]["title"] == "plain — RediWM Files", "Escape in Trash Properties navigated away"
+ trash_properties()
+ key(TAB)
+ key(ENTER) # Open
+ title("Trash")
finally:
for peer in peers:
stop_process(peer)