layout/tests: Add column resize animation tests
Browse files at this commitea438b21e933d45672e80ca04db42eb54050fccaParent: 42bd1072 changed files +911 -0
- src/layout/tests.rs +2 -0
- src/layout/tests/animations.rs +909 -0
src/layout/tests.rsmodified+2 -0
| @@ -11,6 +11,8 @@ use smithay::utils::Rectangle; | |||
| 11 | 11 | ||
| 12 | use super::*; | 12 | use super::*; |
| 13 | 13 | ||
| 14 | +mod animations; | ||
| 15 | + | ||
| 14 | impl<W: LayoutElement> Default for Layout<W> { | 16 | impl<W: LayoutElement> Default for Layout<W> { |
| 15 | fn default() -> Self { | 17 | fn default() -> Self { |
| 16 | Self::with_options(Clock::with_time(Duration::ZERO), Default::default()) | 18 | Self::with_options(Clock::with_time(Duration::ZERO), Default::default()) |
src/layout/tests/animations.rsadded+909 -0
| @@ -0,0 +1,909 @@ | |||
| 1 | +use std::fmt::Write as _; | ||
| 2 | + | ||
| 3 | +use insta::assert_snapshot; | ||
| 4 | +use niri_config::{AnimationCurve, AnimationKind, EasingParams}; | ||
| 5 | + | ||
| 6 | +use super::*; | ||
| 7 | + | ||
| 8 | +fn format_tiles(layout: &Layout<TestWindow>) -> String { | ||
| 9 | + let mut buf = String::new(); | ||
| 10 | + let ws = layout.active_workspace().unwrap(); | ||
| 11 | + let mut tiles: Vec<_> = ws.tiles_with_render_positions().collect(); | ||
| 12 | + | ||
| 13 | + // We sort by id since that gives us a consistent order (from first opened to last), but we | ||
| 14 | + // don't print the id since it's nondeterministic (the id is a global counter across all | ||
| 15 | + // running tests in the same binary). | ||
| 16 | + tiles.sort_by_key(|(tile, _, _)| tile.window().id()); | ||
| 17 | + for (tile, pos, _visible) in tiles { | ||
| 18 | + let Size { w, h, .. } = tile.animated_tile_size(); | ||
| 19 | + let Point { x, y, .. } = pos; | ||
| 20 | + writeln!(&mut buf, "{w:>3.0} × {h:>3.0} at x:{x:>3.0} y:{y:>3.0}").unwrap(); | ||
| 21 | + } | ||
| 22 | + buf | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +fn make_options() -> Options { | ||
| 26 | + const LINEAR: AnimationKind = AnimationKind::Easing(EasingParams { | ||
| 27 | + duration_ms: 1000, | ||
| 28 | + curve: AnimationCurve::Linear, | ||
| 29 | + }); | ||
| 30 | + | ||
| 31 | + let mut options = Options { | ||
| 32 | + gaps: 0.0, | ||
| 33 | + ..Options::default() | ||
| 34 | + }; | ||
| 35 | + options.animations.window_resize.anim.kind = LINEAR; | ||
| 36 | + options.animations.window_movement.0.kind = LINEAR; | ||
| 37 | + | ||
| 38 | + options | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +fn set_up_two_in_column() -> Layout<TestWindow> { | ||
| 42 | + let ops = [ | ||
| 43 | + Op::AddOutput(1), | ||
| 44 | + Op::AddWindow { | ||
| 45 | + params: TestWindowParams::new(1), | ||
| 46 | + }, | ||
| 47 | + Op::AddWindow { | ||
| 48 | + params: TestWindowParams::new(2), | ||
| 49 | + }, | ||
| 50 | + Op::FocusColumnLeft, | ||
| 51 | + Op::ConsumeWindowIntoColumn, | ||
| 52 | + Op::SetForcedSize { | ||
| 53 | + id: 1, | ||
| 54 | + size: Some(Size::new(100, 100)), | ||
| 55 | + }, | ||
| 56 | + Op::SetForcedSize { | ||
| 57 | + id: 2, | ||
| 58 | + size: Some(Size::new(200, 200)), | ||
| 59 | + }, | ||
| 60 | + Op::Communicate(1), | ||
| 61 | + Op::Communicate(2), | ||
| 62 | + Op::CompleteAnimations, | ||
| 63 | + ]; | ||
| 64 | + | ||
| 65 | + check_ops_with_options(make_options(), &ops) | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +#[test] | ||
| 69 | +fn height_resize_animates_next_y() { | ||
| 70 | + let mut layout = set_up_two_in_column(); | ||
| 71 | + | ||
| 72 | + let ops = [ | ||
| 73 | + // Issue a resize. | ||
| 74 | + Op::SetWindowHeight { | ||
| 75 | + id: None, | ||
| 76 | + change: SizeChange::AdjustFixed(-50), | ||
| 77 | + }, | ||
| 78 | + // The top window shrinks in response, the bottom remains as is. | ||
| 79 | + Op::SetForcedSize { | ||
| 80 | + id: 1, | ||
| 81 | + size: Some(Size::new(100, 50)), | ||
| 82 | + }, | ||
| 83 | + Op::Communicate(1), | ||
| 84 | + Op::Communicate(2), | ||
| 85 | + ]; | ||
| 86 | + check_ops_on_layout(&mut layout, &ops); | ||
| 87 | + | ||
| 88 | + // No time had passed yet, so we're at the initial state. | ||
| 89 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 90 | + 100 × 100 at x: 0 y: 0 | ||
| 91 | + 200 × 200 at x: 0 y:100 | ||
| 92 | + "); | ||
| 93 | + | ||
| 94 | + // Advance the time halfway. | ||
| 95 | + Op::AdvanceAnimations { msec_delta: 500 }.apply(&mut layout); | ||
| 96 | + | ||
| 97 | + // Top window is half-resized at 75 px tall, bottom window is at y=75 matching it. | ||
| 98 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 99 | + 100 × 75 at x: 0 y: 0 | ||
| 100 | + 200 × 200 at x: 0 y: 75 | ||
| 101 | + "); | ||
| 102 | + | ||
| 103 | + // Advance the time to completion. | ||
| 104 | + Op::AdvanceAnimations { msec_delta: 500 }.apply(&mut layout); | ||
| 105 | + | ||
| 106 | + // Final state at 50 px. | ||
| 107 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 108 | + 100 × 50 at x: 0 y: 0 | ||
| 109 | + 200 × 200 at x: 0 y: 50 | ||
| 110 | + "); | ||
| 111 | +} | ||
| 112 | + | ||
| 113 | +#[test] | ||
| 114 | +fn clientside_height_change_doesnt_animate() { | ||
| 115 | + let mut layout = set_up_two_in_column(); | ||
| 116 | + | ||
| 117 | + // The initial state. | ||
| 118 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 119 | + 100 × 100 at x: 0 y: 0 | ||
| 120 | + 200 × 200 at x: 0 y:100 | ||
| 121 | + "); | ||
| 122 | + | ||
| 123 | + let ops = [ | ||
| 124 | + // The top window shrinks by itself, without a niri-issued resize. | ||
| 125 | + Op::SetForcedSize { | ||
| 126 | + id: 1, | ||
| 127 | + size: Some(Size::new(100, 50)), | ||
| 128 | + }, | ||
| 129 | + // This does not start any animations. | ||
| 130 | + Op::Communicate(1), | ||
| 131 | + Op::Communicate(2), | ||
| 132 | + ]; | ||
| 133 | + check_ops_on_layout(&mut layout, &ops); | ||
| 134 | + | ||
| 135 | + // No time had passed yet, but we are at the final state right away. | ||
| 136 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 137 | + 100 × 50 at x: 0 y: 0 | ||
| 138 | + 200 × 200 at x: 0 y: 50 | ||
| 139 | + "); | ||
| 140 | +} | ||
| 141 | + | ||
| 142 | +#[test] | ||
| 143 | +fn height_resize_and_back() { | ||
| 144 | + let mut layout = set_up_two_in_column(); | ||
| 145 | + | ||
| 146 | + // The initial state. | ||
| 147 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 148 | + 100 × 100 at x: 0 y: 0 | ||
| 149 | + 200 × 200 at x: 0 y:100 | ||
| 150 | + "); | ||
| 151 | + | ||
| 152 | + let ops = [ | ||
| 153 | + // Issue a resize. | ||
| 154 | + Op::SetWindowHeight { | ||
| 155 | + id: None, | ||
| 156 | + change: SizeChange::SetFixed(200), | ||
| 157 | + }, | ||
| 158 | + // The top window grows in response, the bottom remains as is. | ||
| 159 | + Op::SetForcedSize { | ||
| 160 | + id: 1, | ||
| 161 | + size: Some(Size::new(100, 200)), | ||
| 162 | + }, | ||
| 163 | + // This starts the resize animation. | ||
| 164 | + Op::Communicate(1), | ||
| 165 | + Op::Communicate(2), | ||
| 166 | + // Advance the time halfway. | ||
| 167 | + Op::AdvanceAnimations { msec_delta: 500 }, | ||
| 168 | + ]; | ||
| 169 | + check_ops_on_layout(&mut layout, &ops); | ||
| 170 | + | ||
| 171 | + // Top window is half-resized at 150 px tall, bottom window is at y=150 matching it. | ||
| 172 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 173 | + 100 × 150 at x: 0 y: 0 | ||
| 174 | + 200 × 200 at x: 0 y:150 | ||
| 175 | + "); | ||
| 176 | + | ||
| 177 | + let ops = [ | ||
| 178 | + // Issue a resize back. | ||
| 179 | + Op::SetWindowHeight { | ||
| 180 | + id: None, | ||
| 181 | + change: SizeChange::SetFixed(100), | ||
| 182 | + }, | ||
| 183 | + // The top window shrinks in response, the bottom remains as is. | ||
| 184 | + Op::SetForcedSize { | ||
| 185 | + id: 1, | ||
| 186 | + size: Some(Size::new(100, 100)), | ||
| 187 | + }, | ||
| 188 | + // This starts a new resize animation. | ||
| 189 | + Op::Communicate(1), | ||
| 190 | + Op::Communicate(2), | ||
| 191 | + ]; | ||
| 192 | + check_ops_on_layout(&mut layout, &ops); | ||
| 193 | + | ||
| 194 | + // No time had passed yet, and we expect no animation jumps, so this state matches the last. | ||
| 195 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 196 | + 100 × 150 at x: 0 y: 0 | ||
| 197 | + 200 × 200 at x: 0 y:150 | ||
| 198 | + "); | ||
| 199 | + | ||
| 200 | + // Advance the time halfway. | ||
| 201 | + Op::AdvanceAnimations { msec_delta: 500 }.apply(&mut layout); | ||
| 202 | + | ||
| 203 | + // Halfway through at 125px. | ||
| 204 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 205 | + 100 × 125 at x: 0 y: 0 | ||
| 206 | + 200 × 200 at x: 0 y:125 | ||
| 207 | + "); | ||
| 208 | + | ||
| 209 | + // Advance the time to completion. | ||
| 210 | + Op::AdvanceAnimations { msec_delta: 500 }.apply(&mut layout); | ||
| 211 | + | ||
| 212 | + // Final state back at 100px. | ||
| 213 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 214 | + 100 × 100 at x: 0 y: 0 | ||
| 215 | + 200 × 200 at x: 0 y:100 | ||
| 216 | + "); | ||
| 217 | +} | ||
| 218 | + | ||
| 219 | +#[test] | ||
| 220 | +fn height_resize_and_cancel() { | ||
| 221 | + let mut layout = set_up_two_in_column(); | ||
| 222 | + | ||
| 223 | + // The initial state. | ||
| 224 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 225 | + 100 × 100 at x: 0 y: 0 | ||
| 226 | + 200 × 200 at x: 0 y:100 | ||
| 227 | + "); | ||
| 228 | + | ||
| 229 | + let ops = [ | ||
| 230 | + // Issue a resize. | ||
| 231 | + Op::SetWindowHeight { | ||
| 232 | + id: None, | ||
| 233 | + change: SizeChange::SetFixed(200), | ||
| 234 | + }, | ||
| 235 | + // The top window grows in response, the bottom remains as is. | ||
| 236 | + Op::SetForcedSize { | ||
| 237 | + id: 1, | ||
| 238 | + size: Some(Size::new(100, 200)), | ||
| 239 | + }, | ||
| 240 | + // This starts the resize animation. | ||
| 241 | + Op::Communicate(1), | ||
| 242 | + Op::Communicate(2), | ||
| 243 | + // Advance the time slightly. | ||
| 244 | + Op::AdvanceAnimations { msec_delta: 50 }, | ||
| 245 | + ]; | ||
| 246 | + check_ops_on_layout(&mut layout, &ops); | ||
| 247 | + | ||
| 248 | + // Top window is half-resized at 105 px tall, bottom window is at y=105 matching it. | ||
| 249 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 250 | + 100 × 105 at x: 0 y: 0 | ||
| 251 | + 200 × 200 at x: 0 y:105 | ||
| 252 | + "); | ||
| 253 | + | ||
| 254 | + let ops = [ | ||
| 255 | + // Issue a resize back. | ||
| 256 | + Op::SetWindowHeight { | ||
| 257 | + id: None, | ||
| 258 | + change: SizeChange::SetFixed(100), | ||
| 259 | + }, | ||
| 260 | + // The top window shrinks in response, the bottom remains as is. | ||
| 261 | + Op::SetForcedSize { | ||
| 262 | + id: 1, | ||
| 263 | + size: Some(Size::new(100, 100)), | ||
| 264 | + }, | ||
| 265 | + // This cancels the resize animation since the change of 5 px is less than the resize | ||
| 266 | + // animation threshold. | ||
| 267 | + Op::Communicate(1), | ||
| 268 | + Op::Communicate(2), | ||
| 269 | + ]; | ||
| 270 | + check_ops_on_layout(&mut layout, &ops); | ||
| 271 | + | ||
| 272 | + // Since the resize animation is cancelled, the height goes to the new value immediately, and | ||
| 273 | + // the Y position should also go to 100 immediately, cancelling the movement. | ||
| 274 | + // | ||
| 275 | + // FIXME: right now, the Y position jumps to 5 and will continue animating to 100 from there | ||
| 276 | + // because cancelling the resize anim doesn't cancel the induced Y movement. | ||
| 277 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 278 | + 100 × 100 at x: 0 y: 0 | ||
| 279 | + 200 × 200 at x: 0 y: 5 | ||
| 280 | + "); | ||
| 281 | +} | ||
| 282 | + | ||
| 283 | +#[test] | ||
| 284 | +fn height_resize_and_back_during_another_y_anim() { | ||
| 285 | + let ops = [ | ||
| 286 | + Op::AddOutput(1), | ||
| 287 | + Op::AddWindow { | ||
| 288 | + params: TestWindowParams::new(1), | ||
| 289 | + }, | ||
| 290 | + Op::AddWindow { | ||
| 291 | + params: TestWindowParams::new(2), | ||
| 292 | + }, | ||
| 293 | + Op::FocusColumnLeft, | ||
| 294 | + Op::SetForcedSize { | ||
| 295 | + id: 1, | ||
| 296 | + size: Some(Size::new(100, 100)), | ||
| 297 | + }, | ||
| 298 | + Op::SetForcedSize { | ||
| 299 | + id: 2, | ||
| 300 | + size: Some(Size::new(200, 200)), | ||
| 301 | + }, | ||
| 302 | + Op::Communicate(1), | ||
| 303 | + Op::Communicate(2), | ||
| 304 | + Op::CompleteAnimations, | ||
| 305 | + ]; | ||
| 306 | + let mut layout = check_ops_with_options(make_options(), &ops); | ||
| 307 | + | ||
| 308 | + // The initial state. | ||
| 309 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 310 | + 100 × 100 at x: 0 y: 0 | ||
| 311 | + 200 × 200 at x:100 y: 0 | ||
| 312 | + "); | ||
| 313 | + | ||
| 314 | + // Consume second window into column, starting the X/Y move anim down. | ||
| 315 | + Op::ConsumeWindowIntoColumn.apply(&mut layout); | ||
| 316 | + | ||
| 317 | + // No time had passed, so no change in coordinates yet. | ||
| 318 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 319 | + 100 × 100 at x: 0 y: 0 | ||
| 320 | + 200 × 200 at x:100 y: 0 | ||
| 321 | + "); | ||
| 322 | + | ||
| 323 | + // Advance the time halfway. | ||
| 324 | + Op::AdvanceAnimations { msec_delta: 500 }.apply(&mut layout); | ||
| 325 | + | ||
| 326 | + // Second window halfway to the bottom. | ||
| 327 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 328 | + 100 × 100 at x: 0 y: 0 | ||
| 329 | + 200 × 200 at x: 50 y: 50 | ||
| 330 | + "); | ||
| 331 | + | ||
| 332 | + let ops = [ | ||
| 333 | + // Issue a resize. | ||
| 334 | + Op::SetWindowHeight { | ||
| 335 | + id: None, | ||
| 336 | + change: SizeChange::SetFixed(200), | ||
| 337 | + }, | ||
| 338 | + // The top window grows in response, the bottom remains as is. | ||
| 339 | + Op::SetForcedSize { | ||
| 340 | + id: 1, | ||
| 341 | + size: Some(Size::new(100, 200)), | ||
| 342 | + }, | ||
| 343 | + // This starts the resize animation. | ||
| 344 | + Op::Communicate(1), | ||
| 345 | + Op::Communicate(2), | ||
| 346 | + ]; | ||
| 347 | + check_ops_on_layout(&mut layout, &ops); | ||
| 348 | + | ||
| 349 | + // No time had passed, so no change in state yet. | ||
| 350 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 351 | + 100 × 100 at x: 0 y: 0 | ||
| 352 | + 200 × 200 at x: 50 y: 50 | ||
| 353 | + "); | ||
| 354 | + | ||
| 355 | + // Advance the time a bit. | ||
| 356 | + Op::AdvanceAnimations { msec_delta: 200 }.apply(&mut layout); | ||
| 357 | + | ||
| 358 | + // X changed by 20, but y changed by 30 since the Y movement from the resize compounds with the | ||
| 359 | + // Y movement from consume-into-column. | ||
| 360 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 361 | + 100 × 120 at x: 0 y: 0 | ||
| 362 | + 200 × 200 at x: 30 y: 80 | ||
| 363 | + "); | ||
| 364 | + | ||
| 365 | + let ops = [ | ||
| 366 | + // Issue a resize back. | ||
| 367 | + Op::SetWindowHeight { | ||
| 368 | + id: None, | ||
| 369 | + change: SizeChange::SetFixed(100), | ||
| 370 | + }, | ||
| 371 | + // The top window shrinks in response, the bottom remains as is. | ||
| 372 | + Op::SetForcedSize { | ||
| 373 | + id: 1, | ||
| 374 | + size: Some(Size::new(100, 100)), | ||
| 375 | + }, | ||
| 376 | + // This starts the resize animation. | ||
| 377 | + Op::Communicate(1), | ||
| 378 | + Op::Communicate(2), | ||
| 379 | + ]; | ||
| 380 | + check_ops_on_layout(&mut layout, &ops); | ||
| 381 | + | ||
| 382 | + // No time had passed, so no change in state yet. | ||
| 383 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 384 | + 100 × 120 at x: 0 y: 0 | ||
| 385 | + 200 × 200 at x: 30 y: 80 | ||
| 386 | + "); | ||
| 387 | + | ||
| 388 | + // Advance the time a bit. Both resize and consume movement are still ongoing. | ||
| 389 | + Op::AdvanceAnimations { msec_delta: 200 }.apply(&mut layout); | ||
| 390 | + | ||
| 391 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 392 | + 100 × 116 at x: 0 y: 0 | ||
| 393 | + 200 × 200 at x: 10 y: 84 | ||
| 394 | + "); | ||
| 395 | + | ||
| 396 | + // Advance the time to complete the consume movement. | ||
| 397 | + Op::AdvanceAnimations { msec_delta: 100 }.apply(&mut layout); | ||
| 398 | + | ||
| 399 | + // The Y position is still lower than the height since the window started the resize-induced Y | ||
| 400 | + // movement high up. | ||
| 401 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 402 | + 100 × 114 at x: 0 y: 0 | ||
| 403 | + 200 × 200 at x: 0 y: 86 | ||
| 404 | + "); | ||
| 405 | + | ||
| 406 | + // Advance the time to complete the resize. | ||
| 407 | + Op::AdvanceAnimations { msec_delta: 700 }.apply(&mut layout); | ||
| 408 | + | ||
| 409 | + // Final state. | ||
| 410 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 411 | + 100 × 100 at x: 0 y: 0 | ||
| 412 | + 200 × 200 at x: 0 y:100 | ||
| 413 | + "); | ||
| 414 | +} | ||
| 415 | + | ||
| 416 | +#[test] | ||
| 417 | +fn height_resize_and_cancel_during_another_y_anim() { | ||
| 418 | + let ops = [ | ||
| 419 | + Op::AddOutput(1), | ||
| 420 | + Op::AddWindow { | ||
| 421 | + params: TestWindowParams::new(1), | ||
| 422 | + }, | ||
| 423 | + Op::AddWindow { | ||
| 424 | + params: TestWindowParams::new(2), | ||
| 425 | + }, | ||
| 426 | + Op::FocusColumnLeft, | ||
| 427 | + Op::SetForcedSize { | ||
| 428 | + id: 1, | ||
| 429 | + size: Some(Size::new(100, 100)), | ||
| 430 | + }, | ||
| 431 | + Op::SetForcedSize { | ||
| 432 | + id: 2, | ||
| 433 | + size: Some(Size::new(200, 200)), | ||
| 434 | + }, | ||
| 435 | + Op::Communicate(1), | ||
| 436 | + Op::Communicate(2), | ||
| 437 | + Op::CompleteAnimations, | ||
| 438 | + ]; | ||
| 439 | + let mut layout = check_ops_with_options(make_options(), &ops); | ||
| 440 | + | ||
| 441 | + // The initial state. | ||
| 442 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 443 | + 100 × 100 at x: 0 y: 0 | ||
| 444 | + 200 × 200 at x:100 y: 0 | ||
| 445 | + "); | ||
| 446 | + | ||
| 447 | + // Consume second window into column, starting the X/Y move anim down. | ||
| 448 | + Op::ConsumeWindowIntoColumn.apply(&mut layout); | ||
| 449 | + | ||
| 450 | + // No time had passed, so no change in coordinates yet. | ||
| 451 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 452 | + 100 × 100 at x: 0 y: 0 | ||
| 453 | + 200 × 200 at x:100 y: 0 | ||
| 454 | + "); | ||
| 455 | + | ||
| 456 | + // Advance the time halfway. | ||
| 457 | + Op::AdvanceAnimations { msec_delta: 500 }.apply(&mut layout); | ||
| 458 | + | ||
| 459 | + // Second window halfway to the bottom. | ||
| 460 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 461 | + 100 × 100 at x: 0 y: 0 | ||
| 462 | + 200 × 200 at x: 50 y: 50 | ||
| 463 | + "); | ||
| 464 | + | ||
| 465 | + let ops = [ | ||
| 466 | + // Issue a resize. | ||
| 467 | + Op::SetWindowHeight { | ||
| 468 | + id: None, | ||
| 469 | + change: SizeChange::SetFixed(200), | ||
| 470 | + }, | ||
| 471 | + // The top window grows in response, the bottom remains as is. | ||
| 472 | + Op::SetForcedSize { | ||
| 473 | + id: 1, | ||
| 474 | + size: Some(Size::new(100, 200)), | ||
| 475 | + }, | ||
| 476 | + // This starts the resize animation. | ||
| 477 | + Op::Communicate(1), | ||
| 478 | + Op::Communicate(2), | ||
| 479 | + // Advance the time slightly. | ||
| 480 | + Op::AdvanceAnimations { msec_delta: 50 }, | ||
| 481 | + ]; | ||
| 482 | + check_ops_on_layout(&mut layout, &ops); | ||
| 483 | + | ||
| 484 | + // X changed by 5, but y changed by 8 since the Y movement from the resize compounds with the Y | ||
| 485 | + // movement from consume-into-column. | ||
| 486 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 487 | + 100 × 105 at x: 0 y: 0 | ||
| 488 | + 200 × 200 at x: 45 y: 58 | ||
| 489 | + "); | ||
| 490 | + | ||
| 491 | + let ops = [ | ||
| 492 | + // Issue a resize back. | ||
| 493 | + Op::SetWindowHeight { | ||
| 494 | + id: None, | ||
| 495 | + change: SizeChange::SetFixed(100), | ||
| 496 | + }, | ||
| 497 | + // The top window shrinks in response, the bottom remains as is. | ||
| 498 | + Op::SetForcedSize { | ||
| 499 | + id: 1, | ||
| 500 | + size: Some(Size::new(100, 100)), | ||
| 501 | + }, | ||
| 502 | + // This cancels the resize animation since the change of 5 px is less than the resize | ||
| 503 | + // animation threshold. | ||
| 504 | + Op::Communicate(1), | ||
| 505 | + Op::Communicate(2), | ||
| 506 | + ]; | ||
| 507 | + check_ops_on_layout(&mut layout, &ops); | ||
| 508 | + | ||
| 509 | + // Since the resize anim was cancelled, second window's Y should jump a little to go back to | ||
| 510 | + // its original trajectory. | ||
| 511 | + // | ||
| 512 | + // FIXME: right now, the Y position jumps and will continue to animate from there because | ||
| 513 | + // cancelling the resize anim doesn't cancel the induced Y movement. | ||
| 514 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 515 | + 100 × 100 at x: 0 y: 0 | ||
| 516 | + 200 × 200 at x: 45 y:-43 | ||
| 517 | + "); | ||
| 518 | + | ||
| 519 | + // Advance the time to complete the consume movement. | ||
| 520 | + Op::AdvanceAnimations { msec_delta: 450 }.apply(&mut layout); | ||
| 521 | + | ||
| 522 | + // Final state. Y should be at 100 since the resize-induced Y anim was cancelled. | ||
| 523 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 524 | + 100 × 100 at x: 0 y: 0 | ||
| 525 | + 200 × 200 at x: 0 y: 25 | ||
| 526 | + "); | ||
| 527 | +} | ||
| 528 | + | ||
| 529 | +#[test] | ||
| 530 | +fn height_resize_before_another_y_anim_then_back() { | ||
| 531 | + let ops = [ | ||
| 532 | + Op::AddOutput(1), | ||
| 533 | + Op::AddWindow { | ||
| 534 | + params: TestWindowParams::new(1), | ||
| 535 | + }, | ||
| 536 | + Op::AddWindow { | ||
| 537 | + params: TestWindowParams::new(2), | ||
| 538 | + }, | ||
| 539 | + Op::FocusColumnLeft, | ||
| 540 | + Op::SetForcedSize { | ||
| 541 | + id: 1, | ||
| 542 | + size: Some(Size::new(100, 100)), | ||
| 543 | + }, | ||
| 544 | + Op::SetForcedSize { | ||
| 545 | + id: 2, | ||
| 546 | + size: Some(Size::new(200, 200)), | ||
| 547 | + }, | ||
| 548 | + Op::Communicate(1), | ||
| 549 | + Op::Communicate(2), | ||
| 550 | + Op::CompleteAnimations, | ||
| 551 | + // Issue a resize. | ||
| 552 | + Op::SetWindowHeight { | ||
| 553 | + id: None, | ||
| 554 | + change: SizeChange::SetFixed(200), | ||
| 555 | + }, | ||
| 556 | + // The top window grows in response, the bottom remains as is. | ||
| 557 | + Op::SetForcedSize { | ||
| 558 | + id: 1, | ||
| 559 | + size: Some(Size::new(100, 200)), | ||
| 560 | + }, | ||
| 561 | + // This starts the resize animation. | ||
| 562 | + Op::Communicate(1), | ||
| 563 | + Op::Communicate(2), | ||
| 564 | + // Advance the time a bit. | ||
| 565 | + Op::AdvanceAnimations { msec_delta: 200 }, | ||
| 566 | + ]; | ||
| 567 | + let mut layout = check_ops_with_options(make_options(), &ops); | ||
| 568 | + | ||
| 569 | + // The resize is in progress. | ||
| 570 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 571 | + 100 × 120 at x: 0 y: 0 | ||
| 572 | + 200 × 200 at x:100 y: 0 | ||
| 573 | + "); | ||
| 574 | + | ||
| 575 | + // Consume second window into column, starting the X/Y move anim down. | ||
| 576 | + Op::ConsumeWindowIntoColumn.apply(&mut layout); | ||
| 577 | + | ||
| 578 | + // No time had passed, so no change in coordinates yet. | ||
| 579 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 580 | + 100 × 120 at x: 0 y: 0 | ||
| 581 | + 200 × 200 at x:100 y: 0 | ||
| 582 | + "); | ||
| 583 | + | ||
| 584 | + // Advance the time halfway. | ||
| 585 | + Op::AdvanceAnimations { msec_delta: 600 }.apply(&mut layout); | ||
| 586 | + | ||
| 587 | + // Second window halfway to the bottom. Since consume happened after the start of the first | ||
| 588 | + // window's resize, the second window's Y is unaffected by it and is animating towards the | ||
| 589 | + // final position right away. | ||
| 590 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 591 | + 100 × 180 at x: 0 y: 0 | ||
| 592 | + 200 × 200 at x: 40 y:120 | ||
| 593 | + "); | ||
| 594 | + | ||
| 595 | + let ops = [ | ||
| 596 | + // Issue a resize back. | ||
| 597 | + Op::SetWindowHeight { | ||
| 598 | + id: None, | ||
| 599 | + change: SizeChange::SetFixed(100), | ||
| 600 | + }, | ||
| 601 | + // The top window shrinks in response, the bottom remains as is. | ||
| 602 | + Op::SetForcedSize { | ||
| 603 | + id: 1, | ||
| 604 | + size: Some(Size::new(100, 100)), | ||
| 605 | + }, | ||
| 606 | + // This starts the resize animation. | ||
| 607 | + Op::Communicate(1), | ||
| 608 | + Op::Communicate(2), | ||
| 609 | + ]; | ||
| 610 | + check_ops_on_layout(&mut layout, &ops); | ||
| 611 | + | ||
| 612 | + // No time had passed, so no change in state yet. | ||
| 613 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 614 | + 100 × 180 at x: 0 y: 0 | ||
| 615 | + 200 × 200 at x: 40 y:120 | ||
| 616 | + "); | ||
| 617 | + | ||
| 618 | + // Advance the time a bit. Both resize and consume movement are still ongoing. | ||
| 619 | + Op::AdvanceAnimations { msec_delta: 200 }.apply(&mut layout); | ||
| 620 | + | ||
| 621 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 622 | + 100 × 164 at x: 0 y: 0 | ||
| 623 | + 200 × 200 at x: 20 y:116 | ||
| 624 | + "); | ||
| 625 | + | ||
| 626 | + // Advance the time to complete the consume movement. | ||
| 627 | + Op::AdvanceAnimations { msec_delta: 200 }.apply(&mut layout); | ||
| 628 | + | ||
| 629 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 630 | + 100 × 148 at x: 0 y: 0 | ||
| 631 | + 200 × 200 at x: 0 y:112 | ||
| 632 | + "); | ||
| 633 | + | ||
| 634 | + // Advance the time to complete the resize. | ||
| 635 | + Op::AdvanceAnimations { msec_delta: 600 }.apply(&mut layout); | ||
| 636 | + | ||
| 637 | + // Final state. | ||
| 638 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 639 | + 100 × 100 at x: 0 y: 0 | ||
| 640 | + 200 × 200 at x: 0 y:100 | ||
| 641 | + "); | ||
| 642 | +} | ||
| 643 | + | ||
| 644 | +#[test] | ||
| 645 | +fn height_resize_before_another_y_anim_then_cancel() { | ||
| 646 | + let ops = [ | ||
| 647 | + Op::AddOutput(1), | ||
| 648 | + Op::AddWindow { | ||
| 649 | + params: TestWindowParams::new(1), | ||
| 650 | + }, | ||
| 651 | + Op::AddWindow { | ||
| 652 | + params: TestWindowParams::new(2), | ||
| 653 | + }, | ||
| 654 | + Op::FocusColumnLeft, | ||
| 655 | + Op::SetForcedSize { | ||
| 656 | + id: 1, | ||
| 657 | + size: Some(Size::new(100, 100)), | ||
| 658 | + }, | ||
| 659 | + Op::SetForcedSize { | ||
| 660 | + id: 2, | ||
| 661 | + size: Some(Size::new(200, 200)), | ||
| 662 | + }, | ||
| 663 | + Op::Communicate(1), | ||
| 664 | + Op::Communicate(2), | ||
| 665 | + Op::CompleteAnimations, | ||
| 666 | + // Issue a resize. | ||
| 667 | + Op::SetWindowHeight { | ||
| 668 | + id: None, | ||
| 669 | + change: SizeChange::SetFixed(200), | ||
| 670 | + }, | ||
| 671 | + // The top window grows in response, the bottom remains as is. | ||
| 672 | + Op::SetForcedSize { | ||
| 673 | + id: 1, | ||
| 674 | + size: Some(Size::new(100, 200)), | ||
| 675 | + }, | ||
| 676 | + // This starts the resize animation. | ||
| 677 | + Op::Communicate(1), | ||
| 678 | + Op::Communicate(2), | ||
| 679 | + // Advance the time a bit. | ||
| 680 | + Op::AdvanceAnimations { msec_delta: 20 }, | ||
| 681 | + ]; | ||
| 682 | + let mut layout = check_ops_with_options(make_options(), &ops); | ||
| 683 | + | ||
| 684 | + // The resize is in progress. | ||
| 685 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 686 | + 100 × 102 at x: 0 y: 0 | ||
| 687 | + 200 × 200 at x:100 y: 0 | ||
| 688 | + "); | ||
| 689 | + | ||
| 690 | + // Consume second window into column, starting the X/Y move anim down. | ||
| 691 | + Op::ConsumeWindowIntoColumn.apply(&mut layout); | ||
| 692 | + | ||
| 693 | + // No time had passed, so no change in coordinates yet. | ||
| 694 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 695 | + 100 × 102 at x: 0 y: 0 | ||
| 696 | + 200 × 200 at x:100 y: 0 | ||
| 697 | + "); | ||
| 698 | + | ||
| 699 | + // Advance the time a little. | ||
| 700 | + Op::AdvanceAnimations { msec_delta: 20 }.apply(&mut layout); | ||
| 701 | + | ||
| 702 | + // Second window on its way to the bottom. | ||
| 703 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 704 | + 100 × 104 at x: 0 y: 0 | ||
| 705 | + 200 × 200 at x: 98 y: 4 | ||
| 706 | + "); | ||
| 707 | + | ||
| 708 | + let ops = [ | ||
| 709 | + // Issue a resize back. | ||
| 710 | + Op::SetWindowHeight { | ||
| 711 | + id: None, | ||
| 712 | + change: SizeChange::SetFixed(100), | ||
| 713 | + }, | ||
| 714 | + // The top window shrinks in response, the bottom remains as is. | ||
| 715 | + Op::SetForcedSize { | ||
| 716 | + id: 1, | ||
| 717 | + size: Some(Size::new(100, 100)), | ||
| 718 | + }, | ||
| 719 | + // This cancels the resize animation since the change of 4 px is less than the resize | ||
| 720 | + // animation threshold. | ||
| 721 | + Op::Communicate(1), | ||
| 722 | + Op::Communicate(2), | ||
| 723 | + ]; | ||
| 724 | + check_ops_on_layout(&mut layout, &ops); | ||
| 725 | + | ||
| 726 | + // This should cause the second window's trajectory to readjust to the new final position at | ||
| 727 | + // 100px. Ideally without big jumps because even though the first window's actual size changed | ||
| 728 | + // from 200 px to 100 px, the cancelled resize only shifted it from 104 px to 100 px. | ||
| 729 | + // | ||
| 730 | + // FIXME: currently causes a 100 px jump due to the change in the actual window size. | ||
| 731 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 732 | + 100 × 100 at x: 0 y: 0 | ||
| 733 | + 200 × 200 at x: 98 y:-96 | ||
| 734 | + "); | ||
| 735 | + | ||
| 736 | + // Advance the time to complete the consume movement. | ||
| 737 | + Op::AdvanceAnimations { msec_delta: 980 }.apply(&mut layout); | ||
| 738 | + | ||
| 739 | + // Final state. | ||
| 740 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 741 | + 100 × 100 at x: 0 y: 0 | ||
| 742 | + 200 × 200 at x: 0 y:100 | ||
| 743 | + "); | ||
| 744 | +} | ||
| 745 | + | ||
| 746 | +#[test] | ||
| 747 | +fn clientside_height_change_during_another_y_anim() { | ||
| 748 | + let ops = [ | ||
| 749 | + Op::AddOutput(1), | ||
| 750 | + Op::AddWindow { | ||
| 751 | + params: TestWindowParams::new(1), | ||
| 752 | + }, | ||
| 753 | + Op::AddWindow { | ||
| 754 | + params: TestWindowParams::new(2), | ||
| 755 | + }, | ||
| 756 | + Op::FocusColumnLeft, | ||
| 757 | + Op::SetForcedSize { | ||
| 758 | + id: 1, | ||
| 759 | + size: Some(Size::new(100, 100)), | ||
| 760 | + }, | ||
| 761 | + Op::SetForcedSize { | ||
| 762 | + id: 2, | ||
| 763 | + size: Some(Size::new(200, 200)), | ||
| 764 | + }, | ||
| 765 | + Op::Communicate(1), | ||
| 766 | + Op::Communicate(2), | ||
| 767 | + Op::CompleteAnimations, | ||
| 768 | + Op::ConsumeWindowIntoColumn, | ||
| 769 | + // Clear the animate next configure flag. | ||
| 770 | + Op::Communicate(1), | ||
| 771 | + Op::Communicate(2), | ||
| 772 | + // Advance the time a bit. | ||
| 773 | + Op::AdvanceAnimations { msec_delta: 200 }, | ||
| 774 | + ]; | ||
| 775 | + let mut layout = check_ops_with_options(make_options(), &ops); | ||
| 776 | + | ||
| 777 | + // Second window on its way to the bottom. | ||
| 778 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 779 | + 100 × 100 at x: 0 y: 0 | ||
| 780 | + 200 × 200 at x: 80 y: 20 | ||
| 781 | + "); | ||
| 782 | + | ||
| 783 | + let ops = [ | ||
| 784 | + // The top window suddenly grows. | ||
| 785 | + Op::SetForcedSize { | ||
| 786 | + id: 1, | ||
| 787 | + size: Some(Size::new(100, 200)), | ||
| 788 | + }, | ||
| 789 | + Op::Communicate(1), | ||
| 790 | + Op::Communicate(2), | ||
| 791 | + ]; | ||
| 792 | + check_ops_on_layout(&mut layout, &ops); | ||
| 793 | + | ||
| 794 | + // This should cause the second window's trajectory to readjust to the new final position at | ||
| 795 | + // 200px. Ideally without big jumps. | ||
| 796 | + // | ||
| 797 | + // FIXME: currently causes a 100 px jump due to the change in the window size. | ||
| 798 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 799 | + 100 × 200 at x: 0 y: 0 | ||
| 800 | + 200 × 200 at x: 80 y:120 | ||
| 801 | + "); | ||
| 802 | + | ||
| 803 | + // Advance the time to complete the consume movement. | ||
| 804 | + Op::AdvanceAnimations { msec_delta: 800 }.apply(&mut layout); | ||
| 805 | + | ||
| 806 | + // Final state. | ||
| 807 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 808 | + 100 × 200 at x: 0 y: 0 | ||
| 809 | + 200 × 200 at x: 0 y:200 | ||
| 810 | + "); | ||
| 811 | +} | ||
| 812 | + | ||
| 813 | +#[test] | ||
| 814 | +fn height_resize_cancel_with_stationary_second_window() { | ||
| 815 | + let ops = [ | ||
| 816 | + Op::AddOutput(1), | ||
| 817 | + Op::AddWindow { | ||
| 818 | + params: TestWindowParams::new(1), | ||
| 819 | + }, | ||
| 820 | + Op::AddWindow { | ||
| 821 | + params: TestWindowParams::new(2), | ||
| 822 | + }, | ||
| 823 | + Op::FocusColumnLeft, | ||
| 824 | + Op::SetForcedSize { | ||
| 825 | + id: 1, | ||
| 826 | + size: Some(Size::new(100, 100)), | ||
| 827 | + }, | ||
| 828 | + Op::SetForcedSize { | ||
| 829 | + id: 2, | ||
| 830 | + size: Some(Size::new(200, 200)), | ||
| 831 | + }, | ||
| 832 | + Op::Communicate(1), | ||
| 833 | + Op::Communicate(2), | ||
| 834 | + Op::CompleteAnimations, | ||
| 835 | + // Issue a resize. | ||
| 836 | + Op::SetWindowHeight { | ||
| 837 | + id: None, | ||
| 838 | + change: SizeChange::SetFixed(200), | ||
| 839 | + }, | ||
| 840 | + // The top window grows in response, the bottom remains as is. | ||
| 841 | + Op::SetForcedSize { | ||
| 842 | + id: 1, | ||
| 843 | + size: Some(Size::new(100, 200)), | ||
| 844 | + }, | ||
| 845 | + // This starts the resize animation. | ||
| 846 | + Op::Communicate(1), | ||
| 847 | + Op::Communicate(2), | ||
| 848 | + // Advance the time a bit. | ||
| 849 | + Op::AdvanceAnimations { msec_delta: 20 }, | ||
| 850 | + ]; | ||
| 851 | + let mut options = make_options(); | ||
| 852 | + // Window movement will happen instantly. | ||
| 853 | + options.animations.window_movement.0.off = true; | ||
| 854 | + let mut layout = check_ops_with_options(options, &ops); | ||
| 855 | + | ||
| 856 | + // The resize is in progress. | ||
| 857 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 858 | + 100 × 102 at x: 0 y: 0 | ||
| 859 | + 200 × 200 at x:100 y: 0 | ||
| 860 | + "); | ||
| 861 | + | ||
| 862 | + // Consume second window into column, starting the X/Y move anim down. | ||
| 863 | + Op::ConsumeWindowIntoColumn.apply(&mut layout); | ||
| 864 | + | ||
| 865 | + // No time had passed, so no change in coordinates yet. | ||
| 866 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 867 | + 100 × 102 at x: 0 y: 0 | ||
| 868 | + 200 × 200 at x:100 y: 0 | ||
| 869 | + "); | ||
| 870 | + | ||
| 871 | + // Advance the time a little. | ||
| 872 | + Op::AdvanceAnimations { msec_delta: 20 }.apply(&mut layout); | ||
| 873 | + | ||
| 874 | + // The window movement anim is off, so the second window is already at the bottom. Since | ||
| 875 | + // consume started after the resize, the second window is unaffected by the resize-induced Y | ||
| 876 | + // movement, and sits at the final position at 200 px. | ||
| 877 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 878 | + 100 × 104 at x: 0 y: 0 | ||
| 879 | + 200 × 200 at x: 0 y:200 | ||
| 880 | + "); | ||
| 881 | + | ||
| 882 | + let ops = [ | ||
| 883 | + // Issue a resize back. | ||
| 884 | + Op::SetWindowHeight { | ||
| 885 | + id: None, | ||
| 886 | + change: SizeChange::SetFixed(100), | ||
| 887 | + }, | ||
| 888 | + // The top window shrinks in response, the bottom remains as is. | ||
| 889 | + Op::SetForcedSize { | ||
| 890 | + id: 1, | ||
| 891 | + size: Some(Size::new(100, 100)), | ||
| 892 | + }, | ||
| 893 | + // This cancels the resize animation since the change of 4 px is less than the resize | ||
| 894 | + // animation threshold. | ||
| 895 | + Op::Communicate(1), | ||
| 896 | + Op::Communicate(2), | ||
| 897 | + ]; | ||
| 898 | + check_ops_on_layout(&mut layout, &ops); | ||
| 899 | + | ||
| 900 | + // This causes the second window to jump down, which is correct because it hadn't been in an | ||
| 901 | + // animation, and as far as it's concerned, this is the same case as a window just deciding to | ||
| 902 | + // do a clientside resize on its own, which is not animated. | ||
| 903 | + // | ||
| 904 | + // Since the resize is also cancelled, this is the final state. | ||
| 905 | + assert_snapshot!(format_tiles(&layout), @r" | ||
| 906 | + 100 × 100 at x: 0 y: 0 | ||
| 907 | + 200 × 200 at x: 0 y:100 | ||
| 908 | + "); | ||
| 909 | +} | ||