RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
Add taskbar drag regression coverage
Meled65a2dac9ba
diff --git a/src/input/motion.zig b/src/input/motion.zigindex 57f154a..fb5b532 100644--- a/src/input/motion.zig+++ b/src/input/motion.zig@@ -271,10 +271,12 @@ pub fn processCursorMotion(input: *Input, time_msec: u32) void {pub fn passthroughMotion(input: *Input, time_msec: u32) void {if (input.taskbar_drag) |*session| {- const dx = input.cursor.x - session.press_x;- const dy = input.cursor.y - session.press_y;- const threshold: f64 = 6;- if (!session.dragging and dx * dx + dy * dy >= threshold * threshold) {+ if (!session.dragging and @import("../taskbar/pointer.zig").dragThresholdCrossed(+ session.press_x,+ session.press_y,+ input.cursor.x,+ input.cursor.y,+ )) {session.dragging = true;}if (session.dragging) {diff --git a/src/taskbar/pointer.zig b/src/taskbar/pointer.zigindex 3d7a076..474589d 100644--- a/src/taskbar/pointer.zig+++ b/src/taskbar/pointer.zig@@ -26,6 +26,14 @@ const markPaintCauseFromTarget = Taskbar.markPaintCauseFromTarget;const trayItem = Taskbar.trayItem;const source_scroll_step: f32 = 60;+pub const drag_threshold: f64 = 6;++/// Whether pointer movement from the initial press is large enough to drag.+pub fn dragThresholdCrossed(press_x: f64, press_y: f64, x: f64, y: f64) bool {+ const dx = x - press_x;+ const dy = y - press_y;+ return dx * dx + dy * dy >= drag_threshold * drag_threshold;+}/// A visible chip's horizontal bounds, used to calculate a drag insertion slot.pub const ChipSlot = struct {diff --git a/src/taskbar/tests.zig b/src/taskbar/tests.zigindex f4a809c..786f30b 100644--- a/src/taskbar/tests.zig+++ b/src/taskbar/tests.zig@@ -106,6 +106,36 @@ test "taskbar drag insertion ignores the dragged chip and handles a lone chip" {);}+test "taskbar drag threshold distinguishes clicks from drags" {+ const crossed = taskbar_pointer.dragThresholdCrossed;++ try std.testing.expect(!crossed(100, 100, 105.99, 100));+ try std.testing.expect(crossed(100, 100, 106, 100));+ try std.testing.expect(crossed(100, 100, 107, 100));+ try std.testing.expect(!crossed(100, 100, 104, 104));+ try std.testing.expect(crossed(100, 100, 104.25, 104.25));+}++test "taskbar drag insertion handles exact midpoints and a non-leading dragged chip" {+ const chips = [_]taskbar_pointer.ChipSlot{+ .{ .id = 10, .x = 0, .width = 100 },+ .{ .id = 20, .x = 110, .width = 100 },+ .{ .id = 30, .x = 220, .width = 100 },+ };++ // At the midpoint, the insertion point is after that chip.+ try std.testing.expectEqual(+ taskbar_pointer.InsertionTarget{ .neighbor_id = 30, .before = true },+ taskbar_pointer.insertionTarget(&chips, 10, 160).?,+ );++ // Excluding a dragged chip in the middle still finds the correct slot.+ try std.testing.expectEqual(+ taskbar_pointer.InsertionTarget{ .neighbor_id = 10, .before = true },+ taskbar_pointer.insertionTarget(&chips, 20, 25).?,+ );+}+test "chip/tile/tray sizing matches default theme" {const saved = ui_theme.global;defer ui_theme.global = saved;