refactor(core): reuse contains for border hit zones
- commit
- 00a0a44da34e46b9a9fa695e01cab7fdeb1f1578
- author
- brice · · 2026-10-21 05:46 UTC
- committer
- brice · · 2026-10-21 07:11 UTC
- parent
- d029245
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +4 -8
M internal/core/border.go +4 -8
| @@ -18,10 +18,6 @@ type border struct { | |||
| 18 | 18 | // The effective minimum also includes 5% of the lane and four border widths. | |
| 19 | 19 | const borderMinWidth = 48 | |
| 20 | 20 | ||
| 21 | - | func borderContains(r Rect, x, y int) bool { | |
| 22 | - | return x >= r.X && x < r.X+r.W && y >= r.Y && y < r.Y+r.H | |
| 23 | - | } | |
| 24 | - | ||
| 25 | 21 | func borderZone(a, b, pad int) (int, int) { | |
| 26 | 22 | mid := (a + b) / 2 | |
| 27 | 23 | lo, hi := min(a, mid-pad), max(b, mid+pad) | |
| @@ -29,13 +25,13 @@ func borderZone(a, b, pad int) (int, int) { | |||
| 29 | 25 | } | |
| 30 | 26 | ||
| 31 | 27 | func (w *Workspace) borderAt(x, y, pad int) (border, bool) { | |
| 32 | - | if w.fullscreen != 0 || !borderContains(w.Usable, x, y) { | |
| 28 | + | if w.fullscreen != 0 || !contains(w.Usable, x, y) { | |
| 33 | 29 | return border{}, false | |
| 34 | 30 | } | |
| 35 | 31 | // Overview and preview are Monitor presentation, not Workspace state. Their | |
| 36 | 32 | // caller must not ask for workspace borders while presenting those scenes. | |
| 37 | 33 | for _, p := range w.Layout() { | |
| 38 | - | if p.Floating && !p.Hidden && !p.Below && borderContains(p.Rect, x, y) { | |
| 34 | + | if p.Floating && !p.Hidden && !p.Below && contains(p.Rect, x, y) { | |
| 39 | 35 | return border{}, false | |
| 40 | 36 | } | |
| 41 | 37 | } | |
| @@ -52,7 +48,7 @@ func (w *Workspace) borderAt(x, y, pad int) (border, bool) { | |||
| 52 | 48 | for j := 0; j+1 < len(rows); j++ { | |
| 53 | 49 | lo, size := borderZone(rows[j].Y+rows[j].H, rows[j+1].Y, pad) | |
| 54 | 50 | b := border{kind: borderRow, col: i, row: j, rect: Rect{X: r.X, Y: lo, W: r.W, H: size}} | |
| 55 | - | if borderContains(b.rect, x, y) { | |
| 51 | + | if contains(b.rect, x, y) { | |
| 56 | 52 | return b, true | |
| 57 | 53 | } | |
| 58 | 54 | } | |
| @@ -66,7 +62,7 @@ func (w *Workspace) borderAt(x, y, pad int) (border, bool) { | |||
| 66 | 62 | top, bottom := max(r.Y, next.Y), min(r.Y+r.H, next.Y+next.H) | |
| 67 | 63 | lo, size := borderZone(r.X+r.W, next.X, pad) | |
| 68 | 64 | b := border{kind: borderColumn, col: i, rect: Rect{X: lo, Y: top, W: size, H: max(bottom-top, 0)}} | |
| 69 | - | if borderContains(b.rect, x, y) { | |
| 65 | + | if contains(b.rect, x, y) { | |
| 70 | 66 | return b, true | |
| 71 | 67 | } | |
| 72 | 68 | } | |
| @@ -18,10 +18,6 @@ type border struct { | |||||
| 18 | // The effective minimum also includes 5% of the lane and four border widths. | 18 | // The effective minimum also includes 5% of the lane and four border widths. | ||
| 19 | const borderMinWidth = 48 | 19 | const borderMinWidth = 48 | ||
| 20 | 20 | ||||
| 21 | - | func borderContains(r Rect, x, y int) bool { | |||
| 22 | - | return x >= r.X && x < r.X+r.W && y >= r.Y && y < r.Y+r.H | |||
| 23 | - | } | |||
| 24 | - | ||||
| 25 | func borderZone(a, b, pad int) (int, int) { | 21 | func borderZone(a, b, pad int) (int, int) { | ||
| 26 | mid := (a + b) / 2 | 22 | mid := (a + b) / 2 | ||
| 27 | lo, hi := min(a, mid-pad), max(b, mid+pad) | 23 | lo, hi := min(a, mid-pad), max(b, mid+pad) | ||
| @@ -29,13 +25,13 @@ func borderZone(a, b, pad int) (int, int) { | |||||
| 29 | } | 25 | } | ||
| 30 | 26 | ||||
| 31 | func (w *Workspace) borderAt(x, y, pad int) (border, bool) { | 27 | func (w *Workspace) borderAt(x, y, pad int) (border, bool) { | ||
| 32 | - | if w.fullscreen != 0 || !borderContains(w.Usable, x, y) { | 28 | + | if w.fullscreen != 0 || !contains(w.Usable, x, y) { |
| 33 | return border{}, false | 29 | return border{}, false | ||
| 34 | } | 30 | } | ||
| 35 | // Overview and preview are Monitor presentation, not Workspace state. Their | 31 | // Overview and preview are Monitor presentation, not Workspace state. Their | ||
| 36 | // caller must not ask for workspace borders while presenting those scenes. | 32 | // caller must not ask for workspace borders while presenting those scenes. | ||
| 37 | for _, p := range w.Layout() { | 33 | for _, p := range w.Layout() { | ||
| 38 | - | if p.Floating && !p.Hidden && !p.Below && borderContains(p.Rect, x, y) { | 34 | + | if p.Floating && !p.Hidden && !p.Below && contains(p.Rect, x, y) { |
| 39 | return border{}, false | 35 | return border{}, false | ||
| 40 | } | 36 | } | ||
| 41 | } | 37 | } | ||
| @@ -52,7 +48,7 @@ func (w *Workspace) borderAt(x, y, pad int) (border, bool) { | |||||
| 52 | for j := 0; j+1 < len(rows); j++ { | 48 | for j := 0; j+1 < len(rows); j++ { | ||
| 53 | lo, size := borderZone(rows[j].Y+rows[j].H, rows[j+1].Y, pad) | 49 | lo, size := borderZone(rows[j].Y+rows[j].H, rows[j+1].Y, pad) | ||
| 54 | b := border{kind: borderRow, col: i, row: j, rect: Rect{X: r.X, Y: lo, W: r.W, H: size}} | 50 | b := border{kind: borderRow, col: i, row: j, rect: Rect{X: r.X, Y: lo, W: r.W, H: size}} | ||
| 55 | - | if borderContains(b.rect, x, y) { | 51 | + | if contains(b.rect, x, y) { |
| 56 | return b, true | 52 | return b, true | ||
| 57 | } | 53 | } | ||
| 58 | } | 54 | } | ||
| @@ -66,7 +62,7 @@ func (w *Workspace) borderAt(x, y, pad int) (border, bool) { | |||||
| 66 | top, bottom := max(r.Y, next.Y), min(r.Y+r.H, next.Y+next.H) | 62 | top, bottom := max(r.Y, next.Y), min(r.Y+r.H, next.Y+next.H) | ||
| 67 | lo, size := borderZone(r.X+r.W, next.X, pad) | 63 | lo, size := borderZone(r.X+r.W, next.X, pad) | ||
| 68 | b := border{kind: borderColumn, col: i, rect: Rect{X: lo, Y: top, W: size, H: max(bottom-top, 0)}} | 64 | b := border{kind: borderColumn, col: i, rect: Rect{X: lo, Y: top, W: size, H: max(bottom-top, 0)}} | ||
| 69 | - | if borderContains(b.rect, x, y) { | 65 | + | if contains(b.rect, x, y) { |
| 70 | return b, true | 66 | return b, true | ||
| 71 | } | 67 | } | ||
| 72 | } | 68 | } | ||