forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiBb0eb8adIvan Molodetskikh3 months ago2857 commits

animations.rs1099 lines, 32.0 KiBHistoryRawDownload
1use std::fmt::Write as _;
2
3use insta::assert_snapshot;
4use niri_config::animations::{Curve, EasingParams, Kind};
5
6use super::*;
7
8fn 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
25fn make_options() -> Options {
26 const LINEAR: Kind = Kind::Easing(EasingParams {
27 duration_ms: 1000,
28 curve: Curve::Linear,
29 });
30
31 let mut options = Options {
32 layout: niri_config::Layout {
33 gaps: 0.0,
34 ..Default::default()
35 },
36 ..Options::default()
37 };
38 options.animations.window_resize.anim.kind = LINEAR;
39 options.animations.window_movement.0.kind = LINEAR;
40
41 options
42}
43
44fn set_up_two_in_column() -> Layout<TestWindow> {
45 let ops = [
46 Op::AddOutput(1),
47 Op::AddWindow {
48 params: TestWindowParams::new(1),
49 },
50 Op::AddWindow {
51 params: TestWindowParams::new(2),
52 },
53 Op::FocusColumnLeft,
54 Op::ConsumeWindowIntoColumn,
55 Op::SetForcedSize {
56 id: 1,
57 size: Some(Size::new(100, 100)),
58 },
59 Op::SetForcedSize {
60 id: 2,
61 size: Some(Size::new(200, 200)),
62 },
63 Op::Communicate(1),
64 Op::Communicate(2),
65 Op::CompleteAnimations,
66 ];
67
68 check_ops_with_options(make_options(), ops)
69}
70
71#[test]
72fn height_resize_animates_next_y() {
73 let mut layout = set_up_two_in_column();
74
75 let ops = [
76 // Issue a resize.
77 Op::SetWindowHeight {
78 id: None,
79 change: SizeChange::AdjustFixed(-50),
80 },
81 // The top window shrinks in response, the bottom remains as is.
82 Op::SetForcedSize {
83 id: 1,
84 size: Some(Size::new(100, 50)),
85 },
86 Op::Communicate(1),
87 Op::Communicate(2),
88 ];
89 check_ops_on_layout(&mut layout, ops);
90
91 // No time had passed yet, so we're at the initial state.
92 assert_snapshot!(format_tiles(&layout), @r"
93 100 × 100 at x: 0 y: 0
94 200 × 200 at x: 0 y:100
95 ");
96
97 // Advance the time halfway.
98 Op::AdvanceAnimations { msec_delta: 500 }.apply(&mut layout);
99
100 // Top window is half-resized at 75 px tall, bottom window is at y=75 matching it.
101 assert_snapshot!(format_tiles(&layout), @r"
102 100 × 75 at x: 0 y: 0
103 200 × 200 at x: 0 y: 75
104 ");
105
106 // Advance the time to completion.
107 Op::AdvanceAnimations { msec_delta: 500 }.apply(&mut layout);
108
109 // Final state at 50 px.
110 assert_snapshot!(format_tiles(&layout), @r"
111 100 × 50 at x: 0 y: 0
112 200 × 200 at x: 0 y: 50
113 ");
114}
115
116#[test]
117fn clientside_height_change_doesnt_animate() {
118 let mut layout = set_up_two_in_column();
119
120 // The initial state.
121 assert_snapshot!(format_tiles(&layout), @r"
122 100 × 100 at x: 0 y: 0
123 200 × 200 at x: 0 y:100
124 ");
125
126 let ops = [
127 // The top window shrinks by itself, without a niri-issued resize.
128 Op::SetForcedSize {
129 id: 1,
130 size: Some(Size::new(100, 50)),
131 },
132 // This does not start any animations.
133 Op::Communicate(1),
134 Op::Communicate(2),
135 ];
136 check_ops_on_layout(&mut layout, ops);
137
138 // No time had passed yet, but we are at the final state right away.
139 assert_snapshot!(format_tiles(&layout), @r"
140 100 × 50 at x: 0 y: 0
141 200 × 200 at x: 0 y: 50
142 ");
143}
144
145#[test]
146fn height_resize_and_back() {
147 let mut layout = set_up_two_in_column();
148
149 // The initial state.
150 assert_snapshot!(format_tiles(&layout), @r"
151 100 × 100 at x: 0 y: 0
152 200 × 200 at x: 0 y:100
153 ");
154
155 let ops = [
156 // Issue a resize.
157 Op::SetWindowHeight {
158 id: None,
159 change: SizeChange::SetFixed(200),
160 },
161 // The top window grows in response, the bottom remains as is.
162 Op::SetForcedSize {
163 id: 1,
164 size: Some(Size::new(100, 200)),
165 },
166 // This starts the resize animation.
167 Op::Communicate(1),
168 Op::Communicate(2),
169 // Advance the time halfway.
170 Op::AdvanceAnimations { msec_delta: 500 },
171 ];
172 check_ops_on_layout(&mut layout, ops);
173
174 // Top window is half-resized at 150 px tall, bottom window is at y=150 matching it.
175 assert_snapshot!(format_tiles(&layout), @r"
176 100 × 150 at x: 0 y: 0
177 200 × 200 at x: 0 y:150
178 ");
179
180 let ops = [
181 // Issue a resize back.
182 Op::SetWindowHeight {
183 id: None,
184 change: SizeChange::SetFixed(100),
185 },
186 // The top window shrinks in response, the bottom remains as is.
187 Op::SetForcedSize {
188 id: 1,
189 size: Some(Size::new(100, 100)),
190 },
191 // This starts a new resize animation.
192 Op::Communicate(1),
193 Op::Communicate(2),
194 ];
195 check_ops_on_layout(&mut layout, ops);
196
197 // No time had passed yet, and we expect no animation jumps, so this state matches the last.
198 assert_snapshot!(format_tiles(&layout), @r"
199 100 × 150 at x: 0 y: 0
200 200 × 200 at x: 0 y:150
201 ");
202
203 // Advance the time halfway.
204 Op::AdvanceAnimations { msec_delta: 500 }.apply(&mut layout);
205
206 // Halfway through at 125px.
207 assert_snapshot!(format_tiles(&layout), @r"
208 100 × 125 at x: 0 y: 0
209 200 × 200 at x: 0 y:125
210 ");
211
212 // Advance the time to completion.
213 Op::AdvanceAnimations { msec_delta: 500 }.apply(&mut layout);
214
215 // Final state back at 100px.
216 assert_snapshot!(format_tiles(&layout), @r"
217 100 × 100 at x: 0 y: 0
218 200 × 200 at x: 0 y:100
219 ");
220}
221
222#[test]
223fn height_resize_and_cancel() {
224 let mut layout = set_up_two_in_column();
225
226 // The initial state.
227 assert_snapshot!(format_tiles(&layout), @r"
228 100 × 100 at x: 0 y: 0
229 200 × 200 at x: 0 y:100
230 ");
231
232 let ops = [
233 // Issue a resize.
234 Op::SetWindowHeight {
235 id: None,
236 change: SizeChange::SetFixed(200),
237 },
238 // The top window grows in response, the bottom remains as is.
239 Op::SetForcedSize {
240 id: 1,
241 size: Some(Size::new(100, 200)),
242 },
243 // This starts the resize animation.
244 Op::Communicate(1),
245 Op::Communicate(2),
246 // Advance the time slightly.
247 Op::AdvanceAnimations { msec_delta: 50 },
248 ];
249 check_ops_on_layout(&mut layout, ops);
250
251 // Top window is half-resized at 105 px tall, bottom window is at y=105 matching it.
252 assert_snapshot!(format_tiles(&layout), @r"
253 100 × 105 at x: 0 y: 0
254 200 × 200 at x: 0 y:105
255 ");
256
257 let ops = [
258 // Issue a resize back.
259 Op::SetWindowHeight {
260 id: None,
261 change: SizeChange::SetFixed(100),
262 },
263 // The top window shrinks in response, the bottom remains as is.
264 Op::SetForcedSize {
265 id: 1,
266 size: Some(Size::new(100, 100)),
267 },
268 // This cancels the resize animation since the change of 5 px is less than the resize
269 // animation threshold.
270 Op::Communicate(1),
271 Op::Communicate(2),
272 ];
273 check_ops_on_layout(&mut layout, ops);
274
275 // Since the resize animation is cancelled, the height goes to the new value immediately. The Y
276 // position doesn't jump, instead the animation is offset to preserve the current position.
277 assert_snapshot!(format_tiles(&layout), @r"
278 100 × 100 at x: 0 y: 0
279 200 × 200 at x: 0 y:105
280 ");
281
282 // Advance to the end of the move animation.
283 Op::AdvanceAnimations { msec_delta: 950 }.apply(&mut layout);
284
285 // Final state.
286 assert_snapshot!(format_tiles(&layout), @r"
287 100 × 100 at x: 0 y: 0
288 200 × 200 at x: 0 y:100
289 ");
290}
291
292#[test]
293fn height_resize_and_back_during_another_y_anim() {
294 let ops = [
295 Op::AddOutput(1),
296 Op::AddWindow {
297 params: TestWindowParams::new(1),
298 },
299 Op::AddWindow {
300 params: TestWindowParams::new(2),
301 },
302 Op::FocusColumnLeft,
303 Op::SetForcedSize {
304 id: 1,
305 size: Some(Size::new(100, 100)),
306 },
307 Op::SetForcedSize {
308 id: 2,
309 size: Some(Size::new(200, 200)),
310 },
311 Op::Communicate(1),
312 Op::Communicate(2),
313 Op::CompleteAnimations,
314 ];
315 let mut layout = check_ops_with_options(make_options(), ops);
316
317 // The initial state.
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 // Consume second window into column, starting the X/Y move anim down.
324 Op::ConsumeWindowIntoColumn.apply(&mut layout);
325
326 // No time had passed, so no change in coordinates yet.
327 assert_snapshot!(format_tiles(&layout), @r"
328 100 × 100 at x: 0 y: 0
329 200 × 200 at x:100 y: 0
330 ");
331
332 // Advance the time halfway.
333 Op::AdvanceAnimations { msec_delta: 500 }.apply(&mut layout);
334
335 // Second window halfway to the bottom.
336 assert_snapshot!(format_tiles(&layout), @r"
337 100 × 100 at x: 0 y: 0
338 200 × 200 at x: 50 y: 50
339 ");
340
341 let ops = [
342 // Issue a resize.
343 Op::SetWindowHeight {
344 id: None,
345 change: SizeChange::SetFixed(200),
346 },
347 // The top window grows in response, the bottom remains as is.
348 Op::SetForcedSize {
349 id: 1,
350 size: Some(Size::new(100, 200)),
351 },
352 // This starts the resize animation.
353 Op::Communicate(1),
354 Op::Communicate(2),
355 ];
356 check_ops_on_layout(&mut layout, ops);
357
358 // No time had passed, so no change in state yet.
359 assert_snapshot!(format_tiles(&layout), @r"
360 100 × 100 at x: 0 y: 0
361 200 × 200 at x: 50 y: 50
362 ");
363
364 // Advance the time a bit.
365 Op::AdvanceAnimations { msec_delta: 200 }.apply(&mut layout);
366
367 // X changed by 20, but y changed by 30 since the Y movement from the resize compounds with the
368 // Y movement from consume-into-column.
369 assert_snapshot!(format_tiles(&layout), @r"
370 100 × 120 at x: 0 y: 0
371 200 × 200 at x: 30 y: 80
372 ");
373
374 let ops = [
375 // Issue a resize back.
376 Op::SetWindowHeight {
377 id: None,
378 change: SizeChange::SetFixed(100),
379 },
380 // The top window shrinks in response, the bottom remains as is.
381 Op::SetForcedSize {
382 id: 1,
383 size: Some(Size::new(100, 100)),
384 },
385 // This starts the resize animation.
386 Op::Communicate(1),
387 Op::Communicate(2),
388 ];
389 check_ops_on_layout(&mut layout, ops);
390
391 // No time had passed, so no change in state yet.
392 assert_snapshot!(format_tiles(&layout), @r"
393 100 × 120 at x: 0 y: 0
394 200 × 200 at x: 30 y: 80
395 ");
396
397 // Advance the time a bit. Both resize and consume movement are still ongoing.
398 Op::AdvanceAnimations { msec_delta: 200 }.apply(&mut layout);
399
400 assert_snapshot!(format_tiles(&layout), @r"
401 100 × 116 at x: 0 y: 0
402 200 × 200 at x: 10 y: 84
403 ");
404
405 // Advance the time to complete the consume movement.
406 Op::AdvanceAnimations { msec_delta: 100 }.apply(&mut layout);
407
408 // The Y position is still lower than the height since the window started the resize-induced Y
409 // movement high up.
410 assert_snapshot!(format_tiles(&layout), @r"
411 100 × 114 at x: 0 y: 0
412 200 × 200 at x: 0 y: 86
413 ");
414
415 // Advance the time to complete the resize.
416 Op::AdvanceAnimations { msec_delta: 700 }.apply(&mut layout);
417
418 // Final state.
419 assert_snapshot!(format_tiles(&layout), @r"
420 100 × 100 at x: 0 y: 0
421 200 × 200 at x: 0 y:100
422 ");
423}
424
425#[test]
426fn height_resize_and_cancel_during_another_y_anim() {
427 let ops = [
428 Op::AddOutput(1),
429 Op::AddWindow {
430 params: TestWindowParams::new(1),
431 },
432 Op::AddWindow {
433 params: TestWindowParams::new(2),
434 },
435 Op::FocusColumnLeft,
436 Op::SetForcedSize {
437 id: 1,
438 size: Some(Size::new(100, 100)),
439 },
440 Op::SetForcedSize {
441 id: 2,
442 size: Some(Size::new(200, 200)),
443 },
444 Op::Communicate(1),
445 Op::Communicate(2),
446 Op::CompleteAnimations,
447 ];
448 let mut layout = check_ops_with_options(make_options(), ops);
449
450 // The initial state.
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 // Consume second window into column, starting the X/Y move anim down.
457 Op::ConsumeWindowIntoColumn.apply(&mut layout);
458
459 // No time had passed, so no change in coordinates yet.
460 assert_snapshot!(format_tiles(&layout), @r"
461 100 × 100 at x: 0 y: 0
462 200 × 200 at x:100 y: 0
463 ");
464
465 // Advance the time halfway.
466 Op::AdvanceAnimations { msec_delta: 500 }.apply(&mut layout);
467
468 // Second window halfway to the bottom.
469 assert_snapshot!(format_tiles(&layout), @r"
470 100 × 100 at x: 0 y: 0
471 200 × 200 at x: 50 y: 50
472 ");
473
474 let ops = [
475 // Issue a resize.
476 Op::SetWindowHeight {
477 id: None,
478 change: SizeChange::SetFixed(200),
479 },
480 // The top window grows in response, the bottom remains as is.
481 Op::SetForcedSize {
482 id: 1,
483 size: Some(Size::new(100, 200)),
484 },
485 // This starts the resize animation.
486 Op::Communicate(1),
487 Op::Communicate(2),
488 // Advance the time slightly.
489 Op::AdvanceAnimations { msec_delta: 50 },
490 ];
491 check_ops_on_layout(&mut layout, ops);
492
493 // X changed by 5, but y changed by 8 since the Y movement from the resize compounds with the Y
494 // movement from consume-into-column.
495 assert_snapshot!(format_tiles(&layout), @r"
496 100 × 105 at x: 0 y: 0
497 200 × 200 at x: 45 y: 58
498 ");
499
500 let ops = [
501 // Issue a resize back.
502 Op::SetWindowHeight {
503 id: None,
504 change: SizeChange::SetFixed(100),
505 },
506 // The top window shrinks in response, the bottom remains as is.
507 Op::SetForcedSize {
508 id: 1,
509 size: Some(Size::new(100, 100)),
510 },
511 // This cancels the resize animation since the change of 5 px is less than the resize
512 // animation threshold.
513 Op::Communicate(1),
514 Op::Communicate(2),
515 ];
516 check_ops_on_layout(&mut layout, ops);
517
518 // Since the resize anim was cancelled, second window's Y anim is adjusted to preserve the
519 // current position while targeting the new final position.
520 assert_snapshot!(format_tiles(&layout), @r"
521 100 × 100 at x: 0 y: 0
522 200 × 200 at x: 45 y: 58
523 ");
524
525 // Advance the time to complete the consume movement.
526 Op::AdvanceAnimations { msec_delta: 450 }.apply(&mut layout);
527
528 // Since we don't cancel the resize-induced part of the anim (in fact the move Y anim isn't
529 // split into parts, so there's no way to tell), it keeps going still.
530 assert_snapshot!(format_tiles(&layout), @r"
531 100 × 100 at x: 0 y: 0
532 200 × 200 at x: 0 y: 78
533 ");
534
535 // Advance the time to complete the resize-induced anim.
536 Op::AdvanceAnimations { msec_delta: 550 }.apply(&mut layout);
537
538 // Final state.
539 assert_snapshot!(format_tiles(&layout), @r"
540 100 × 100 at x: 0 y: 0
541 200 × 200 at x: 0 y:100
542 ");
543}
544
545#[test]
546fn height_resize_before_another_y_anim_then_back() {
547 let ops = [
548 Op::AddOutput(1),
549 Op::AddWindow {
550 params: TestWindowParams::new(1),
551 },
552 Op::AddWindow {
553 params: TestWindowParams::new(2),
554 },
555 Op::FocusColumnLeft,
556 Op::SetForcedSize {
557 id: 1,
558 size: Some(Size::new(100, 100)),
559 },
560 Op::SetForcedSize {
561 id: 2,
562 size: Some(Size::new(200, 200)),
563 },
564 Op::Communicate(1),
565 Op::Communicate(2),
566 Op::CompleteAnimations,
567 // Issue a resize.
568 Op::SetWindowHeight {
569 id: None,
570 change: SizeChange::SetFixed(200),
571 },
572 // The top window grows in response, the bottom remains as is.
573 Op::SetForcedSize {
574 id: 1,
575 size: Some(Size::new(100, 200)),
576 },
577 // This starts the resize animation.
578 Op::Communicate(1),
579 Op::Communicate(2),
580 // Advance the time a bit.
581 Op::AdvanceAnimations { msec_delta: 200 },
582 ];
583 let mut layout = check_ops_with_options(make_options(), ops);
584
585 // The resize is in progress.
586 assert_snapshot!(format_tiles(&layout), @r"
587 100 × 120 at x: 0 y: 0
588 200 × 200 at x:100 y: 0
589 ");
590
591 // Consume second window into column, starting the X/Y move anim down.
592 Op::ConsumeWindowIntoColumn.apply(&mut layout);
593
594 // No time had passed, so no change in coordinates yet.
595 assert_snapshot!(format_tiles(&layout), @r"
596 100 × 120 at x: 0 y: 0
597 200 × 200 at x:100 y: 0
598 ");
599
600 // Advance the time halfway.
601 Op::AdvanceAnimations { msec_delta: 600 }.apply(&mut layout);
602
603 // Second window halfway to the bottom. Since consume happened after the start of the first
604 // window's resize, the second window's Y is unaffected by it and is animating towards the
605 // final position right away.
606 assert_snapshot!(format_tiles(&layout), @r"
607 100 × 180 at x: 0 y: 0
608 200 × 200 at x: 40 y:120
609 ");
610
611 let ops = [
612 // Issue a resize back.
613 Op::SetWindowHeight {
614 id: None,
615 change: SizeChange::SetFixed(100),
616 },
617 // The top window shrinks in response, the bottom remains as is.
618 Op::SetForcedSize {
619 id: 1,
620 size: Some(Size::new(100, 100)),
621 },
622 // This starts the resize animation.
623 Op::Communicate(1),
624 Op::Communicate(2),
625 ];
626 check_ops_on_layout(&mut layout, ops);
627
628 // No time had passed, so no change in state yet.
629 assert_snapshot!(format_tiles(&layout), @r"
630 100 × 180 at x: 0 y: 0
631 200 × 200 at x: 40 y:120
632 ");
633
634 // Advance the time a bit. Both resize and consume movement are still ongoing.
635 Op::AdvanceAnimations { msec_delta: 200 }.apply(&mut layout);
636
637 assert_snapshot!(format_tiles(&layout), @r"
638 100 × 164 at x: 0 y: 0
639 200 × 200 at x: 20 y:116
640 ");
641
642 // Advance the time to complete the consume movement.
643 Op::AdvanceAnimations { msec_delta: 200 }.apply(&mut layout);
644
645 assert_snapshot!(format_tiles(&layout), @r"
646 100 × 148 at x: 0 y: 0
647 200 × 200 at x: 0 y:112
648 ");
649
650 // Advance the time to complete the resize.
651 Op::AdvanceAnimations { msec_delta: 600 }.apply(&mut layout);
652
653 // Final state.
654 assert_snapshot!(format_tiles(&layout), @r"
655 100 × 100 at x: 0 y: 0
656 200 × 200 at x: 0 y:100
657 ");
658}
659
660#[test]
661fn height_resize_before_another_y_anim_then_cancel() {
662 let ops = [
663 Op::AddOutput(1),
664 Op::AddWindow {
665 params: TestWindowParams::new(1),
666 },
667 Op::AddWindow {
668 params: TestWindowParams::new(2),
669 },
670 Op::FocusColumnLeft,
671 Op::SetForcedSize {
672 id: 1,
673 size: Some(Size::new(100, 100)),
674 },
675 Op::SetForcedSize {
676 id: 2,
677 size: Some(Size::new(200, 200)),
678 },
679 Op::Communicate(1),
680 Op::Communicate(2),
681 Op::CompleteAnimations,
682 // Issue a resize.
683 Op::SetWindowHeight {
684 id: None,
685 change: SizeChange::SetFixed(200),
686 },
687 // The top window grows in response, the bottom remains as is.
688 Op::SetForcedSize {
689 id: 1,
690 size: Some(Size::new(100, 200)),
691 },
692 // This starts the resize animation.
693 Op::Communicate(1),
694 Op::Communicate(2),
695 // Advance the time a bit.
696 Op::AdvanceAnimations { msec_delta: 20 },
697 ];
698 let mut layout = check_ops_with_options(make_options(), ops);
699
700 // The resize is in progress.
701 assert_snapshot!(format_tiles(&layout), @r"
702 100 × 102 at x: 0 y: 0
703 200 × 200 at x:100 y: 0
704 ");
705
706 // Consume second window into column, starting the X/Y move anim down.
707 Op::ConsumeWindowIntoColumn.apply(&mut layout);
708
709 // No time had passed, so no change in coordinates yet.
710 assert_snapshot!(format_tiles(&layout), @r"
711 100 × 102 at x: 0 y: 0
712 200 × 200 at x:100 y: 0
713 ");
714
715 // Advance the time a little.
716 Op::AdvanceAnimations { msec_delta: 20 }.apply(&mut layout);
717
718 // Second window on its way to the bottom.
719 assert_snapshot!(format_tiles(&layout), @r"
720 100 × 104 at x: 0 y: 0
721 200 × 200 at x: 98 y: 4
722 ");
723
724 let ops = [
725 // Issue a resize back.
726 Op::SetWindowHeight {
727 id: None,
728 change: SizeChange::SetFixed(100),
729 },
730 // The top window shrinks in response, the bottom remains as is.
731 Op::SetForcedSize {
732 id: 1,
733 size: Some(Size::new(100, 100)),
734 },
735 // This cancels the resize animation since the change of 4 px is less than the resize
736 // animation threshold.
737 Op::Communicate(1),
738 Op::Communicate(2),
739 ];
740 check_ops_on_layout(&mut layout, ops);
741
742 // The second window's trajectory readjusts to the new final position at 100 px, without jumps.
743 assert_snapshot!(format_tiles(&layout), @r"
744 100 × 100 at x: 0 y: 0
745 200 × 200 at x: 98 y: 4
746 ");
747
748 // Advance the time to complete the consume movement.
749 Op::AdvanceAnimations { msec_delta: 980 }.apply(&mut layout);
750
751 // Final state.
752 assert_snapshot!(format_tiles(&layout), @r"
753 100 × 100 at x: 0 y: 0
754 200 × 200 at x: 0 y:100
755 ");
756}
757
758#[test]
759fn clientside_height_change_during_another_y_anim() {
760 let ops = [
761 Op::AddOutput(1),
762 Op::AddWindow {
763 params: TestWindowParams::new(1),
764 },
765 Op::AddWindow {
766 params: TestWindowParams::new(2),
767 },
768 Op::FocusColumnLeft,
769 Op::SetForcedSize {
770 id: 1,
771 size: Some(Size::new(100, 100)),
772 },
773 Op::SetForcedSize {
774 id: 2,
775 size: Some(Size::new(200, 200)),
776 },
777 Op::Communicate(1),
778 Op::Communicate(2),
779 Op::CompleteAnimations,
780 Op::ConsumeWindowIntoColumn,
781 // Clear the animate next configure flag.
782 Op::Communicate(1),
783 Op::Communicate(2),
784 // Advance the time a bit.
785 Op::AdvanceAnimations { msec_delta: 200 },
786 ];
787 let mut layout = check_ops_with_options(make_options(), ops);
788
789 // Second window on its way to the bottom.
790 assert_snapshot!(format_tiles(&layout), @r"
791 100 × 100 at x: 0 y: 0
792 200 × 200 at x: 80 y: 20
793 ");
794
795 let ops = [
796 // The top window suddenly grows.
797 Op::SetForcedSize {
798 id: 1,
799 size: Some(Size::new(100, 200)),
800 },
801 Op::Communicate(1),
802 Op::Communicate(2),
803 ];
804 check_ops_on_layout(&mut layout, ops);
805
806 // The second window's trajectory readjusts to the new final position at 200 px, without jumps.
807 assert_snapshot!(format_tiles(&layout), @r"
808 100 × 200 at x: 0 y: 0
809 200 × 200 at x: 80 y: 20
810 ");
811
812 // Advance the time to complete the consume movement.
813 Op::AdvanceAnimations { msec_delta: 800 }.apply(&mut layout);
814
815 // Final state.
816 assert_snapshot!(format_tiles(&layout), @r"
817 100 × 200 at x: 0 y: 0
818 200 × 200 at x: 0 y:200
819 ");
820}
821
822#[test]
823fn height_resize_cancel_with_stationary_second_window() {
824 let ops = [
825 Op::AddOutput(1),
826 Op::AddWindow {
827 params: TestWindowParams::new(1),
828 },
829 Op::AddWindow {
830 params: TestWindowParams::new(2),
831 },
832 Op::FocusColumnLeft,
833 Op::SetForcedSize {
834 id: 1,
835 size: Some(Size::new(100, 100)),
836 },
837 Op::SetForcedSize {
838 id: 2,
839 size: Some(Size::new(200, 200)),
840 },
841 Op::Communicate(1),
842 Op::Communicate(2),
843 Op::CompleteAnimations,
844 // Issue a resize.
845 Op::SetWindowHeight {
846 id: None,
847 change: SizeChange::SetFixed(200),
848 },
849 // The top window grows in response, the bottom remains as is.
850 Op::SetForcedSize {
851 id: 1,
852 size: Some(Size::new(100, 200)),
853 },
854 // This starts the resize animation.
855 Op::Communicate(1),
856 Op::Communicate(2),
857 // Advance the time a bit.
858 Op::AdvanceAnimations { msec_delta: 20 },
859 ];
860 let mut options = make_options();
861 // Window movement will happen instantly.
862 options.animations.window_movement.0.off = true;
863 let mut layout = check_ops_with_options(options, ops);
864
865 // The resize is in progress.
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 // Consume second window into column, starting the X/Y move anim down.
872 Op::ConsumeWindowIntoColumn.apply(&mut layout);
873
874 // No time had passed, so no change in coordinates yet.
875 assert_snapshot!(format_tiles(&layout), @r"
876 100 × 102 at x: 0 y: 0
877 200 × 200 at x:100 y: 0
878 ");
879
880 // Advance the time a little.
881 Op::AdvanceAnimations { msec_delta: 20 }.apply(&mut layout);
882
883 // The window movement anim is off, so the second window is already at the bottom. Since
884 // consume started after the resize, the second window is unaffected by the resize-induced Y
885 // movement, and sits at the final position at 200 px.
886 assert_snapshot!(format_tiles(&layout), @r"
887 100 × 104 at x: 0 y: 0
888 200 × 200 at x: 0 y:200
889 ");
890
891 let ops = [
892 // Issue a resize back.
893 Op::SetWindowHeight {
894 id: None,
895 change: SizeChange::SetFixed(100),
896 },
897 // The top window shrinks in response, the bottom remains as is.
898 Op::SetForcedSize {
899 id: 1,
900 size: Some(Size::new(100, 100)),
901 },
902 // This cancels the resize animation since the change of 4 px is less than the resize
903 // animation threshold.
904 Op::Communicate(1),
905 Op::Communicate(2),
906 ];
907 check_ops_on_layout(&mut layout, ops);
908
909 // This causes the second window to jump down, which is correct because it hadn't been in an
910 // animation, and as far as it's concerned, this is the same case as a window just deciding to
911 // do a clientside resize on its own, which is not animated.
912 //
913 // Since the resize is also cancelled, this is the final state.
914 assert_snapshot!(format_tiles(&layout), @r"
915 100 × 100 at x: 0 y: 0
916 200 × 200 at x: 0 y:100
917 ");
918}
919
920#[test]
921fn width_resize_and_cancel() {
922 let ops = [
923 Op::AddOutput(1),
924 Op::AddWindow {
925 params: TestWindowParams::new(1),
926 },
927 Op::AddWindow {
928 params: TestWindowParams::new(2),
929 },
930 Op::FocusColumnLeft,
931 Op::SetForcedSize {
932 id: 1,
933 size: Some(Size::new(100, 100)),
934 },
935 Op::SetForcedSize {
936 id: 2,
937 size: Some(Size::new(200, 200)),
938 },
939 Op::Communicate(1),
940 Op::Communicate(2),
941 Op::CompleteAnimations,
942 ];
943 let mut layout = check_ops_with_options(make_options(), ops);
944
945 // The initial state.
946 assert_snapshot!(format_tiles(&layout), @r"
947 100 × 100 at x: 0 y: 0
948 200 × 200 at x:100 y: 0
949 ");
950
951 let ops = [
952 // Issue a resize.
953 Op::SetWindowWidth {
954 id: None,
955 change: SizeChange::SetFixed(200),
956 },
957 // The left window grows in response.
958 Op::SetForcedSize {
959 id: 1,
960 size: Some(Size::new(200, 100)),
961 },
962 // This starts the resize animation.
963 Op::Communicate(1),
964 Op::Communicate(2),
965 // Advance the time slightly.
966 Op::AdvanceAnimations { msec_delta: 50 },
967 ];
968 check_ops_on_layout(&mut layout, ops);
969
970 // Left window is half-resized at 105 px wide, right window is at x=105 matching it.
971 assert_snapshot!(format_tiles(&layout), @r"
972 105 × 100 at x: 0 y: 0
973 200 × 200 at x:105 y: 0
974 ");
975
976 let ops = [
977 // Issue a resize back.
978 Op::SetWindowWidth {
979 id: None,
980 change: SizeChange::SetFixed(100),
981 },
982 // The top window shrinks in response.
983 Op::SetForcedSize {
984 id: 1,
985 size: Some(Size::new(100, 100)),
986 },
987 // This cancels the resize animation since the change of 5 px is less than the resize
988 // animation threshold.
989 Op::Communicate(1),
990 Op::Communicate(2),
991 ];
992 check_ops_on_layout(&mut layout, ops);
993
994 // Since the resize animation is cancelled, the width goes to the new value immediately. The X
995 // position doesn't jump, instead the animation is restarted to preserve the current position.
996 assert_snapshot!(format_tiles(&layout), @r"
997 100 × 100 at x: 0 y: 0
998 200 × 200 at x:105 y: 0
999 ");
1000
1001 // Advance to the end of the move animation.
1002 Op::AdvanceAnimations { msec_delta: 1000 }.apply(&mut layout);
1003
1004 // Final state.
1005 assert_snapshot!(format_tiles(&layout), @r"
1006 100 × 100 at x: 0 y: 0
1007 200 × 200 at x:100 y: 0
1008 ");
1009}
1010
1011#[test]
1012fn width_resize_and_cancel_of_column_to_the_left() {
1013 let ops = [
1014 Op::AddOutput(1),
1015 Op::AddWindow {
1016 params: TestWindowParams::new(1),
1017 },
1018 Op::AddWindow {
1019 params: TestWindowParams::new(2),
1020 },
1021 Op::SetForcedSize {
1022 id: 1,
1023 size: Some(Size::new(100, 100)),
1024 },
1025 Op::SetForcedSize {
1026 id: 2,
1027 size: Some(Size::new(200, 200)),
1028 },
1029 Op::Communicate(1),
1030 Op::Communicate(2),
1031 Op::CompleteAnimations,
1032 ];
1033 let mut layout = check_ops_with_options(make_options(), ops);
1034
1035 // The initial state.
1036 assert_snapshot!(format_tiles(&layout), @r"
1037 100 × 100 at x: 0 y: 0
1038 200 × 200 at x:100 y: 0
1039 ");
1040
1041 let ops = [
1042 // Issue a resize.
1043 Op::SetWindowWidth {
1044 id: Some(1),
1045 change: SizeChange::SetFixed(200),
1046 },
1047 // The left window grows in response.
1048 Op::SetForcedSize {
1049 id: 1,
1050 size: Some(Size::new(200, 100)),
1051 },
1052 // This starts the resize animation.
1053 Op::Communicate(1),
1054 Op::Communicate(2),
1055 // Advance the time slightly.
1056 Op::AdvanceAnimations { msec_delta: 50 },
1057 ];
1058 check_ops_on_layout(&mut layout, ops);
1059
1060 // Left window is half-resized at 105 px wide, it's at x=-5 matching the right edge position.
1061 assert_snapshot!(format_tiles(&layout), @r"
1062 105 × 100 at x: -5 y: 0
1063 200 × 200 at x:100 y: 0
1064 ");
1065
1066 let ops = [
1067 // Issue a resize back.
1068 Op::SetWindowWidth {
1069 id: Some(1),
1070 change: SizeChange::SetFixed(100),
1071 },
1072 // The top window shrinks in response.
1073 Op::SetForcedSize {
1074 id: 1,
1075 size: Some(Size::new(100, 100)),
1076 },
1077 // This cancels the resize animation since the change of 5 px is less than the resize
1078 // animation threshold.
1079 Op::Communicate(1),
1080 Op::Communicate(2),
1081 ];
1082 check_ops_on_layout(&mut layout, ops);
1083
1084 // Since the resize animation is cancelled, the width goes to the new value immediately. The X
1085 // position doesn't jump, instead the animation is restarted to preserve the current position.
1086 assert_snapshot!(format_tiles(&layout), @r"
1087 100 × 100 at x: -5 y: 0
1088 200 × 200 at x:100 y: 0
1089 ");
1090
1091 // Advance to the end of the move animation.
1092 Op::AdvanceAnimations { msec_delta: 1000 }.apply(&mut layout);
1093
1094 // Final state.
1095 assert_snapshot!(format_tiles(&layout), @r"
1096 100 × 100 at x: 0 y: 0
1097 200 × 200 at x:100 y: 0
1098 ");
1099}