RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
Files: a double-click on an icon opens the file once
oxydizer45541414c99f
diff --git a/src/files/app.zig b/src/files/app.zigindex f71aba1..5821ce9 100644--- a/src/files/app.zig+++ b/src/files/app.zig@@ -268,6 +268,10 @@ pub const App = struct {mouse_y: f64 = 0,last_click_time: i64 = 0,last_click_index: ?usize = null,+ /// The item a single-click last opened, and when: the second click of a+ /// double-click on its icon must not open it again.+ last_open_index: ?usize = null,+ last_open_time: i64 = 0,ctrl: bool = false,shift: bool = false,alt: bool = false,diff --git a/src/files/app_pointer.zig b/src/files/app_pointer.zigindex 5069f2a..0a64fb4 100644--- a/src/files/app_pointer.zig+++ b/src/files/app_pointer.zig@@ -307,6 +307,8 @@ pub fn handleButton(self: *App, button: u32, pressed: bool) void {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.last_open_index = idx;+ self.last_open_time = nowMs();self.activateItem(idx);}}@@ -593,6 +595,9 @@ pub fn handleButton(self: *App, button: u32, pressed: bool) void {}const single_click = button == 0x110 and !self.ctrl and !self.shift and !self.alt and self.singleClickIconAt(x, y) == idx;+ // A single click opens on release, so a double-click on an icon+ // would open it twice: the second click only selects.+ const just_opened = single_click and self.last_open_index == idx and now - self.last_open_time < 400;// 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);@@ -628,7 +633,7 @@ pub fn handleButton(self: *App, button: u32, pressed: bool) void {}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 and !self.items.items[idx].missing) self.drag_origin = .{ .x = x, .y = y };- if (single_click) self.open_on_release = idx;+ if (single_click and !just_opened) self.open_on_release = idx;} else {// A background press starts a rubber-band selection; pressing// an item still starts an outgoing file drag.diff --git a/src/files/app_pointer_tests.zig b/src/files/app_pointer_tests.zigindex 5c35d96..bb5fd5d 100644--- a/src/files/app_pointer_tests.zig+++ b/src/files/app_pointer_tests.zig@@ -8,6 +8,32 @@ const app_tests = @import("app_tests.zig");const testApp = app_tests.testApp;const testItems = app_tests.testItems;+test "Files: the second click of a double-click on an icon does not open it again" {+ var app = try testApp();+ defer app.deinit();+ try testItems(&app, 20);+ const rect = app.itemIconRect(0);+ const x = rect.x + rect.w / 2;+ const y = rect.y + rect.h / 2;+ app.handleMotion(x, y);+ // Opened a moment ago: the press selects but does not arm another open.+ app.last_open_index = 0;+ app.last_open_time = nowMs();+ app.handleButton(0x110, true);+ try std.testing.expect(app.open_on_release == null and app.items.items[0].selected);+ app.cancelDrag();+ // Another item, or the interval passed: a click opens as usual.+ app.last_open_index = 1;+ app.handleButton(0x110, true);+ try std.testing.expectEqual(@as(?usize, 0), app.open_on_release);+ app.cancelDrag();+ app.last_open_index = 0;+ app.last_open_time = nowMs() - 500;+ app.handleButton(0x110, true);+ try std.testing.expectEqual(@as(?usize, 0), app.open_on_release);+ app.cancelDrag();+}+test "Files wheel follows the shell spring, accumulates and reverses without lag" {var app = try testApp();defer app.deinit();