forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB2d82fddIvan Molodetskikh1 year ago2536 commits

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