diff options
Diffstat (limited to 'src/mouse.zig')
| -rw-r--r-- | src/mouse.zig | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/src/mouse.zig b/src/mouse.zig index 02f966bd..7905735c 100644 --- a/src/mouse.zig +++ b/src/mouse.zig @@ -154,16 +154,15 @@ fn clampBorderCol(lx: u16, lw: u16, rw: u16, mcol: u16) u16 { return if (lo <= hi) std.math.clamp(mcol, lo, hi) else mcol; } -fn clampBorderRow(ay: u16, ah: u16, bh: u16, mrow: u16, tag_bottom: bool) u16 { - const d: u16 = if (tag_bottom) 1 else 0; - const lo = ay + BOX_H - 1 + d; - const hi = (ay +| ah +| bh -| (BOX_H + 1)) +| d; +fn clampBorderRow(ay: u16, ah: u16, bh: u16, mrow: u16) u16 { + const lo = ay + BOX_H - 1; + const hi = ay +| ah +| bh -| (BOX_H + 1); return if (lo <= hi) std.math.clamp(mrow, lo, hi) else mrow; } fn seamRowOf(p: *const Pardes, c: usize, k: usize) u16 { const r = p.rects[p.cols[c].panes[k]]; - return if (p.settings.tag_bottom) r.y +| r.h else r.y + r.h -| 1; + return r.y + r.h -| 1; } fn cornerFixture(gpa: std.mem.Allocator) !*Pardes { @@ -747,7 +746,7 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void { // window by its button. if (m.rule_above and mrow > 0) for (0..p.ncol) |cc| { if (mcol < p.col_x[cc] or mcol >= p.col_x[cc] + p.col_w[cc]) continue; - const seam = if (p.settings.tag_bottom) mrow else mrow - 1; + const seam = mrow - 1; if (seamIdxAt(p, cc, seam)) |k| { p.drag = .{ .border_h = .{ .col = cc, .top_idx = k, .cur_y = seam } }; return; @@ -903,7 +902,7 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo if (d.corner) |k| if (k.idx + 1 < p.cols[k.col].n) { const a = p.rects[p.cols[k.col].panes[k.idx]]; const b = p.rects[p.cols[k.col].panes[k.idx + 1]]; - d.cur_y = clampBorderRow(a.y, a.h, b.h, mrow, p.settings.tag_bottom); + d.cur_y = clampBorderRow(a.y, a.h, b.h, mrow); } else { d.cur_y = mrow; }; @@ -915,8 +914,7 @@ pub fn dragUpdate(p: *Pardes, mcol: u16, mrow: u16, body_hit: ?Mouse.BodyHit) vo const a = p.rects[p.cols[cc].panes[k]]; const b = p.rects[p.cols[cc].panes[k + 1]]; // Held by the rule over the lower pane: the seam is the row above. - const seam = if (p.settings.tag_bottom) mrow else mrow -| 1; - d.cur_y = clampBorderRow(a.y, a.h, b.h, seam, p.settings.tag_bottom); + d.cur_y = clampBorderRow(a.y, a.h, b.h, mrow -| 1); } else d.cur_y = mrow; }, .column_move => |*d| d.cur_x = mcol, @@ -1545,29 +1543,25 @@ test "a corner drag's two axes clamp independently" { // each axis alone, at both walls try std.testing.expectEqual(@as(u16, config.MINW), clampBorderCol(lx, lw, rw, 0)); try std.testing.expectEqual(@as(u16, 100 - config.MINW), clampBorderCol(lx, lw, rw, 999)); - try std.testing.expectEqual(row_lo, clampBorderRow(ay, ah, bh, 0, false)); - try std.testing.expectEqual(row_hi, clampBorderRow(ay, ah, bh, 999, false)); + try std.testing.expectEqual(row_lo, clampBorderRow(ay, ah, bh, 0)); + try std.testing.expectEqual(row_hi, clampBorderRow(ay, ah, bh, 999)); // THE corner property: drag off the right edge while staying mid-height — // x sits at its wall, y still tracks the mouse row exactly try std.testing.expectEqual(@as(u16, 100 - config.MINW), clampBorderCol(lx, lw, rw, 999)); - try std.testing.expectEqual(@as(u16, 12), clampBorderRow(ay, ah, bh, 12, false)); + try std.testing.expectEqual(@as(u16, 12), clampBorderRow(ay, ah, bh, 12)); // and the mirror: pinned at the bottom, x still free - try std.testing.expectEqual(row_hi, clampBorderRow(ay, ah, bh, 999, false)); + try std.testing.expectEqual(row_hi, clampBorderRow(ay, ah, bh, 999)); try std.testing.expectEqual(@as(u16, 40), clampBorderCol(lx, lw, rw, 40)); // both pinned at once is just both walls, not a stuck gesture try std.testing.expectEqual(@as(u16, config.MINW), clampBorderCol(lx, lw, rw, 0)); - try std.testing.expectEqual(row_hi, clampBorderRow(ay, ah, bh, 999, false)); - - try std.testing.expectEqual(row_lo + 1, clampBorderRow(ay, ah, bh, 0, true)); - try std.testing.expectEqual(row_hi + 1, clampBorderRow(ay, ah, bh, 999, true)); - try std.testing.expectEqual(@as(u16, 12), clampBorderRow(ay, ah, bh, 12, true)); + try std.testing.expectEqual(row_hi, clampBorderRow(ay, ah, bh, 999)); // degenerate pairs pass through untouched, each on its own terms: a pane // pair with no room stays draggable even when the column pair has room try std.testing.expectEqual(@as(u16, 7), clampBorderCol(0, 5, 5, 7)); try std.testing.expectEqual(@as(u16, 40), clampBorderCol(lx, lw, rw, 40)); - try std.testing.expectEqual(@as(u16, 9), clampBorderRow(TOPBAR_H, 1, 0, 9, false)); + try std.testing.expectEqual(@as(u16, 9), clampBorderRow(TOPBAR_H, 1, 0, 9)); } test "a v-handle press at the RIGHT column's seam drags both boundaries" { @@ -1668,7 +1662,7 @@ test "a RIGHT-column corner's two axes clamp independently" { try std.testing.expectEqual(handle, p.drag.border_v.cur_x); const a = p.rects[p.cols[1].panes[0]]; const b = p.rects[p.cols[1].panes[1]]; - try std.testing.expectEqual(clampBorderRow(a.y, a.h, b.h, 999, p.settings.tag_bottom), p.drag.border_v.cur_y); + try std.testing.expectEqual(clampBorderRow(a.y, a.h, b.h, 999), p.drag.border_v.cur_y); p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = handle, .row = 999 } }); } |
