forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiBa6baef7Anton Kesy10 months ago2623 commits

tests.rs3890 lines, 115.6 KiBHistoryRawDownload
1use std::cell::{Cell, OnceCell, RefCell};
2
3use niri_config::utils::{Flag, MergeWith as _};
4use niri_config::workspace::WorkspaceName;
5use niri_config::{
6 CenterFocusedColumn, FloatOrInt, OutputName, Struts, TabIndicatorLength, TabIndicatorPosition,
7 WorkspaceReference,
8};
9use proptest::prelude::*;
10use proptest_derive::Arbitrary;
11use smithay::output::{Mode, PhysicalProperties, Subpixel};
12use smithay::utils::Rectangle;
13
14use super::*;
15
16mod animations;
17mod fullscreen;
18
19impl<W: LayoutElement> Default for Layout<W> {
20 fn default() -> Self {
21 Self::with_options(Clock::with_time(Duration::ZERO), Default::default())
22 }
23}
24
25#[derive(Debug)]
26struct TestWindowInner {
27 id: usize,
28 parent_id: Cell<Option<usize>>,
29 bbox: Cell<Rectangle<i32, Logical>>,
30 initial_bbox: Rectangle<i32, Logical>,
31 requested_size: Cell<Option<Size<i32, Logical>>>,
32 // Emulates the window ignoring the compositor-provided size.
33 forced_size: Cell<Option<Size<i32, Logical>>>,
34 min_size: Size<i32, Logical>,
35 max_size: Size<i32, Logical>,
36 pending_sizing_mode: Cell<SizingMode>,
37 pending_activated: Cell<bool>,
38 sizing_mode: Cell<SizingMode>,
39 is_windowed_fullscreen: Cell<bool>,
40 is_pending_windowed_fullscreen: Cell<bool>,
41 animate_next_configure: Cell<bool>,
42 animation_snapshot: RefCell<Option<LayoutElementRenderSnapshot>>,
43 rules: ResolvedWindowRules,
44}
45
46#[derive(Debug, Clone)]
47struct TestWindow(Rc<TestWindowInner>);
48
49#[derive(Debug, Clone, Arbitrary)]
50struct TestWindowParams {
51 #[proptest(strategy = "1..=5usize")]
52 id: usize,
53 #[proptest(strategy = "arbitrary_parent_id()")]
54 parent_id: Option<usize>,
55 is_floating: bool,
56 #[proptest(strategy = "arbitrary_bbox()")]
57 bbox: Rectangle<i32, Logical>,
58 #[proptest(strategy = "arbitrary_min_max_size()")]
59 min_max_size: (Size<i32, Logical>, Size<i32, Logical>),
60 #[proptest(strategy = "prop::option::of(arbitrary_rules())")]
61 rules: Option<ResolvedWindowRules>,
62}
63
64impl TestWindowParams {
65 pub fn new(id: usize) -> Self {
66 Self {
67 id,
68 parent_id: None,
69 is_floating: false,
70 bbox: Rectangle::from_size(Size::from((100, 200))),
71 min_max_size: Default::default(),
72 rules: None,
73 }
74 }
75}
76
77impl TestWindow {
78 fn new(params: TestWindowParams) -> Self {
79 Self(Rc::new(TestWindowInner {
80 id: params.id,
81 parent_id: Cell::new(params.parent_id),
82 bbox: Cell::new(params.bbox),
83 initial_bbox: params.bbox,
84 requested_size: Cell::new(None),
85 forced_size: Cell::new(None),
86 min_size: params.min_max_size.0,
87 max_size: params.min_max_size.1,
88 pending_sizing_mode: Cell::new(SizingMode::Normal),
89 pending_activated: Cell::new(false),
90 sizing_mode: Cell::new(SizingMode::Normal),
91 is_windowed_fullscreen: Cell::new(false),
92 is_pending_windowed_fullscreen: Cell::new(false),
93 animate_next_configure: Cell::new(false),
94 animation_snapshot: RefCell::new(None),
95 rules: params.rules.unwrap_or_default(),
96 }))
97 }
98
99 fn communicate(&self) -> bool {
100 let mut changed = false;
101
102 let size = self.0.forced_size.get().or(self.0.requested_size.get());
103 if let Some(size) = size {
104 assert!(size.w >= 0);
105 assert!(size.h >= 0);
106
107 let mut new_bbox = self.0.initial_bbox;
108 if size.w != 0 {
109 new_bbox.size.w = size.w;
110 }
111 if size.h != 0 {
112 new_bbox.size.h = size.h;
113 }
114
115 if self.0.bbox.get() != new_bbox {
116 if self.0.animate_next_configure.get() {
117 self.0.animation_snapshot.replace(Some(RenderSnapshot {
118 contents: Vec::new(),
119 blocked_out_contents: Vec::new(),
120 block_out_from: None,
121 size: self.0.bbox.get().size.to_f64(),
122 texture: OnceCell::new(),
123 blocked_out_texture: OnceCell::new(),
124 }));
125 }
126
127 self.0.bbox.set(new_bbox);
128 changed = true;
129 }
130 }
131
132 self.0.animate_next_configure.set(false);
133
134 if self.0.sizing_mode.get() != self.0.pending_sizing_mode.get() {
135 self.0.sizing_mode.set(self.0.pending_sizing_mode.get());
136 changed = true;
137 }
138
139 if self.0.is_windowed_fullscreen.get() != self.0.is_pending_windowed_fullscreen.get() {
140 self.0
141 .is_windowed_fullscreen
142 .set(self.0.is_pending_windowed_fullscreen.get());
143 changed = true;
144 }
145
146 changed
147 }
148}
149
150impl LayoutElement for TestWindow {
151 type Id = usize;
152
153 fn id(&self) -> &Self::Id {
154 &self.0.id
155 }
156
157 fn size(&self) -> Size<i32, Logical> {
158 self.0.bbox.get().size
159 }
160
161 fn buf_loc(&self) -> Point<i32, Logical> {
162 (0, 0).into()
163 }
164
165 fn is_in_input_region(&self, _point: Point<f64, Logical>) -> bool {
166 false
167 }
168
169 fn request_size(
170 &mut self,
171 size: Size<i32, Logical>,
172 mode: SizingMode,
173 _animate: bool,
174 _transaction: Option<Transaction>,
175 ) {
176 if self.0.requested_size.get() != Some(size) {
177 self.0.requested_size.set(Some(size));
178 self.0.animate_next_configure.set(true);
179 }
180
181 self.0.pending_sizing_mode.set(mode);
182
183 if mode.is_fullscreen() {
184 self.0.is_pending_windowed_fullscreen.set(false);
185 }
186 }
187
188 fn min_size(&self) -> Size<i32, Logical> {
189 self.0.min_size
190 }
191
192 fn max_size(&self) -> Size<i32, Logical> {
193 self.0.max_size
194 }
195
196 fn is_wl_surface(&self, _wl_surface: &WlSurface) -> bool {
197 false
198 }
199
200 fn set_preferred_scale_transform(&self, _scale: output::Scale, _transform: Transform) {}
201
202 fn has_ssd(&self) -> bool {
203 false
204 }
205
206 fn output_enter(&self, _output: &Output) {}
207
208 fn output_leave(&self, _output: &Output) {}
209
210 fn set_offscreen_data(&self, _data: Option<OffscreenData>) {}
211
212 fn set_activated(&mut self, active: bool) {
213 self.0.pending_activated.set(active);
214 }
215
216 fn set_bounds(&self, _bounds: Size<i32, Logical>) {}
217
218 fn is_ignoring_opacity_window_rule(&self) -> bool {
219 false
220 }
221
222 fn configure_intent(&self) -> ConfigureIntent {
223 ConfigureIntent::CanSend
224 }
225
226 fn send_pending_configure(&mut self) {}
227
228 fn set_active_in_column(&mut self, _active: bool) {}
229
230 fn set_floating(&mut self, _floating: bool) {}
231
232 fn sizing_mode(&self) -> SizingMode {
233 self.0.sizing_mode.get()
234 }
235
236 fn pending_sizing_mode(&self) -> SizingMode {
237 self.0.pending_sizing_mode.get()
238 }
239
240 fn requested_size(&self) -> Option<Size<i32, Logical>> {
241 self.0.requested_size.get()
242 }
243
244 fn is_pending_windowed_fullscreen(&self) -> bool {
245 self.0.is_pending_windowed_fullscreen.get()
246 }
247
248 fn request_windowed_fullscreen(&mut self, value: bool) {
249 self.0.is_pending_windowed_fullscreen.set(value);
250 }
251
252 fn is_child_of(&self, parent: &Self) -> bool {
253 self.0.parent_id.get() == Some(parent.0.id)
254 }
255
256 fn refresh(&self) {}
257
258 fn rules(&self) -> &ResolvedWindowRules {
259 &self.0.rules
260 }
261
262 fn take_animation_snapshot(&mut self) -> Option<LayoutElementRenderSnapshot> {
263 self.0.animation_snapshot.take()
264 }
265
266 fn set_interactive_resize(&mut self, _data: Option<InteractiveResizeData>) {}
267
268 fn cancel_interactive_resize(&mut self) {}
269
270 fn on_commit(&mut self, _serial: Serial) {}
271
272 fn interactive_resize_data(&self) -> Option<InteractiveResizeData> {
273 None
274 }
275
276 fn is_urgent(&self) -> bool {
277 false
278 }
279}
280
281fn arbitrary_size() -> impl Strategy<Value = Size<i32, Logical>> {
282 any::<(u16, u16)>().prop_map(|(w, h)| Size::from((w.max(1).into(), h.max(1).into())))
283}
284
285fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> {
286 any::<(i16, i16, u16, u16)>().prop_map(|(x, y, w, h)| {
287 let loc: Point<i32, _> = Point::from((x.into(), y.into()));
288 let size: Size<i32, _> = Size::from((w.max(1).into(), h.max(1).into()));
289 Rectangle::new(loc, size)
290 })
291}
292
293fn arbitrary_size_change() -> impl Strategy<Value = SizeChange> {
294 prop_oneof![
295 (0..).prop_map(SizeChange::SetFixed),
296 (0f64..).prop_map(SizeChange::SetProportion),
297 any::<i32>().prop_map(SizeChange::AdjustFixed),
298 any::<f64>().prop_map(SizeChange::AdjustProportion),
299 // Interactive resize can have negative values here.
300 Just(SizeChange::SetFixed(-100)),
301 ]
302}
303
304fn arbitrary_position_change() -> impl Strategy<Value = PositionChange> {
305 prop_oneof![
306 (-1000f64..1000f64).prop_map(PositionChange::SetFixed),
307 any::<f64>().prop_map(PositionChange::SetProportion),
308 (-1000f64..1000f64).prop_map(PositionChange::AdjustFixed),
309 any::<f64>().prop_map(PositionChange::AdjustProportion),
310 any::<f64>().prop_map(PositionChange::SetFixed),
311 any::<f64>().prop_map(PositionChange::AdjustFixed),
312 ]
313}
314
315fn arbitrary_min_max() -> impl Strategy<Value = (i32, i32)> {
316 prop_oneof![
317 Just((0, 0)),
318 (1..65536).prop_map(|n| (n, n)),
319 (1..65536).prop_map(|min| (min, 0)),
320 (1..).prop_map(|max| (0, max)),
321 (1..65536, 1..).prop_map(|(min, max): (i32, i32)| (min, max.max(min))),
322 ]
323}
324
325fn arbitrary_min_max_size() -> impl Strategy<Value = (Size<i32, Logical>, Size<i32, Logical>)> {
326 prop_oneof![
327 5 => (arbitrary_min_max(), arbitrary_min_max()).prop_map(
328 |((min_w, max_w), (min_h, max_h))| {
329 let min_size = Size::from((min_w, min_h));
330 let max_size = Size::from((max_w, max_h));
331 (min_size, max_size)
332 },
333 ),
334 1 => arbitrary_min_max().prop_map(|(w, h)| {
335 let size = Size::from((w, h));
336 (size, size)
337 }),
338 ]
339}
340
341prop_compose! {
342 fn arbitrary_rules()(
343 focus_ring in arbitrary_focus_ring(),
344 border in arbitrary_border(),
345 ) -> ResolvedWindowRules {
346 ResolvedWindowRules {
347 focus_ring,
348 border,
349 ..ResolvedWindowRules::default()
350 }
351 }
352}
353
354fn arbitrary_view_offset_gesture_delta() -> impl Strategy<Value = f64> {
355 prop_oneof![(-10f64..10f64), (-50000f64..50000f64),]
356}
357
358fn arbitrary_resize_edge() -> impl Strategy<Value = ResizeEdge> {
359 prop_oneof![
360 Just(ResizeEdge::RIGHT),
361 Just(ResizeEdge::BOTTOM),
362 Just(ResizeEdge::LEFT),
363 Just(ResizeEdge::TOP),
364 Just(ResizeEdge::BOTTOM_RIGHT),
365 Just(ResizeEdge::BOTTOM_LEFT),
366 Just(ResizeEdge::TOP_RIGHT),
367 Just(ResizeEdge::TOP_LEFT),
368 Just(ResizeEdge::empty()),
369 ]
370}
371
372fn arbitrary_scale() -> impl Strategy<Value = f64> {
373 prop_oneof![Just(1.), Just(1.5), Just(2.),]
374}
375
376fn arbitrary_msec_delta() -> impl Strategy<Value = i32> {
377 prop_oneof![
378 1 => Just(-1000),
379 2 => Just(-10),
380 1 => Just(0),
381 2 => Just(10),
382 6 => Just(1000),
383 ]
384}
385
386fn arbitrary_parent_id() -> impl Strategy<Value = Option<usize>> {
387 prop_oneof![
388 5 => Just(None),
389 1 => prop::option::of(1..=5usize),
390 ]
391}
392
393fn arbitrary_scroll_direction() -> impl Strategy<Value = ScrollDirection> {
394 prop_oneof![Just(ScrollDirection::Left), Just(ScrollDirection::Right)]
395}
396
397fn arbitrary_column_display() -> impl Strategy<Value = ColumnDisplay> {
398 prop_oneof![Just(ColumnDisplay::Normal), Just(ColumnDisplay::Tabbed)]
399}
400
401#[derive(Debug, Clone, Arbitrary)]
402enum Op {
403 AddOutput(#[proptest(strategy = "1..=5usize")] usize),
404 AddScaledOutput {
405 #[proptest(strategy = "1..=5usize")]
406 id: usize,
407 #[proptest(strategy = "arbitrary_scale()")]
408 scale: f64,
409 #[proptest(strategy = "prop::option::of(arbitrary_layout_part().prop_map(Box::new))")]
410 layout_config: Option<Box<niri_config::LayoutPart>>,
411 },
412 RemoveOutput(#[proptest(strategy = "1..=5usize")] usize),
413 FocusOutput(#[proptest(strategy = "1..=5usize")] usize),
414 UpdateOutputLayoutConfig {
415 #[proptest(strategy = "1..=5usize")]
416 id: usize,
417 #[proptest(strategy = "prop::option::of(arbitrary_layout_part().prop_map(Box::new))")]
418 layout_config: Option<Box<niri_config::LayoutPart>>,
419 },
420 AddNamedWorkspace {
421 #[proptest(strategy = "1..=5usize")]
422 ws_name: usize,
423 #[proptest(strategy = "prop::option::of(1..=5usize)")]
424 output_name: Option<usize>,
425 #[proptest(strategy = "prop::option::of(arbitrary_layout_part().prop_map(Box::new))")]
426 layout_config: Option<Box<niri_config::LayoutPart>>,
427 },
428 UnnameWorkspace {
429 #[proptest(strategy = "1..=5usize")]
430 ws_name: usize,
431 },
432 UpdateWorkspaceLayoutConfig {
433 #[proptest(strategy = "1..=5usize")]
434 ws_name: usize,
435 #[proptest(strategy = "prop::option::of(arbitrary_layout_part().prop_map(Box::new))")]
436 layout_config: Option<Box<niri_config::LayoutPart>>,
437 },
438 AddWindow {
439 params: TestWindowParams,
440 },
441 AddWindowNextTo {
442 params: TestWindowParams,
443 #[proptest(strategy = "1..=5usize")]
444 next_to_id: usize,
445 },
446 AddWindowToNamedWorkspace {
447 params: TestWindowParams,
448 #[proptest(strategy = "1..=5usize")]
449 ws_name: usize,
450 },
451 CloseWindow(#[proptest(strategy = "1..=5usize")] usize),
452 FullscreenWindow(#[proptest(strategy = "1..=5usize")] usize),
453 SetFullscreenWindow {
454 #[proptest(strategy = "1..=5usize")]
455 window: usize,
456 is_fullscreen: bool,
457 },
458 ToggleWindowedFullscreen(#[proptest(strategy = "1..=5usize")] usize),
459 FocusColumnLeft,
460 FocusColumnRight,
461 FocusColumnFirst,
462 FocusColumnLast,
463 FocusColumnRightOrFirst,
464 FocusColumnLeftOrLast,
465 FocusColumn(#[proptest(strategy = "1..=5usize")] usize),
466 FocusWindowOrMonitorUp(#[proptest(strategy = "1..=2u8")] u8),
467 FocusWindowOrMonitorDown(#[proptest(strategy = "1..=2u8")] u8),
468 FocusColumnOrMonitorLeft(#[proptest(strategy = "1..=2u8")] u8),
469 FocusColumnOrMonitorRight(#[proptest(strategy = "1..=2u8")] u8),
470 FocusWindowDown,
471 FocusWindowUp,
472 FocusWindowDownOrColumnLeft,
473 FocusWindowDownOrColumnRight,
474 FocusWindowUpOrColumnLeft,
475 FocusWindowUpOrColumnRight,
476 FocusWindowOrWorkspaceDown,
477 FocusWindowOrWorkspaceUp,
478 FocusWindow(#[proptest(strategy = "1..=5usize")] usize),
479 FocusWindowInColumn(#[proptest(strategy = "1..=5u8")] u8),
480 FocusWindowTop,
481 FocusWindowBottom,
482 FocusWindowDownOrTop,
483 FocusWindowUpOrBottom,
484 MoveColumnLeft,
485 MoveColumnRight,
486 MoveColumnToFirst,
487 MoveColumnToLast,
488 MoveColumnLeftOrToMonitorLeft(#[proptest(strategy = "1..=2u8")] u8),
489 MoveColumnRightOrToMonitorRight(#[proptest(strategy = "1..=2u8")] u8),
490 MoveColumnToIndex(#[proptest(strategy = "1..=5usize")] usize),
491 MoveWindowDown,
492 MoveWindowUp,
493 MoveWindowDownOrToWorkspaceDown,
494 MoveWindowUpOrToWorkspaceUp,
495 ConsumeOrExpelWindowLeft {
496 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
497 id: Option<usize>,
498 },
499 ConsumeOrExpelWindowRight {
500 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
501 id: Option<usize>,
502 },
503 ConsumeWindowIntoColumn,
504 ExpelWindowFromColumn,
505 SwapWindowInDirection(#[proptest(strategy = "arbitrary_scroll_direction()")] ScrollDirection),
506 ToggleColumnTabbedDisplay,
507 SetColumnDisplay(#[proptest(strategy = "arbitrary_column_display()")] ColumnDisplay),
508 CenterColumn,
509 CenterWindow {
510 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
511 id: Option<usize>,
512 },
513 CenterVisibleColumns,
514 FocusWorkspaceDown,
515 FocusWorkspaceUp,
516 FocusWorkspace(#[proptest(strategy = "0..=4usize")] usize),
517 FocusWorkspaceAutoBackAndForth(#[proptest(strategy = "0..=4usize")] usize),
518 FocusWorkspacePrevious,
519 MoveWindowToWorkspaceDown(bool),
520 MoveWindowToWorkspaceUp(bool),
521 MoveWindowToWorkspace {
522 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
523 window_id: Option<usize>,
524 #[proptest(strategy = "0..=4usize")]
525 workspace_idx: usize,
526 },
527 MoveColumnToWorkspaceDown(bool),
528 MoveColumnToWorkspaceUp(bool),
529 MoveColumnToWorkspace(#[proptest(strategy = "0..=4usize")] usize, bool),
530 MoveWorkspaceDown,
531 MoveWorkspaceUp,
532 MoveWorkspaceToIndex {
533 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
534 ws_name: Option<usize>,
535 #[proptest(strategy = "0..=4usize")]
536 target_idx: usize,
537 },
538 MoveWorkspaceToMonitor {
539 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
540 ws_name: Option<usize>,
541 #[proptest(strategy = "0..=5usize")]
542 output_id: usize,
543 },
544 SetWorkspaceName {
545 #[proptest(strategy = "1..=5usize")]
546 new_ws_name: usize,
547 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
548 ws_name: Option<usize>,
549 },
550 UnsetWorkspaceName {
551 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
552 ws_name: Option<usize>,
553 },
554 MoveWindowToOutput {
555 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
556 window_id: Option<usize>,
557 #[proptest(strategy = "1..=5usize")]
558 output_id: usize,
559 #[proptest(strategy = "proptest::option::of(0..=4usize)")]
560 target_ws_idx: Option<usize>,
561 },
562 MoveColumnToOutput {
563 #[proptest(strategy = "1..=5usize")]
564 output_id: usize,
565 #[proptest(strategy = "proptest::option::of(0..=4usize)")]
566 target_ws_idx: Option<usize>,
567 activate: bool,
568 },
569 SwitchPresetColumnWidth,
570 SwitchPresetColumnWidthBack,
571 SwitchPresetWindowWidth {
572 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
573 id: Option<usize>,
574 },
575 SwitchPresetWindowWidthBack {
576 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
577 id: Option<usize>,
578 },
579 SwitchPresetWindowHeight {
580 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
581 id: Option<usize>,
582 },
583 SwitchPresetWindowHeightBack {
584 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
585 id: Option<usize>,
586 },
587 MaximizeColumn,
588 MaximizeWindowToEdges {
589 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
590 id: Option<usize>,
591 },
592 SetColumnWidth(#[proptest(strategy = "arbitrary_size_change()")] SizeChange),
593 SetWindowWidth {
594 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
595 id: Option<usize>,
596 #[proptest(strategy = "arbitrary_size_change()")]
597 change: SizeChange,
598 },
599 SetWindowHeight {
600 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
601 id: Option<usize>,
602 #[proptest(strategy = "arbitrary_size_change()")]
603 change: SizeChange,
604 },
605 ResetWindowHeight {
606 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
607 id: Option<usize>,
608 },
609 ExpandColumnToAvailableWidth,
610 ToggleWindowFloating {
611 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
612 id: Option<usize>,
613 },
614 SetWindowFloating {
615 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
616 id: Option<usize>,
617 floating: bool,
618 },
619 FocusFloating,
620 FocusTiling,
621 SwitchFocusFloatingTiling,
622 MoveFloatingWindow {
623 #[proptest(strategy = "proptest::option::of(1..=5usize)")]
624 id: Option<usize>,
625 #[proptest(strategy = "arbitrary_position_change()")]
626 x: PositionChange,
627 #[proptest(strategy = "arbitrary_position_change()")]
628 y: PositionChange,
629 animate: bool,
630 },
631 SetParent {
632 #[proptest(strategy = "1..=5usize")]
633 id: usize,
634 #[proptest(strategy = "prop::option::of(1..=5usize)")]
635 new_parent_id: Option<usize>,
636 },
637 SetForcedSize {
638 #[proptest(strategy = "1..=5usize")]
639 id: usize,
640 #[proptest(strategy = "proptest::option::of(arbitrary_size())")]
641 size: Option<Size<i32, Logical>>,
642 },
643 Communicate(#[proptest(strategy = "1..=5usize")] usize),
644 Refresh {
645 is_active: bool,
646 },
647 AdvanceAnimations {
648 #[proptest(strategy = "arbitrary_msec_delta()")]
649 msec_delta: i32,
650 },
651 CompleteAnimations,
652 MoveWorkspaceToOutput(#[proptest(strategy = "1..=5usize")] usize),
653 ViewOffsetGestureBegin {
654 #[proptest(strategy = "1..=5usize")]
655 output_idx: usize,
656 #[proptest(strategy = "proptest::option::of(0..=4usize)")]
657 workspace_idx: Option<usize>,
658 is_touchpad: bool,
659 },
660 ViewOffsetGestureUpdate {
661 #[proptest(strategy = "arbitrary_view_offset_gesture_delta()")]
662 delta: f64,
663 timestamp: Duration,
664 is_touchpad: bool,
665 },
666 ViewOffsetGestureEnd {
667 is_touchpad: Option<bool>,
668 },
669 WorkspaceSwitchGestureBegin {
670 #[proptest(strategy = "1..=5usize")]
671 output_idx: usize,
672 is_touchpad: bool,
673 },
674 WorkspaceSwitchGestureUpdate {
675 #[proptest(strategy = "-400f64..400f64")]
676 delta: f64,
677 timestamp: Duration,
678 is_touchpad: bool,
679 },
680 WorkspaceSwitchGestureEnd {
681 is_touchpad: Option<bool>,
682 },
683 OverviewGestureBegin,
684 OverviewGestureUpdate {
685 #[proptest(strategy = "-400f64..400f64")]
686 delta: f64,
687 timestamp: Duration,
688 },
689 OverviewGestureEnd,
690 InteractiveMoveBegin {
691 #[proptest(strategy = "1..=5usize")]
692 window: usize,
693 #[proptest(strategy = "1..=5usize")]
694 output_idx: usize,
695 #[proptest(strategy = "-20000f64..20000f64")]
696 px: f64,
697 #[proptest(strategy = "-20000f64..20000f64")]
698 py: f64,
699 },
700 InteractiveMoveUpdate {
701 #[proptest(strategy = "1..=5usize")]
702 window: usize,
703 #[proptest(strategy = "-20000f64..20000f64")]
704 dx: f64,
705 #[proptest(strategy = "-20000f64..20000f64")]
706 dy: f64,
707 #[proptest(strategy = "1..=5usize")]
708 output_idx: usize,
709 #[proptest(strategy = "-20000f64..20000f64")]
710 px: f64,
711 #[proptest(strategy = "-20000f64..20000f64")]
712 py: f64,
713 },
714 InteractiveMoveEnd {
715 #[proptest(strategy = "1..=5usize")]
716 window: usize,
717 },
718 DndUpdate {
719 #[proptest(strategy = "1..=5usize")]
720 output_idx: usize,
721 #[proptest(strategy = "-20000f64..20000f64")]
722 px: f64,
723 #[proptest(strategy = "-20000f64..20000f64")]
724 py: f64,
725 },
726 DndEnd,
727 InteractiveResizeBegin {
728 #[proptest(strategy = "1..=5usize")]
729 window: usize,
730 #[proptest(strategy = "arbitrary_resize_edge()")]
731 edges: ResizeEdge,
732 },
733 InteractiveResizeUpdate {
734 #[proptest(strategy = "1..=5usize")]
735 window: usize,
736 #[proptest(strategy = "-20000f64..20000f64")]
737 dx: f64,
738 #[proptest(strategy = "-20000f64..20000f64")]
739 dy: f64,
740 },
741 InteractiveResizeEnd {
742 #[proptest(strategy = "1..=5usize")]
743 window: usize,
744 },
745 ToggleOverview,
746 UpdateConfig {
747 #[proptest(strategy = "arbitrary_layout_part().prop_map(Box::new)")]
748 layout_config: Box<niri_config::LayoutPart>,
749 },
750}
751
752impl Op {
753 fn apply(self, layout: &mut Layout<TestWindow>) {
754 match self {
755 Op::AddOutput(id) => {
756 let name = format!("output{id}");
757 if layout.outputs().any(|o| o.name() == name) {
758 return;
759 }
760
761 let output = Output::new(
762 name.clone(),
763 PhysicalProperties {
764 size: Size::from((1280, 720)),
765 subpixel: Subpixel::Unknown,
766 make: String::new(),
767 model: String::new(),
768 serial_number: String::new(),
769 },
770 );
771 output.change_current_state(
772 Some(Mode {
773 size: Size::from((1280, 720)),
774 refresh: 60000,
775 }),
776 None,
777 None,
778 None,
779 );
780 output.user_data().insert_if_missing(|| OutputName {
781 connector: name,
782 make: None,
783 model: None,
784 serial: None,
785 });
786 layout.add_output(output.clone(), None);
787 }
788 Op::AddScaledOutput {
789 id,
790 scale,
791 layout_config,
792 } => {
793 let name = format!("output{id}");
794 if layout.outputs().any(|o| o.name() == name) {
795 return;
796 }
797
798 let output = Output::new(
799 name.clone(),
800 PhysicalProperties {
801 size: Size::from((1280, 720)),
802 subpixel: Subpixel::Unknown,
803 make: String::new(),
804 model: String::new(),
805 serial_number: String::new(),
806 },
807 );
808 output.change_current_state(
809 Some(Mode {
810 size: Size::from((1280, 720)),
811 refresh: 60000,
812 }),
813 None,
814 Some(smithay::output::Scale::Fractional(scale)),
815 None,
816 );
817 output.user_data().insert_if_missing(|| OutputName {
818 connector: name,
819 make: None,
820 model: None,
821 serial: None,
822 });
823 layout.add_output(output.clone(), layout_config.map(|x| *x));
824 }
825 Op::RemoveOutput(id) => {
826 let name = format!("output{id}");
827 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
828 return;
829 };
830
831 layout.remove_output(&output);
832 }
833 Op::FocusOutput(id) => {
834 let name = format!("output{id}");
835 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
836 return;
837 };
838
839 layout.focus_output(&output);
840 }
841 Op::UpdateOutputLayoutConfig { id, layout_config } => {
842 let name = format!("output{id}");
843 let Some(mon) = layout.monitors_mut().find(|m| m.output_name() == &name) else {
844 return;
845 };
846
847 mon.update_layout_config(layout_config.map(|x| *x));
848 }
849 Op::AddNamedWorkspace {
850 ws_name,
851 output_name,
852 layout_config,
853 } => {
854 layout.ensure_named_workspace(&WorkspaceConfig {
855 name: WorkspaceName(format!("ws{ws_name}")),
856 open_on_output: output_name.map(|name| format!("output{name}")),
857 layout: layout_config.map(|x| niri_config::WorkspaceLayoutPart(*x)),
858 });
859 }
860 Op::UnnameWorkspace { ws_name } => {
861 layout.unname_workspace(&format!("ws{ws_name}"));
862 }
863 Op::UpdateWorkspaceLayoutConfig {
864 ws_name,
865 layout_config,
866 } => {
867 let ws_name = format!("ws{ws_name}");
868 let Some(ws) = layout
869 .workspaces_mut()
870 .find(|ws| ws.name() == Some(&ws_name))
871 else {
872 return;
873 };
874
875 ws.update_layout_config(layout_config.map(|x| *x));
876 }
877 Op::SetWorkspaceName {
878 new_ws_name,
879 ws_name,
880 } => {
881 let ws_ref =
882 ws_name.map(|ws_name| WorkspaceReference::Name(format!("ws{ws_name}")));
883 layout.set_workspace_name(format!("ws{new_ws_name}"), ws_ref);
884 }
885 Op::UnsetWorkspaceName { ws_name } => {
886 let ws_ref =
887 ws_name.map(|ws_name| WorkspaceReference::Name(format!("ws{ws_name}")));
888 layout.unset_workspace_name(ws_ref);
889 }
890 Op::AddWindow { mut params } => {
891 if layout.has_window(&params.id) {
892 return;
893 }
894 if let Some(parent_id) = params.parent_id {
895 if parent_id_causes_loop(layout, params.id, parent_id) {
896 params.parent_id = None;
897 }
898 }
899
900 let is_floating = params.is_floating;
901 let win = TestWindow::new(params);
902 layout.add_window(
903 win,
904 AddWindowTarget::Auto,
905 None,
906 None,
907 false,
908 is_floating,
909 ActivateWindow::default(),
910 );
911 }
912 Op::AddWindowNextTo {
913 mut params,
914 next_to_id,
915 } => {
916 let mut found_next_to = false;
917
918 if let Some(InteractiveMoveState::Moving(move_)) = &layout.interactive_move {
919 let win_id = move_.tile.window().0.id;
920 if win_id == params.id {
921 return;
922 }
923 if win_id == next_to_id {
924 found_next_to = true;
925 }
926 }
927
928 match &mut layout.monitor_set {
929 MonitorSet::Normal { monitors, .. } => {
930 for mon in monitors {
931 for ws in &mut mon.workspaces {
932 for win in ws.windows() {
933 if win.0.id == params.id {
934 return;
935 }
936
937 if win.0.id == next_to_id {
938 found_next_to = true;
939 }
940 }
941 }
942 }
943 }
944 MonitorSet::NoOutputs { workspaces, .. } => {
945 for ws in workspaces {
946 for win in ws.windows() {
947 if win.0.id == params.id {
948 return;
949 }
950
951 if win.0.id == next_to_id {
952 found_next_to = true;
953 }
954 }
955 }
956 }
957 }
958
959 if !found_next_to {
960 return;
961 }
962
963 if let Some(parent_id) = params.parent_id {
964 if parent_id_causes_loop(layout, params.id, parent_id) {
965 params.parent_id = None;
966 }
967 }
968
969 let is_floating = params.is_floating;
970 let win = TestWindow::new(params);
971 layout.add_window(
972 win,
973 AddWindowTarget::NextTo(&next_to_id),
974 None,
975 None,
976 false,
977 is_floating,
978 ActivateWindow::default(),
979 );
980 }
981 Op::AddWindowToNamedWorkspace {
982 mut params,
983 ws_name,
984 } => {
985 let ws_name = format!("ws{ws_name}");
986 let mut ws_id = None;
987
988 if let Some(InteractiveMoveState::Moving(move_)) = &layout.interactive_move {
989 if move_.tile.window().0.id == params.id {
990 return;
991 }
992 }
993
994 match &mut layout.monitor_set {
995 MonitorSet::Normal { monitors, .. } => {
996 for mon in monitors {
997 for ws in &mut mon.workspaces {
998 for win in ws.windows() {
999 if win.0.id == params.id {
1000 return;
1001 }
1002 }
1003
1004 if ws
1005 .name
1006 .as_ref()
1007 .is_some_and(|name| name.eq_ignore_ascii_case(&ws_name))
1008 {
1009 ws_id = Some(ws.id());
1010 }
1011 }
1012 }
1013 }
1014 MonitorSet::NoOutputs { workspaces, .. } => {
1015 for ws in workspaces {
1016 for win in ws.windows() {
1017 if win.0.id == params.id {
1018 return;
1019 }
1020 }
1021
1022 if ws
1023 .name
1024 .as_ref()
1025 .is_some_and(|name| name.eq_ignore_ascii_case(&ws_name))
1026 {
1027 ws_id = Some(ws.id());
1028 }
1029 }
1030 }
1031 }
1032
1033 let Some(ws_id) = ws_id else {
1034 return;
1035 };
1036
1037 if let Some(parent_id) = params.parent_id {
1038 if parent_id_causes_loop(layout, params.id, parent_id) {
1039 params.parent_id = None;
1040 }
1041 }
1042
1043 let is_floating = params.is_floating;
1044 let win = TestWindow::new(params);
1045 layout.add_window(
1046 win,
1047 AddWindowTarget::Workspace(ws_id),
1048 None,
1049 None,
1050 false,
1051 is_floating,
1052 ActivateWindow::default(),
1053 );
1054 }
1055 Op::CloseWindow(id) => {
1056 layout.remove_window(&id, Transaction::new());
1057 }
1058 Op::FullscreenWindow(id) => {
1059 if !layout.has_window(&id) {
1060 return;
1061 }
1062 layout.toggle_fullscreen(&id);
1063 }
1064 Op::SetFullscreenWindow {
1065 window,
1066 is_fullscreen,
1067 } => {
1068 if !layout.has_window(&window) {
1069 return;
1070 }
1071 layout.set_fullscreen(&window, is_fullscreen);
1072 }
1073 Op::ToggleWindowedFullscreen(id) => {
1074 if !layout.has_window(&id) {
1075 return;
1076 }
1077 layout.toggle_windowed_fullscreen(&id);
1078 }
1079 Op::FocusColumnLeft => layout.focus_left(),
1080 Op::FocusColumnRight => layout.focus_right(),
1081 Op::FocusColumnFirst => layout.focus_column_first(),
1082 Op::FocusColumnLast => layout.focus_column_last(),
1083 Op::FocusColumnRightOrFirst => layout.focus_column_right_or_first(),
1084 Op::FocusColumnLeftOrLast => layout.focus_column_left_or_last(),
1085 Op::FocusColumn(index) => layout.focus_column(index),
1086 Op::FocusWindowOrMonitorUp(id) => {
1087 let name = format!("output{id}");
1088 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
1089 return;
1090 };
1091
1092 layout.focus_window_up_or_output(&output);
1093 }
1094 Op::FocusWindowOrMonitorDown(id) => {
1095 let name = format!("output{id}");
1096 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
1097 return;
1098 };
1099
1100 layout.focus_window_down_or_output(&output);
1101 }
1102 Op::FocusColumnOrMonitorLeft(id) => {
1103 let name = format!("output{id}");
1104 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
1105 return;
1106 };
1107
1108 layout.focus_column_left_or_output(&output);
1109 }
1110 Op::FocusColumnOrMonitorRight(id) => {
1111 let name = format!("output{id}");
1112 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
1113 return;
1114 };
1115
1116 layout.focus_column_right_or_output(&output);
1117 }
1118 Op::FocusWindowDown => layout.focus_down(),
1119 Op::FocusWindowUp => layout.focus_up(),
1120 Op::FocusWindowDownOrColumnLeft => layout.focus_down_or_left(),
1121 Op::FocusWindowDownOrColumnRight => layout.focus_down_or_right(),
1122 Op::FocusWindowUpOrColumnLeft => layout.focus_up_or_left(),
1123 Op::FocusWindowUpOrColumnRight => layout.focus_up_or_right(),
1124 Op::FocusWindowOrWorkspaceDown => layout.focus_window_or_workspace_down(),
1125 Op::FocusWindowOrWorkspaceUp => layout.focus_window_or_workspace_up(),
1126 Op::FocusWindow(id) => layout.activate_window(&id),
1127 Op::FocusWindowInColumn(index) => layout.focus_window_in_column(index),
1128 Op::FocusWindowTop => layout.focus_window_top(),
1129 Op::FocusWindowBottom => layout.focus_window_bottom(),
1130 Op::FocusWindowDownOrTop => layout.focus_window_down_or_top(),
1131 Op::FocusWindowUpOrBottom => layout.focus_window_up_or_bottom(),
1132 Op::MoveColumnLeft => layout.move_left(),
1133 Op::MoveColumnRight => layout.move_right(),
1134 Op::MoveColumnToFirst => layout.move_column_to_first(),
1135 Op::MoveColumnToLast => layout.move_column_to_last(),
1136 Op::MoveColumnLeftOrToMonitorLeft(id) => {
1137 let name = format!("output{id}");
1138 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
1139 return;
1140 };
1141
1142 layout.move_column_left_or_to_output(&output);
1143 }
1144 Op::MoveColumnRightOrToMonitorRight(id) => {
1145 let name = format!("output{id}");
1146 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
1147 return;
1148 };
1149
1150 layout.move_column_right_or_to_output(&output);
1151 }
1152 Op::MoveColumnToIndex(index) => layout.move_column_to_index(index),
1153 Op::MoveWindowDown => layout.move_down(),
1154 Op::MoveWindowUp => layout.move_up(),
1155 Op::MoveWindowDownOrToWorkspaceDown => layout.move_down_or_to_workspace_down(),
1156 Op::MoveWindowUpOrToWorkspaceUp => layout.move_up_or_to_workspace_up(),
1157 Op::ConsumeOrExpelWindowLeft { id } => {
1158 let id = id.filter(|id| layout.has_window(id));
1159 layout.consume_or_expel_window_left(id.as_ref());
1160 }
1161 Op::ConsumeOrExpelWindowRight { id } => {
1162 let id = id.filter(|id| layout.has_window(id));
1163 layout.consume_or_expel_window_right(id.as_ref());
1164 }
1165 Op::ConsumeWindowIntoColumn => layout.consume_into_column(),
1166 Op::ExpelWindowFromColumn => layout.expel_from_column(),
1167 Op::SwapWindowInDirection(direction) => layout.swap_window_in_direction(direction),
1168 Op::ToggleColumnTabbedDisplay => layout.toggle_column_tabbed_display(),
1169 Op::SetColumnDisplay(display) => layout.set_column_display(display),
1170 Op::CenterColumn => layout.center_column(),
1171 Op::CenterWindow { id } => {
1172 let id = id.filter(|id| layout.has_window(id));
1173 layout.center_window(id.as_ref());
1174 }
1175 Op::CenterVisibleColumns => layout.center_visible_columns(),
1176 Op::FocusWorkspaceDown => layout.switch_workspace_down(),
1177 Op::FocusWorkspaceUp => layout.switch_workspace_up(),
1178 Op::FocusWorkspace(idx) => layout.switch_workspace(idx),
1179 Op::FocusWorkspaceAutoBackAndForth(idx) => {
1180 layout.switch_workspace_auto_back_and_forth(idx)
1181 }
1182 Op::FocusWorkspacePrevious => layout.switch_workspace_previous(),
1183 Op::MoveWindowToWorkspaceDown(focus) => layout.move_to_workspace_down(focus),
1184 Op::MoveWindowToWorkspaceUp(focus) => layout.move_to_workspace_up(focus),
1185 Op::MoveWindowToWorkspace {
1186 window_id,
1187 workspace_idx,
1188 } => {
1189 let window_id = window_id.filter(|id| layout.has_window(id));
1190 layout.move_to_workspace(window_id.as_ref(), workspace_idx, ActivateWindow::Smart);
1191 }
1192 Op::MoveColumnToWorkspaceDown(focus) => layout.move_column_to_workspace_down(focus),
1193 Op::MoveColumnToWorkspaceUp(focus) => layout.move_column_to_workspace_up(focus),
1194 Op::MoveColumnToWorkspace(idx, focus) => layout.move_column_to_workspace(idx, focus),
1195 Op::MoveWindowToOutput {
1196 window_id,
1197 output_id: id,
1198 target_ws_idx,
1199 } => {
1200 let name = format!("output{id}");
1201 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
1202 return;
1203 };
1204 let mon = layout.monitor_for_output(&output).unwrap();
1205
1206 let window_id = window_id.filter(|id| layout.has_window(id));
1207 let target_ws_idx = target_ws_idx.filter(|idx| mon.workspaces.len() > *idx);
1208 layout.move_to_output(
1209 window_id.as_ref(),
1210 &output,
1211 target_ws_idx,
1212 ActivateWindow::Smart,
1213 );
1214 }
1215 Op::MoveColumnToOutput {
1216 output_id: id,
1217 target_ws_idx,
1218 activate,
1219 } => {
1220 let name = format!("output{id}");
1221 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
1222 return;
1223 };
1224
1225 layout.move_column_to_output(&output, target_ws_idx, activate);
1226 }
1227 Op::MoveWorkspaceDown => layout.move_workspace_down(),
1228 Op::MoveWorkspaceUp => layout.move_workspace_up(),
1229 Op::MoveWorkspaceToIndex {
1230 ws_name: Some(ws_name),
1231 target_idx,
1232 } => {
1233 let MonitorSet::Normal { monitors, .. } = &mut layout.monitor_set else {
1234 return;
1235 };
1236
1237 let Some((old_idx, old_output)) = monitors.iter().find_map(|monitor| {
1238 monitor
1239 .workspaces
1240 .iter()
1241 .enumerate()
1242 .find_map(|(i, ws)| {
1243 if ws.name == Some(format!("ws{ws_name}")) {
1244 Some(i)
1245 } else {
1246 None
1247 }
1248 })
1249 .map(|i| (i, monitor.output.clone()))
1250 }) else {
1251 return;
1252 };
1253
1254 layout.move_workspace_to_idx(Some((Some(old_output), old_idx)), target_idx)
1255 }
1256 Op::MoveWorkspaceToIndex {
1257 ws_name: None,
1258 target_idx,
1259 } => layout.move_workspace_to_idx(None, target_idx),
1260 Op::MoveWorkspaceToMonitor {
1261 ws_name: None,
1262 output_id: id,
1263 } => {
1264 let name = format!("output{id}");
1265 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
1266 return;
1267 };
1268 layout.move_workspace_to_output(&output);
1269 }
1270 Op::MoveWorkspaceToMonitor {
1271 ws_name: Some(ws_name),
1272 output_id: id,
1273 } => {
1274 let name = format!("output{id}");
1275 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
1276 return;
1277 };
1278 let MonitorSet::Normal { monitors, .. } = &mut layout.monitor_set else {
1279 return;
1280 };
1281
1282 let Some((old_idx, old_output)) = monitors.iter().find_map(|monitor| {
1283 monitor
1284 .workspaces
1285 .iter()
1286 .enumerate()
1287 .find_map(|(i, ws)| {
1288 if ws.name == Some(format!("ws{ws_name}")) {
1289 Some(i)
1290 } else {
1291 None
1292 }
1293 })
1294 .map(|i| (i, monitor.output.clone()))
1295 }) else {
1296 return;
1297 };
1298
1299 layout.move_workspace_to_output_by_id(old_idx, Some(old_output), &output);
1300 }
1301 Op::SwitchPresetColumnWidth => layout.toggle_width(true),
1302 Op::SwitchPresetColumnWidthBack => layout.toggle_width(false),
1303 Op::SwitchPresetWindowWidth { id } => {
1304 let id = id.filter(|id| layout.has_window(id));
1305 layout.toggle_window_width(id.as_ref(), true);
1306 }
1307 Op::SwitchPresetWindowWidthBack { id } => {
1308 let id = id.filter(|id| layout.has_window(id));
1309 layout.toggle_window_width(id.as_ref(), false);
1310 }
1311 Op::SwitchPresetWindowHeight { id } => {
1312 let id = id.filter(|id| layout.has_window(id));
1313 layout.toggle_window_height(id.as_ref(), true);
1314 }
1315 Op::SwitchPresetWindowHeightBack { id } => {
1316 let id = id.filter(|id| layout.has_window(id));
1317 layout.toggle_window_height(id.as_ref(), false);
1318 }
1319 Op::MaximizeColumn => layout.toggle_full_width(),
1320 Op::MaximizeWindowToEdges { id } => {
1321 let id = id.or_else(|| layout.focus().map(|win| *win.id()));
1322 let Some(id) = id else {
1323 return;
1324 };
1325 if !layout.has_window(&id) {
1326 return;
1327 }
1328 layout.toggle_maximized(&id);
1329 }
1330 Op::SetColumnWidth(change) => layout.set_column_width(change),
1331 Op::SetWindowWidth { id, change } => {
1332 let id = id.filter(|id| layout.has_window(id));
1333 layout.set_window_width(id.as_ref(), change);
1334 }
1335 Op::SetWindowHeight { id, change } => {
1336 let id = id.filter(|id| layout.has_window(id));
1337 layout.set_window_height(id.as_ref(), change);
1338 }
1339 Op::ResetWindowHeight { id } => {
1340 let id = id.filter(|id| layout.has_window(id));
1341 layout.reset_window_height(id.as_ref());
1342 }
1343 Op::ExpandColumnToAvailableWidth => layout.expand_column_to_available_width(),
1344 Op::ToggleWindowFloating { id } => {
1345 let id = id.filter(|id| layout.has_window(id));
1346 layout.toggle_window_floating(id.as_ref());
1347 }
1348 Op::SetWindowFloating { id, floating } => {
1349 let id = id.filter(|id| layout.has_window(id));
1350 layout.set_window_floating(id.as_ref(), floating);
1351 }
1352 Op::FocusFloating => {
1353 layout.focus_floating();
1354 }
1355 Op::FocusTiling => {
1356 layout.focus_tiling();
1357 }
1358 Op::SwitchFocusFloatingTiling => {
1359 layout.switch_focus_floating_tiling();
1360 }
1361 Op::MoveFloatingWindow { id, x, y, animate } => {
1362 let id = id.filter(|id| layout.has_window(id));
1363 layout.move_floating_window(id.as_ref(), x, y, animate);
1364 }
1365 Op::SetParent {
1366 id,
1367 mut new_parent_id,
1368 } => {
1369 if !layout.has_window(&id) {
1370 return;
1371 }
1372
1373 if let Some(parent_id) = new_parent_id {
1374 if parent_id_causes_loop(layout, id, parent_id) {
1375 new_parent_id = None;
1376 }
1377 }
1378
1379 let mut update = false;
1380
1381 if let Some(InteractiveMoveState::Moving(move_)) = &layout.interactive_move {
1382 if move_.tile.window().0.id == id {
1383 move_.tile.window().0.parent_id.set(new_parent_id);
1384 update = true;
1385 }
1386 }
1387
1388 match &mut layout.monitor_set {
1389 MonitorSet::Normal { monitors, .. } => {
1390 'outer: for mon in monitors {
1391 for ws in &mut mon.workspaces {
1392 for win in ws.windows() {
1393 if win.0.id == id {
1394 win.0.parent_id.set(new_parent_id);
1395 update = true;
1396 break 'outer;
1397 }
1398 }
1399 }
1400 }
1401 }
1402 MonitorSet::NoOutputs { workspaces, .. } => {
1403 'outer: for ws in workspaces {
1404 for win in ws.windows() {
1405 if win.0.id == id {
1406 win.0.parent_id.set(new_parent_id);
1407 update = true;
1408 break 'outer;
1409 }
1410 }
1411 }
1412 }
1413 }
1414
1415 if update {
1416 if let Some(new_parent_id) = new_parent_id {
1417 layout.descendants_added(&new_parent_id);
1418 }
1419 }
1420 }
1421 Op::SetForcedSize { id, size } => {
1422 for (_mon, win) in layout.windows() {
1423 if win.0.id == id {
1424 win.0.forced_size.set(size);
1425 return;
1426 }
1427 }
1428 }
1429 Op::Communicate(id) => {
1430 let mut update = false;
1431
1432 if let Some(InteractiveMoveState::Moving(move_)) = &layout.interactive_move {
1433 if move_.tile.window().0.id == id {
1434 if move_.tile.window().communicate() {
1435 update = true;
1436 }
1437
1438 if update {
1439 // FIXME: serial.
1440 layout.update_window(&id, None);
1441 }
1442 return;
1443 }
1444 }
1445
1446 match &mut layout.monitor_set {
1447 MonitorSet::Normal { monitors, .. } => {
1448 'outer: for mon in monitors {
1449 for ws in &mut mon.workspaces {
1450 for win in ws.windows() {
1451 if win.0.id == id {
1452 if win.communicate() {
1453 update = true;
1454 }
1455 break 'outer;
1456 }
1457 }
1458 }
1459 }
1460 }
1461 MonitorSet::NoOutputs { workspaces, .. } => {
1462 'outer: for ws in workspaces {
1463 for win in ws.windows() {
1464 if win.0.id == id {
1465 if win.communicate() {
1466 update = true;
1467 }
1468 break 'outer;
1469 }
1470 }
1471 }
1472 }
1473 }
1474
1475 if update {
1476 // FIXME: serial.
1477 layout.update_window(&id, None);
1478 }
1479 }
1480 Op::Refresh { is_active } => {
1481 layout.refresh(is_active);
1482 }
1483 Op::AdvanceAnimations { msec_delta } => {
1484 let mut now = layout.clock.now_unadjusted();
1485 if msec_delta >= 0 {
1486 now = now.saturating_add(Duration::from_millis(msec_delta as u64));
1487 } else {
1488 now = now.saturating_sub(Duration::from_millis(-msec_delta as u64));
1489 }
1490 layout.clock.set_unadjusted(now);
1491 layout.advance_animations();
1492 }
1493 Op::CompleteAnimations => {
1494 layout.clock.set_complete_instantly(true);
1495 layout.advance_animations();
1496 layout.clock.set_complete_instantly(false);
1497 }
1498 Op::MoveWorkspaceToOutput(id) => {
1499 let name = format!("output{id}");
1500 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
1501 return;
1502 };
1503
1504 layout.move_workspace_to_output(&output);
1505 }
1506 Op::ViewOffsetGestureBegin {
1507 output_idx: id,
1508 workspace_idx,
1509 is_touchpad: normalize,
1510 } => {
1511 let name = format!("output{id}");
1512 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
1513 return;
1514 };
1515
1516 layout.view_offset_gesture_begin(&output, workspace_idx, normalize);
1517 }
1518 Op::ViewOffsetGestureUpdate {
1519 delta,
1520 timestamp,
1521 is_touchpad,
1522 } => {
1523 layout.view_offset_gesture_update(delta, timestamp, is_touchpad);
1524 }
1525 Op::ViewOffsetGestureEnd { is_touchpad } => {
1526 layout.view_offset_gesture_end(is_touchpad);
1527 }
1528 Op::WorkspaceSwitchGestureBegin {
1529 output_idx: id,
1530 is_touchpad,
1531 } => {
1532 let name = format!("output{id}");
1533 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
1534 return;
1535 };
1536
1537 layout.workspace_switch_gesture_begin(&output, is_touchpad);
1538 }
1539 Op::WorkspaceSwitchGestureUpdate {
1540 delta,
1541 timestamp,
1542 is_touchpad,
1543 } => {
1544 layout.workspace_switch_gesture_update(delta, timestamp, is_touchpad);
1545 }
1546 Op::WorkspaceSwitchGestureEnd { is_touchpad } => {
1547 layout.workspace_switch_gesture_end(is_touchpad);
1548 }
1549 Op::OverviewGestureBegin => {
1550 layout.overview_gesture_begin();
1551 }
1552 Op::OverviewGestureUpdate { delta, timestamp } => {
1553 layout.overview_gesture_update(delta, timestamp);
1554 }
1555 Op::OverviewGestureEnd => {
1556 layout.overview_gesture_end();
1557 }
1558 Op::InteractiveMoveBegin {
1559 window,
1560 output_idx,
1561 px,
1562 py,
1563 } => {
1564 let name = format!("output{output_idx}");
1565 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
1566 return;
1567 };
1568 layout.interactive_move_begin(window, &output, Point::from((px, py)));
1569 }
1570 Op::InteractiveMoveUpdate {
1571 window,
1572 dx,
1573 dy,
1574 output_idx,
1575 px,
1576 py,
1577 } => {
1578 let name = format!("output{output_idx}");
1579 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
1580 return;
1581 };
1582 layout.interactive_move_update(
1583 &window,
1584 Point::from((dx, dy)),
1585 output,
1586 Point::from((px, py)),
1587 );
1588 }
1589 Op::InteractiveMoveEnd { window } => {
1590 layout.interactive_move_end(&window);
1591 }
1592 Op::DndUpdate { output_idx, px, py } => {
1593 let name = format!("output{output_idx}");
1594 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
1595 return;
1596 };
1597 layout.dnd_update(output, Point::from((px, py)));
1598 }
1599 Op::DndEnd => {
1600 layout.dnd_end();
1601 }
1602 Op::InteractiveResizeBegin { window, edges } => {
1603 layout.interactive_resize_begin(window, edges);
1604 }
1605 Op::InteractiveResizeUpdate { window, dx, dy } => {
1606 layout.interactive_resize_update(&window, Point::from((dx, dy)));
1607 }
1608 Op::InteractiveResizeEnd { window } => {
1609 layout.interactive_resize_end(&window);
1610 }
1611 Op::ToggleOverview => {
1612 layout.toggle_overview();
1613 }
1614 Op::UpdateConfig { layout_config } => {
1615 let options = Options {
1616 layout: niri_config::Layout::from_part(&layout_config),
1617 ..Default::default()
1618 };
1619
1620 layout.update_options(options);
1621 }
1622 }
1623 }
1624}
1625
1626#[track_caller]
1627fn check_ops_on_layout(layout: &mut Layout<TestWindow>, ops: impl IntoIterator<Item = Op>) {
1628 for op in ops {
1629 op.apply(layout);
1630 layout.verify_invariants();
1631 }
1632}
1633
1634#[track_caller]
1635fn check_ops(ops: impl IntoIterator<Item = Op>) -> Layout<TestWindow> {
1636 let mut layout = Layout::default();
1637 check_ops_on_layout(&mut layout, ops);
1638 layout
1639}
1640
1641#[track_caller]
1642fn check_ops_with_options(
1643 options: Options,
1644 ops: impl IntoIterator<Item = Op>,
1645) -> Layout<TestWindow> {
1646 let mut layout = Layout::with_options(Clock::with_time(Duration::ZERO), options);
1647 check_ops_on_layout(&mut layout, ops);
1648 layout
1649}
1650
1651#[test]
1652fn operations_dont_panic() {
1653 if std::env::var_os("RUN_SLOW_TESTS").is_none() {
1654 eprintln!("ignoring slow test");
1655 return;
1656 }
1657
1658 let every_op = [
1659 Op::AddOutput(0),
1660 Op::AddOutput(1),
1661 Op::AddOutput(2),
1662 Op::RemoveOutput(0),
1663 Op::RemoveOutput(1),
1664 Op::RemoveOutput(2),
1665 Op::FocusOutput(0),
1666 Op::FocusOutput(1),
1667 Op::FocusOutput(2),
1668 Op::AddNamedWorkspace {
1669 ws_name: 1,
1670 output_name: Some(1),
1671 layout_config: None,
1672 },
1673 Op::UnnameWorkspace { ws_name: 1 },
1674 Op::AddWindow {
1675 params: TestWindowParams::new(0),
1676 },
1677 Op::AddWindow {
1678 params: TestWindowParams::new(1),
1679 },
1680 Op::AddWindowNextTo {
1681 params: TestWindowParams::new(2),
1682 next_to_id: 1,
1683 },
1684 Op::AddWindowToNamedWorkspace {
1685 params: TestWindowParams::new(3),
1686 ws_name: 1,
1687 },
1688 Op::CloseWindow(0),
1689 Op::CloseWindow(1),
1690 Op::CloseWindow(2),
1691 Op::FullscreenWindow(1),
1692 Op::FullscreenWindow(2),
1693 Op::FullscreenWindow(3),
1694 Op::MaximizeWindowToEdges { id: Some(1) },
1695 Op::MaximizeWindowToEdges { id: Some(2) },
1696 Op::MaximizeWindowToEdges { id: Some(3) },
1697 Op::FocusColumnLeft,
1698 Op::FocusColumnRight,
1699 Op::FocusColumnRightOrFirst,
1700 Op::FocusColumnLeftOrLast,
1701 Op::FocusWindowOrMonitorUp(0),
1702 Op::FocusWindowOrMonitorDown(1),
1703 Op::FocusColumnOrMonitorLeft(0),
1704 Op::FocusColumnOrMonitorRight(1),
1705 Op::FocusWindowUp,
1706 Op::FocusWindowUpOrColumnLeft,
1707 Op::FocusWindowUpOrColumnRight,
1708 Op::FocusWindowOrWorkspaceUp,
1709 Op::FocusWindowDown,
1710 Op::FocusWindowDownOrColumnLeft,
1711 Op::FocusWindowDownOrColumnRight,
1712 Op::FocusWindowOrWorkspaceDown,
1713 Op::MoveColumnLeft,
1714 Op::MoveColumnRight,
1715 Op::MoveColumnLeftOrToMonitorLeft(0),
1716 Op::MoveColumnRightOrToMonitorRight(1),
1717 Op::ConsumeWindowIntoColumn,
1718 Op::ExpelWindowFromColumn,
1719 Op::CenterColumn,
1720 Op::FocusWorkspaceDown,
1721 Op::FocusWorkspaceUp,
1722 Op::FocusWorkspace(1),
1723 Op::FocusWorkspace(2),
1724 Op::MoveWindowToWorkspaceDown(true),
1725 Op::MoveWindowToWorkspaceUp(true),
1726 Op::MoveWindowToWorkspace {
1727 window_id: None,
1728 workspace_idx: 1,
1729 },
1730 Op::MoveWindowToWorkspace {
1731 window_id: None,
1732 workspace_idx: 2,
1733 },
1734 Op::MoveColumnToWorkspaceDown(true),
1735 Op::MoveColumnToWorkspaceUp(true),
1736 Op::MoveColumnToWorkspace(1, true),
1737 Op::MoveColumnToWorkspace(2, true),
1738 Op::MoveWindowDown,
1739 Op::MoveWindowDownOrToWorkspaceDown,
1740 Op::MoveWindowUp,
1741 Op::MoveWindowUpOrToWorkspaceUp,
1742 Op::ConsumeOrExpelWindowLeft { id: None },
1743 Op::ConsumeOrExpelWindowRight { id: None },
1744 Op::MoveWorkspaceToOutput(1),
1745 Op::ToggleColumnTabbedDisplay,
1746 ];
1747
1748 for third in &every_op {
1749 for second in &every_op {
1750 for first in &every_op {
1751 // eprintln!("{first:?}, {second:?}, {third:?}");
1752
1753 let mut layout = Layout::default();
1754 first.clone().apply(&mut layout);
1755 layout.verify_invariants();
1756 second.clone().apply(&mut layout);
1757 layout.verify_invariants();
1758 third.clone().apply(&mut layout);
1759 layout.verify_invariants();
1760 }
1761 }
1762 }
1763}
1764
1765#[test]
1766fn operations_from_starting_state_dont_panic() {
1767 if std::env::var_os("RUN_SLOW_TESTS").is_none() {
1768 eprintln!("ignoring slow test");
1769 return;
1770 }
1771
1772 // Running every op from an empty state doesn't get us to all the interesting states. So,
1773 // also run it from a manually-created starting state with more things going on to exercise
1774 // more code paths.
1775 let setup_ops = [
1776 Op::AddOutput(1),
1777 Op::AddWindow {
1778 params: TestWindowParams::new(1),
1779 },
1780 Op::MoveWindowToWorkspaceDown(true),
1781 Op::AddWindow {
1782 params: TestWindowParams::new(2),
1783 },
1784 Op::AddWindow {
1785 params: TestWindowParams::new(3),
1786 },
1787 Op::FocusColumnLeft,
1788 Op::ConsumeWindowIntoColumn,
1789 Op::AddWindow {
1790 params: TestWindowParams::new(4),
1791 },
1792 Op::AddOutput(2),
1793 Op::AddWindow {
1794 params: TestWindowParams::new(5),
1795 },
1796 Op::MoveWindowToOutput {
1797 window_id: None,
1798 output_id: 2,
1799 target_ws_idx: None,
1800 },
1801 Op::FocusOutput(1),
1802 Op::Communicate(1),
1803 Op::Communicate(2),
1804 Op::Communicate(3),
1805 Op::Communicate(4),
1806 Op::Communicate(5),
1807 ];
1808
1809 let every_op = [
1810 Op::AddOutput(0),
1811 Op::AddOutput(1),
1812 Op::AddOutput(2),
1813 Op::RemoveOutput(0),
1814 Op::RemoveOutput(1),
1815 Op::RemoveOutput(2),
1816 Op::FocusOutput(0),
1817 Op::FocusOutput(1),
1818 Op::FocusOutput(2),
1819 Op::AddNamedWorkspace {
1820 ws_name: 1,
1821 output_name: Some(1),
1822 layout_config: None,
1823 },
1824 Op::UnnameWorkspace { ws_name: 1 },
1825 Op::AddWindow {
1826 params: TestWindowParams::new(0),
1827 },
1828 Op::AddWindow {
1829 params: TestWindowParams::new(1),
1830 },
1831 Op::AddWindow {
1832 params: TestWindowParams::new(2),
1833 },
1834 Op::AddWindowNextTo {
1835 params: TestWindowParams::new(6),
1836 next_to_id: 0,
1837 },
1838 Op::AddWindowNextTo {
1839 params: TestWindowParams::new(7),
1840 next_to_id: 1,
1841 },
1842 Op::AddWindowToNamedWorkspace {
1843 params: TestWindowParams::new(5),
1844 ws_name: 1,
1845 },
1846 Op::CloseWindow(0),
1847 Op::CloseWindow(1),
1848 Op::CloseWindow(2),
1849 Op::FullscreenWindow(1),
1850 Op::FullscreenWindow(2),
1851 Op::FullscreenWindow(3),
1852 Op::MaximizeWindowToEdges { id: Some(1) },
1853 Op::MaximizeWindowToEdges { id: Some(2) },
1854 Op::MaximizeWindowToEdges { id: Some(3) },
1855 Op::SetFullscreenWindow {
1856 window: 1,
1857 is_fullscreen: false,
1858 },
1859 Op::SetFullscreenWindow {
1860 window: 1,
1861 is_fullscreen: true,
1862 },
1863 Op::SetFullscreenWindow {
1864 window: 2,
1865 is_fullscreen: false,
1866 },
1867 Op::SetFullscreenWindow {
1868 window: 2,
1869 is_fullscreen: true,
1870 },
1871 Op::FocusColumnLeft,
1872 Op::FocusColumnRight,
1873 Op::FocusColumnRightOrFirst,
1874 Op::FocusColumnLeftOrLast,
1875 Op::FocusWindowOrMonitorUp(0),
1876 Op::FocusWindowOrMonitorDown(1),
1877 Op::FocusColumnOrMonitorLeft(0),
1878 Op::FocusColumnOrMonitorRight(1),
1879 Op::FocusWindowUp,
1880 Op::FocusWindowUpOrColumnLeft,
1881 Op::FocusWindowUpOrColumnRight,
1882 Op::FocusWindowOrWorkspaceUp,
1883 Op::FocusWindowDown,
1884 Op::FocusWindowDownOrColumnLeft,
1885 Op::FocusWindowDownOrColumnRight,
1886 Op::FocusWindowOrWorkspaceDown,
1887 Op::MoveColumnLeft,
1888 Op::MoveColumnRight,
1889 Op::MoveColumnLeftOrToMonitorLeft(0),
1890 Op::MoveColumnRightOrToMonitorRight(1),
1891 Op::ConsumeWindowIntoColumn,
1892 Op::ExpelWindowFromColumn,
1893 Op::CenterColumn,
1894 Op::FocusWorkspaceDown,
1895 Op::FocusWorkspaceUp,
1896 Op::FocusWorkspace(1),
1897 Op::FocusWorkspace(2),
1898 Op::FocusWorkspace(3),
1899 Op::MoveWindowToWorkspaceDown(true),
1900 Op::MoveWindowToWorkspaceUp(true),
1901 Op::MoveWindowToWorkspace {
1902 window_id: None,
1903 workspace_idx: 1,
1904 },
1905 Op::MoveWindowToWorkspace {
1906 window_id: None,
1907 workspace_idx: 2,
1908 },
1909 Op::MoveWindowToWorkspace {
1910 window_id: None,
1911 workspace_idx: 3,
1912 },
1913 Op::MoveColumnToWorkspaceDown(true),
1914 Op::MoveColumnToWorkspaceUp(true),
1915 Op::MoveColumnToWorkspace(1, true),
1916 Op::MoveColumnToWorkspace(2, true),
1917 Op::MoveColumnToWorkspace(3, true),
1918 Op::MoveWindowDown,
1919 Op::MoveWindowDownOrToWorkspaceDown,
1920 Op::MoveWindowUp,
1921 Op::MoveWindowUpOrToWorkspaceUp,
1922 Op::ConsumeOrExpelWindowLeft { id: None },
1923 Op::ConsumeOrExpelWindowRight { id: None },
1924 Op::ToggleColumnTabbedDisplay,
1925 ];
1926
1927 for third in &every_op {
1928 for second in &every_op {
1929 for first in &every_op {
1930 // eprintln!("{first:?}, {second:?}, {third:?}");
1931
1932 let mut layout = Layout::default();
1933 for op in &setup_ops {
1934 op.clone().apply(&mut layout);
1935 }
1936
1937 let mut layout = Layout::default();
1938 first.clone().apply(&mut layout);
1939 layout.verify_invariants();
1940 second.clone().apply(&mut layout);
1941 layout.verify_invariants();
1942 third.clone().apply(&mut layout);
1943 layout.verify_invariants();
1944 }
1945 }
1946 }
1947}
1948
1949#[test]
1950fn primary_active_workspace_idx_not_updated_on_output_add() {
1951 let ops = [
1952 Op::AddOutput(1),
1953 Op::AddOutput(2),
1954 Op::FocusOutput(1),
1955 Op::AddWindow {
1956 params: TestWindowParams::new(0),
1957 },
1958 Op::FocusOutput(2),
1959 Op::AddWindow {
1960 params: TestWindowParams::new(1),
1961 },
1962 Op::RemoveOutput(2),
1963 Op::FocusWorkspace(3),
1964 Op::AddOutput(2),
1965 ];
1966
1967 check_ops(ops);
1968}
1969
1970#[test]
1971fn window_closed_on_previous_workspace() {
1972 let ops = [
1973 Op::AddOutput(1),
1974 Op::AddWindow {
1975 params: TestWindowParams::new(0),
1976 },
1977 Op::FocusWorkspaceDown,
1978 Op::CloseWindow(0),
1979 ];
1980
1981 check_ops(ops);
1982}
1983
1984#[test]
1985fn removing_output_must_keep_empty_focus_on_primary() {
1986 let ops = [
1987 Op::AddOutput(1),
1988 Op::AddWindow {
1989 params: TestWindowParams::new(0),
1990 },
1991 Op::AddOutput(2),
1992 Op::RemoveOutput(1),
1993 ];
1994
1995 let layout = check_ops(ops);
1996
1997 let MonitorSet::Normal { monitors, .. } = layout.monitor_set else {
1998 unreachable!()
1999 };
2000
2001 // The workspace from the removed output was inserted at position 0, so the active workspace
2002 // must change to 1 to keep the focus on the empty workspace.
2003 assert_eq!(monitors[0].active_workspace_idx, 1);
2004}
2005
2006#[test]
2007fn move_to_workspace_by_idx_does_not_leave_empty_workspaces() {
2008 let ops = [
2009 Op::AddOutput(1),
2010 Op::AddWindow {
2011 params: TestWindowParams::new(0),
2012 },
2013 Op::AddOutput(2),
2014 Op::FocusOutput(2),
2015 Op::AddWindow {
2016 params: TestWindowParams::new(1),
2017 },
2018 Op::RemoveOutput(1),
2019 Op::MoveWindowToWorkspace {
2020 window_id: Some(0),
2021 workspace_idx: 2,
2022 },
2023 ];
2024
2025 let layout = check_ops(ops);
2026
2027 let MonitorSet::Normal { monitors, .. } = layout.monitor_set else {
2028 unreachable!()
2029 };
2030
2031 assert!(monitors[0].workspaces[1].has_windows());
2032}
2033
2034#[test]
2035fn empty_workspaces_dont_move_back_to_original_output() {
2036 let ops = [
2037 Op::AddOutput(1),
2038 Op::AddWindow {
2039 params: TestWindowParams::new(1),
2040 },
2041 Op::FocusWorkspaceDown,
2042 Op::AddWindow {
2043 params: TestWindowParams::new(2),
2044 },
2045 Op::AddOutput(2),
2046 Op::RemoveOutput(1),
2047 Op::FocusWorkspace(1),
2048 Op::CloseWindow(1),
2049 Op::AddOutput(1),
2050 ];
2051
2052 check_ops(ops);
2053}
2054
2055#[test]
2056fn named_workspaces_dont_update_original_output_on_adding_window() {
2057 let ops = [
2058 Op::AddOutput(1),
2059 Op::SetWorkspaceName {
2060 new_ws_name: 1,
2061 ws_name: None,
2062 },
2063 Op::AddOutput(2),
2064 Op::RemoveOutput(1),
2065 Op::FocusWorkspaceUp,
2066 // Adding a window updates the original output for unnamed workspaces.
2067 Op::AddWindow {
2068 params: TestWindowParams::new(1),
2069 },
2070 // Connecting the previous output should move the named workspace back since its
2071 // original output wasn't updated.
2072 Op::AddOutput(1),
2073 ];
2074
2075 let layout = check_ops(ops);
2076 let (mon, _, ws) = layout
2077 .workspaces()
2078 .find(|(_, _, ws)| ws.name().is_some())
2079 .unwrap();
2080 assert!(ws.name().is_some()); // Sanity check.
2081 let mon = mon.unwrap();
2082 assert_eq!(mon.output_name(), "output1");
2083}
2084
2085#[test]
2086fn workspaces_update_original_output_on_moving_to_same_output() {
2087 let ops = [
2088 Op::AddOutput(1),
2089 Op::SetWorkspaceName {
2090 new_ws_name: 1,
2091 ws_name: None,
2092 },
2093 Op::AddOutput(2),
2094 Op::RemoveOutput(1),
2095 Op::FocusWorkspaceUp,
2096 Op::MoveWorkspaceToOutput(2),
2097 Op::AddOutput(1),
2098 ];
2099
2100 let layout = check_ops(ops);
2101 let (mon, _, ws) = layout
2102 .workspaces()
2103 .find(|(_, _, ws)| ws.name().is_some())
2104 .unwrap();
2105 assert!(ws.name().is_some()); // Sanity check.
2106 let mon = mon.unwrap();
2107 assert_eq!(mon.output_name(), "output2");
2108}
2109
2110#[test]
2111fn workspaces_update_original_output_on_moving_to_same_monitor() {
2112 let ops = [
2113 Op::AddOutput(1),
2114 Op::SetWorkspaceName {
2115 new_ws_name: 1,
2116 ws_name: None,
2117 },
2118 Op::AddOutput(2),
2119 Op::RemoveOutput(1),
2120 Op::FocusWorkspaceUp,
2121 Op::MoveWorkspaceToMonitor {
2122 ws_name: Some(1),
2123 output_id: 2,
2124 },
2125 Op::AddOutput(1),
2126 ];
2127
2128 let layout = check_ops(ops);
2129 let (mon, _, ws) = layout
2130 .workspaces()
2131 .find(|(_, _, ws)| ws.name().is_some())
2132 .unwrap();
2133 assert!(ws.name().is_some()); // Sanity check.
2134 let mon = mon.unwrap();
2135 assert_eq!(mon.output_name(), "output2");
2136}
2137
2138#[test]
2139fn large_negative_height_change() {
2140 let ops = [
2141 Op::AddOutput(1),
2142 Op::AddWindow {
2143 params: TestWindowParams::new(1),
2144 },
2145 Op::SetWindowHeight {
2146 id: None,
2147 change: SizeChange::AdjustProportion(-1e129),
2148 },
2149 ];
2150
2151 let mut options = Options::default();
2152 options.layout.border.off = false;
2153 options.layout.border.width = 1.;
2154
2155 check_ops_with_options(options, ops);
2156}
2157
2158#[test]
2159fn large_max_size() {
2160 let ops = [
2161 Op::AddOutput(1),
2162 Op::AddWindow {
2163 params: TestWindowParams {
2164 min_max_size: (Size::from((0, 0)), Size::from((i32::MAX, i32::MAX))),
2165 ..TestWindowParams::new(1)
2166 },
2167 },
2168 ];
2169
2170 let mut options = Options::default();
2171 options.layout.border.off = false;
2172 options.layout.border.width = 1.;
2173
2174 check_ops_with_options(options, ops);
2175}
2176
2177#[test]
2178fn workspace_cleanup_during_switch() {
2179 let ops = [
2180 Op::AddOutput(1),
2181 Op::AddWindow {
2182 params: TestWindowParams::new(1),
2183 },
2184 Op::FocusWorkspaceDown,
2185 Op::CloseWindow(1),
2186 ];
2187
2188 check_ops(ops);
2189}
2190
2191#[test]
2192fn workspace_transfer_during_switch() {
2193 let ops = [
2194 Op::AddOutput(1),
2195 Op::AddWindow {
2196 params: TestWindowParams::new(1),
2197 },
2198 Op::AddOutput(2),
2199 Op::FocusOutput(2),
2200 Op::AddWindow {
2201 params: TestWindowParams::new(2),
2202 },
2203 Op::RemoveOutput(1),
2204 Op::FocusWorkspaceDown,
2205 Op::FocusWorkspaceDown,
2206 Op::AddOutput(1),
2207 ];
2208
2209 check_ops(ops);
2210}
2211
2212#[test]
2213fn workspace_transfer_during_switch_from_last() {
2214 let ops = [
2215 Op::AddOutput(1),
2216 Op::AddWindow {
2217 params: TestWindowParams::new(1),
2218 },
2219 Op::AddOutput(2),
2220 Op::RemoveOutput(1),
2221 Op::FocusWorkspaceUp,
2222 Op::AddOutput(1),
2223 ];
2224
2225 check_ops(ops);
2226}
2227
2228#[test]
2229fn workspace_transfer_during_switch_gets_cleaned_up() {
2230 let ops = [
2231 Op::AddOutput(1),
2232 Op::AddWindow {
2233 params: TestWindowParams::new(1),
2234 },
2235 Op::RemoveOutput(1),
2236 Op::AddOutput(2),
2237 Op::MoveColumnToWorkspaceDown(true),
2238 Op::MoveColumnToWorkspaceDown(true),
2239 Op::AddOutput(1),
2240 ];
2241
2242 check_ops(ops);
2243}
2244
2245#[test]
2246fn move_workspace_to_output() {
2247 let ops = [
2248 Op::AddOutput(1),
2249 Op::AddOutput(2),
2250 Op::FocusOutput(1),
2251 Op::AddWindow {
2252 params: TestWindowParams::new(0),
2253 },
2254 Op::MoveWorkspaceToOutput(2),
2255 ];
2256
2257 let layout = check_ops(ops);
2258
2259 let MonitorSet::Normal {
2260 monitors,
2261 active_monitor_idx,
2262 ..
2263 } = layout.monitor_set
2264 else {
2265 unreachable!()
2266 };
2267
2268 assert_eq!(active_monitor_idx, 1);
2269 assert_eq!(monitors[0].workspaces.len(), 1);
2270 assert!(!monitors[0].workspaces[0].has_windows());
2271 assert_eq!(monitors[1].active_workspace_idx, 0);
2272 assert_eq!(monitors[1].workspaces.len(), 2);
2273 assert!(monitors[1].workspaces[0].has_windows());
2274}
2275
2276#[test]
2277fn open_right_of_on_different_workspace() {
2278 let ops = [
2279 Op::AddOutput(1),
2280 Op::AddWindow {
2281 params: TestWindowParams::new(1),
2282 },
2283 Op::FocusWorkspaceDown,
2284 Op::AddWindow {
2285 params: TestWindowParams::new(2),
2286 },
2287 Op::AddWindowNextTo {
2288 params: TestWindowParams::new(3),
2289 next_to_id: 1,
2290 },
2291 ];
2292
2293 let layout = check_ops(ops);
2294
2295 let MonitorSet::Normal { monitors, .. } = layout.monitor_set else {
2296 unreachable!()
2297 };
2298
2299 let mon = monitors.into_iter().next().unwrap();
2300 assert_eq!(
2301 mon.active_workspace_idx, 1,
2302 "the second workspace must remain active"
2303 );
2304 assert_eq!(
2305 mon.workspaces[0].scrolling().active_column_idx(),
2306 1,
2307 "the new window must become active"
2308 );
2309}
2310
2311#[test]
2312// empty_workspace_above_first = true
2313fn open_right_of_on_different_workspace_ewaf() {
2314 let ops = [
2315 Op::AddOutput(1),
2316 Op::AddWindow {
2317 params: TestWindowParams::new(1),
2318 },
2319 Op::FocusWorkspaceDown,
2320 Op::AddWindow {
2321 params: TestWindowParams::new(2),
2322 },
2323 Op::AddWindowNextTo {
2324 params: TestWindowParams::new(3),
2325 next_to_id: 1,
2326 },
2327 ];
2328
2329 let options = Options {
2330 layout: niri_config::Layout {
2331 empty_workspace_above_first: true,
2332 ..Default::default()
2333 },
2334 ..Default::default()
2335 };
2336 let layout = check_ops_with_options(options, ops);
2337
2338 let MonitorSet::Normal { monitors, .. } = layout.monitor_set else {
2339 unreachable!()
2340 };
2341
2342 let mon = monitors.into_iter().next().unwrap();
2343 assert_eq!(
2344 mon.active_workspace_idx, 2,
2345 "the second workspace must remain active"
2346 );
2347 assert_eq!(
2348 mon.workspaces[1].scrolling().active_column_idx(),
2349 1,
2350 "the new window must become active"
2351 );
2352}
2353
2354#[test]
2355fn removing_all_outputs_preserves_empty_named_workspaces() {
2356 let ops = [
2357 Op::AddOutput(1),
2358 Op::AddNamedWorkspace {
2359 ws_name: 1,
2360 output_name: None,
2361 layout_config: None,
2362 },
2363 Op::AddNamedWorkspace {
2364 ws_name: 2,
2365 output_name: None,
2366 layout_config: None,
2367 },
2368 Op::RemoveOutput(1),
2369 ];
2370
2371 let layout = check_ops(ops);
2372
2373 let MonitorSet::NoOutputs { workspaces } = layout.monitor_set else {
2374 unreachable!()
2375 };
2376
2377 assert_eq!(workspaces.len(), 2);
2378}
2379
2380#[test]
2381fn config_change_updates_cached_sizes() {
2382 let mut config = Config::default();
2383 let border = &mut config.layout.border;
2384 border.off = false;
2385 border.width = 2.;
2386
2387 let mut layout = Layout::new(Clock::default(), &config);
2388
2389 Op::AddWindow {
2390 params: TestWindowParams {
2391 bbox: Rectangle::from_size(Size::from((1280, 200))),
2392 ..TestWindowParams::new(1)
2393 },
2394 }
2395 .apply(&mut layout);
2396
2397 config.layout.border.width = 4.;
2398 layout.update_config(&config);
2399
2400 layout.verify_invariants();
2401}
2402
2403#[test]
2404fn preset_height_change_removes_preset() {
2405 let mut config = Config::default();
2406 config.layout.preset_window_heights = vec![PresetSize::Fixed(1), PresetSize::Fixed(2)];
2407
2408 let mut layout = Layout::new(Clock::default(), &config);
2409
2410 let ops = [
2411 Op::AddOutput(1),
2412 Op::AddWindow {
2413 params: TestWindowParams::new(1),
2414 },
2415 Op::AddWindow {
2416 params: TestWindowParams::new(2),
2417 },
2418 Op::ConsumeOrExpelWindowLeft { id: None },
2419 Op::SwitchPresetWindowHeight { id: None },
2420 Op::SwitchPresetWindowHeight { id: None },
2421 ];
2422 for op in ops {
2423 op.apply(&mut layout);
2424 }
2425
2426 // Leave only one.
2427 config.layout.preset_window_heights = vec![PresetSize::Fixed(1)];
2428
2429 layout.update_config(&config);
2430
2431 layout.verify_invariants();
2432}
2433
2434#[test]
2435fn set_window_height_recomputes_to_auto() {
2436 let ops = [
2437 Op::AddOutput(1),
2438 Op::AddWindow {
2439 params: TestWindowParams::new(0),
2440 },
2441 Op::AddWindow {
2442 params: TestWindowParams::new(1),
2443 },
2444 Op::ConsumeOrExpelWindowLeft { id: None },
2445 Op::AddWindow {
2446 params: TestWindowParams::new(2),
2447 },
2448 Op::ConsumeOrExpelWindowLeft { id: None },
2449 Op::SetWindowHeight {
2450 id: None,
2451 change: SizeChange::SetFixed(100),
2452 },
2453 Op::FocusWindowUp,
2454 Op::SetWindowHeight {
2455 id: None,
2456 change: SizeChange::SetFixed(200),
2457 },
2458 ];
2459
2460 check_ops(ops);
2461}
2462
2463#[test]
2464fn one_window_in_column_becomes_weight_1() {
2465 let ops = [
2466 Op::AddOutput(1),
2467 Op::AddWindow {
2468 params: TestWindowParams::new(0),
2469 },
2470 Op::AddWindow {
2471 params: TestWindowParams::new(1),
2472 },
2473 Op::ConsumeOrExpelWindowLeft { id: None },
2474 Op::AddWindow {
2475 params: TestWindowParams::new(2),
2476 },
2477 Op::ConsumeOrExpelWindowLeft { id: None },
2478 Op::SetWindowHeight {
2479 id: None,
2480 change: SizeChange::SetFixed(100),
2481 },
2482 Op::Communicate(2),
2483 Op::FocusWindowUp,
2484 Op::SetWindowHeight {
2485 id: None,
2486 change: SizeChange::SetFixed(200),
2487 },
2488 Op::Communicate(1),
2489 Op::CloseWindow(0),
2490 Op::CloseWindow(1),
2491 ];
2492
2493 check_ops(ops);
2494}
2495
2496#[test]
2497fn fixed_height_takes_max_non_auto_into_account() {
2498 let ops = [
2499 Op::AddOutput(1),
2500 Op::AddWindow {
2501 params: TestWindowParams::new(0),
2502 },
2503 Op::SetWindowHeight {
2504 id: Some(0),
2505 change: SizeChange::SetFixed(704),
2506 },
2507 Op::AddWindow {
2508 params: TestWindowParams::new(1),
2509 },
2510 Op::ConsumeOrExpelWindowLeft { id: None },
2511 ];
2512
2513 let options = Options {
2514 layout: niri_config::Layout {
2515 border: niri_config::Border {
2516 off: false,
2517 width: 4.,
2518 ..Default::default()
2519 },
2520 gaps: 0.,
2521 ..Default::default()
2522 },
2523 ..Default::default()
2524 };
2525 check_ops_with_options(options, ops);
2526}
2527
2528#[test]
2529fn start_interactive_move_then_remove_window() {
2530 let ops = [
2531 Op::AddOutput(1),
2532 Op::AddWindow {
2533 params: TestWindowParams::new(0),
2534 },
2535 Op::InteractiveMoveBegin {
2536 window: 0,
2537 output_idx: 1,
2538 px: 0.,
2539 py: 0.,
2540 },
2541 Op::CloseWindow(0),
2542 ];
2543
2544 check_ops(ops);
2545}
2546
2547#[test]
2548fn interactive_move_onto_empty_output() {
2549 let ops = [
2550 Op::AddOutput(1),
2551 Op::AddWindow {
2552 params: TestWindowParams::new(0),
2553 },
2554 Op::InteractiveMoveBegin {
2555 window: 0,
2556 output_idx: 1,
2557 px: 0.,
2558 py: 0.,
2559 },
2560 Op::AddOutput(2),
2561 Op::InteractiveMoveUpdate {
2562 window: 0,
2563 dx: 1000.,
2564 dy: 0.,
2565 output_idx: 2,
2566 px: 0.,
2567 py: 0.,
2568 },
2569 Op::InteractiveMoveEnd { window: 0 },
2570 ];
2571
2572 check_ops(ops);
2573}
2574
2575#[test]
2576fn interactive_move_onto_empty_output_ewaf() {
2577 let ops = [
2578 Op::AddOutput(1),
2579 Op::AddWindow {
2580 params: TestWindowParams::new(0),
2581 },
2582 Op::InteractiveMoveBegin {
2583 window: 0,
2584 output_idx: 1,
2585 px: 0.,
2586 py: 0.,
2587 },
2588 Op::AddOutput(2),
2589 Op::InteractiveMoveUpdate {
2590 window: 0,
2591 dx: 1000.,
2592 dy: 0.,
2593 output_idx: 2,
2594 px: 0.,
2595 py: 0.,
2596 },
2597 Op::InteractiveMoveEnd { window: 0 },
2598 ];
2599
2600 let options = Options {
2601 layout: niri_config::Layout {
2602 empty_workspace_above_first: true,
2603 ..Default::default()
2604 },
2605 ..Default::default()
2606 };
2607 check_ops_with_options(options, ops);
2608}
2609
2610#[test]
2611fn interactive_move_onto_last_workspace() {
2612 let ops = [
2613 Op::AddOutput(1),
2614 Op::AddWindow {
2615 params: TestWindowParams::new(0),
2616 },
2617 Op::InteractiveMoveBegin {
2618 window: 0,
2619 output_idx: 1,
2620 px: 0.,
2621 py: 0.,
2622 },
2623 Op::InteractiveMoveUpdate {
2624 window: 0,
2625 dx: 1000.,
2626 dy: 0.,
2627 output_idx: 1,
2628 px: 0.,
2629 py: 0.,
2630 },
2631 Op::FocusWorkspaceDown,
2632 Op::AdvanceAnimations { msec_delta: 1000 },
2633 Op::InteractiveMoveEnd { window: 0 },
2634 ];
2635
2636 check_ops(ops);
2637}
2638
2639#[test]
2640fn interactive_move_onto_first_empty_workspace() {
2641 let ops = [
2642 Op::AddOutput(1),
2643 Op::AddWindow {
2644 params: TestWindowParams::new(1),
2645 },
2646 Op::InteractiveMoveBegin {
2647 window: 1,
2648 output_idx: 1,
2649 px: 0.,
2650 py: 0.,
2651 },
2652 Op::InteractiveMoveUpdate {
2653 window: 1,
2654 dx: 1000.,
2655 dy: 0.,
2656 output_idx: 1,
2657 px: 0.,
2658 py: 0.,
2659 },
2660 Op::FocusWorkspaceUp,
2661 Op::AdvanceAnimations { msec_delta: 1000 },
2662 Op::InteractiveMoveEnd { window: 1 },
2663 ];
2664 let options = Options {
2665 layout: niri_config::Layout {
2666 empty_workspace_above_first: true,
2667 ..Default::default()
2668 },
2669 ..Default::default()
2670 };
2671 check_ops_with_options(options, ops);
2672}
2673
2674#[test]
2675fn output_active_workspace_is_preserved() {
2676 let ops = [
2677 Op::AddOutput(1),
2678 Op::AddWindow {
2679 params: TestWindowParams::new(1),
2680 },
2681 Op::FocusWorkspaceDown,
2682 Op::AddWindow {
2683 params: TestWindowParams::new(2),
2684 },
2685 Op::RemoveOutput(1),
2686 Op::AddOutput(1),
2687 ];
2688
2689 let layout = check_ops(ops);
2690
2691 let MonitorSet::Normal { monitors, .. } = layout.monitor_set else {
2692 unreachable!()
2693 };
2694
2695 assert_eq!(monitors[0].active_workspace_idx, 1);
2696}
2697
2698#[test]
2699fn output_active_workspace_is_preserved_with_other_outputs() {
2700 let ops = [
2701 Op::AddOutput(1),
2702 Op::AddOutput(2),
2703 Op::AddWindow {
2704 params: TestWindowParams::new(1),
2705 },
2706 Op::FocusWorkspaceDown,
2707 Op::AddWindow {
2708 params: TestWindowParams::new(2),
2709 },
2710 Op::RemoveOutput(1),
2711 Op::AddOutput(1),
2712 ];
2713
2714 let layout = check_ops(ops);
2715
2716 let MonitorSet::Normal { monitors, .. } = layout.monitor_set else {
2717 unreachable!()
2718 };
2719
2720 assert_eq!(monitors[1].active_workspace_idx, 1);
2721}
2722
2723#[test]
2724fn named_workspace_to_output() {
2725 let ops = [
2726 Op::AddNamedWorkspace {
2727 ws_name: 1,
2728 output_name: None,
2729 layout_config: None,
2730 },
2731 Op::AddOutput(1),
2732 Op::MoveWorkspaceToOutput(1),
2733 Op::FocusWorkspaceUp,
2734 ];
2735 check_ops(ops);
2736}
2737
2738#[test]
2739// empty_workspace_above_first = true
2740fn named_workspace_to_output_ewaf() {
2741 let ops = [
2742 Op::AddNamedWorkspace {
2743 ws_name: 1,
2744 output_name: Some(2),
2745 layout_config: None,
2746 },
2747 Op::AddOutput(1),
2748 Op::AddOutput(2),
2749 ];
2750 let options = Options {
2751 layout: niri_config::Layout {
2752 empty_workspace_above_first: true,
2753 ..Default::default()
2754 },
2755 ..Default::default()
2756 };
2757 check_ops_with_options(options, ops);
2758}
2759
2760#[test]
2761fn move_window_to_empty_workspace_above_first() {
2762 let ops = [
2763 Op::AddOutput(1),
2764 Op::AddWindow {
2765 params: TestWindowParams::new(1),
2766 },
2767 Op::MoveWorkspaceUp,
2768 Op::MoveWorkspaceDown,
2769 Op::FocusWorkspaceUp,
2770 Op::MoveWorkspaceDown,
2771 ];
2772 let options = Options {
2773 layout: niri_config::Layout {
2774 empty_workspace_above_first: true,
2775 ..Default::default()
2776 },
2777 ..Default::default()
2778 };
2779 check_ops_with_options(options, ops);
2780}
2781
2782#[test]
2783fn move_window_to_different_output() {
2784 let ops = [
2785 Op::AddWindow {
2786 params: TestWindowParams::new(1),
2787 },
2788 Op::AddOutput(1),
2789 Op::AddOutput(2),
2790 Op::MoveWorkspaceToOutput(2),
2791 ];
2792 let options = Options {
2793 layout: niri_config::Layout {
2794 empty_workspace_above_first: true,
2795 ..Default::default()
2796 },
2797 ..Default::default()
2798 };
2799 check_ops_with_options(options, ops);
2800}
2801
2802#[test]
2803fn close_window_empty_ws_above_first() {
2804 let ops = [
2805 Op::AddWindow {
2806 params: TestWindowParams::new(1),
2807 },
2808 Op::AddOutput(1),
2809 Op::CloseWindow(1),
2810 ];
2811 let options = Options {
2812 layout: niri_config::Layout {
2813 empty_workspace_above_first: true,
2814 ..Default::default()
2815 },
2816 ..Default::default()
2817 };
2818 check_ops_with_options(options, ops);
2819}
2820
2821#[test]
2822fn add_and_remove_output() {
2823 let ops = [
2824 Op::AddOutput(2),
2825 Op::AddOutput(1),
2826 Op::AddWindow {
2827 params: TestWindowParams::new(1),
2828 },
2829 Op::RemoveOutput(2),
2830 ];
2831 let options = Options {
2832 layout: niri_config::Layout {
2833 empty_workspace_above_first: true,
2834 ..Default::default()
2835 },
2836 ..Default::default()
2837 };
2838 check_ops_with_options(options, ops);
2839}
2840
2841#[test]
2842fn switch_ewaf_on() {
2843 let ops = [
2844 Op::AddOutput(1),
2845 Op::AddWindow {
2846 params: TestWindowParams::new(1),
2847 },
2848 ];
2849
2850 let mut layout = check_ops(ops);
2851 layout.update_options(Options {
2852 layout: niri_config::Layout {
2853 empty_workspace_above_first: true,
2854 ..Default::default()
2855 },
2856 ..Default::default()
2857 });
2858 layout.verify_invariants();
2859}
2860
2861#[test]
2862fn switch_ewaf_off() {
2863 let ops = [
2864 Op::AddOutput(1),
2865 Op::AddWindow {
2866 params: TestWindowParams::new(1),
2867 },
2868 ];
2869
2870 let options = Options {
2871 layout: niri_config::Layout {
2872 empty_workspace_above_first: true,
2873 ..Default::default()
2874 },
2875 ..Default::default()
2876 };
2877 let mut layout = check_ops_with_options(options, ops);
2878 layout.update_options(Options::default());
2879 layout.verify_invariants();
2880}
2881
2882#[test]
2883fn interactive_move_drop_on_other_output_during_animation() {
2884 let ops = [
2885 Op::AddOutput(3),
2886 Op::AddWindow {
2887 params: TestWindowParams::new(3),
2888 },
2889 Op::InteractiveMoveBegin {
2890 window: 3,
2891 output_idx: 3,
2892 px: 0.0,
2893 py: 0.0,
2894 },
2895 Op::FocusWorkspaceDown,
2896 Op::AddOutput(4),
2897 Op::InteractiveMoveUpdate {
2898 window: 3,
2899 dx: 0.0,
2900 dy: 8300.68619826683,
2901 output_idx: 4,
2902 px: 0.0,
2903 py: 0.0,
2904 },
2905 Op::RemoveOutput(4),
2906 Op::InteractiveMoveEnd { window: 3 },
2907 ];
2908 check_ops(ops);
2909}
2910
2911#[test]
2912fn add_window_next_to_only_interactively_moved_without_outputs() {
2913 let ops = [
2914 Op::AddWindow {
2915 params: TestWindowParams::new(2),
2916 },
2917 Op::AddOutput(1),
2918 Op::InteractiveMoveBegin {
2919 window: 2,
2920 output_idx: 1,
2921 px: 0.0,
2922 py: 0.0,
2923 },
2924 Op::InteractiveMoveUpdate {
2925 window: 2,
2926 dx: 0.0,
2927 dy: 3586.692842955048,
2928 output_idx: 1,
2929 px: 0.0,
2930 py: 0.0,
2931 },
2932 Op::RemoveOutput(1),
2933 // We have no outputs, and the only existing window is interactively moved, meaning there
2934 // are no workspaces either.
2935 Op::AddWindowNextTo {
2936 params: TestWindowParams::new(3),
2937 next_to_id: 2,
2938 },
2939 ];
2940
2941 check_ops(ops);
2942}
2943
2944#[test]
2945fn interactive_move_toggle_floating_ends_dnd_gesture() {
2946 let ops = [
2947 Op::AddOutput(1),
2948 Op::AddWindow {
2949 params: TestWindowParams::new(2),
2950 },
2951 Op::InteractiveMoveBegin {
2952 window: 2,
2953 output_idx: 1,
2954 px: 0.0,
2955 py: 0.0,
2956 },
2957 Op::InteractiveMoveUpdate {
2958 window: 2,
2959 dx: 0.0,
2960 dy: 3586.692842955048,
2961 output_idx: 1,
2962 px: 0.0,
2963 py: 0.0,
2964 },
2965 Op::Refresh { is_active: false },
2966 Op::ToggleWindowFloating { id: None },
2967 Op::InteractiveMoveEnd { window: 2 },
2968 ];
2969
2970 check_ops(ops);
2971}
2972
2973#[test]
2974fn interactive_move_from_workspace_with_layout_config() {
2975 let ops = [
2976 Op::AddNamedWorkspace {
2977 ws_name: 1,
2978 output_name: Some(2),
2979 layout_config: Some(Box::new(niri_config::LayoutPart {
2980 border: Some(niri_config::BorderRule {
2981 on: true,
2982 ..Default::default()
2983 }),
2984 ..Default::default()
2985 })),
2986 },
2987 Op::AddOutput(1),
2988 Op::AddWindow {
2989 params: TestWindowParams::new(2),
2990 },
2991 Op::InteractiveMoveBegin {
2992 window: 2,
2993 output_idx: 1,
2994 px: 0.0,
2995 py: 0.0,
2996 },
2997 Op::InteractiveMoveUpdate {
2998 window: 2,
2999 dx: 0.0,
3000 dy: 3586.692842955048,
3001 output_idx: 1,
3002 px: 0.0,
3003 py: 0.0,
3004 },
3005 // Now remove and add the output. It will have the same workspace.
3006 Op::RemoveOutput(1),
3007 Op::AddOutput(1),
3008 Op::InteractiveMoveUpdate {
3009 window: 2,
3010 dx: 0.0,
3011 dy: 0.0,
3012 output_idx: 1,
3013 px: 0.0,
3014 py: 0.0,
3015 },
3016 // Now move onto a different workspace.
3017 Op::FocusWorkspaceDown,
3018 Op::CompleteAnimations,
3019 Op::InteractiveMoveUpdate {
3020 window: 2,
3021 dx: 0.0,
3022 dy: 0.0,
3023 output_idx: 1,
3024 px: 0.0,
3025 py: 0.0,
3026 },
3027 ];
3028
3029 check_ops(ops);
3030}
3031
3032#[test]
3033fn set_width_fixed_negative() {
3034 let ops = [
3035 Op::AddOutput(3),
3036 Op::AddWindow {
3037 params: TestWindowParams::new(3),
3038 },
3039 Op::ToggleWindowFloating { id: Some(3) },
3040 Op::SetColumnWidth(SizeChange::SetFixed(-100)),
3041 ];
3042 check_ops(ops);
3043}
3044
3045#[test]
3046fn set_height_fixed_negative() {
3047 let ops = [
3048 Op::AddOutput(3),
3049 Op::AddWindow {
3050 params: TestWindowParams::new(3),
3051 },
3052 Op::ToggleWindowFloating { id: Some(3) },
3053 Op::SetWindowHeight {
3054 id: None,
3055 change: SizeChange::SetFixed(-100),
3056 },
3057 ];
3058 check_ops(ops);
3059}
3060
3061#[test]
3062fn interactive_resize_to_negative() {
3063 let ops = [
3064 Op::AddOutput(3),
3065 Op::AddWindow {
3066 params: TestWindowParams::new(3),
3067 },
3068 Op::ToggleWindowFloating { id: Some(3) },
3069 Op::InteractiveResizeBegin {
3070 window: 3,
3071 edges: ResizeEdge::BOTTOM_RIGHT,
3072 },
3073 Op::InteractiveResizeUpdate {
3074 window: 3,
3075 dx: -10000.,
3076 dy: -10000.,
3077 },
3078 ];
3079 check_ops(ops);
3080}
3081
3082#[test]
3083fn windows_on_other_workspaces_remain_activated() {
3084 let ops = [
3085 Op::AddOutput(3),
3086 Op::AddWindow {
3087 params: TestWindowParams::new(3),
3088 },
3089 Op::FocusWorkspaceDown,
3090 Op::Refresh { is_active: true },
3091 ];
3092
3093 let layout = check_ops(ops);
3094 let (_, win) = layout.windows().next().unwrap();
3095 assert!(win.0.pending_activated.get());
3096}
3097
3098#[test]
3099fn stacking_add_parent_brings_up_child() {
3100 let ops = [
3101 Op::AddOutput(0),
3102 Op::AddWindow {
3103 params: TestWindowParams {
3104 is_floating: true,
3105 parent_id: Some(1),
3106 ..TestWindowParams::new(0)
3107 },
3108 },
3109 Op::AddWindow {
3110 params: TestWindowParams {
3111 is_floating: true,
3112 ..TestWindowParams::new(1)
3113 },
3114 },
3115 ];
3116
3117 check_ops(ops);
3118}
3119
3120#[test]
3121fn stacking_add_parent_brings_up_descendants() {
3122 let ops = [
3123 Op::AddOutput(0),
3124 Op::AddWindow {
3125 params: TestWindowParams {
3126 is_floating: true,
3127 parent_id: Some(2),
3128 ..TestWindowParams::new(0)
3129 },
3130 },
3131 Op::AddWindow {
3132 params: TestWindowParams {
3133 is_floating: true,
3134 parent_id: Some(0),
3135 ..TestWindowParams::new(1)
3136 },
3137 },
3138 Op::AddWindow {
3139 params: TestWindowParams {
3140 is_floating: true,
3141 ..TestWindowParams::new(2)
3142 },
3143 },
3144 ];
3145
3146 check_ops(ops);
3147}
3148
3149#[test]
3150fn stacking_activate_brings_up_descendants() {
3151 let ops = [
3152 Op::AddOutput(0),
3153 Op::AddWindow {
3154 params: TestWindowParams {
3155 is_floating: true,
3156 ..TestWindowParams::new(0)
3157 },
3158 },
3159 Op::AddWindow {
3160 params: TestWindowParams {
3161 is_floating: true,
3162 parent_id: Some(0),
3163 ..TestWindowParams::new(1)
3164 },
3165 },
3166 Op::AddWindow {
3167 params: TestWindowParams {
3168 is_floating: true,
3169 parent_id: Some(1),
3170 ..TestWindowParams::new(2)
3171 },
3172 },
3173 Op::AddWindow {
3174 params: TestWindowParams {
3175 is_floating: true,
3176 ..TestWindowParams::new(3)
3177 },
3178 },
3179 Op::FocusWindow(0),
3180 ];
3181
3182 check_ops(ops);
3183}
3184
3185#[test]
3186fn stacking_set_parent_brings_up_child() {
3187 let ops = [
3188 Op::AddOutput(0),
3189 Op::AddWindow {
3190 params: TestWindowParams {
3191 is_floating: true,
3192 ..TestWindowParams::new(0)
3193 },
3194 },
3195 Op::AddWindow {
3196 params: TestWindowParams {
3197 is_floating: true,
3198 ..TestWindowParams::new(1)
3199 },
3200 },
3201 Op::SetParent {
3202 id: 0,
3203 new_parent_id: Some(1),
3204 },
3205 ];
3206
3207 check_ops(ops);
3208}
3209
3210#[test]
3211fn move_window_to_workspace_with_different_active_output() {
3212 let ops = [
3213 Op::AddOutput(0),
3214 Op::AddOutput(1),
3215 Op::AddWindow {
3216 params: TestWindowParams::new(0),
3217 },
3218 Op::FocusOutput(1),
3219 Op::MoveWindowToWorkspace {
3220 window_id: Some(0),
3221 workspace_idx: 2,
3222 },
3223 ];
3224
3225 check_ops(ops);
3226}
3227
3228#[test]
3229fn set_first_workspace_name() {
3230 let ops = [
3231 Op::AddOutput(0),
3232 Op::SetWorkspaceName {
3233 new_ws_name: 0,
3234 ws_name: None,
3235 },
3236 ];
3237
3238 check_ops(ops);
3239}
3240
3241#[test]
3242fn set_first_workspace_name_ewaf() {
3243 let ops = [
3244 Op::AddOutput(0),
3245 Op::SetWorkspaceName {
3246 new_ws_name: 0,
3247 ws_name: None,
3248 },
3249 ];
3250
3251 let options = Options {
3252 layout: niri_config::Layout {
3253 empty_workspace_above_first: true,
3254 ..Default::default()
3255 },
3256 ..Default::default()
3257 };
3258 check_ops_with_options(options, ops);
3259}
3260
3261#[test]
3262fn set_last_workspace_name() {
3263 let ops = [
3264 Op::AddOutput(0),
3265 Op::AddWindow {
3266 params: TestWindowParams::new(0),
3267 },
3268 Op::FocusWorkspaceDown,
3269 Op::SetWorkspaceName {
3270 new_ws_name: 0,
3271 ws_name: None,
3272 },
3273 ];
3274
3275 check_ops(ops);
3276}
3277
3278#[test]
3279fn move_workspace_to_same_monitor_doesnt_reorder() {
3280 let ops = [
3281 Op::AddOutput(0),
3282 Op::SetWorkspaceName {
3283 new_ws_name: 0,
3284 ws_name: None,
3285 },
3286 Op::AddWindow {
3287 params: TestWindowParams::new(0),
3288 },
3289 Op::FocusWorkspaceDown,
3290 Op::AddWindow {
3291 params: TestWindowParams::new(1),
3292 },
3293 Op::AddWindow {
3294 params: TestWindowParams::new(2),
3295 },
3296 Op::MoveWorkspaceToMonitor {
3297 ws_name: Some(0),
3298 output_id: 0,
3299 },
3300 ];
3301
3302 let layout = check_ops(ops);
3303 let counts: Vec<_> = layout
3304 .workspaces()
3305 .map(|(_, _, ws)| ws.windows().count())
3306 .collect();
3307 assert_eq!(counts, &[1, 2, 0]);
3308}
3309
3310#[test]
3311fn removing_window_above_preserves_focused_window() {
3312 let ops = [
3313 Op::AddOutput(0),
3314 Op::AddWindow {
3315 params: TestWindowParams::new(0),
3316 },
3317 Op::AddWindow {
3318 params: TestWindowParams::new(1),
3319 },
3320 Op::AddWindow {
3321 params: TestWindowParams::new(2),
3322 },
3323 Op::FocusColumnFirst,
3324 Op::ConsumeWindowIntoColumn,
3325 Op::ConsumeWindowIntoColumn,
3326 Op::FocusWindowDown,
3327 Op::CloseWindow(0),
3328 ];
3329
3330 let layout = check_ops(ops);
3331 let win = layout.focus().unwrap();
3332 assert_eq!(win.0.id, 1);
3333}
3334
3335#[test]
3336fn preset_column_width_fixed_correct_with_border() {
3337 let ops = [
3338 Op::AddOutput(0),
3339 Op::AddWindow {
3340 params: TestWindowParams::new(0),
3341 },
3342 Op::SwitchPresetColumnWidth,
3343 ];
3344
3345 let options = Options {
3346 layout: niri_config::Layout {
3347 preset_column_widths: vec![PresetSize::Fixed(500)],
3348 ..Default::default()
3349 },
3350 ..Default::default()
3351 };
3352 let mut layout = check_ops_with_options(options, ops);
3353
3354 let win = layout.windows().next().unwrap().1;
3355 assert_eq!(win.requested_size().unwrap().w, 500);
3356
3357 // Add border.
3358 let options = Options {
3359 layout: niri_config::Layout {
3360 preset_column_widths: vec![PresetSize::Fixed(500)],
3361 border: niri_config::Border {
3362 off: false,
3363 width: 5.,
3364 ..Default::default()
3365 },
3366 ..Default::default()
3367 },
3368 ..Default::default()
3369 };
3370 layout.update_options(options);
3371
3372 // With border, the window gets less size.
3373 let win = layout.windows().next().unwrap().1;
3374 assert_eq!(win.requested_size().unwrap().w, 490);
3375
3376 // However, preset fixed width will still work correctly.
3377 layout.toggle_width(true);
3378 let win = layout.windows().next().unwrap().1;
3379 assert_eq!(win.requested_size().unwrap().w, 500);
3380}
3381
3382#[test]
3383fn preset_column_width_reset_after_set_width() {
3384 let ops = [
3385 Op::AddOutput(0),
3386 Op::AddWindow {
3387 params: TestWindowParams::new(0),
3388 },
3389 Op::SwitchPresetColumnWidth,
3390 Op::SetWindowWidth {
3391 id: None,
3392 change: SizeChange::AdjustFixed(-10),
3393 },
3394 Op::SwitchPresetColumnWidth,
3395 ];
3396
3397 let options = Options {
3398 layout: niri_config::Layout {
3399 preset_column_widths: vec![PresetSize::Fixed(500), PresetSize::Fixed(1000)],
3400 ..Default::default()
3401 },
3402 ..Default::default()
3403 };
3404 let layout = check_ops_with_options(options, ops);
3405 let win = layout.windows().next().unwrap().1;
3406 assert_eq!(win.requested_size().unwrap().w, 500);
3407}
3408
3409#[test]
3410fn move_column_to_workspace_unfocused_with_multiple_monitors() {
3411 let ops = [
3412 Op::AddOutput(1),
3413 Op::SetWorkspaceName {
3414 new_ws_name: 101,
3415 ws_name: None,
3416 },
3417 Op::AddWindow {
3418 params: TestWindowParams::new(1),
3419 },
3420 Op::FocusWorkspaceDown,
3421 Op::SetWorkspaceName {
3422 new_ws_name: 102,
3423 ws_name: None,
3424 },
3425 Op::AddWindow {
3426 params: TestWindowParams::new(2),
3427 },
3428 Op::AddOutput(2),
3429 Op::FocusOutput(2),
3430 Op::SetWorkspaceName {
3431 new_ws_name: 201,
3432 ws_name: None,
3433 },
3434 Op::AddWindow {
3435 params: TestWindowParams::new(3),
3436 },
3437 Op::AddWindow {
3438 params: TestWindowParams::new(4),
3439 },
3440 Op::MoveColumnToOutput {
3441 output_id: 1,
3442 target_ws_idx: Some(0),
3443 activate: false,
3444 },
3445 Op::FocusOutput(1),
3446 ];
3447
3448 let layout = check_ops(ops);
3449
3450 assert_eq!(layout.active_workspace().unwrap().name().unwrap(), "ws102");
3451
3452 for (mon, win) in layout.windows() {
3453 let mon = mon.unwrap();
3454 let ws = mon
3455 .workspaces
3456 .iter()
3457 .find(|w| w.has_window(win.id()))
3458 .unwrap();
3459
3460 assert_eq!(
3461 ws.name().unwrap(),
3462 match win.id() {
3463 1 | 4 => "ws101",
3464 2 => "ws102",
3465 3 => "ws201",
3466 _ => unreachable!(),
3467 }
3468 );
3469 }
3470}
3471
3472#[test]
3473fn move_column_to_workspace_down_focus_false_on_floating_window() {
3474 let ops = [
3475 Op::AddOutput(1),
3476 Op::AddWindow {
3477 params: TestWindowParams::new(1),
3478 },
3479 Op::AddWindow {
3480 params: TestWindowParams::new(2),
3481 },
3482 Op::ToggleWindowFloating { id: None },
3483 Op::MoveColumnToWorkspaceDown(false),
3484 ];
3485
3486 let layout = check_ops(ops);
3487
3488 let MonitorSet::Normal { monitors, .. } = layout.monitor_set else {
3489 unreachable!()
3490 };
3491
3492 assert_eq!(monitors[0].active_workspace_idx, 0);
3493}
3494
3495#[test]
3496fn move_column_to_workspace_focus_false_on_floating_window() {
3497 let ops = [
3498 Op::AddOutput(1),
3499 Op::AddWindow {
3500 params: TestWindowParams::new(1),
3501 },
3502 Op::AddWindow {
3503 params: TestWindowParams::new(2),
3504 },
3505 Op::ToggleWindowFloating { id: None },
3506 Op::MoveColumnToWorkspace(1, false),
3507 ];
3508
3509 let layout = check_ops(ops);
3510
3511 let MonitorSet::Normal { monitors, .. } = layout.monitor_set else {
3512 unreachable!()
3513 };
3514
3515 assert_eq!(monitors[0].active_workspace_idx, 0);
3516}
3517
3518#[test]
3519fn restore_to_floating_persists_across_fullscreen_maximize() {
3520 let ops = [
3521 Op::AddOutput(1),
3522 Op::AddWindow {
3523 params: TestWindowParams::new(1),
3524 },
3525 Op::ToggleWindowFloating { id: None },
3526 // Maximize then fullscreen.
3527 Op::MaximizeWindowToEdges { id: None },
3528 Op::FullscreenWindow(1),
3529 // Unfullscreen.
3530 Op::FullscreenWindow(1),
3531 ];
3532
3533 let mut layout = check_ops(ops);
3534
3535 // Unfullscreening should return the window to the maximized state.
3536 let scrolling = layout.active_workspace().unwrap().scrolling();
3537 assert!(scrolling.tiles().next().is_some());
3538
3539 let ops = [
3540 // Unmaximize.
3541 Op::MaximizeWindowToEdges { id: None },
3542 ];
3543 check_ops_on_layout(&mut layout, ops);
3544
3545 // Unmaximize should return the window back to floating.
3546 let scrolling = layout.active_workspace().unwrap().scrolling();
3547 assert!(scrolling.tiles().next().is_none());
3548}
3549
3550#[test]
3551fn unmaximize_during_fullscreen_does_not_float() {
3552 let ops = [
3553 Op::AddOutput(1),
3554 Op::AddWindow {
3555 params: TestWindowParams::new(1),
3556 },
3557 Op::ToggleWindowFloating { id: None },
3558 // Maximize then fullscreen.
3559 Op::MaximizeWindowToEdges { id: None },
3560 Op::FullscreenWindow(1),
3561 // Unmaximize.
3562 Op::MaximizeWindowToEdges { id: None },
3563 ];
3564
3565 let mut layout = check_ops(ops);
3566
3567 // Unmaximize shouldn't have changed the window state since it's fullscreen.
3568 let scrolling = layout.active_workspace().unwrap().scrolling();
3569 assert!(scrolling.tiles().next().is_some());
3570
3571 let ops = [
3572 // Unfullscreen.
3573 Op::FullscreenWindow(1),
3574 ];
3575 check_ops_on_layout(&mut layout, ops);
3576
3577 // Unfullscreen should return the window back to floating.
3578 let scrolling = layout.active_workspace().unwrap().scrolling();
3579 assert!(scrolling.tiles().next().is_none());
3580}
3581
3582#[test]
3583fn move_column_to_workspace_maximize_and_fullscreen() {
3584 let ops = [
3585 Op::AddOutput(1),
3586 Op::AddWindow {
3587 params: TestWindowParams::new(1),
3588 },
3589 Op::MaximizeWindowToEdges { id: None },
3590 Op::FullscreenWindow(1),
3591 Op::MoveColumnToWorkspaceDown(true),
3592 Op::FullscreenWindow(1),
3593 ];
3594
3595 let layout = check_ops(ops);
3596 let (_, win) = layout.windows().next().unwrap();
3597
3598 // Unfullscreening should return to maximized because the window was maximized before.
3599 assert_eq!(win.pending_sizing_mode(), SizingMode::Maximized);
3600}
3601
3602#[test]
3603fn move_window_to_workspace_maximize_and_fullscreen() {
3604 let ops = [
3605 Op::AddOutput(1),
3606 Op::AddWindow {
3607 params: TestWindowParams::new(1),
3608 },
3609 Op::MaximizeWindowToEdges { id: None },
3610 Op::FullscreenWindow(1),
3611 Op::MoveWindowToWorkspaceDown(true),
3612 Op::FullscreenWindow(1),
3613 ];
3614
3615 let layout = check_ops(ops);
3616 let (_, win) = layout.windows().next().unwrap();
3617
3618 // Unfullscreening should return to maximized because the window was maximized before.
3619 //
3620 // FIXME: it currently doesn't because windows themselves can only be either fullscreen or
3621 // maximized. So when a window is fullscreen, whether it is also maximized or not is stored in
3622 // the column. MoveWindowToWorkspace removes the window from the column and this information is
3623 // forgotten.
3624 assert_eq!(win.pending_sizing_mode(), SizingMode::Normal);
3625}
3626
3627#[test]
3628fn tabs_with_different_border() {
3629 let ops = [
3630 Op::AddOutput(1),
3631 Op::AddWindow {
3632 params: TestWindowParams {
3633 rules: Some(ResolvedWindowRules {
3634 border: niri_config::BorderRule {
3635 on: true,
3636 ..Default::default()
3637 },
3638 ..ResolvedWindowRules::default()
3639 }),
3640 ..TestWindowParams::new(2)
3641 },
3642 },
3643 Op::SwitchPresetWindowHeight { id: None },
3644 Op::ToggleColumnTabbedDisplay,
3645 Op::AddWindow {
3646 params: TestWindowParams::new(3),
3647 },
3648 Op::ConsumeOrExpelWindowLeft { id: None },
3649 ];
3650
3651 let options = Options {
3652 layout: niri_config::Layout {
3653 struts: Struts {
3654 left: FloatOrInt(0.),
3655 right: FloatOrInt(0.),
3656 top: FloatOrInt(20000.),
3657 bottom: FloatOrInt(0.),
3658 },
3659 ..Default::default()
3660 },
3661 ..Default::default()
3662 };
3663 check_ops_with_options(options, ops);
3664}
3665
3666#[test]
3667fn expel_pending_left_from_fullscreen_tabbed_column() {
3668 let ops = [
3669 Op::AddOutput(1),
3670 Op::AddWindow {
3671 params: TestWindowParams::new(1),
3672 },
3673 Op::FullscreenWindow(1),
3674 Op::Communicate(1),
3675 // 1 is now fullscreen, view_offset_to_restore is set.
3676 Op::ToggleColumnTabbedDisplay,
3677 Op::AddWindow {
3678 params: TestWindowParams::new(2),
3679 },
3680 Op::ConsumeOrExpelWindowLeft { id: Some(2) },
3681 // 2 is consumed into a fullscreen column, fullscreen is requested but not applied.
3682 //
3683 // Now, get it back out while keeping it focused.
3684 //
3685 // Importantly, we expel it *left*, which results in adding a new column with the exact
3686 // same active_column_idx.
3687 Op::FocusWindow(2),
3688 Op::ConsumeOrExpelWindowLeft { id: None },
3689 ];
3690
3691 check_ops(ops);
3692}
3693
3694fn parent_id_causes_loop(layout: &Layout<TestWindow>, id: usize, mut parent_id: usize) -> bool {
3695 if parent_id == id {
3696 return true;
3697 }
3698
3699 'outer: loop {
3700 for (_, win) in layout.windows() {
3701 if win.0.id == parent_id {
3702 match win.0.parent_id.get() {
3703 Some(new_parent_id) => {
3704 if new_parent_id == id {
3705 // Found a loop.
3706 return true;
3707 }
3708
3709 parent_id = new_parent_id;
3710 continue 'outer;
3711 }
3712 // Reached window with no parent.
3713 None => return false,
3714 }
3715 }
3716 }
3717
3718 // Parent is not in the layout.
3719 return false;
3720 }
3721}
3722
3723fn arbitrary_spacing() -> impl Strategy<Value = f64> {
3724 // Give equal weight to:
3725 // - 0: the element is disabled
3726 // - 4: some reasonable value
3727 // - random value, likely unreasonably big
3728 prop_oneof![Just(0.), Just(4.), ((1.)..=65535.)]
3729}
3730
3731fn arbitrary_spacing_neg() -> impl Strategy<Value = f64> {
3732 // Give equal weight to:
3733 // - 0: the element is disabled
3734 // - 4: some reasonable value
3735 // - -4: some reasonable negative value
3736 // - random value, likely unreasonably big
3737 prop_oneof![Just(0.), Just(4.), Just(-4.), ((1.)..=65535.)]
3738}
3739
3740fn arbitrary_struts() -> impl Strategy<Value = Struts> {
3741 (
3742 arbitrary_spacing_neg(),
3743 arbitrary_spacing_neg(),
3744 arbitrary_spacing_neg(),
3745 arbitrary_spacing_neg(),
3746 )
3747 .prop_map(|(left, right, top, bottom)| Struts {
3748 left: FloatOrInt(left),
3749 right: FloatOrInt(right),
3750 top: FloatOrInt(top),
3751 bottom: FloatOrInt(bottom),
3752 })
3753}
3754
3755fn arbitrary_center_focused_column() -> impl Strategy<Value = CenterFocusedColumn> {
3756 prop_oneof![
3757 Just(CenterFocusedColumn::Never),
3758 Just(CenterFocusedColumn::OnOverflow),
3759 Just(CenterFocusedColumn::Always),
3760 ]
3761}
3762
3763fn arbitrary_tab_indicator_position() -> impl Strategy<Value = TabIndicatorPosition> {
3764 prop_oneof![
3765 Just(TabIndicatorPosition::Left),
3766 Just(TabIndicatorPosition::Right),
3767 Just(TabIndicatorPosition::Top),
3768 Just(TabIndicatorPosition::Bottom),
3769 ]
3770}
3771
3772prop_compose! {
3773 fn arbitrary_focus_ring()(
3774 off in any::<bool>(),
3775 width in prop::option::of(arbitrary_spacing().prop_map(FloatOrInt)),
3776 ) -> niri_config::BorderRule {
3777 niri_config::BorderRule {
3778 off,
3779 on: !off,
3780 width,
3781 ..Default::default()
3782 }
3783 }
3784}
3785
3786prop_compose! {
3787 fn arbitrary_border()(
3788 off in any::<bool>(),
3789 width in prop::option::of(arbitrary_spacing().prop_map(FloatOrInt)),
3790 ) -> niri_config::BorderRule {
3791 niri_config::BorderRule {
3792 off,
3793 on: !off,
3794 width,
3795 ..Default::default()
3796 }
3797 }
3798}
3799
3800prop_compose! {
3801 fn arbitrary_shadow()(
3802 off in any::<bool>(),
3803 softness in prop::option::of(arbitrary_spacing().prop_map(FloatOrInt)),
3804 ) -> niri_config::ShadowRule {
3805 niri_config::ShadowRule {
3806 off,
3807 on: !off,
3808 softness,
3809 ..Default::default()
3810 }
3811 }
3812}
3813
3814prop_compose! {
3815 fn arbitrary_tab_indicator()(
3816 off in any::<bool>(),
3817 hide_when_single_tab in prop::option::of(any::<bool>().prop_map(Flag)),
3818 place_within_column in prop::option::of(any::<bool>().prop_map(Flag)),
3819 width in prop::option::of(arbitrary_spacing().prop_map(FloatOrInt)),
3820 gap in prop::option::of(arbitrary_spacing_neg().prop_map(FloatOrInt)),
3821 length in prop::option::of((0f64..2f64)
3822 .prop_map(|x| TabIndicatorLength { total_proportion: Some(x) })),
3823 position in prop::option::of(arbitrary_tab_indicator_position()),
3824 ) -> niri_config::TabIndicatorPart {
3825 niri_config::TabIndicatorPart {
3826 off,
3827 on: !off,
3828 hide_when_single_tab,
3829 place_within_column,
3830 width,
3831 gap,
3832 length,
3833 position,
3834 ..Default::default()
3835 }
3836 }
3837}
3838
3839prop_compose! {
3840 fn arbitrary_layout_part()(
3841 gaps in prop::option::of(arbitrary_spacing().prop_map(FloatOrInt)),
3842 struts in prop::option::of(arbitrary_struts()),
3843 focus_ring in prop::option::of(arbitrary_focus_ring()),
3844 border in prop::option::of(arbitrary_border()),
3845 shadow in prop::option::of(arbitrary_shadow()),
3846 tab_indicator in prop::option::of(arbitrary_tab_indicator()),
3847 center_focused_column in prop::option::of(arbitrary_center_focused_column()),
3848 always_center_single_column in prop::option::of(any::<bool>().prop_map(Flag)),
3849 empty_workspace_above_first in prop::option::of(any::<bool>().prop_map(Flag)),
3850 ) -> niri_config::LayoutPart {
3851 niri_config::LayoutPart {
3852 gaps,
3853 struts,
3854 center_focused_column,
3855 always_center_single_column,
3856 empty_workspace_above_first,
3857 focus_ring,
3858 border,
3859 shadow,
3860 tab_indicator,
3861 ..Default::default()
3862 }
3863 }
3864}
3865
3866proptest! {
3867 #![proptest_config(ProptestConfig {
3868 cases: if std::env::var_os("RUN_SLOW_TESTS").is_none() {
3869 eprintln!("ignoring slow test");
3870 0
3871 } else {
3872 ProptestConfig::default().cases
3873 },
3874 ..ProptestConfig::default()
3875 })]
3876
3877 #[test]
3878 fn random_operations_dont_panic(
3879 ops: Vec<Op>,
3880 layout_config in arbitrary_layout_part(),
3881 ) {
3882 // eprintln!("{ops:?}");
3883 let options = Options {
3884 layout: niri_config::Layout::from_part(&layout_config),
3885 ..Default::default()
3886 };
3887
3888 check_ops_with_options(options, ops);
3889 }
3890}