refactor(core): store row shares in basis points
- commit
- d458689758fcb0affa099046e5d659b2279efa56
- author
- brice · · 2026-10-21 05:17 UTC
- committer
- brice · · 2026-10-21 07:11 UTC
- parent
- dbc10e2
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
3 files · +31 -31
M internal/core/layout.go +12 -12
| @@ -26,9 +26,9 @@ type Column struct { | |||
| 26 | 26 | // Slot is the declared column number (workspace.<name>.column.N) of a | |
| 27 | 27 | // slot window; 0 for normal columns. | |
| 28 | 28 | Slot int | |
| 29 | - | // Shares are the row heights set by set-window-height, in percent, in | |
| 29 | + | // Shares are the row heights set by set-window-height, in basis points, in | |
| 30 | 30 | // Windows order. They apply only while there is one per window and | |
| 31 | - | // they sum to 100; otherwise the rows share the height equally. | |
| 31 | + | // they sum to 10000; otherwise the rows share the height equally. | |
| 32 | 32 | Shares []int | |
| 33 | 33 | // BandStart marks the first column of a cascade band. It belongs to the | |
| 34 | 34 | // position, not the column: swaps leave it in place. See cascade.go. | |
| @@ -916,33 +916,33 @@ func (w *Workspace) MoveWindow(dir int) { | |||
| 916 | 916 | w.scroll() | |
| 917 | 917 | } | |
| 918 | 918 | ||
| 919 | - | // minShare is the smallest row height set-window-height leaves, percent. | |
| 920 | - | const minShare = 10 | |
| 919 | + | // minShare is the smallest row height set-window-height leaves, in basis points. | |
| 920 | + | const minShare = 1000 | |
| 921 | 921 | ||
| 922 | 922 | // ResizeRow changes the focused window's height share by pct percent; the | |
| 923 | 923 | // other rows of its column give or take it in proportion to their shares. | |
| 924 | - | // Every row keeps at least minShare percent. | |
| 924 | + | // Every row keeps at least minShare basis points. | |
| 925 | 925 | func (w *Workspace) ResizeRow(pct int) { | |
| 926 | 926 | if w.onFloat() || len(w.Columns) == 0 || w.fullscreenHides() { | |
| 927 | 927 | return | |
| 928 | 928 | } | |
| 929 | 929 | c := &w.Columns[w.Focus] | |
| 930 | 930 | n := len(c.Windows) | |
| 931 | - | if n < 2 || n*minShare > 100 { | |
| 931 | + | if n < 2 || n*minShare > 10000 { | |
| 932 | 932 | return | |
| 933 | 933 | } | |
| 934 | 934 | shares := c.Shares | |
| 935 | 935 | if !validShares(*c) { | |
| 936 | 936 | shares = make([]int, n) | |
| 937 | 937 | for i := range shares { | |
| 938 | - | shares[i] = 100 / n | |
| 938 | + | shares[i] = 10000 / n | |
| 939 | 939 | } | |
| 940 | - | shares[n-1] += 100 % n | |
| 940 | + | shares[n-1] += 10000 % n | |
| 941 | 941 | } else { | |
| 942 | 942 | shares = slices.Clone(shares) | |
| 943 | 943 | } | |
| 944 | 944 | f := c.Focus | |
| 945 | - | target := min(max(shares[f]+pct, minShare), 100-minShare*(n-1)) | |
| 945 | + | target := min(max(shares[f]+pct*100, minShare), 10000-minShare*(n-1)) | |
| 946 | 946 | delta := target - shares[f] | |
| 947 | 947 | if delta == 0 { | |
| 948 | 948 | return | |
| @@ -1804,7 +1804,7 @@ func rowRectsInto(dst []Rect, r Rect, c Column, gap int) []Rect { | |||
| 1804 | 1804 | avail := max(r.H-(n-1)*gap, 0) | |
| 1805 | 1805 | yy, bottom, used := r.Y, r.Y+r.H, 0 | |
| 1806 | 1806 | for i, share := range c.Shares { | |
| 1807 | - | hh := avail * share / 100 | |
| 1807 | + | hh := avail * share / 10000 | |
| 1808 | 1808 | if i == n-1 { | |
| 1809 | 1809 | hh = avail - used | |
| 1810 | 1810 | } | |
| @@ -1818,7 +1818,7 @@ func rowRectsInto(dst []Rect, r Rect, c Column, gap int) []Rect { | |||
| 1818 | 1818 | } | |
| 1819 | 1819 | ||
| 1820 | 1820 | // validShares reports whether c.Shares has one share per window, each at | |
| 1821 | - | // least 1, summing to 100. | |
| 1821 | + | // least 1, summing to 10000. | |
| 1822 | 1822 | func validShares(c Column) bool { | |
| 1823 | 1823 | if len(c.Shares) != len(c.Windows) || len(c.Shares) < 2 { | |
| 1824 | 1824 | return false | |
| @@ -1830,7 +1830,7 @@ func validShares(c Column) bool { | |||
| 1830 | 1830 | } | |
| 1831 | 1831 | sum += v | |
| 1832 | 1832 | } | |
| 1833 | - | return sum == 100 | |
| 1833 | + | return sum == 10000 | |
| 1834 | 1834 | } | |
| 1835 | 1835 | ||
| 1836 | 1836 | // split cuts r in two halves with a gap: top/bottom when vertical, else left/right. | |
| @@ -26,9 +26,9 @@ type Column struct { | |||||
| 26 | // Slot is the declared column number (workspace.<name>.column.N) of a | 26 | // Slot is the declared column number (workspace.<name>.column.N) of a | ||
| 27 | // slot window; 0 for normal columns. | 27 | // slot window; 0 for normal columns. | ||
| 28 | Slot int | 28 | Slot int | ||
| 29 | - | // Shares are the row heights set by set-window-height, in percent, in | 29 | + | // Shares are the row heights set by set-window-height, in basis points, in |
| 30 | // Windows order. They apply only while there is one per window and | 30 | // Windows order. They apply only while there is one per window and | ||
| 31 | - | // they sum to 100; otherwise the rows share the height equally. | 31 | + | // they sum to 10000; otherwise the rows share the height equally. |
| 32 | Shares []int | 32 | Shares []int | ||
| 33 | // BandStart marks the first column of a cascade band. It belongs to the | 33 | // BandStart marks the first column of a cascade band. It belongs to the | ||
| 34 | // position, not the column: swaps leave it in place. See cascade.go. | 34 | // position, not the column: swaps leave it in place. See cascade.go. | ||
| @@ -916,33 +916,33 @@ func (w *Workspace) MoveWindow(dir int) { | |||||
| 916 | w.scroll() | 916 | w.scroll() | ||
| 917 | } | 917 | } | ||
| 918 | 918 | ||||
| 919 | - | // minShare is the smallest row height set-window-height leaves, percent. | 919 | + | // minShare is the smallest row height set-window-height leaves, in basis points. |
| 920 | - | const minShare = 10 | 920 | + | const minShare = 1000 |
| 921 | 921 | ||||
| 922 | // ResizeRow changes the focused window's height share by pct percent; the | 922 | // ResizeRow changes the focused window's height share by pct percent; the | ||
| 923 | // other rows of its column give or take it in proportion to their shares. | 923 | // other rows of its column give or take it in proportion to their shares. | ||
| 924 | - | // Every row keeps at least minShare percent. | 924 | + | // Every row keeps at least minShare basis points. |
| 925 | func (w *Workspace) ResizeRow(pct int) { | 925 | func (w *Workspace) ResizeRow(pct int) { | ||
| 926 | if w.onFloat() || len(w.Columns) == 0 || w.fullscreenHides() { | 926 | if w.onFloat() || len(w.Columns) == 0 || w.fullscreenHides() { | ||
| 927 | return | 927 | return | ||
| 928 | } | 928 | } | ||
| 929 | c := &w.Columns[w.Focus] | 929 | c := &w.Columns[w.Focus] | ||
| 930 | n := len(c.Windows) | 930 | n := len(c.Windows) | ||
| 931 | - | if n < 2 || n*minShare > 100 { | 931 | + | if n < 2 || n*minShare > 10000 { |
| 932 | return | 932 | return | ||
| 933 | } | 933 | } | ||
| 934 | shares := c.Shares | 934 | shares := c.Shares | ||
| 935 | if !validShares(*c) { | 935 | if !validShares(*c) { | ||
| 936 | shares = make([]int, n) | 936 | shares = make([]int, n) | ||
| 937 | for i := range shares { | 937 | for i := range shares { | ||
| 938 | - | shares[i] = 100 / n | 938 | + | shares[i] = 10000 / n |
| 939 | } | 939 | } | ||
| 940 | - | shares[n-1] += 100 % n | 940 | + | shares[n-1] += 10000 % n |
| 941 | } else { | 941 | } else { | ||
| 942 | shares = slices.Clone(shares) | 942 | shares = slices.Clone(shares) | ||
| 943 | } | 943 | } | ||
| 944 | f := c.Focus | 944 | f := c.Focus | ||
| 945 | - | target := min(max(shares[f]+pct, minShare), 100-minShare*(n-1)) | 945 | + | target := min(max(shares[f]+pct*100, minShare), 10000-minShare*(n-1)) |
| 946 | delta := target - shares[f] | 946 | delta := target - shares[f] | ||
| 947 | if delta == 0 { | 947 | if delta == 0 { | ||
| 948 | return | 948 | return | ||
| @@ -1804,7 +1804,7 @@ func rowRectsInto(dst []Rect, r Rect, c Column, gap int) []Rect { | |||||
| 1804 | avail := max(r.H-(n-1)*gap, 0) | 1804 | avail := max(r.H-(n-1)*gap, 0) | ||
| 1805 | yy, bottom, used := r.Y, r.Y+r.H, 0 | 1805 | yy, bottom, used := r.Y, r.Y+r.H, 0 | ||
| 1806 | for i, share := range c.Shares { | 1806 | for i, share := range c.Shares { | ||
| 1807 | - | hh := avail * share / 100 | 1807 | + | hh := avail * share / 10000 |
| 1808 | if i == n-1 { | 1808 | if i == n-1 { | ||
| 1809 | hh = avail - used | 1809 | hh = avail - used | ||
| 1810 | } | 1810 | } | ||
| @@ -1818,7 +1818,7 @@ func rowRectsInto(dst []Rect, r Rect, c Column, gap int) []Rect { | |||||
| 1818 | } | 1818 | } | ||
| 1819 | 1819 | ||||
| 1820 | // validShares reports whether c.Shares has one share per window, each at | 1820 | // validShares reports whether c.Shares has one share per window, each at | ||
| 1821 | - | // least 1, summing to 100. | 1821 | + | // least 1, summing to 10000. |
| 1822 | func validShares(c Column) bool { | 1822 | func validShares(c Column) bool { | ||
| 1823 | if len(c.Shares) != len(c.Windows) || len(c.Shares) < 2 { | 1823 | if len(c.Shares) != len(c.Windows) || len(c.Shares) < 2 { | ||
| 1824 | return false | 1824 | return false | ||
| @@ -1830,7 +1830,7 @@ func validShares(c Column) bool { | |||||
| 1830 | } | 1830 | } | ||
| 1831 | sum += v | 1831 | sum += v | ||
| 1832 | } | 1832 | } | ||
| 1833 | - | return sum == 100 | 1833 | + | return sum == 10000 |
| 1834 | } | 1834 | } | ||
| 1835 | 1835 | ||||
| 1836 | // split cuts r in two halves with a gap: top/bottom when vertical, else left/right. | 1836 | // split cuts r in two halves with a gap: top/bottom when vertical, else left/right. | ||
M internal/core/layout_buffers_test.go +2 -2
| @@ -39,7 +39,7 @@ func layoutVariants(t *testing.T) map[string]*Monitor { | |||
| 39 | 39 | m = base(OverflowScroll, 4) | |
| 40 | 40 | w := m.Current() | |
| 41 | 41 | w.Columns[0].Windows = []WindowID{1, 5, 6} | |
| 42 | - | w.Columns[0].Shares = []int{50, 30, 20} | |
| 42 | + | w.Columns[0].Shares = []int{5000, 3000, 2000} | |
| 43 | 43 | m.AddWindow(5) | |
| 44 | 44 | v["shares"] = m | |
| 45 | 45 | ||
| @@ -204,7 +204,7 @@ func TestRectHelpersKeepAppendSemantics(t *testing.T) { | |||
| 204 | 204 | if !slices.Equal(got[:2], pre) || !slices.Equal(got[2:], stackRects(r, 3, 5)) { | |
| 205 | 205 | t.Fatalf("stackRectsInto: %+v", got) | |
| 206 | 206 | } | |
| 207 | - | c := Column{Windows: []WindowID{1, 2, 3}, Shares: []int{50, 30, 20}} | |
| 207 | + | c := Column{Windows: []WindowID{1, 2, 3}, Shares: []int{5000, 3000, 2000}} | |
| 208 | 208 | got = rowRectsInto(slices.Clone(pre), r, c, 5) | |
| 209 | 209 | if !slices.Equal(got[:2], pre) || !slices.Equal(got[2:], rowRects(r, c, 5)) { | |
| 210 | 210 | t.Fatalf("rowRectsInto: %+v", got) | |
| @@ -39,7 +39,7 @@ func layoutVariants(t *testing.T) map[string]*Monitor { | |||||
| 39 | m = base(OverflowScroll, 4) | 39 | m = base(OverflowScroll, 4) | ||
| 40 | w := m.Current() | 40 | w := m.Current() | ||
| 41 | w.Columns[0].Windows = []WindowID{1, 5, 6} | 41 | w.Columns[0].Windows = []WindowID{1, 5, 6} | ||
| 42 | - | w.Columns[0].Shares = []int{50, 30, 20} | 42 | + | w.Columns[0].Shares = []int{5000, 3000, 2000} |
| 43 | m.AddWindow(5) | 43 | m.AddWindow(5) | ||
| 44 | v["shares"] = m | 44 | v["shares"] = m | ||
| 45 | 45 | ||||
| @@ -204,7 +204,7 @@ func TestRectHelpersKeepAppendSemantics(t *testing.T) { | |||||
| 204 | if !slices.Equal(got[:2], pre) || !slices.Equal(got[2:], stackRects(r, 3, 5)) { | 204 | if !slices.Equal(got[:2], pre) || !slices.Equal(got[2:], stackRects(r, 3, 5)) { | ||
| 205 | t.Fatalf("stackRectsInto: %+v", got) | 205 | t.Fatalf("stackRectsInto: %+v", got) | ||
| 206 | } | 206 | } | ||
| 207 | - | c := Column{Windows: []WindowID{1, 2, 3}, Shares: []int{50, 30, 20}} | 207 | + | c := Column{Windows: []WindowID{1, 2, 3}, Shares: []int{5000, 3000, 2000}} |
| 208 | got = rowRectsInto(slices.Clone(pre), r, c, 5) | 208 | got = rowRectsInto(slices.Clone(pre), r, c, 5) | ||
| 209 | if !slices.Equal(got[:2], pre) || !slices.Equal(got[2:], rowRects(r, c, 5)) { | 209 | if !slices.Equal(got[:2], pre) || !slices.Equal(got[2:], rowRects(r, c, 5)) { | ||
| 210 | t.Fatalf("rowRectsInto: %+v", got) | 210 | t.Fatalf("rowRectsInto: %+v", got) | ||
M internal/core/row_shares_test.go +17 -17
| @@ -29,15 +29,15 @@ func TestRowRectsEqualWithoutShares(t *testing.T) { | |||
| 29 | 29 | if !slices.Equal(rowRects(r, c, 5), stackRects(r, 3, 5)) { | |
| 30 | 30 | t.Fatal(rowRects(r, c, 5)) | |
| 31 | 31 | } | |
| 32 | - | c.Shares = []int{50, 50} // wrong length: ignored | |
| 32 | + | c.Shares = []int{5000, 5000} // wrong length: ignored | |
| 33 | 33 | if !slices.Equal(rowRects(r, c, 5), stackRects(r, 3, 5)) { | |
| 34 | 34 | t.Fatal(rowRects(r, c, 5)) | |
| 35 | 35 | } | |
| 36 | - | c.Shares = []int{50, 30, 30} // wrong sum: ignored | |
| 36 | + | c.Shares = []int{5000, 3000, 3000} // wrong sum: ignored | |
| 37 | 37 | if !slices.Equal(rowRects(r, c, 5), stackRects(r, 3, 5)) { | |
| 38 | 38 | t.Fatal(rowRects(r, c, 5)) | |
| 39 | 39 | } | |
| 40 | - | c.Shares = []int{50, 30, 20} | |
| 40 | + | c.Shares = []int{5000, 3000, 2000} | |
| 41 | 41 | rows := rowRects(r, c, 5) | |
| 42 | 42 | if rows[0].H != 46 || rows[1].H != 27 || rows[2].H != 93-46-27 || rows[2].Y+rows[2].H != 103 { | |
| 43 | 43 | t.Fatal(rows) | |
| @@ -51,7 +51,7 @@ func TestResizeRow(t *testing.T) { | |||
| 51 | 51 | w.SetOutput(1000, 800) | |
| 52 | 52 | w.Columns = []Column{{Windows: []WindowID{1, 2}}} | |
| 53 | 53 | w.Apply("set-window-height +10%") | |
| 54 | - | if !slices.Equal(w.Columns[0].Shares, []int{60, 40}) { | |
| 54 | + | if !slices.Equal(w.Columns[0].Shares, []int{6000, 4000}) { | |
| 55 | 55 | t.Fatal(o, w.Columns[0].Shares) | |
| 56 | 56 | } | |
| 57 | 57 | h := heights(w) | |
| @@ -61,13 +61,13 @@ func TestResizeRow(t *testing.T) { | |||
| 61 | 61 | for range 10 { | |
| 62 | 62 | w.Apply("set-window-height +10%") | |
| 63 | 63 | } | |
| 64 | - | if !slices.Equal(w.Columns[0].Shares, []int{90, 10}) { | |
| 64 | + | if !slices.Equal(w.Columns[0].Shares, []int{9000, 1000}) { | |
| 65 | 65 | t.Fatal(o, w.Columns[0].Shares) | |
| 66 | 66 | } | |
| 67 | 67 | for range 10 { | |
| 68 | 68 | w.Apply("set-window-height -10%") | |
| 69 | 69 | } | |
| 70 | - | if !slices.Equal(w.Columns[0].Shares, []int{10, 90}) { | |
| 70 | + | if !slices.Equal(w.Columns[0].Shares, []int{1000, 9000}) { | |
| 71 | 71 | t.Fatal(o, w.Columns[0].Shares) | |
| 72 | 72 | } | |
| 73 | 73 | } | |
| @@ -79,24 +79,24 @@ func TestResizeRowThree(t *testing.T) { | |||
| 79 | 79 | w.Columns = []Column{{Windows: []WindowID{1, 2, 3}, Focus: 1}} | |
| 80 | 80 | w.Apply("set-window-height +10%") | |
| 81 | 81 | s := w.Columns[0].Shares | |
| 82 | - | if sum(s) != 100 || s[1] != 43 || s[0] < 10 || s[2] < 10 { | |
| 82 | + | if sum(s) != 10000 || s[1] != 4333 || s[0] < 1000 || s[2] < 1000 { | |
| 83 | 83 | t.Fatal(s) | |
| 84 | 84 | } | |
| 85 | 85 | for _, step := range []string{"+25%", "+25%", "-7%", "-100%", "+100%", "-3%"} { | |
| 86 | 86 | w.Apply(Action("set-window-height " + step)) | |
| 87 | 87 | s := w.Columns[0].Shares | |
| 88 | - | if sum(s) != 100 || slices.Min(s) < 10 { | |
| 88 | + | if sum(s) != 10000 || slices.Min(s) < 1000 { | |
| 89 | 89 | t.Fatal(step, s) | |
| 90 | 90 | } | |
| 91 | 91 | } | |
| 92 | - | if s := w.Columns[0].Shares; s[1] != 77 { | |
| 92 | + | if s := w.Columns[0].Shares; s[1] != 7700 { | |
| 93 | 93 | t.Fatal(s) | |
| 94 | 94 | } | |
| 95 | 95 | // Proportional: the others shrink by their room above the minimum. | |
| 96 | - | w.Columns[0].Shares = []int{50, 20, 30} | |
| 96 | + | w.Columns[0].Shares = []int{5000, 2000, 3000} | |
| 97 | 97 | w.Columns[0].Focus = 1 | |
| 98 | 98 | w.Apply("set-window-height +20%") | |
| 99 | - | if s := w.Columns[0].Shares; !slices.Equal(s, []int{37, 40, 23}) { | |
| 99 | + | if s := w.Columns[0].Shares; !slices.Equal(s, []int{3667, 4000, 2333}) { | |
| 100 | 100 | t.Fatal(s) | |
| 101 | 101 | } | |
| 102 | 102 | } | |
| @@ -140,25 +140,25 @@ func TestSharesResetAndTravel(t *testing.T) { | |||
| 140 | 140 | t.Fatal(w.Columns) | |
| 141 | 141 | } | |
| 142 | 142 | w.Apply("set-window-height +20%") | |
| 143 | - | if !slices.Equal(w.Columns[0].Shares, []int{30, 70}) { | |
| 143 | + | if !slices.Equal(w.Columns[0].Shares, []int{3000, 7000}) { | |
| 144 | 144 | t.Fatal(w.Columns[0].Shares) | |
| 145 | 145 | } | |
| 146 | 146 | // Moving the window inside the column swaps the shares with it. | |
| 147 | 147 | w.Apply(ActionMoveWindowUp) | |
| 148 | - | if !slices.Equal(w.Columns[0].Shares, []int{70, 30}) || w.Columns[0].Windows[0] != 2 { | |
| 148 | + | if !slices.Equal(w.Columns[0].Shares, []int{7000, 3000}) || w.Columns[0].Windows[0] != 2 { | |
| 149 | 149 | t.Fatal(w.Columns[0]) | |
| 150 | 150 | } | |
| 151 | 151 | // The column takes its shares to another workspace. | |
| 152 | 152 | m.MoveToWorkspace(1, true) | |
| 153 | 153 | m.FocusNumber(2) | |
| 154 | - | if c := m.Current().Columns[0]; !slices.Equal(c.Shares, []int{70, 30}) { | |
| 154 | + | if c := m.Current().Columns[0]; !slices.Equal(c.Shares, []int{7000, 3000}) { | |
| 155 | 155 | t.Fatal(c) | |
| 156 | 156 | } | |
| 157 | 157 | // MoveColumn keeps them. | |
| 158 | 158 | m.AddWindow(3) | |
| 159 | 159 | m.Current().FocusColumn(-1) | |
| 160 | 160 | m.Current().MoveColumn(1) | |
| 161 | - | if c := m.Current().Columns[1]; !slices.Equal(c.Shares, []int{70, 30}) { | |
| 161 | + | if c := m.Current().Columns[1]; !slices.Equal(c.Shares, []int{7000, 3000}) { | |
| 162 | 162 | t.Fatal(m.Current().Columns) | |
| 163 | 163 | } | |
| 164 | 164 | // A window leaving resets the column to equal rows. | |
| @@ -171,7 +171,7 @@ func TestSharesResetAndTravel(t *testing.T) { | |||
| 171 | 171 | } | |
| 172 | 172 | } | |
| 173 | 173 | // A window joining invalidates them: equal rows. | |
| 174 | - | w.Columns = []Column{{Windows: []WindowID{1, 3}, Shares: []int{80, 20}}} | |
| 174 | + | w.Columns = []Column{{Windows: []WindowID{1, 3}, Shares: []int{8000, 2000}}} | |
| 175 | 175 | w.Columns[0].Windows = append(w.Columns[0].Windows, 4) | |
| 176 | 176 | h := heights(w) | |
| 177 | 177 | if h[1] != h[3] { | |
| @@ -182,7 +182,7 @@ func TestSharesResetAndTravel(t *testing.T) { | |||
| 182 | 182 | func TestOverviewPreviewUsesShares(t *testing.T) { | |
| 183 | 183 | w := workspace() | |
| 184 | 184 | w.SetOutput(1000, 800) | |
| 185 | - | w.Columns = []Column{{Windows: []WindowID{1, 2}, Shares: []int{70, 30}}} | |
| 185 | + | w.Columns = []Column{{Windows: []WindowID{1, 2}, Shares: []int{7000, 3000}}} | |
| 186 | 186 | tiles, _, _ := w.previewTiles() | |
| 187 | 187 | h := map[WindowID]int{} | |
| 188 | 188 | for _, p := range tiles { | |
| @@ -29,15 +29,15 @@ func TestRowRectsEqualWithoutShares(t *testing.T) { | |||||
| 29 | if !slices.Equal(rowRects(r, c, 5), stackRects(r, 3, 5)) { | 29 | if !slices.Equal(rowRects(r, c, 5), stackRects(r, 3, 5)) { | ||
| 30 | t.Fatal(rowRects(r, c, 5)) | 30 | t.Fatal(rowRects(r, c, 5)) | ||
| 31 | } | 31 | } | ||
| 32 | - | c.Shares = []int{50, 50} // wrong length: ignored | 32 | + | c.Shares = []int{5000, 5000} // wrong length: ignored |
| 33 | if !slices.Equal(rowRects(r, c, 5), stackRects(r, 3, 5)) { | 33 | if !slices.Equal(rowRects(r, c, 5), stackRects(r, 3, 5)) { | ||
| 34 | t.Fatal(rowRects(r, c, 5)) | 34 | t.Fatal(rowRects(r, c, 5)) | ||
| 35 | } | 35 | } | ||
| 36 | - | c.Shares = []int{50, 30, 30} // wrong sum: ignored | 36 | + | c.Shares = []int{5000, 3000, 3000} // wrong sum: ignored |
| 37 | if !slices.Equal(rowRects(r, c, 5), stackRects(r, 3, 5)) { | 37 | if !slices.Equal(rowRects(r, c, 5), stackRects(r, 3, 5)) { | ||
| 38 | t.Fatal(rowRects(r, c, 5)) | 38 | t.Fatal(rowRects(r, c, 5)) | ||
| 39 | } | 39 | } | ||
| 40 | - | c.Shares = []int{50, 30, 20} | 40 | + | c.Shares = []int{5000, 3000, 2000} |
| 41 | rows := rowRects(r, c, 5) | 41 | rows := rowRects(r, c, 5) | ||
| 42 | if rows[0].H != 46 || rows[1].H != 27 || rows[2].H != 93-46-27 || rows[2].Y+rows[2].H != 103 { | 42 | if rows[0].H != 46 || rows[1].H != 27 || rows[2].H != 93-46-27 || rows[2].Y+rows[2].H != 103 { | ||
| 43 | t.Fatal(rows) | 43 | t.Fatal(rows) | ||
| @@ -51,7 +51,7 @@ func TestResizeRow(t *testing.T) { | |||||
| 51 | w.SetOutput(1000, 800) | 51 | w.SetOutput(1000, 800) | ||
| 52 | w.Columns = []Column{{Windows: []WindowID{1, 2}}} | 52 | w.Columns = []Column{{Windows: []WindowID{1, 2}}} | ||
| 53 | w.Apply("set-window-height +10%") | 53 | w.Apply("set-window-height +10%") | ||
| 54 | - | if !slices.Equal(w.Columns[0].Shares, []int{60, 40}) { | 54 | + | if !slices.Equal(w.Columns[0].Shares, []int{6000, 4000}) { |
| 55 | t.Fatal(o, w.Columns[0].Shares) | 55 | t.Fatal(o, w.Columns[0].Shares) | ||
| 56 | } | 56 | } | ||
| 57 | h := heights(w) | 57 | h := heights(w) | ||
| @@ -61,13 +61,13 @@ func TestResizeRow(t *testing.T) { | |||||
| 61 | for range 10 { | 61 | for range 10 { | ||
| 62 | w.Apply("set-window-height +10%") | 62 | w.Apply("set-window-height +10%") | ||
| 63 | } | 63 | } | ||
| 64 | - | if !slices.Equal(w.Columns[0].Shares, []int{90, 10}) { | 64 | + | if !slices.Equal(w.Columns[0].Shares, []int{9000, 1000}) { |
| 65 | t.Fatal(o, w.Columns[0].Shares) | 65 | t.Fatal(o, w.Columns[0].Shares) | ||
| 66 | } | 66 | } | ||
| 67 | for range 10 { | 67 | for range 10 { | ||
| 68 | w.Apply("set-window-height -10%") | 68 | w.Apply("set-window-height -10%") | ||
| 69 | } | 69 | } | ||
| 70 | - | if !slices.Equal(w.Columns[0].Shares, []int{10, 90}) { | 70 | + | if !slices.Equal(w.Columns[0].Shares, []int{1000, 9000}) { |
| 71 | t.Fatal(o, w.Columns[0].Shares) | 71 | t.Fatal(o, w.Columns[0].Shares) | ||
| 72 | } | 72 | } | ||
| 73 | } | 73 | } | ||
| @@ -79,24 +79,24 @@ func TestResizeRowThree(t *testing.T) { | |||||
| 79 | w.Columns = []Column{{Windows: []WindowID{1, 2, 3}, Focus: 1}} | 79 | w.Columns = []Column{{Windows: []WindowID{1, 2, 3}, Focus: 1}} | ||
| 80 | w.Apply("set-window-height +10%") | 80 | w.Apply("set-window-height +10%") | ||
| 81 | s := w.Columns[0].Shares | 81 | s := w.Columns[0].Shares | ||
| 82 | - | if sum(s) != 100 || s[1] != 43 || s[0] < 10 || s[2] < 10 { | 82 | + | if sum(s) != 10000 || s[1] != 4333 || s[0] < 1000 || s[2] < 1000 { |
| 83 | t.Fatal(s) | 83 | t.Fatal(s) | ||
| 84 | } | 84 | } | ||
| 85 | for _, step := range []string{"+25%", "+25%", "-7%", "-100%", "+100%", "-3%"} { | 85 | for _, step := range []string{"+25%", "+25%", "-7%", "-100%", "+100%", "-3%"} { | ||
| 86 | w.Apply(Action("set-window-height " + step)) | 86 | w.Apply(Action("set-window-height " + step)) | ||
| 87 | s := w.Columns[0].Shares | 87 | s := w.Columns[0].Shares | ||
| 88 | - | if sum(s) != 100 || slices.Min(s) < 10 { | 88 | + | if sum(s) != 10000 || slices.Min(s) < 1000 { |
| 89 | t.Fatal(step, s) | 89 | t.Fatal(step, s) | ||
| 90 | } | 90 | } | ||
| 91 | } | 91 | } | ||
| 92 | - | if s := w.Columns[0].Shares; s[1] != 77 { | 92 | + | if s := w.Columns[0].Shares; s[1] != 7700 { |
| 93 | t.Fatal(s) | 93 | t.Fatal(s) | ||
| 94 | } | 94 | } | ||
| 95 | // Proportional: the others shrink by their room above the minimum. | 95 | // Proportional: the others shrink by their room above the minimum. | ||
| 96 | - | w.Columns[0].Shares = []int{50, 20, 30} | 96 | + | w.Columns[0].Shares = []int{5000, 2000, 3000} |
| 97 | w.Columns[0].Focus = 1 | 97 | w.Columns[0].Focus = 1 | ||
| 98 | w.Apply("set-window-height +20%") | 98 | w.Apply("set-window-height +20%") | ||
| 99 | - | if s := w.Columns[0].Shares; !slices.Equal(s, []int{37, 40, 23}) { | 99 | + | if s := w.Columns[0].Shares; !slices.Equal(s, []int{3667, 4000, 2333}) { |
| 100 | t.Fatal(s) | 100 | t.Fatal(s) | ||
| 101 | } | 101 | } | ||
| 102 | } | 102 | } | ||
| @@ -140,25 +140,25 @@ func TestSharesResetAndTravel(t *testing.T) { | |||||
| 140 | t.Fatal(w.Columns) | 140 | t.Fatal(w.Columns) | ||
| 141 | } | 141 | } | ||
| 142 | w.Apply("set-window-height +20%") | 142 | w.Apply("set-window-height +20%") | ||
| 143 | - | if !slices.Equal(w.Columns[0].Shares, []int{30, 70}) { | 143 | + | if !slices.Equal(w.Columns[0].Shares, []int{3000, 7000}) { |
| 144 | t.Fatal(w.Columns[0].Shares) | 144 | t.Fatal(w.Columns[0].Shares) | ||
| 145 | } | 145 | } | ||
| 146 | // Moving the window inside the column swaps the shares with it. | 146 | // Moving the window inside the column swaps the shares with it. | ||
| 147 | w.Apply(ActionMoveWindowUp) | 147 | w.Apply(ActionMoveWindowUp) | ||
| 148 | - | if !slices.Equal(w.Columns[0].Shares, []int{70, 30}) || w.Columns[0].Windows[0] != 2 { | 148 | + | if !slices.Equal(w.Columns[0].Shares, []int{7000, 3000}) || w.Columns[0].Windows[0] != 2 { |
| 149 | t.Fatal(w.Columns[0]) | 149 | t.Fatal(w.Columns[0]) | ||
| 150 | } | 150 | } | ||
| 151 | // The column takes its shares to another workspace. | 151 | // The column takes its shares to another workspace. | ||
| 152 | m.MoveToWorkspace(1, true) | 152 | m.MoveToWorkspace(1, true) | ||
| 153 | m.FocusNumber(2) | 153 | m.FocusNumber(2) | ||
| 154 | - | if c := m.Current().Columns[0]; !slices.Equal(c.Shares, []int{70, 30}) { | 154 | + | if c := m.Current().Columns[0]; !slices.Equal(c.Shares, []int{7000, 3000}) { |
| 155 | t.Fatal(c) | 155 | t.Fatal(c) | ||
| 156 | } | 156 | } | ||
| 157 | // MoveColumn keeps them. | 157 | // MoveColumn keeps them. | ||
| 158 | m.AddWindow(3) | 158 | m.AddWindow(3) | ||
| 159 | m.Current().FocusColumn(-1) | 159 | m.Current().FocusColumn(-1) | ||
| 160 | m.Current().MoveColumn(1) | 160 | m.Current().MoveColumn(1) | ||
| 161 | - | if c := m.Current().Columns[1]; !slices.Equal(c.Shares, []int{70, 30}) { | 161 | + | if c := m.Current().Columns[1]; !slices.Equal(c.Shares, []int{7000, 3000}) { |
| 162 | t.Fatal(m.Current().Columns) | 162 | t.Fatal(m.Current().Columns) | ||
| 163 | } | 163 | } | ||
| 164 | // A window leaving resets the column to equal rows. | 164 | // A window leaving resets the column to equal rows. | ||
| @@ -171,7 +171,7 @@ func TestSharesResetAndTravel(t *testing.T) { | |||||
| 171 | } | 171 | } | ||
| 172 | } | 172 | } | ||
| 173 | // A window joining invalidates them: equal rows. | 173 | // A window joining invalidates them: equal rows. | ||
| 174 | - | w.Columns = []Column{{Windows: []WindowID{1, 3}, Shares: []int{80, 20}}} | 174 | + | w.Columns = []Column{{Windows: []WindowID{1, 3}, Shares: []int{8000, 2000}}} |
| 175 | w.Columns[0].Windows = append(w.Columns[0].Windows, 4) | 175 | w.Columns[0].Windows = append(w.Columns[0].Windows, 4) | ||
| 176 | h := heights(w) | 176 | h := heights(w) | ||
| 177 | if h[1] != h[3] { | 177 | if h[1] != h[3] { | ||
| @@ -182,7 +182,7 @@ func TestSharesResetAndTravel(t *testing.T) { | |||||
| 182 | func TestOverviewPreviewUsesShares(t *testing.T) { | 182 | func TestOverviewPreviewUsesShares(t *testing.T) { | ||
| 183 | w := workspace() | 183 | w := workspace() | ||
| 184 | w.SetOutput(1000, 800) | 184 | w.SetOutput(1000, 800) | ||
| 185 | - | w.Columns = []Column{{Windows: []WindowID{1, 2}, Shares: []int{70, 30}}} | 185 | + | w.Columns = []Column{{Windows: []WindowID{1, 2}, Shares: []int{7000, 3000}}} |
| 186 | tiles, _, _ := w.previewTiles() | 186 | tiles, _, _ := w.previewTiles() | ||
| 187 | h := map[WindowID]int{} | 187 | h := map[WindowID]int{} | ||
| 188 | for _, p := range tiles { | 188 | for _, p := range tiles { | ||