| @@ -1,297 +0,0 @@ |
| 1 | | - | package core |
| 2 | | - | |
| 3 | | - | import "testing" |
| 4 | | - | |
| 5 | | - | // Entering fullscreen gives a cascade column a band below its own; the |
| 6 | | - | // others stay. Leaving keeps it there. |
| 7 | | - | func TestCascadeFullscreenOwnBand(t *testing.T) { |
| 8 | | - | for _, tc := range []struct { |
| 9 | | - | name string |
| 10 | | - | do func(w *Workspace) |
| 11 | | - | }{ |
| 12 | | - | {"toggle", func(w *Workspace) { w.ToggleFullscreen() }}, |
| 13 | | - | {"client request", func(w *Workspace) { w.SetFullscreen(3, true) }}, |
| 14 | | - | } { |
| 15 | | - | t.Run(tc.name, func(t *testing.T) { |
| 16 | | - | c, w := cascadeMovesCore(t, 3, 3, false) |
| 17 | | - | wantBands(t, w, []WindowID{1, 2, 3}) |
| 18 | | - | tc.do(w) |
| 19 | | - | wantBands(t, w, []WindowID{1, 2}, []WindowID{3}) |
| 20 | | - | wantFocus(t, c, "M", 3) |
| 21 | | - | if w.fullscreen != 3 { |
| 22 | | - | t.Fatalf("fullscreen %d, want 3", w.fullscreen) |
| 23 | | - | } |
| 24 | | - | w.ToggleFullscreen() |
| 25 | | - | wantBands(t, w, []WindowID{1, 2}, []WindowID{3}) |
| 26 | | - | }) |
| 27 | | - | } |
| 28 | | - | } |
| 29 | | - | |
| 30 | | - | func TestCascadeFullscreenMiddleAndAlone(t *testing.T) { |
| 31 | | - | c, w := cascadeMovesCore(t, 3, 3, false) |
| 32 | | - | w.FocusID(2) |
| 33 | | - | w.ToggleFullscreen() |
| 34 | | - | wantBands(t, w, []WindowID{1, 3}, []WindowID{2}) |
| 35 | | - | wantFocus(t, c, "M", 2) |
| 36 | | - | |
| 37 | | - | _, w = cascadeMovesCore(t, 1, 3, false) |
| 38 | | - | w.ToggleFullscreen() |
| 39 | | - | wantBands(t, w, []WindowID{1}) |
| 40 | | - | } |
| 41 | | - | |
| 42 | | - | func TestCascadeFullscreenExpelsFromStack(t *testing.T) { |
| 43 | | - | c, w := cascadeMovesCore(t, 2, 3, false) |
| 44 | | - | w.FocusID(2) |
| 45 | | - | c.applyAction(ActionConsumeOrExpelLeft) // 2 stacks under 1 |
| 46 | | - | wantColumns(t, w, 1) |
| 47 | | - | w.ToggleFullscreen() |
| 48 | | - | wantBands(t, w, []WindowID{1}, []WindowID{2}) |
| 49 | | - | if len(w.Columns[0].Windows) != 1 || w.fullscreen != 2 { |
| 50 | | - | t.Fatalf("columns %v fullscreen %d", w.Columns, w.fullscreen) |
| 51 | | - | } |
| 52 | | - | wantFocus(t, c, "M", 2) |
| 53 | | - | } |
| 54 | | - | |
| 55 | | - | func TestScrollFullscreenKeepsColumns(t *testing.T) { |
| 56 | | - | _, w := cascadeMovesCore(t, 3, 3, false) |
| 57 | | - | w.Overflow = OverflowScroll |
| 58 | | - | w.forgetBands() |
| 59 | | - | w.ToggleFullscreen() |
| 60 | | - | if len(w.Columns) != 3 { |
| 61 | | - | t.Fatalf("columns %d", len(w.Columns)) |
| 62 | | - | } |
| 63 | | - | } |
| 64 | | - | |
| 65 | | - | func TestFullscreenColumnMovesToNeighborMonitor(t *testing.T) { |
| 66 | | - | for _, tc := range []struct { |
| 67 | | - | action Action |
| 68 | | - | screen string |
| 69 | | - | }{{ActionMoveColumnLeft, "L"}, {ActionMoveColumnRight, "R"}} { |
| 70 | | - | t.Run(tc.screen, func(t *testing.T) { |
| 71 | | - | c, w := cascadeMovesCore(t, 3, 3, true) |
| 72 | | - | w.ToggleFullscreen() |
| 73 | | - | c.applyAction(tc.action) |
| 74 | | - | wantColumns(t, w, 1, 2) |
| 75 | | - | dst := screenWorkspace(c, tc.screen) |
| 76 | | - | wantColumns(t, dst, 3) |
| 77 | | - | wantFocus(t, c, tc.screen, 3) |
| 78 | | - | if dst.fullscreen != 3 || w.fullscreen != 0 { |
| 79 | | - | t.Fatalf("fullscreen dst %d src %d", dst.fullscreen, w.fullscreen) |
| 80 | | - | } |
| 81 | | - | }) |
| 82 | | - | } |
| 83 | | - | } |
| 84 | | - | |
| 85 | | - | func TestFullscreenColumnNoNeighborStays(t *testing.T) { |
| 86 | | - | c, w := cascadeMovesCore(t, 3, 3, false) |
| 87 | | - | w.ToggleFullscreen() |
| 88 | | - | c.applyAction(ActionMoveColumnLeft) |
| 89 | | - | c.applyAction(ActionMoveColumnRight) |
| 90 | | - | wantBands(t, w, []WindowID{1, 2}, []WindowID{3}) |
| 91 | | - | if w.fullscreen != 3 { |
| 92 | | - | t.Fatalf("fullscreen %d", w.fullscreen) |
| 93 | | - | } |
| 94 | | - | } |
| 95 | | - | |
| 96 | | - | func TestFullscreenFloatMovesToNeighborMonitor(t *testing.T) { |
| 97 | | - | for _, tc := range []struct { |
| 98 | | - | action Action |
| 99 | | - | screen string |
| 100 | | - | }{{ActionMoveColumnLeft, "L"}, {ActionMoveColumnRight, "R"}} { |
| 101 | | - | t.Run(tc.screen, func(t *testing.T) { |
| 102 | | - | c, w := cascadeMovesCore(t, 2, 3, true) |
| 103 | | - | w.AddFloating(9, 5120, 2160) |
| 104 | | - | w.SetFullscreen(9, true) |
| 105 | | - | c.applyAction(tc.action) |
| 106 | | - | dst := screenWorkspace(c, tc.screen) |
| 107 | | - | if w.floatIndex(9) >= 0 || dst.floatIndex(9) < 0 || w.fullscreen != 0 || dst.fullscreen != 9 { |
| 108 | | - | t.Fatalf("float on src %v dst %v, fullscreen src %d dst %d", w.Floats, dst.Floats, w.fullscreen, dst.fullscreen) |
| 109 | | - | } |
| 110 | | - | wantFocus(t, c, tc.screen, 9) |
| 111 | | - | wantColumns(t, w, 1, 2) |
| 112 | | - | }) |
| 113 | | - | } |
| 114 | | - | } |
| 115 | | - | |
| 116 | | - | func TestFullscreenFloatNoNeighborStays(t *testing.T) { |
| 117 | | - | c, w := cascadeMovesCore(t, 2, 3, false) |
| 118 | | - | w.AddFloating(9, 800, 600) |
| 119 | | - | w.SetFullscreen(9, true) |
| 120 | | - | c.applyAction(ActionMoveColumnLeft) |
| 121 | | - | if w.floatIndex(9) < 0 || w.fullscreen != 9 { |
| 122 | | - | t.Fatalf("float moved: %v fullscreen %d", w.Floats, w.fullscreen) |
| 123 | | - | } |
| 124 | | - | } |
| 125 | | - | |
| 126 | | - | func TestCascadeFullscreenRepeatedRequestKeepsBands(t *testing.T) { |
| 127 | | - | _, w := cascadeMovesCore(t, 3, 3, false) |
| 128 | | - | w.SetFullscreen(3, true) |
| 129 | | - | w.SetFullscreen(3, true) |
| 130 | | - | w.SetFullscreen(3, true) |
| 131 | | - | wantBands(t, w, []WindowID{1, 2}, []WindowID{3}) |
| 132 | | - | } |
| 133 | | - | |
| 134 | | - | func TestCascadeFullscreenStackedFixups(t *testing.T) { |
| 135 | | - | for _, tc := range []struct { |
| 136 | | - | name string |
| 137 | | - | focus WindowID |
| 138 | | - | rest WindowID |
| 139 | | - | slotKept bool |
| 140 | | - | }{{"last row", 3, 2, true}, {"first row", 2, 3, false}} { |
| 141 | | - | t.Run(tc.name, func(t *testing.T) { |
| 142 | | - | c, w := cascadeMovesCore(t, 3, 3, false) |
| 143 | | - | w.FocusID(3) |
| 144 | | - | c.applyAction(ActionConsumeOrExpelLeft) // 3 stacks under 2 |
| 145 | | - | w.FocusID(tc.focus) |
| 146 | | - | w.Columns[1].Shares = []int{5000, 5000} |
| 147 | | - | w.Columns[1].Span = 3000 |
| 148 | | - | w.Columns[1].Slot = 4 |
| 149 | | - | w.SetFullscreen(tc.focus, true) |
| 150 | | - | wantBands(t, w, []WindowID{1, tc.rest}, []WindowID{tc.focus}) |
| 151 | | - | col := w.Columns[1] |
| 152 | | - | if len(col.Windows) != 1 || col.Windows[0] != tc.rest || col.Shares != nil || col.Focus != 0 || (col.Slot == 4) != tc.slotKept { |
| 153 | | - | t.Fatalf("remaining column %+v", col) |
| 154 | | - | } |
| 155 | | - | if got, _ := w.Focused(); got != tc.focus { |
| 156 | | - | t.Fatalf("focus %d, want %d", got, tc.focus) |
| 157 | | - | } |
| 158 | | - | if w.Columns[2].Span != 0 || w.Columns[2].Slot != 0 { |
| 159 | | - | t.Fatalf("expelled column %+v", w.Columns[2]) |
| 160 | | - | } |
| 161 | | - | }) |
| 162 | | - | } |
| 163 | | - | } |
| 164 | | - | |
| 165 | | - | func TestCascadeFullscreenKeepsSlotOfIntactColumn(t *testing.T) { |
| 166 | | - | _, w := cascadeMovesCore(t, 3, 3, false) |
| 167 | | - | w.Columns[2].Slot = 4 |
| 168 | | - | w.ToggleFullscreen() |
| 169 | | - | if i := w.columnOf(3); w.Columns[i].Slot != 4 { |
| 170 | | - | t.Fatalf("slot %d, want 4", w.Columns[i].Slot) |
| 171 | | - | } |
| 172 | | - | } |
| 173 | | - | |
| 174 | | - | func TestCascadeFullscreenAfterMaximizeRestores(t *testing.T) { |
| 175 | | - | _, w := cascadeMovesCore(t, 3, 3, false) |
| 176 | | - | w.FocusID(1) |
| 177 | | - | w.ToggleFullWidth() |
| 178 | | - | w.FocusID(3) |
| 179 | | - | w.ToggleFullscreen() |
| 180 | | - | w.ToggleFullscreen() |
| 181 | | - | w.FocusID(1) |
| 182 | | - | w.ToggleFullWidth() |
| 183 | | - | wantBands(t, w, []WindowID{1, 2, 3}) |
| 184 | | - | } |
| 185 | | - | |
| 186 | | - | func TestFullscreenMoveEdges(t *testing.T) { |
| 187 | | - | t.Run("destination fullscreen elsewhere", func(t *testing.T) { |
| 188 | | - | c, w := cascadeMovesCore(t, 2, 3, true) |
| 189 | | - | dst := screenWorkspace(c, "R") |
| 190 | | - | dst.AddWindow(20) |
| 191 | | - | dst.SetFullscreen(20, true) |
| 192 | | - | w.ToggleFullscreen() |
| 193 | | - | c.applyAction(ActionMoveColumnRight) |
| 194 | | - | if dst.fullscreen != 2 { |
| 195 | | - | t.Fatalf("fullscreen %d, want 2", dst.fullscreen) |
| 196 | | - | } |
| 197 | | - | wantFocus(t, c, "R", 2) |
| 198 | | - | }) |
| 199 | | - | t.Run("scroll layout", func(t *testing.T) { |
| 200 | | - | c, w := cascadeMovesCore(t, 2, 3, true) |
| 201 | | - | w.Overflow = OverflowScroll |
| 202 | | - | w.ToggleFullscreen() |
| 203 | | - | c.applyAction(ActionMoveColumnLeft) |
| 204 | | - | dst := screenWorkspace(c, "L") |
| 205 | | - | wantColumns(t, dst, 2) |
| 206 | | - | if dst.fullscreen != 2 || w.fullscreen != 0 { |
| 207 | | - | t.Fatalf("fullscreen dst %d src %d", dst.fullscreen, w.fullscreen) |
| 208 | | - | } |
| 209 | | - | }) |
| 210 | | - | t.Run("source floats promoted", func(t *testing.T) { |
| 211 | | - | c, w := cascadeMovesCore(t, 2, 3, true) |
| 212 | | - | w.AddFloating(9, 100, 100) |
| 213 | | - | w.FocusID(2) |
| 214 | | - | w.ToggleFullscreen() |
| 215 | | - | // A fullscreen keeps a float demoted without it covering the output. |
| 216 | | - | w.Floats[0].below = true |
| 217 | | - | if len(w.Floats) != 1 || !w.Floats[0].below || w.fullscreen != 2 { |
| 218 | | - | t.Fatalf("setup: float not demoted: %+v", w.Floats) |
| 219 | | - | } |
| 220 | | - | c.applyAction(ActionMoveColumnRight) |
| 221 | | - | if len(w.Floats) != 1 || w.Floats[0].below { |
| 222 | | - | t.Fatalf("float still demoted: %+v", w.Floats) |
| 223 | | - | } |
| 224 | | - | }) |
| 225 | | - | } |
| 226 | | - | |
| 227 | | - | func TestCascadeFullscreenRestoresAcrossBand(t *testing.T) { |
| 228 | | - | _, w := cascadeMovesCore(t, 3, 3, false) |
| 229 | | - | w.FocusID(1) |
| 230 | | - | w.ToggleFullWidth() // X=1 alone; 2 and 3 pushed below |
| 231 | | - | wantBands(t, w, []WindowID{1}, []WindowID{2, 3}) |
| 232 | | - | w.FocusID(2) |
| 233 | | - | w.ToggleFullscreen() |
| 234 | | - | wantBands(t, w, []WindowID{1}, []WindowID{3}, []WindowID{2}) |
| 235 | | - | w.ToggleFullscreen() |
| 236 | | - | w.FocusID(1) |
| 237 | | - | w.ToggleFullWidth() |
| 238 | | - | wantBands(t, w, []WindowID{1, 2, 3}) |
| 239 | | - | } |
| 240 | | - | |
| 241 | | - | func TestFullscreenMoveDestinations(t *testing.T) { |
| 242 | | - | t.Run("arrival focused despite left mark", func(t *testing.T) { |
| 243 | | - | // The destination has a pending "left" mark on the window, which |
| 244 | | - | // mayCover would refuse unless it is focused; the arrival is |
| 245 | | - | // focused, so it ends fullscreen. |
| 246 | | - | c, w := cascadeMovesCore(t, 2, 3, true) |
| 247 | | - | dst := screenWorkspace(c, "R") |
| 248 | | - | dst.left = 2 |
| 249 | | - | w.ToggleFullscreen() |
| 250 | | - | c.applyAction(ActionMoveColumnRight) |
| 251 | | - | wantFocus(t, c, "R", 2) |
| 252 | | - | if dst.fullscreen != 2 { |
| 253 | | - | t.Fatalf("fullscreen %d, want 2", dst.fullscreen) |
| 254 | | - | } |
| 255 | | - | }) |
| 256 | | - | t.Run("fullscreen window expelled from a stack then moved", func(t *testing.T) { |
| 257 | | - | c, w := cascadeMovesCore(t, 3, 3, true) |
| 258 | | - | w.FocusID(3) |
| 259 | | - | c.applyAction(ActionConsumeOrExpelLeft) // 3 under 2 |
| 260 | | - | w.ToggleFullscreen() // 3 expelled to its own band |
| 261 | | - | c.applyAction(ActionMoveColumnLeft) |
| 262 | | - | wantColumns(t, w, 1, 2) |
| 263 | | - | dst := screenWorkspace(c, "L") |
| 264 | | - | wantColumns(t, dst, 3) |
| 265 | | - | if dst.fullscreen != 3 || len(w.Columns[1].Windows) != 1 { |
| 266 | | - | t.Fatalf("fullscreen %d, source column %v", dst.fullscreen, w.Columns[1].Windows) |
| 267 | | - | } |
| 268 | | - | }) |
| 269 | | - | t.Run("destination with columns gets its own band", func(t *testing.T) { |
| 270 | | - | c, w := cascadeMovesCore(t, 1, 3, true) |
| 271 | | - | dst := screenWorkspace(c, "R") |
| 272 | | - | dst.Overflow = OverflowCascade |
| 273 | | - | dst.SetMaxColumns(3) |
| 274 | | - | dst.AddWindow(20) |
| 275 | | - | dst.AddWindow(21) |
| 276 | | - | w.ToggleFullscreen() |
| 277 | | - | c.applyAction(ActionMoveColumnRight) |
| 278 | | - | wantBands(t, dst, []WindowID{20, 21}, []WindowID{1}) |
| 279 | | - | if dst.fullscreen != 1 { |
| 280 | | - | t.Fatalf("fullscreen %d", dst.fullscreen) |
| 281 | | - | } |
| 282 | | - | }) |
| 283 | | - | } |
| 284 | | - | |
| 285 | | - | // A band the user shaped is not looked past: P, pushed down from F, then |
| 286 | | - | // moved past Y on purpose, stays there. |
| 287 | | - | func TestRestoreBandDoesNotLookPastUserBand(t *testing.T) { |
| 288 | | - | c, w := cascadeMovesCore(t, 3, 3, false) |
| 289 | | - | w.FocusID(1) |
| 290 | | - | w.ToggleFullWidth() // {1} {2 3} |
| 291 | | - | w.FocusID(2) |
| 292 | | - | c.applyAction(ActionMoveWindowDown) // {1} {3} {2} |
| 293 | | - | wantBands(t, w, []WindowID{1}, []WindowID{3}, []WindowID{2}) |
| 294 | | - | w.FocusID(1) |
| 295 | | - | w.ToggleFullWidth() |
| 296 | | - | wantBands(t, w, []WindowID{1, 3}, []WindowID{2}) |
| 297 | | - | } |