RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
add single click folder open
oxydizer037cf0e8d0e4
diff --git a/TESTING.md b/TESTING.mdindex 25ae034..269514f 100644--- a/TESTING.md+++ b/TESTING.md@@ -262,7 +262,9 @@ a JSON result on stdout.`files_browser.py` (file-path selection; with `REDIWM_FORCE_DBUS=1` on a private`dbus-run-session` bus, also checks `FileManager1.ShowItems`), `files_controls.py`, `files_decoration.py`,`files_controls.py --places-only` isolates navigation, Recent history and sidebar-controls from the Git checks. `files_thumbnails.py` (draws real pictures and reads thumbnail pixels back: shape,+controls from the Git checks; `--single-click-only` checks icon-only opening in+both views, hand cursors, selection/drag cancellation and the live Settings toggle.+`files_thumbnails.py` (draws real pictures and reads thumbnail pixels back: shape,colour, EXIF rotation, the shared freedesktop cache read and write, a 240-picturefolder, the `REDIWM_FILES_THUMBNAILS=0` switch and idle wakeups; it sets a scratch`XDG_CACHE_HOME`), `files_fixes.py` (wl-clipboard), `files_associations.py` (private MIME/appdiff --git a/docs/wiki/Apps-and-Services.md b/docs/wiki/Apps-and-Services.mdindex 8113371..1feb833 100644--- a/docs/wiki/Apps-and-Services.md+++ b/docs/wiki/Apps-and-Services.md@@ -24,6 +24,9 @@ The file manager. Space opens images, PDFs and text files.- **Pins:** drop a folder on the PLACES sidebar to pin it. Stored one path perline in `$XDG_STATE_HOME/rediwm/files-places`.- Drag a file out and the window slides aside (`dodge_file_drags`).+- File and folder icons open with one click in list and icons view, with a hand+ cursor on hover. Names select; Ctrl/Shift clicks and dragging still work.+ Turn this off in Settings → General (`files_single_click_open`).## Text editor (`rediwm-editor [FILE ...]`)diff --git a/docs/wiki/Configuration.md b/docs/wiki/Configuration.mdindex cd08b6f..7f29626 100644--- a/docs/wiki/Configuration.md+++ b/docs/wiki/Configuration.md@@ -82,6 +82,7 @@ keep 12-hour time and Sunday first until changed.| `window_gap` | `0` | px between snapped windows || `snap_to_edges` | `true` | || `dodge_file_drags` | `true` | file manager slides aside while you drag a file out |+| `files_single_click_open` | `true` | Files opens files and folders with one click on their icon in list or icons view || `switcher_opacity`, `inactive_opacity` | `1.0` | || `border_radius` | `10` | Legacy frame radius; `[theme].radius_lg` takes precedence. || `xwayland` | `true` | `false` means native only |diff --git a/src/config/default.zig b/src/config/default.zigindex 72644cf..d65b84c 100644--- a/src/config/default.zig+++ b/src/config/default.zig@@ -137,6 +137,7 @@ pub const source =\\# window_gap = 8 # px around and between tiled windows\\snap_to_edges = true # drag a window to a screen edge to tile or maximize it\\dodge_file_drags = true # a file manager slides aside while you drag a file out of it+ \\files_single_click_open = true # Files: one click on an icon opens the file or folder\\switcher_opacity = 1.0 # 0.0-1.0, background only; previews stay opaque\\inactive_opacity = 1.0 # 0.0-1.0, 1.0 = no change\\border_radius = 10 # window corner radiusdiff --git a/src/config/loader.zig b/src/config/loader.zigindex 3890ea4..65b79fa 100644--- a/src/config/loader.zig+++ b/src/config/loader.zig@@ -155,6 +155,8 @@ pub const CompositorConfig = struct {/// A file manager slides aside while a file is dragged out of it; see/// `input/drag_dodge.zig`.dodge_file_drags: bool = true,+ /// Files opens an item with one click on its icon; names still select.+ files_single_click_open: bool = true,inactive_opacity: f32 = 1.0,switcher_opacity: f32 = 1.0,border_radius: u32 = 10,@@ -1062,6 +1064,7 @@ const compositor_rules: std.enums.EnumFieldStruct(std.meta.FieldEnum(CompositorC.window_gap = .{ .uint = .{ .min = 0, .max = 512 } },.snap_to_edges = .boolean,.dodge_file_drags = .boolean,+ .files_single_click_open = .boolean,.inactive_opacity = .{ .float = .{ .min = 0, .max = 1 } },.switcher_opacity = .{ .float = .{ .min = 0, .max = 1 } },.border_radius = .{ .uint = .{ .min = 0, .max = 128 } },diff --git a/src/control_center/panel.zig b/src/control_center/panel.zigindex 846e525..96d6bd4 100644--- a/src/control_center/panel.zig+++ b/src/control_center/panel.zig@@ -185,6 +185,8 @@ pub const ControlCenter = struct {general_output_text: [2]Widget = undefined,general_display: [2]Widget = undefined,general_display_text: [2]Widget = undefined,+ general_files: [2]Widget = undefined,+ general_files_text: [2]Widget = undefined,brightness_children: [2]Widget = undefined,brightness_row: [3]Widget = undefined,brightness_percent: [8]u8 = undefined,@@ -638,6 +640,18 @@ pub const ControlCenter = struct {cc.append(display_card);default_apps_section.build(&cc.default_apps, cc);cc.append(cc.default_apps.root);+ cc.general_files_text = .{+ label("Single-click file and folder icons", 14, false),+ label("In Files, click an icon to open it in list or icons view. Click the name to select.", 12, true),+ };+ cc.general_files = .{+ .{ .kind = .container, .direction = .column, .gap = 5, .width = .{ .flex = 1 }, .children = &cc.general_files_text },+ .{ .name = "files_single_click_open", .kind = .{ .toggle = .{ .on = cc.server.config.compositor.files_single_click_open, .owner = cc, .on_change = filesSingleClickChanged } } },+ };+ var files_card = card(&cc.general_files);+ files_card.direction = .row;+ files_card.@"align" = .center;+ cc.append(files_card);}fn buildDevices(cc: *ControlCenter) void {@@ -1246,3 +1260,14 @@ fn brightnessChanged(owner: ?*anyopaque, _: usize, value: f32) void {cc.brightness_row[2].kind.text.content = std.fmt.bufPrint(&cc.brightness_percent, "{d}%", .{@as(i32, @intFromFloat(@round(value * 100)))}) catch "";cc.brightness_row[2].markDirty();}++fn filesSingleClickChanged(owner: ?*anyopaque, _: usize, on: bool) void {+ const cc: *ControlCenter = @ptrCast(@alignCast(owner orelse return));+ @import("config").setting_save.saveCompositor(gpa, cc.server.io, cc.server.config.path, "files_single_click_open", on) catch |err| {+ std.log.warn("could not save Files single-click setting: {}", .{err});+ cc.default_apps.message = "Could not save the Files setting.";+ cc.refresh();+ return;+ };+ cc.server.config.compositor.files_single_click_open = on;+}diff --git a/src/files/app.zig b/src/files/app.zigindex f1c8799..4bf7d43 100644--- a/src/files/app.zig+++ b/src/files/app.zig@@ -361,6 +361,8 @@ pub const App = struct {drag_ready: bool = false,collapse_on_release: ?usize = null,deselect_on_release: ?usize = null,+ open_on_release: ?usize = null,+ single_click_open: bool = true,selection_band: ?struct {x: f64,y: f64, // Content coordinates, so the anchor survives edge scrolling.@@ -459,6 +461,7 @@ pub const App = struct {.job_runner = ops_mod.JobRunner.init(allocator) catch null,.folder_sizes = std.StringHashMap(SizeState).init(allocator),.thumbs_enabled = !thumb_decode.disabled(environ),+ .single_click_open = @import("settings.zig").singleClickOpen(),};self.theme_cfg.override_root = @import("settings.zig").iconRoot();@@ -1003,6 +1006,8 @@ pub const App = struct {self.worker.theme = null;_ = c.pthread_mutex_unlock(&self.worker.mutex);if (new_theme) |t| {+ self.single_click_open = t.single_click_open;+ self.open_on_release = null;t.apply();self.theme_cfg.override_root = @import("settings.zig").iconRoot();const base = @import("settings.zig").iconTheme();@@ -3982,6 +3987,7 @@ pub const App = struct {self.drag_origin = null;self.collapse_on_release = null;self.deselect_on_release = null;+ self.open_on_release = null;self.last_click_index = null;}}@@ -4036,6 +4042,7 @@ pub const App = struct {self.drag_ready = false;self.collapse_on_release = null;self.deselect_on_release = null;+ self.open_on_release = null;}fn bandRect(self: *App) header.Rect {@@ -4216,6 +4223,7 @@ pub const App = struct {}if (!pressed) {if (button == 0x110) {+ const open_index = self.open_on_release;if (self.collapse_on_release) |idx| {for (self.items.items, 0..) |*it, i| it.selected = i == idx;self.invalidate();@@ -4225,6 +4233,13 @@ pub const App = struct {self.invalidate();}self.cancelDrag();+ if (open_index) |idx| {+ if (!self.ctrl and !self.shift and !self.alt and self.singleClickIconAt(self.mouse_x, self.mouse_y) == idx) {+ self.last_click_index = null;+ self.last_click_time = 0;+ self.activateItem(idx);+ }+ }}self.text_dragging = false;self.scroll_drag.end();@@ -4497,15 +4512,16 @@ pub const App = struct {}}- // Double click check- if (button == 0x110 and self.last_click_index == idx and (now - self.last_click_time < 400)) {+ const single_click = button == 0x110 and !self.ctrl and !self.shift and !self.alt and self.singleClickIconAt(x, y) == idx;+ // Icon clicks activate on release so they can still start a drag.+ if (!single_click and button == 0x110 and !self.ctrl and !self.shift and !self.alt and self.last_click_index == idx and (now - self.last_click_time < 400)) {self.activateItem(idx);self.last_click_index = null;self.last_click_time = 0;return;}- self.last_click_index = idx;+ self.last_click_index = if (single_click or button != 0x110 or self.ctrl or self.shift or self.alt) null else idx;self.last_click_time = now;self.focused_index = idx;@@ -4532,6 +4548,7 @@ pub const App = struct {}if (self.chooser != null and !self.items.items[idx].is_dir) self.setChooserName(self.items.items[idx].name);if (self.chooser == null and button == 0x110 and self.items.items[idx].selected) self.drag_origin = .{ .x = x, .y = y };+ if (single_click) self.open_on_release = idx;} else {// A background press starts a rubber-band selection; pressing// an item still starts an outgoing file drag.@@ -5416,9 +5433,17 @@ pub const App = struct {if (self.overSidebarDivider(x, y)) return "col-resize";if (self.chooser != null and self.chooserRect(0).contains(x, y)) return "text";if (self.focus != .location_bar and !self.search_visible and header.field(self.w).contains(x, y)) return "pointer";+ if (self.singleClickIconAt(x, y) != null) return "pointer";return if (header.field(self.w).contains(x, y)) "text" else "default";}+ fn singleClickIconAt(self: *App, x: f64, y: f64) ?usize {+ if (!self.single_click_open or self.chooser != null or self.dialog != null or self.menu != null) return null;+ if (x < @as(f64, @floatFromInt(self.sidebarWidth())) or x >= @as(f64, @floatFromInt(self.w - self.scrollbarGutter()))) return null;+ const idx = self.itemAt(x, y) orelse return null;+ return if (self.itemIconRect(@intCast(idx)).contains(x, y)) idx else null;+ }+/// The rename card, anchored to the item being renamed: the same inline/// popover the desktop uses (field plus confirm / cancel buttons), clamped/// to the file view.@@ -6873,6 +6898,55 @@ test "file drag threshold preserves multi-selection and ordinary release collapstry std.testing.expect(!app.items.items[0].selected);}+test "single-click opening targets only visible icons and cancels for selection or dragging" {+ for ([_]bool{ false, true }) |list| {+ var app = try testApp();+ defer app.deinit();+ app.list_view = list;+ try testItems(&app, 20);+ const rect = app.itemIconRect(0);+ const x = rect.x + rect.w / 2;+ const y = rect.y + rect.h / 2;+ try std.testing.expectEqualStrings("pointer", std.mem.span(app.pointerCursor(x, y)));+ try std.testing.expectEqualStrings("default", std.mem.span(app.pointerCursor(rect.x + rect.w + 8, y)));+ app.handleMotion(x, y);+ app.handleButton(0x110, true);+ try std.testing.expectEqual(@as(?usize, 0), app.open_on_release);+ app.handleMotion(x + 9, y);+ try std.testing.expect(app.drag_ready and app.open_on_release == null);+ app.handleButton(0x110, false);+ app.handleMotion(x, y);+ for (0..3) |modifier| {+ app.ctrl = modifier == 0;+ app.shift = modifier == 1;+ app.alt = modifier == 2;+ app.handleButton(0x110, true);+ try std.testing.expect(app.open_on_release == null);+ app.handleButton(0x110, false);+ }+ app.ctrl = false;+ app.shift = false;+ app.alt = false;+ app.handleButton(0x110, true);+ app.cancelDrag();+ try std.testing.expect(app.open_on_release == null);+ app.single_click_open = false;+ try std.testing.expectEqualStrings("default", std.mem.span(app.pointerCursor(x, y)));+ app.handleButton(0x110, true);+ try std.testing.expect(app.open_on_release == null);+ app.cancelDrag();+ app.single_click_open = true;+ app.scroll_y = @intFromFloat(rect.y + rect.h - app.viewTop());+ try std.testing.expect(app.singleClickIconAt(x, @floatFromInt(app.viewTop() - 1)) == null);+ if (list) {+ app.scroll_y = 0;+ app.scroll_x = 12;+ const shifted = app.itemIconRect(0);+ try std.testing.expectEqualStrings("pointer", std.mem.span(app.pointerCursor(shifted.x + 1, y)));+ }+ }+}+test "Files reduced motion scrolls immediately" {const saved = anim.currentSettings();defer anim.applySettings(saved);diff --git a/src/files/settings.zig b/src/files/settings.zigindex 62d15d4..7c393e5 100644--- a/src/files/settings.zig+++ b/src/files/settings.zig@@ -17,6 +17,7 @@ pub const ThemeUpdate = struct {pack_root: []const u8 = "",icon_theme: []const u8 = "",io: std.Io,+ single_click_open: bool = true,fn init(a: std.mem.Allocator, t: theme.Theme, prefs: config.RegionConfig, root: []const u8, icon_name: []const u8, io: std.Io) !ThemeUpdate {var value = t;@@ -125,6 +126,7 @@ pub const Settings = struct {var icon_name: []const u8 = "";var root: []const u8 = "";var prefs: config.RegionConfig = .{};+ var single_click_open = true;self.animations = .{};self.region = .{};for (paths, 0..) |path, i| {@@ -141,6 +143,7 @@ pub const Settings = struct {};icon_name = arena.allocator().dupe(u8, icon_name) catch return null;t = value.theme;+ single_click_open = value.compositor.files_single_click_open;if (value.theme_pack) |pack| root = arena.allocator().dupe(u8, pack.root) catch return null;inline for (.{ "font", "mono_font", "start_button_icon" }) |field| @field(t, field) = arena.allocator().dupe(u8, @field(t, field)) catch return null;prefs = value.region;@@ -156,7 +159,9 @@ pub const Settings = struct {// Settings only retains scalar preferences; returned updates own strings.self.region.clock_24h = prefs.clock_24h;self.region.first_day_of_week = prefs.first_day_of_week;- return ThemeUpdate.init(a, t, prefs, root, icon_name, io) catch null;+ var update = ThemeUpdate.init(a, t, prefs, root, icon_name, io) catch return null;+ update.single_click_open = single_click_open;+ return update;}};@@ -208,6 +213,7 @@ test "Files follows config edits, theme overrides and file removal" {try std.testing.expectEqualStrings("Noto Sans", update0.value.font);try std.testing.expectEqualStrings("Noto Sans Mono", update0.value.mono_font);try std.testing.expect(!update0.region.clock_24h);+ try std.testing.expect(update0.single_click_open);settings.last_second = -1;try std.testing.expect(settings.poll(a, io) == null);try std.Io.Dir.cwd().writeFile(io, .{ .sub_path = &theme_path, .data = "[theme]\nscrollbar_width = 24\nfont = \"Liberation Sans\"\n" });@@ -223,13 +229,19 @@ test "Files follows config edits, theme overrides and file removal" {defer update2.deinit();try std.testing.expectEqual(@as(f32, 12), update2.value.scrollbar_width);try std.testing.expectEqualStrings("Noto Sans", update2.value.font);- try std.Io.Dir.cwd().writeFile(io, .{ .sub_path = &config_path, .data = "[theme]\nscrollbar_width = 4\n[region]\nclock_24h = true\ntimezone = \"Pacific/Auckland\"\nlanguage = \"C.utf8\"\nformats = \"en_NZ.utf8\"\n" });+ try std.Io.Dir.cwd().writeFile(io, .{ .sub_path = &config_path, .data = "[compositor]\nfiles_single_click_open = false\n[theme]\nscrollbar_width = 4\n[region]\nclock_24h = true\ntimezone = \"Pacific/Auckland\"\nlanguage = \"C.utf8\"\nformats = \"en_NZ.utf8\"\n" });settings.last_second = -1;const update3 = settings.poll(a, io).?;defer update3.deinit();try std.testing.expectEqual(@as(f32, 4), update3.value.scrollbar_width);try std.testing.expectEqualStrings((theme.Theme{}).font, update3.value.font);try std.testing.expect(update3.region.clock_24h);+ try std.testing.expect(!update3.single_click_open);+ _ = c.unlink(&config_path);+ settings.last_second = -1;+ const update4 = settings.poll(a, io).?;+ defer update4.deinit();+ try std.testing.expect(update4.single_click_open);// The config's preference travels with the worker update, independently// of theme overrides; verify both clock formats in local time.var tm: c.struct_tm = std.mem.zeroes(c.struct_tm);@@ -309,3 +321,7 @@ pub fn iconRoot() []const u8 {pub fn iconTheme() []const u8 {return if (applied_theme) |t| t.icon_theme else "";}++pub fn singleClickOpen() bool {+ return if (applied_theme) |t| t.single_click_open else true;+}diff --git a/tests/files_controls.py b/tests/files_controls.pyindex b9ad315..3e54605 100644--- a/tests/files_controls.py+++ b/tests/files_controls.py@@ -178,6 +178,97 @@ def run():action('focus_window', {"id": win["id"]})time.sleep(.2)+ if "--single-click-only" in sys.argv:+ import tomllib+ from ipc_client import IPCClient+ from ui_driver import UIDriver++ with IPCClient(tmp) as ipc:+ ui = UIDriver(ipc)++ def move_local(x, y):+ box = ipc.get_window_debug(win["id"])["client_box"]+ ipc.move_cursor(box["x"] + x, box["y"] + y)++ def cursor(x, y, expected):+ move_local(x, y)+ # Let the client handle enter/motion before accepting+ # a cursor left by the Settings window.+ time.sleep(.15)+ wait_for(lambda: ipc.get_input_state()["cursor_name"] == expected,+ "Files cursor did not become " + expected)++ def toggle(enabled):+ ipc.open_control_center()+ ui.wait_settled("control_center")+ ui.click(ui.scroll_into_view("files_single_click_open"), panel="control_center")+ wait_for(lambda: tomllib.loads(config.read_text()).get("compositor", {}).get(+ "files_single_click_open") is enabled, "single-click setting did not save")+ settings = next(w for w in ipc.get_windows() if w["app_id"] == "rediwm-settings")+ ipc.close_window(settings["id"])+ ui.wait_absent("control_center")+ ipc.focus_window(win["id"])++ def navigate_home():+ key(38, ctrl=True)+ text(str(home))+ key(28)+ title("Home")++ for list_view in (False, True):+ box = ipc.get_window_debug(win["id"])["client_box"]+ click(box["width"] - (233 if list_view else 269), 82)+ ix, iy = (252, 180) if list_view else (278, 176)+ nx, ny = (330, 180) if list_view else (278, 220)+ search("Archive")+ cursor(ix, iy, "pointer")+ cursor(nx, ny, "default")+ click(nx, ny)+ title("Home")+ for modifier in (29, 42): # Ctrl/Shift click selects.+ ipc.key(modifier, True)+ click(ix, iy)+ ipc.key(modifier, False)+ title("Home")+ move_local(ix, iy)+ ipc.pointer_button(272, True)+ move_local(ix + 10, iy)+ ipc.pointer_button(272, False)+ title("Home") # Dragging must not open the folder.+ click(ix, iy)+ title("Archive")+ navigate_home()+ search("alpha-file.txt")+ cursor(ix, iy, "pointer")+ click(nx, ny)+ assert not marker.exists(), "clicking a name opened the file"+ click(ix, iy)+ opened("alpha-file.txt")+ toggle(False)+ cursor(ix, iy, "default") # Live preference reaches the open client.+ click(ix, iy)+ assert not marker.exists(), "disabled single-click opened the file"+ click(ix, iy)+ opened("alpha-file.txt")+ search("Archive")+ click(ix, iy)+ title("Home")+ click(ix, iy)+ title("Archive")+ navigate_home()+ search("Archive")+ toggle(True)+ cursor(ix, iy, "pointer")+ # Reload under a stationary pointer, including removing the preference.+ config.write_text('[compositor]\nfiles_single_click_open = false\n')+ wait_for(lambda: ipc.get_input_state()["cursor_name"] == "default",+ "stationary pointer did not follow disabled single-click")+ config.write_text("")+ wait_for(lambda: ipc.get_input_state()["cursor_name"] == "pointer",+ "removing the preference did not restore default single-click")+ print("PASS: icon-only single-click files/folders, hand cursors, selection, drag cancellation, Settings persistence and live reload in both views")+ return+if "--archive-only" in sys.argv:archive_dir = tmp / "archive-check"archive_dir.mkdir()