layout: Move tests to separate file
Browse files at this commit49ddf66c2f77d6dab8bdb84de7345b9c3a28f9dfParent: a169e032 changed files +3166 -3169
- src/layout/mod.rs +3 -3169
- src/layout/tests.rs +3163 -0
src/layout/mod.rsmodified+3 -3169
Diff too large; view file
| @@ -81,6 +81,9 @@ pub mod shadow; | ||
| 81 | 81 | pub mod tile; |
| 82 | 82 | pub mod workspace; |
| 83 | 83 | |
| 84 | +#[cfg(test)] | |
| 85 | +mod tests; | |
| 86 | + | |
| 84 | 87 | /// Size changes up to this many pixels don't animate. |
| 85 | 88 | pub const RESIZE_ANIMATION_THRESHOLD: f64 = 10.; |
| 86 | 89 | |
| @@ -4311,3172 +4314,3 @@ impl<W: LayoutElement> Default for MonitorSet<W> { | ||
| 4311 | 4314 | Self::NoOutputs { workspaces: vec![] } |
| 4312 | 4315 | } |
| 4313 | 4316 | } |
| 4314 | - | |
| 4315 | -#[cfg(test)] | |
| 4316 | -mod tests { | |
| 4317 | - use std::cell::Cell; | |
| 4318 | - | |
| 4319 | - use niri_config::{FloatOrInt, OutputName, WorkspaceName, WorkspaceReference}; | |
| 4320 | - use proptest::prelude::*; | |
| 4321 | - use proptest_derive::Arbitrary; | |
| 4322 | - use smithay::output::{Mode, PhysicalProperties, Subpixel}; | |
| 4323 | - use smithay::utils::Rectangle; | |
| 4324 | - | |
| 4325 | - use super::*; | |
| 4326 | - | |
| 4327 | - impl<W: LayoutElement> Default for Layout<W> { | |
| 4328 | - fn default() -> Self { | |
| 4329 | - Self::with_options(Clock::with_time(Duration::ZERO), Default::default()) | |
| 4330 | - } | |
| 4331 | - } | |
| 4332 | - | |
| 4333 | - #[derive(Debug)] | |
| 4334 | - struct TestWindowInner { | |
| 4335 | - id: usize, | |
| 4336 | - parent_id: Cell<Option<usize>>, | |
| 4337 | - bbox: Cell<Rectangle<i32, Logical>>, | |
| 4338 | - initial_bbox: Rectangle<i32, Logical>, | |
| 4339 | - requested_size: Cell<Option<Size<i32, Logical>>>, | |
| 4340 | - min_size: Size<i32, Logical>, | |
| 4341 | - max_size: Size<i32, Logical>, | |
| 4342 | - pending_fullscreen: Cell<bool>, | |
| 4343 | - pending_activated: Cell<bool>, | |
| 4344 | - } | |
| 4345 | - | |
| 4346 | - #[derive(Debug, Clone)] | |
| 4347 | - struct TestWindow(Rc<TestWindowInner>); | |
| 4348 | - | |
| 4349 | - #[derive(Debug, Clone, Copy, Arbitrary)] | |
| 4350 | - struct TestWindowParams { | |
| 4351 | - #[proptest(strategy = "1..=5usize")] | |
| 4352 | - id: usize, | |
| 4353 | - #[proptest(strategy = "arbitrary_parent_id()")] | |
| 4354 | - parent_id: Option<usize>, | |
| 4355 | - is_floating: bool, | |
| 4356 | - #[proptest(strategy = "arbitrary_bbox()")] | |
| 4357 | - bbox: Rectangle<i32, Logical>, | |
| 4358 | - #[proptest(strategy = "arbitrary_min_max_size()")] | |
| 4359 | - min_max_size: (Size<i32, Logical>, Size<i32, Logical>), | |
| 4360 | - } | |
| 4361 | - | |
| 4362 | - impl TestWindowParams { | |
| 4363 | - pub fn new(id: usize) -> Self { | |
| 4364 | - Self { | |
| 4365 | - id, | |
| 4366 | - parent_id: None, | |
| 4367 | - is_floating: false, | |
| 4368 | - bbox: Rectangle::from_size(Size::from((100, 200))), | |
| 4369 | - min_max_size: Default::default(), | |
| 4370 | - } | |
| 4371 | - } | |
| 4372 | - } | |
| 4373 | - | |
| 4374 | - impl TestWindow { | |
| 4375 | - fn new(params: TestWindowParams) -> Self { | |
| 4376 | - Self(Rc::new(TestWindowInner { | |
| 4377 | - id: params.id, | |
| 4378 | - parent_id: Cell::new(params.parent_id), | |
| 4379 | - bbox: Cell::new(params.bbox), | |
| 4380 | - initial_bbox: params.bbox, | |
| 4381 | - requested_size: Cell::new(None), | |
| 4382 | - min_size: params.min_max_size.0, | |
| 4383 | - max_size: params.min_max_size.1, | |
| 4384 | - pending_fullscreen: Cell::new(false), | |
| 4385 | - pending_activated: Cell::new(false), | |
| 4386 | - })) | |
| 4387 | - } | |
| 4388 | - | |
| 4389 | - fn communicate(&self) -> bool { | |
| 4390 | - if let Some(size) = self.0.requested_size.get() { | |
| 4391 | - assert!(size.w >= 0); | |
| 4392 | - assert!(size.h >= 0); | |
| 4393 | - | |
| 4394 | - let mut new_bbox = self.0.initial_bbox; | |
| 4395 | - if size.w != 0 { | |
| 4396 | - new_bbox.size.w = size.w; | |
| 4397 | - } | |
| 4398 | - if size.h != 0 { | |
| 4399 | - new_bbox.size.h = size.h; | |
| 4400 | - } | |
| 4401 | - | |
| 4402 | - if self.0.bbox.get() != new_bbox { | |
| 4403 | - self.0.bbox.set(new_bbox); | |
| 4404 | - return true; | |
| 4405 | - } | |
| 4406 | - } | |
| 4407 | - | |
| 4408 | - false | |
| 4409 | - } | |
| 4410 | - } | |
| 4411 | - | |
| 4412 | - impl LayoutElement for TestWindow { | |
| 4413 | - type Id = usize; | |
| 4414 | - | |
| 4415 | - fn id(&self) -> &Self::Id { | |
| 4416 | - &self.0.id | |
| 4417 | - } | |
| 4418 | - | |
| 4419 | - fn size(&self) -> Size<i32, Logical> { | |
| 4420 | - self.0.bbox.get().size | |
| 4421 | - } | |
| 4422 | - | |
| 4423 | - fn buf_loc(&self) -> Point<i32, Logical> { | |
| 4424 | - (0, 0).into() | |
| 4425 | - } | |
| 4426 | - | |
| 4427 | - fn is_in_input_region(&self, _point: Point<f64, Logical>) -> bool { | |
| 4428 | - false | |
| 4429 | - } | |
| 4430 | - | |
| 4431 | - fn render<R: NiriRenderer>( | |
| 4432 | - &self, | |
| 4433 | - _renderer: &mut R, | |
| 4434 | - _location: Point<f64, Logical>, | |
| 4435 | - _scale: Scale<f64>, | |
| 4436 | - _alpha: f32, | |
| 4437 | - _target: RenderTarget, | |
| 4438 | - ) -> SplitElements<LayoutElementRenderElement<R>> { | |
| 4439 | - SplitElements::default() | |
| 4440 | - } | |
| 4441 | - | |
| 4442 | - fn request_size( | |
| 4443 | - &mut self, | |
| 4444 | - size: Size<i32, Logical>, | |
| 4445 | - _animate: bool, | |
| 4446 | - _transaction: Option<Transaction>, | |
| 4447 | - ) { | |
| 4448 | - self.0.requested_size.set(Some(size)); | |
| 4449 | - self.0.pending_fullscreen.set(false); | |
| 4450 | - } | |
| 4451 | - | |
| 4452 | - fn request_fullscreen(&mut self, _size: Size<i32, Logical>) { | |
| 4453 | - self.0.pending_fullscreen.set(true); | |
| 4454 | - } | |
| 4455 | - | |
| 4456 | - fn min_size(&self) -> Size<i32, Logical> { | |
| 4457 | - self.0.min_size | |
| 4458 | - } | |
| 4459 | - | |
| 4460 | - fn max_size(&self) -> Size<i32, Logical> { | |
| 4461 | - self.0.max_size | |
| 4462 | - } | |
| 4463 | - | |
| 4464 | - fn is_wl_surface(&self, _wl_surface: &WlSurface) -> bool { | |
| 4465 | - false | |
| 4466 | - } | |
| 4467 | - | |
| 4468 | - fn set_preferred_scale_transform(&self, _scale: output::Scale, _transform: Transform) {} | |
| 4469 | - | |
| 4470 | - fn has_ssd(&self) -> bool { | |
| 4471 | - false | |
| 4472 | - } | |
| 4473 | - | |
| 4474 | - fn output_enter(&self, _output: &Output) {} | |
| 4475 | - | |
| 4476 | - fn output_leave(&self, _output: &Output) {} | |
| 4477 | - | |
| 4478 | - fn set_offscreen_element_id(&self, _id: Option<Id>) {} | |
| 4479 | - | |
| 4480 | - fn set_activated(&mut self, active: bool) { | |
| 4481 | - self.0.pending_activated.set(active); | |
| 4482 | - } | |
| 4483 | - | |
| 4484 | - fn set_bounds(&self, _bounds: Size<i32, Logical>) {} | |
| 4485 | - | |
| 4486 | - fn is_ignoring_opacity_window_rule(&self) -> bool { | |
| 4487 | - false | |
| 4488 | - } | |
| 4489 | - | |
| 4490 | - fn configure_intent(&self) -> ConfigureIntent { | |
| 4491 | - ConfigureIntent::CanSend | |
| 4492 | - } | |
| 4493 | - | |
| 4494 | - fn send_pending_configure(&mut self) {} | |
| 4495 | - | |
| 4496 | - fn set_active_in_column(&mut self, _active: bool) {} | |
| 4497 | - | |
| 4498 | - fn set_floating(&mut self, _floating: bool) {} | |
| 4499 | - | |
| 4500 | - fn is_fullscreen(&self) -> bool { | |
| 4501 | - false | |
| 4502 | - } | |
| 4503 | - | |
| 4504 | - fn is_pending_fullscreen(&self) -> bool { | |
| 4505 | - self.0.pending_fullscreen.get() | |
| 4506 | - } | |
| 4507 | - | |
| 4508 | - fn requested_size(&self) -> Option<Size<i32, Logical>> { | |
| 4509 | - self.0.requested_size.get() | |
| 4510 | - } | |
| 4511 | - | |
| 4512 | - fn is_child_of(&self, parent: &Self) -> bool { | |
| 4513 | - self.0.parent_id.get() == Some(parent.0.id) | |
| 4514 | - } | |
| 4515 | - | |
| 4516 | - fn refresh(&self) {} | |
| 4517 | - | |
| 4518 | - fn rules(&self) -> &ResolvedWindowRules { | |
| 4519 | - static EMPTY: ResolvedWindowRules = ResolvedWindowRules::empty(); | |
| 4520 | - &EMPTY | |
| 4521 | - } | |
| 4522 | - | |
| 4523 | - fn animation_snapshot(&self) -> Option<&LayoutElementRenderSnapshot> { | |
| 4524 | - None | |
| 4525 | - } | |
| 4526 | - | |
| 4527 | - fn take_animation_snapshot(&mut self) -> Option<LayoutElementRenderSnapshot> { | |
| 4528 | - None | |
| 4529 | - } | |
| 4530 | - | |
| 4531 | - fn set_interactive_resize(&mut self, _data: Option<InteractiveResizeData>) {} | |
| 4532 | - | |
| 4533 | - fn cancel_interactive_resize(&mut self) {} | |
| 4534 | - | |
| 4535 | - fn on_commit(&mut self, _serial: Serial) {} | |
| 4536 | - | |
| 4537 | - fn interactive_resize_data(&self) -> Option<InteractiveResizeData> { | |
| 4538 | - None | |
| 4539 | - } | |
| 4540 | - } | |
| 4541 | - | |
| 4542 | - fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> { | |
| 4543 | - any::<(i16, i16, u16, u16)>().prop_map(|(x, y, w, h)| { | |
| 4544 | - let loc: Point<i32, _> = Point::from((x.into(), y.into())); | |
| 4545 | - let size: Size<i32, _> = Size::from((w.max(1).into(), h.max(1).into())); | |
| 4546 | - Rectangle::new(loc, size) | |
| 4547 | - }) | |
| 4548 | - } | |
| 4549 | - | |
| 4550 | - fn arbitrary_size_change() -> impl Strategy<Value = SizeChange> { | |
| 4551 | - prop_oneof![ | |
| 4552 | - (0..).prop_map(SizeChange::SetFixed), | |
| 4553 | - (0f64..).prop_map(SizeChange::SetProportion), | |
| 4554 | - any::<i32>().prop_map(SizeChange::AdjustFixed), | |
| 4555 | - any::<f64>().prop_map(SizeChange::AdjustProportion), | |
| 4556 | - // Interactive resize can have negative values here. | |
| 4557 | - Just(SizeChange::SetFixed(-100)), | |
| 4558 | - ] | |
| 4559 | - } | |
| 4560 | - | |
| 4561 | - fn arbitrary_position_change() -> impl Strategy<Value = PositionChange> { | |
| 4562 | - prop_oneof![ | |
| 4563 | - (-1000f64..1000f64).prop_map(PositionChange::SetFixed), | |
| 4564 | - (-1000f64..1000f64).prop_map(PositionChange::AdjustFixed), | |
| 4565 | - any::<f64>().prop_map(PositionChange::SetFixed), | |
| 4566 | - any::<f64>().prop_map(PositionChange::AdjustFixed), | |
| 4567 | - ] | |
| 4568 | - } | |
| 4569 | - | |
| 4570 | - fn arbitrary_min_max() -> impl Strategy<Value = (i32, i32)> { | |
| 4571 | - prop_oneof![ | |
| 4572 | - Just((0, 0)), | |
| 4573 | - (1..65536).prop_map(|n| (n, n)), | |
| 4574 | - (1..65536).prop_map(|min| (min, 0)), | |
| 4575 | - (1..).prop_map(|max| (0, max)), | |
| 4576 | - (1..65536, 1..).prop_map(|(min, max): (i32, i32)| (min, max.max(min))), | |
| 4577 | - ] | |
| 4578 | - } | |
| 4579 | - | |
| 4580 | - fn arbitrary_min_max_size() -> impl Strategy<Value = (Size<i32, Logical>, Size<i32, Logical>)> { | |
| 4581 | - prop_oneof![ | |
| 4582 | - 5 => (arbitrary_min_max(), arbitrary_min_max()).prop_map( | |
| 4583 | - |((min_w, max_w), (min_h, max_h))| { | |
| 4584 | - let min_size = Size::from((min_w, min_h)); | |
| 4585 | - let max_size = Size::from((max_w, max_h)); | |
| 4586 | - (min_size, max_size) | |
| 4587 | - }, | |
| 4588 | - ), | |
| 4589 | - 1 => arbitrary_min_max().prop_map(|(w, h)| { | |
| 4590 | - let size = Size::from((w, h)); | |
| 4591 | - (size, size) | |
| 4592 | - }), | |
| 4593 | - ] | |
| 4594 | - } | |
| 4595 | - | |
| 4596 | - fn arbitrary_view_offset_gesture_delta() -> impl Strategy<Value = f64> { | |
| 4597 | - prop_oneof![(-10f64..10f64), (-50000f64..50000f64),] | |
| 4598 | - } | |
| 4599 | - | |
| 4600 | - fn arbitrary_resize_edge() -> impl Strategy<Value = ResizeEdge> { | |
| 4601 | - prop_oneof![ | |
| 4602 | - Just(ResizeEdge::RIGHT), | |
| 4603 | - Just(ResizeEdge::BOTTOM), | |
| 4604 | - Just(ResizeEdge::LEFT), | |
| 4605 | - Just(ResizeEdge::TOP), | |
| 4606 | - Just(ResizeEdge::BOTTOM_RIGHT), | |
| 4607 | - Just(ResizeEdge::BOTTOM_LEFT), | |
| 4608 | - Just(ResizeEdge::TOP_RIGHT), | |
| 4609 | - Just(ResizeEdge::TOP_LEFT), | |
| 4610 | - Just(ResizeEdge::empty()), | |
| 4611 | - ] | |
| 4612 | - } | |
| 4613 | - | |
| 4614 | - fn arbitrary_scale() -> impl Strategy<Value = f64> { | |
| 4615 | - prop_oneof![Just(1.), Just(1.5), Just(2.),] | |
| 4616 | - } | |
| 4617 | - | |
| 4618 | - fn arbitrary_msec_delta() -> impl Strategy<Value = i32> { | |
| 4619 | - prop_oneof![ | |
| 4620 | - 1 => Just(-1000), | |
| 4621 | - 2 => Just(-10), | |
| 4622 | - 1 => Just(0), | |
| 4623 | - 2 => Just(10), | |
| 4624 | - 6 => Just(1000), | |
| 4625 | - ] | |
| 4626 | - } | |
| 4627 | - | |
| 4628 | - fn arbitrary_parent_id() -> impl Strategy<Value = Option<usize>> { | |
| 4629 | - prop_oneof![ | |
| 4630 | - 5 => Just(None), | |
| 4631 | - 1 => prop::option::of(1..=5usize), | |
| 4632 | - ] | |
| 4633 | - } | |
| 4634 | - | |
| 4635 | - fn arbitrary_scroll_direction() -> impl Strategy<Value = ScrollDirection> { | |
| 4636 | - prop_oneof![Just(ScrollDirection::Left), Just(ScrollDirection::Right)] | |
| 4637 | - } | |
| 4638 | - | |
| 4639 | - #[derive(Debug, Clone, Copy, Arbitrary)] | |
| 4640 | - enum Op { | |
| 4641 | - AddOutput(#[proptest(strategy = "1..=5usize")] usize), | |
| 4642 | - AddScaledOutput { | |
| 4643 | - #[proptest(strategy = "1..=5usize")] | |
| 4644 | - id: usize, | |
| 4645 | - #[proptest(strategy = "arbitrary_scale()")] | |
| 4646 | - scale: f64, | |
| 4647 | - }, | |
| 4648 | - RemoveOutput(#[proptest(strategy = "1..=5usize")] usize), | |
| 4649 | - FocusOutput(#[proptest(strategy = "1..=5usize")] usize), | |
| 4650 | - AddNamedWorkspace { | |
| 4651 | - #[proptest(strategy = "1..=5usize")] | |
| 4652 | - ws_name: usize, | |
| 4653 | - #[proptest(strategy = "prop::option::of(1..=5usize)")] | |
| 4654 | - output_name: Option<usize>, | |
| 4655 | - }, | |
| 4656 | - UnnameWorkspace { | |
| 4657 | - #[proptest(strategy = "1..=5usize")] | |
| 4658 | - ws_name: usize, | |
| 4659 | - }, | |
| 4660 | - AddWindow { | |
| 4661 | - params: TestWindowParams, | |
| 4662 | - }, | |
| 4663 | - AddWindowNextTo { | |
| 4664 | - params: TestWindowParams, | |
| 4665 | - #[proptest(strategy = "1..=5usize")] | |
| 4666 | - next_to_id: usize, | |
| 4667 | - }, | |
| 4668 | - AddWindowToNamedWorkspace { | |
| 4669 | - params: TestWindowParams, | |
| 4670 | - #[proptest(strategy = "1..=5usize")] | |
| 4671 | - ws_name: usize, | |
| 4672 | - }, | |
| 4673 | - CloseWindow(#[proptest(strategy = "1..=5usize")] usize), | |
| 4674 | - FullscreenWindow(#[proptest(strategy = "1..=5usize")] usize), | |
| 4675 | - SetFullscreenWindow { | |
| 4676 | - #[proptest(strategy = "1..=5usize")] | |
| 4677 | - window: usize, | |
| 4678 | - is_fullscreen: bool, | |
| 4679 | - }, | |
| 4680 | - FocusColumnLeft, | |
| 4681 | - FocusColumnRight, | |
| 4682 | - FocusColumnFirst, | |
| 4683 | - FocusColumnLast, | |
| 4684 | - FocusColumnRightOrFirst, | |
| 4685 | - FocusColumnLeftOrLast, | |
| 4686 | - FocusWindowOrMonitorUp(#[proptest(strategy = "1..=2u8")] u8), | |
| 4687 | - FocusWindowOrMonitorDown(#[proptest(strategy = "1..=2u8")] u8), | |
| 4688 | - FocusColumnOrMonitorLeft(#[proptest(strategy = "1..=2u8")] u8), | |
| 4689 | - FocusColumnOrMonitorRight(#[proptest(strategy = "1..=2u8")] u8), | |
| 4690 | - FocusWindowDown, | |
| 4691 | - FocusWindowUp, | |
| 4692 | - FocusWindowDownOrColumnLeft, | |
| 4693 | - FocusWindowDownOrColumnRight, | |
| 4694 | - FocusWindowUpOrColumnLeft, | |
| 4695 | - FocusWindowUpOrColumnRight, | |
| 4696 | - FocusWindowOrWorkspaceDown, | |
| 4697 | - FocusWindowOrWorkspaceUp, | |
| 4698 | - FocusWindow(#[proptest(strategy = "1..=5usize")] usize), | |
| 4699 | - MoveColumnLeft, | |
| 4700 | - MoveColumnRight, | |
| 4701 | - MoveColumnToFirst, | |
| 4702 | - MoveColumnToLast, | |
| 4703 | - MoveColumnLeftOrToMonitorLeft(#[proptest(strategy = "1..=2u8")] u8), | |
| 4704 | - MoveColumnRightOrToMonitorRight(#[proptest(strategy = "1..=2u8")] u8), | |
| 4705 | - MoveWindowDown, | |
| 4706 | - MoveWindowUp, | |
| 4707 | - MoveWindowDownOrToWorkspaceDown, | |
| 4708 | - MoveWindowUpOrToWorkspaceUp, | |
| 4709 | - ConsumeOrExpelWindowLeft { | |
| 4710 | - #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 4711 | - id: Option<usize>, | |
| 4712 | - }, | |
| 4713 | - ConsumeOrExpelWindowRight { | |
| 4714 | - #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 4715 | - id: Option<usize>, | |
| 4716 | - }, | |
| 4717 | - ConsumeWindowIntoColumn, | |
| 4718 | - ExpelWindowFromColumn, | |
| 4719 | - SwapWindowInDirection( | |
| 4720 | - #[proptest(strategy = "arbitrary_scroll_direction()")] ScrollDirection, | |
| 4721 | - ), | |
| 4722 | - CenterColumn, | |
| 4723 | - CenterWindow { | |
| 4724 | - #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 4725 | - id: Option<usize>, | |
| 4726 | - }, | |
| 4727 | - FocusWorkspaceDown, | |
| 4728 | - FocusWorkspaceUp, | |
| 4729 | - FocusWorkspace(#[proptest(strategy = "0..=4usize")] usize), | |
| 4730 | - FocusWorkspaceAutoBackAndForth(#[proptest(strategy = "0..=4usize")] usize), | |
| 4731 | - FocusWorkspacePrevious, | |
| 4732 | - MoveWindowToWorkspaceDown, | |
| 4733 | - MoveWindowToWorkspaceUp, | |
| 4734 | - MoveWindowToWorkspace { | |
| 4735 | - #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 4736 | - window_id: Option<usize>, | |
| 4737 | - #[proptest(strategy = "0..=4usize")] | |
| 4738 | - workspace_idx: usize, | |
| 4739 | - }, | |
| 4740 | - MoveColumnToWorkspaceDown, | |
| 4741 | - MoveColumnToWorkspaceUp, | |
| 4742 | - MoveColumnToWorkspace(#[proptest(strategy = "0..=4usize")] usize), | |
| 4743 | - MoveWorkspaceDown, | |
| 4744 | - MoveWorkspaceUp, | |
| 4745 | - MoveWorkspaceToIndex { | |
| 4746 | - #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 4747 | - ws_name: Option<usize>, | |
| 4748 | - #[proptest(strategy = "0..=4usize")] | |
| 4749 | - target_idx: usize, | |
| 4750 | - }, | |
| 4751 | - MoveWorkspaceToMonitor { | |
| 4752 | - #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 4753 | - ws_name: Option<usize>, | |
| 4754 | - #[proptest(strategy = "0..=5usize")] | |
| 4755 | - output_id: usize, | |
| 4756 | - }, | |
| 4757 | - SetWorkspaceName { | |
| 4758 | - #[proptest(strategy = "1..=5usize")] | |
| 4759 | - new_ws_name: usize, | |
| 4760 | - #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 4761 | - ws_name: Option<usize>, | |
| 4762 | - }, | |
| 4763 | - UnsetWorkspaceName { | |
| 4764 | - #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 4765 | - ws_name: Option<usize>, | |
| 4766 | - }, | |
| 4767 | - MoveWindowToOutput { | |
| 4768 | - #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 4769 | - window_id: Option<usize>, | |
| 4770 | - #[proptest(strategy = "1..=5usize")] | |
| 4771 | - output_id: usize, | |
| 4772 | - #[proptest(strategy = "proptest::option::of(0..=4usize)")] | |
| 4773 | - target_ws_idx: Option<usize>, | |
| 4774 | - }, | |
| 4775 | - MoveColumnToOutput(#[proptest(strategy = "1..=5usize")] usize), | |
| 4776 | - SwitchPresetColumnWidth, | |
| 4777 | - SwitchPresetWindowWidth { | |
| 4778 | - #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 4779 | - id: Option<usize>, | |
| 4780 | - }, | |
| 4781 | - SwitchPresetWindowHeight { | |
| 4782 | - #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 4783 | - id: Option<usize>, | |
| 4784 | - }, | |
| 4785 | - MaximizeColumn, | |
| 4786 | - SetColumnWidth(#[proptest(strategy = "arbitrary_size_change()")] SizeChange), | |
| 4787 | - SetWindowWidth { | |
| 4788 | - #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 4789 | - id: Option<usize>, | |
| 4790 | - #[proptest(strategy = "arbitrary_size_change()")] | |
| 4791 | - change: SizeChange, | |
| 4792 | - }, | |
| 4793 | - SetWindowHeight { | |
| 4794 | - #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 4795 | - id: Option<usize>, | |
| 4796 | - #[proptest(strategy = "arbitrary_size_change()")] | |
| 4797 | - change: SizeChange, | |
| 4798 | - }, | |
| 4799 | - ResetWindowHeight { | |
| 4800 | - #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 4801 | - id: Option<usize>, | |
| 4802 | - }, | |
| 4803 | - ToggleWindowFloating { | |
| 4804 | - #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 4805 | - id: Option<usize>, | |
| 4806 | - }, | |
| 4807 | - SetWindowFloating { | |
| 4808 | - #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 4809 | - id: Option<usize>, | |
| 4810 | - floating: bool, | |
| 4811 | - }, | |
| 4812 | - FocusFloating, | |
| 4813 | - FocusTiling, | |
| 4814 | - SwitchFocusFloatingTiling, | |
| 4815 | - MoveFloatingWindow { | |
| 4816 | - #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 4817 | - id: Option<usize>, | |
| 4818 | - #[proptest(strategy = "arbitrary_position_change()")] | |
| 4819 | - x: PositionChange, | |
| 4820 | - #[proptest(strategy = "arbitrary_position_change()")] | |
| 4821 | - y: PositionChange, | |
| 4822 | - animate: bool, | |
| 4823 | - }, | |
| 4824 | - SetParent { | |
| 4825 | - #[proptest(strategy = "1..=5usize")] | |
| 4826 | - id: usize, | |
| 4827 | - #[proptest(strategy = "prop::option::of(1..=5usize)")] | |
| 4828 | - new_parent_id: Option<usize>, | |
| 4829 | - }, | |
| 4830 | - Communicate(#[proptest(strategy = "1..=5usize")] usize), | |
| 4831 | - Refresh { | |
| 4832 | - is_active: bool, | |
| 4833 | - }, | |
| 4834 | - AdvanceAnimations { | |
| 4835 | - #[proptest(strategy = "arbitrary_msec_delta()")] | |
| 4836 | - msec_delta: i32, | |
| 4837 | - }, | |
| 4838 | - MoveWorkspaceToOutput(#[proptest(strategy = "1..=5usize")] usize), | |
| 4839 | - ViewOffsetGestureBegin { | |
| 4840 | - #[proptest(strategy = "1..=5usize")] | |
| 4841 | - output_idx: usize, | |
| 4842 | - is_touchpad: bool, | |
| 4843 | - }, | |
| 4844 | - ViewOffsetGestureUpdate { | |
| 4845 | - #[proptest(strategy = "arbitrary_view_offset_gesture_delta()")] | |
| 4846 | - delta: f64, | |
| 4847 | - timestamp: Duration, | |
| 4848 | - is_touchpad: bool, | |
| 4849 | - }, | |
| 4850 | - ViewOffsetGestureEnd { | |
| 4851 | - is_touchpad: Option<bool>, | |
| 4852 | - }, | |
| 4853 | - WorkspaceSwitchGestureBegin { | |
| 4854 | - #[proptest(strategy = "1..=5usize")] | |
| 4855 | - output_idx: usize, | |
| 4856 | - is_touchpad: bool, | |
| 4857 | - }, | |
| 4858 | - WorkspaceSwitchGestureUpdate { | |
| 4859 | - #[proptest(strategy = "-400f64..400f64")] | |
| 4860 | - delta: f64, | |
| 4861 | - timestamp: Duration, | |
| 4862 | - is_touchpad: bool, | |
| 4863 | - }, | |
| 4864 | - WorkspaceSwitchGestureEnd { | |
| 4865 | - cancelled: bool, | |
| 4866 | - is_touchpad: Option<bool>, | |
| 4867 | - }, | |
| 4868 | - InteractiveMoveBegin { | |
| 4869 | - #[proptest(strategy = "1..=5usize")] | |
| 4870 | - window: usize, | |
| 4871 | - #[proptest(strategy = "1..=5usize")] | |
| 4872 | - output_idx: usize, | |
| 4873 | - #[proptest(strategy = "-20000f64..20000f64")] | |
| 4874 | - px: f64, | |
| 4875 | - #[proptest(strategy = "-20000f64..20000f64")] | |
| 4876 | - py: f64, | |
| 4877 | - }, | |
| 4878 | - InteractiveMoveUpdate { | |
| 4879 | - #[proptest(strategy = "1..=5usize")] | |
| 4880 | - window: usize, | |
| 4881 | - #[proptest(strategy = "-20000f64..20000f64")] | |
| 4882 | - dx: f64, | |
| 4883 | - #[proptest(strategy = "-20000f64..20000f64")] | |
| 4884 | - dy: f64, | |
| 4885 | - #[proptest(strategy = "1..=5usize")] | |
| 4886 | - output_idx: usize, | |
| 4887 | - #[proptest(strategy = "-20000f64..20000f64")] | |
| 4888 | - px: f64, | |
| 4889 | - #[proptest(strategy = "-20000f64..20000f64")] | |
| 4890 | - py: f64, | |
| 4891 | - }, | |
| 4892 | - InteractiveMoveEnd { | |
| 4893 | - #[proptest(strategy = "1..=5usize")] | |
| 4894 | - window: usize, | |
| 4895 | - }, | |
| 4896 | - InteractiveResizeBegin { | |
| 4897 | - #[proptest(strategy = "1..=5usize")] | |
| 4898 | - window: usize, | |
| 4899 | - #[proptest(strategy = "arbitrary_resize_edge()")] | |
| 4900 | - edges: ResizeEdge, | |
| 4901 | - }, | |
| 4902 | - InteractiveResizeUpdate { | |
| 4903 | - #[proptest(strategy = "1..=5usize")] | |
| 4904 | - window: usize, | |
| 4905 | - #[proptest(strategy = "-20000f64..20000f64")] | |
| 4906 | - dx: f64, | |
| 4907 | - #[proptest(strategy = "-20000f64..20000f64")] | |
| 4908 | - dy: f64, | |
| 4909 | - }, | |
| 4910 | - InteractiveResizeEnd { | |
| 4911 | - #[proptest(strategy = "1..=5usize")] | |
| 4912 | - window: usize, | |
| 4913 | - }, | |
| 4914 | - } | |
| 4915 | - | |
| 4916 | - impl Op { | |
| 4917 | - fn apply(self, layout: &mut Layout<TestWindow>) { | |
| 4918 | - match self { | |
| 4919 | - Op::AddOutput(id) => { | |
| 4920 | - let name = format!("output{id}"); | |
| 4921 | - if layout.outputs().any(|o| o.name() == name) { | |
| 4922 | - return; | |
| 4923 | - } | |
| 4924 | - | |
| 4925 | - let output = Output::new( | |
| 4926 | - name.clone(), | |
| 4927 | - PhysicalProperties { | |
| 4928 | - size: Size::from((1280, 720)), | |
| 4929 | - subpixel: Subpixel::Unknown, | |
| 4930 | - make: String::new(), | |
| 4931 | - model: String::new(), | |
| 4932 | - }, | |
| 4933 | - ); | |
| 4934 | - output.change_current_state( | |
| 4935 | - Some(Mode { | |
| 4936 | - size: Size::from((1280, 720)), | |
| 4937 | - refresh: 60000, | |
| 4938 | - }), | |
| 4939 | - None, | |
| 4940 | - None, | |
| 4941 | - None, | |
| 4942 | - ); | |
| 4943 | - output.user_data().insert_if_missing(|| OutputName { | |
| 4944 | - connector: name, | |
| 4945 | - make: None, | |
| 4946 | - model: None, | |
| 4947 | - serial: None, | |
| 4948 | - }); | |
| 4949 | - layout.add_output(output.clone()); | |
| 4950 | - } | |
| 4951 | - Op::AddScaledOutput { id, scale } => { | |
| 4952 | - let name = format!("output{id}"); | |
| 4953 | - if layout.outputs().any(|o| o.name() == name) { | |
| 4954 | - return; | |
| 4955 | - } | |
| 4956 | - | |
| 4957 | - let output = Output::new( | |
| 4958 | - name.clone(), | |
| 4959 | - PhysicalProperties { | |
| 4960 | - size: Size::from((1280, 720)), | |
| 4961 | - subpixel: Subpixel::Unknown, | |
| 4962 | - make: String::new(), | |
| 4963 | - model: String::new(), | |
| 4964 | - }, | |
| 4965 | - ); | |
| 4966 | - output.change_current_state( | |
| 4967 | - Some(Mode { | |
| 4968 | - size: Size::from((1280, 720)), | |
| 4969 | - refresh: 60000, | |
| 4970 | - }), | |
| 4971 | - None, | |
| 4972 | - Some(smithay::output::Scale::Fractional(scale)), | |
| 4973 | - None, | |
| 4974 | - ); | |
| 4975 | - output.user_data().insert_if_missing(|| OutputName { | |
| 4976 | - connector: name, | |
| 4977 | - make: None, | |
| 4978 | - model: None, | |
| 4979 | - serial: None, | |
| 4980 | - }); | |
| 4981 | - layout.add_output(output.clone()); | |
| 4982 | - } | |
| 4983 | - Op::RemoveOutput(id) => { | |
| 4984 | - let name = format!("output{id}"); | |
| 4985 | - let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 4986 | - return; | |
| 4987 | - }; | |
| 4988 | - | |
| 4989 | - layout.remove_output(&output); | |
| 4990 | - } | |
| 4991 | - Op::FocusOutput(id) => { | |
| 4992 | - let name = format!("output{id}"); | |
| 4993 | - let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 4994 | - return; | |
| 4995 | - }; | |
| 4996 | - | |
| 4997 | - layout.focus_output(&output); | |
| 4998 | - } | |
| 4999 | - Op::AddNamedWorkspace { | |
| 5000 | - ws_name, | |
| 5001 | - output_name, | |
| 5002 | - } => { | |
| 5003 | - layout.ensure_named_workspace(&WorkspaceConfig { | |
| 5004 | - name: WorkspaceName(format!("ws{ws_name}")), | |
| 5005 | - open_on_output: output_name.map(|name| format!("output{name}")), | |
| 5006 | - }); | |
| 5007 | - } | |
| 5008 | - Op::UnnameWorkspace { ws_name } => { | |
| 5009 | - layout.unname_workspace(&format!("ws{ws_name}")); | |
| 5010 | - } | |
| 5011 | - Op::SetWorkspaceName { | |
| 5012 | - new_ws_name, | |
| 5013 | - ws_name, | |
| 5014 | - } => { | |
| 5015 | - let ws_ref = | |
| 5016 | - ws_name.map(|ws_name| WorkspaceReference::Name(format!("ws{ws_name}"))); | |
| 5017 | - layout.set_workspace_name(format!("ws{new_ws_name}"), ws_ref); | |
| 5018 | - } | |
| 5019 | - Op::UnsetWorkspaceName { ws_name } => { | |
| 5020 | - let ws_ref = | |
| 5021 | - ws_name.map(|ws_name| WorkspaceReference::Name(format!("ws{ws_name}"))); | |
| 5022 | - layout.unset_workspace_name(ws_ref); | |
| 5023 | - } | |
| 5024 | - Op::AddWindow { mut params } => { | |
| 5025 | - if layout.has_window(¶ms.id) { | |
| 5026 | - return; | |
| 5027 | - } | |
| 5028 | - if let Some(parent_id) = params.parent_id { | |
| 5029 | - if parent_id_causes_loop(layout, params.id, parent_id) { | |
| 5030 | - params.parent_id = None; | |
| 5031 | - } | |
| 5032 | - } | |
| 5033 | - | |
| 5034 | - let win = TestWindow::new(params); | |
| 5035 | - layout.add_window( | |
| 5036 | - win, | |
| 5037 | - AddWindowTarget::Auto, | |
| 5038 | - None, | |
| 5039 | - None, | |
| 5040 | - false, | |
| 5041 | - params.is_floating, | |
| 5042 | - ActivateWindow::default(), | |
| 5043 | - ); | |
| 5044 | - } | |
| 5045 | - Op::AddWindowNextTo { | |
| 5046 | - mut params, | |
| 5047 | - next_to_id, | |
| 5048 | - } => { | |
| 5049 | - let mut found_next_to = false; | |
| 5050 | - | |
| 5051 | - if let Some(InteractiveMoveState::Moving(move_)) = &layout.interactive_move { | |
| 5052 | - let win_id = move_.tile.window().0.id; | |
| 5053 | - if win_id == params.id { | |
| 5054 | - return; | |
| 5055 | - } | |
| 5056 | - if win_id == next_to_id { | |
| 5057 | - found_next_to = true; | |
| 5058 | - } | |
| 5059 | - } | |
| 5060 | - | |
| 5061 | - match &mut layout.monitor_set { | |
| 5062 | - MonitorSet::Normal { monitors, .. } => { | |
| 5063 | - for mon in monitors { | |
| 5064 | - for ws in &mut mon.workspaces { | |
| 5065 | - for win in ws.windows() { | |
| 5066 | - if win.0.id == params.id { | |
| 5067 | - return; | |
| 5068 | - } | |
| 5069 | - | |
| 5070 | - if win.0.id == next_to_id { | |
| 5071 | - found_next_to = true; | |
| 5072 | - } | |
| 5073 | - } | |
| 5074 | - } | |
| 5075 | - } | |
| 5076 | - } | |
| 5077 | - MonitorSet::NoOutputs { workspaces, .. } => { | |
| 5078 | - for ws in workspaces { | |
| 5079 | - for win in ws.windows() { | |
| 5080 | - if win.0.id == params.id { | |
| 5081 | - return; | |
| 5082 | - } | |
| 5083 | - | |
| 5084 | - if win.0.id == next_to_id { | |
| 5085 | - found_next_to = true; | |
| 5086 | - } | |
| 5087 | - } | |
| 5088 | - } | |
| 5089 | - } | |
| 5090 | - } | |
| 5091 | - | |
| 5092 | - if !found_next_to { | |
| 5093 | - return; | |
| 5094 | - } | |
| 5095 | - | |
| 5096 | - if let Some(parent_id) = params.parent_id { | |
| 5097 | - if parent_id_causes_loop(layout, params.id, parent_id) { | |
| 5098 | - params.parent_id = None; | |
| 5099 | - } | |
| 5100 | - } | |
| 5101 | - | |
| 5102 | - let win = TestWindow::new(params); | |
| 5103 | - layout.add_window( | |
| 5104 | - win, | |
| 5105 | - AddWindowTarget::NextTo(&next_to_id), | |
| 5106 | - None, | |
| 5107 | - None, | |
| 5108 | - false, | |
| 5109 | - params.is_floating, | |
| 5110 | - ActivateWindow::default(), | |
| 5111 | - ); | |
| 5112 | - } | |
| 5113 | - Op::AddWindowToNamedWorkspace { | |
| 5114 | - mut params, | |
| 5115 | - ws_name, | |
| 5116 | - } => { | |
| 5117 | - let ws_name = format!("ws{ws_name}"); | |
| 5118 | - let mut ws_id = None; | |
| 5119 | - | |
| 5120 | - if let Some(InteractiveMoveState::Moving(move_)) = &layout.interactive_move { | |
| 5121 | - if move_.tile.window().0.id == params.id { | |
| 5122 | - return; | |
| 5123 | - } | |
| 5124 | - } | |
| 5125 | - | |
| 5126 | - match &mut layout.monitor_set { | |
| 5127 | - MonitorSet::Normal { monitors, .. } => { | |
| 5128 | - for mon in monitors { | |
| 5129 | - for ws in &mut mon.workspaces { | |
| 5130 | - for win in ws.windows() { | |
| 5131 | - if win.0.id == params.id { | |
| 5132 | - return; | |
| 5133 | - } | |
| 5134 | - } | |
| 5135 | - | |
| 5136 | - if ws | |
| 5137 | - .name | |
| 5138 | - .as_ref() | |
| 5139 | - .is_some_and(|name| name.eq_ignore_ascii_case(&ws_name)) | |
| 5140 | - { | |
| 5141 | - ws_id = Some(ws.id()); | |
| 5142 | - } | |
| 5143 | - } | |
| 5144 | - } | |
| 5145 | - } | |
| 5146 | - MonitorSet::NoOutputs { workspaces, .. } => { | |
| 5147 | - for ws in workspaces { | |
| 5148 | - for win in ws.windows() { | |
| 5149 | - if win.0.id == params.id { | |
| 5150 | - return; | |
| 5151 | - } | |
| 5152 | - } | |
| 5153 | - | |
| 5154 | - if ws | |
| 5155 | - .name | |
| 5156 | - .as_ref() | |
| 5157 | - .is_some_and(|name| name.eq_ignore_ascii_case(&ws_name)) | |
| 5158 | - { | |
| 5159 | - ws_id = Some(ws.id()); | |
| 5160 | - } | |
| 5161 | - } | |
| 5162 | - } | |
| 5163 | - } | |
| 5164 | - | |
| 5165 | - let Some(ws_id) = ws_id else { | |
| 5166 | - return; | |
| 5167 | - }; | |
| 5168 | - | |
| 5169 | - if let Some(parent_id) = params.parent_id { | |
| 5170 | - if parent_id_causes_loop(layout, params.id, parent_id) { | |
| 5171 | - params.parent_id = None; | |
| 5172 | - } | |
| 5173 | - } | |
| 5174 | - | |
| 5175 | - let win = TestWindow::new(params); | |
| 5176 | - layout.add_window( | |
| 5177 | - win, | |
| 5178 | - AddWindowTarget::Workspace(ws_id), | |
| 5179 | - None, | |
| 5180 | - None, | |
| 5181 | - false, | |
| 5182 | - params.is_floating, | |
| 5183 | - ActivateWindow::default(), | |
| 5184 | - ); | |
| 5185 | - } | |
| 5186 | - Op::CloseWindow(id) => { | |
| 5187 | - layout.remove_window(&id, Transaction::new()); | |
| 5188 | - } | |
| 5189 | - Op::FullscreenWindow(id) => { | |
| 5190 | - layout.toggle_fullscreen(&id); | |
| 5191 | - } | |
| 5192 | - Op::SetFullscreenWindow { | |
| 5193 | - window, | |
| 5194 | - is_fullscreen, | |
| 5195 | - } => { | |
| 5196 | - layout.set_fullscreen(&window, is_fullscreen); | |
| 5197 | - } | |
| 5198 | - Op::FocusColumnLeft => layout.focus_left(), | |
| 5199 | - Op::FocusColumnRight => layout.focus_right(), | |
| 5200 | - Op::FocusColumnFirst => layout.focus_column_first(), | |
| 5201 | - Op::FocusColumnLast => layout.focus_column_last(), | |
| 5202 | - Op::FocusColumnRightOrFirst => layout.focus_column_right_or_first(), | |
| 5203 | - Op::FocusColumnLeftOrLast => layout.focus_column_left_or_last(), | |
| 5204 | - Op::FocusWindowOrMonitorUp(id) => { | |
| 5205 | - let name = format!("output{id}"); | |
| 5206 | - let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 5207 | - return; | |
| 5208 | - }; | |
| 5209 | - | |
| 5210 | - layout.focus_window_up_or_output(&output); | |
| 5211 | - } | |
| 5212 | - Op::FocusWindowOrMonitorDown(id) => { | |
| 5213 | - let name = format!("output{id}"); | |
| 5214 | - let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 5215 | - return; | |
| 5216 | - }; | |
| 5217 | - | |
| 5218 | - layout.focus_window_down_or_output(&output); | |
| 5219 | - } | |
| 5220 | - Op::FocusColumnOrMonitorLeft(id) => { | |
| 5221 | - let name = format!("output{id}"); | |
| 5222 | - let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 5223 | - return; | |
| 5224 | - }; | |
| 5225 | - | |
| 5226 | - layout.focus_column_left_or_output(&output); | |
| 5227 | - } | |
| 5228 | - Op::FocusColumnOrMonitorRight(id) => { | |
| 5229 | - let name = format!("output{id}"); | |
| 5230 | - let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 5231 | - return; | |
| 5232 | - }; | |
| 5233 | - | |
| 5234 | - layout.focus_column_right_or_output(&output); | |
| 5235 | - } | |
| 5236 | - Op::FocusWindowDown => layout.focus_down(), | |
| 5237 | - Op::FocusWindowUp => layout.focus_up(), | |
| 5238 | - Op::FocusWindowDownOrColumnLeft => layout.focus_down_or_left(), | |
| 5239 | - Op::FocusWindowDownOrColumnRight => layout.focus_down_or_right(), | |
| 5240 | - Op::FocusWindowUpOrColumnLeft => layout.focus_up_or_left(), | |
| 5241 | - Op::FocusWindowUpOrColumnRight => layout.focus_up_or_right(), | |
| 5242 | - Op::FocusWindowOrWorkspaceDown => layout.focus_window_or_workspace_down(), | |
| 5243 | - Op::FocusWindowOrWorkspaceUp => layout.focus_window_or_workspace_up(), | |
| 5244 | - Op::FocusWindow(id) => layout.activate_window(&id), | |
| 5245 | - Op::MoveColumnLeft => layout.move_left(), | |
| 5246 | - Op::MoveColumnRight => layout.move_right(), | |
| 5247 | - Op::MoveColumnToFirst => layout.move_column_to_first(), | |
| 5248 | - Op::MoveColumnToLast => layout.move_column_to_last(), | |
| 5249 | - Op::MoveColumnLeftOrToMonitorLeft(id) => { | |
| 5250 | - let name = format!("output{id}"); | |
| 5251 | - let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 5252 | - return; | |
| 5253 | - }; | |
| 5254 | - | |
| 5255 | - layout.move_column_left_or_to_output(&output); | |
| 5256 | - } | |
| 5257 | - Op::MoveColumnRightOrToMonitorRight(id) => { | |
| 5258 | - let name = format!("output{id}"); | |
| 5259 | - let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 5260 | - return; | |
| 5261 | - }; | |
| 5262 | - | |
| 5263 | - layout.move_column_right_or_to_output(&output); | |
| 5264 | - } | |
| 5265 | - Op::MoveWindowDown => layout.move_down(), | |
| 5266 | - Op::MoveWindowUp => layout.move_up(), | |
| 5267 | - Op::MoveWindowDownOrToWorkspaceDown => layout.move_down_or_to_workspace_down(), | |
| 5268 | - Op::MoveWindowUpOrToWorkspaceUp => layout.move_up_or_to_workspace_up(), | |
| 5269 | - Op::ConsumeOrExpelWindowLeft { id } => { | |
| 5270 | - let id = id.filter(|id| layout.has_window(id)); | |
| 5271 | - layout.consume_or_expel_window_left(id.as_ref()); | |
| 5272 | - } | |
| 5273 | - Op::ConsumeOrExpelWindowRight { id } => { | |
| 5274 | - let id = id.filter(|id| layout.has_window(id)); | |
| 5275 | - layout.consume_or_expel_window_right(id.as_ref()); | |
| 5276 | - } | |
| 5277 | - Op::ConsumeWindowIntoColumn => layout.consume_into_column(), | |
| 5278 | - Op::ExpelWindowFromColumn => layout.expel_from_column(), | |
| 5279 | - Op::SwapWindowInDirection(direction) => layout.swap_window_in_direction(direction), | |
| 5280 | - Op::CenterColumn => layout.center_column(), | |
| 5281 | - Op::CenterWindow { id } => { | |
| 5282 | - let id = id.filter(|id| layout.has_window(id)); | |
| 5283 | - layout.center_window(id.as_ref()); | |
| 5284 | - } | |
| 5285 | - Op::FocusWorkspaceDown => layout.switch_workspace_down(), | |
| 5286 | - Op::FocusWorkspaceUp => layout.switch_workspace_up(), | |
| 5287 | - Op::FocusWorkspace(idx) => layout.switch_workspace(idx), | |
| 5288 | - Op::FocusWorkspaceAutoBackAndForth(idx) => { | |
| 5289 | - layout.switch_workspace_auto_back_and_forth(idx) | |
| 5290 | - } | |
| 5291 | - Op::FocusWorkspacePrevious => layout.switch_workspace_previous(), | |
| 5292 | - Op::MoveWindowToWorkspaceDown => layout.move_to_workspace_down(), | |
| 5293 | - Op::MoveWindowToWorkspaceUp => layout.move_to_workspace_up(), | |
| 5294 | - Op::MoveWindowToWorkspace { | |
| 5295 | - window_id, | |
| 5296 | - workspace_idx, | |
| 5297 | - } => { | |
| 5298 | - let window_id = window_id.filter(|id| layout.has_window(id)); | |
| 5299 | - layout.move_to_workspace(window_id.as_ref(), workspace_idx); | |
| 5300 | - } | |
| 5301 | - Op::MoveColumnToWorkspaceDown => layout.move_column_to_workspace_down(), | |
| 5302 | - Op::MoveColumnToWorkspaceUp => layout.move_column_to_workspace_up(), | |
| 5303 | - Op::MoveColumnToWorkspace(idx) => layout.move_column_to_workspace(idx), | |
| 5304 | - Op::MoveWindowToOutput { | |
| 5305 | - window_id, | |
| 5306 | - output_id: id, | |
| 5307 | - target_ws_idx, | |
| 5308 | - } => { | |
| 5309 | - let name = format!("output{id}"); | |
| 5310 | - let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 5311 | - return; | |
| 5312 | - }; | |
| 5313 | - let mon = layout.monitor_for_output(&output).unwrap(); | |
| 5314 | - | |
| 5315 | - let window_id = window_id.filter(|id| layout.has_window(id)); | |
| 5316 | - let target_ws_idx = target_ws_idx.filter(|idx| mon.workspaces.len() > *idx); | |
| 5317 | - layout.move_to_output(window_id.as_ref(), &output, target_ws_idx); | |
| 5318 | - } | |
| 5319 | - Op::MoveColumnToOutput(id) => { | |
| 5320 | - let name = format!("output{id}"); | |
| 5321 | - let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 5322 | - return; | |
| 5323 | - }; | |
| 5324 | - | |
| 5325 | - layout.move_column_to_output(&output); | |
| 5326 | - } | |
| 5327 | - Op::MoveWorkspaceDown => layout.move_workspace_down(), | |
| 5328 | - Op::MoveWorkspaceUp => layout.move_workspace_up(), | |
| 5329 | - Op::MoveWorkspaceToIndex { | |
| 5330 | - ws_name: Some(ws_name), | |
| 5331 | - target_idx, | |
| 5332 | - } => { | |
| 5333 | - let MonitorSet::Normal { monitors, .. } = &mut layout.monitor_set else { | |
| 5334 | - return; | |
| 5335 | - }; | |
| 5336 | - | |
| 5337 | - let Some((old_idx, old_output)) = monitors.iter().find_map(|monitor| { | |
| 5338 | - monitor | |
| 5339 | - .workspaces | |
| 5340 | - .iter() | |
| 5341 | - .enumerate() | |
| 5342 | - .find_map(|(i, ws)| { | |
| 5343 | - if ws.name == Some(format!("ws{ws_name}")) { | |
| 5344 | - Some(i) | |
| 5345 | - } else { | |
| 5346 | - None | |
| 5347 | - } | |
| 5348 | - }) | |
| 5349 | - .map(|i| (i, monitor.output.clone())) | |
| 5350 | - }) else { | |
| 5351 | - return; | |
| 5352 | - }; | |
| 5353 | - | |
| 5354 | - layout.move_workspace_to_idx(Some((Some(old_output), old_idx)), target_idx) | |
| 5355 | - } | |
| 5356 | - Op::MoveWorkspaceToIndex { | |
| 5357 | - ws_name: None, | |
| 5358 | - target_idx, | |
| 5359 | - } => layout.move_workspace_to_idx(None, target_idx), | |
| 5360 | - Op::MoveWorkspaceToMonitor { | |
| 5361 | - ws_name: None, | |
| 5362 | - output_id: id, | |
| 5363 | - } => { | |
| 5364 | - let name = format!("output{id}"); | |
| 5365 | - let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 5366 | - return; | |
| 5367 | - }; | |
| 5368 | - layout.move_workspace_to_output(&output); | |
| 5369 | - } | |
| 5370 | - Op::MoveWorkspaceToMonitor { | |
| 5371 | - ws_name: Some(ws_name), | |
| 5372 | - output_id: id, | |
| 5373 | - } => { | |
| 5374 | - let name = format!("output{id}"); | |
| 5375 | - let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 5376 | - return; | |
| 5377 | - }; | |
| 5378 | - let MonitorSet::Normal { monitors, .. } = &mut layout.monitor_set else { | |
| 5379 | - return; | |
| 5380 | - }; | |
| 5381 | - | |
| 5382 | - let Some((old_idx, old_output)) = monitors.iter().find_map(|monitor| { | |
| 5383 | - monitor | |
| 5384 | - .workspaces | |
| 5385 | - .iter() | |
| 5386 | - .enumerate() | |
| 5387 | - .find_map(|(i, ws)| { | |
| 5388 | - if ws.name == Some(format!("ws{ws_name}")) { | |
| 5389 | - Some(i) | |
| 5390 | - } else { | |
| 5391 | - None | |
| 5392 | - } | |
| 5393 | - }) | |
| 5394 | - .map(|i| (i, monitor.output.clone())) | |
| 5395 | - }) else { | |
| 5396 | - return; | |
| 5397 | - }; | |
| 5398 | - | |
| 5399 | - layout.move_workspace_to_output_by_id(old_idx, Some(old_output), output); | |
| 5400 | - } | |
| 5401 | - Op::SwitchPresetColumnWidth => layout.toggle_width(), | |
| 5402 | - Op::SwitchPresetWindowWidth { id } => { | |
| 5403 | - let id = id.filter(|id| layout.has_window(id)); | |
| 5404 | - layout.toggle_window_width(id.as_ref()); | |
| 5405 | - } | |
| 5406 | - Op::SwitchPresetWindowHeight { id } => { | |
| 5407 | - let id = id.filter(|id| layout.has_window(id)); | |
| 5408 | - layout.toggle_window_height(id.as_ref()); | |
| 5409 | - } | |
| 5410 | - Op::MaximizeColumn => layout.toggle_full_width(), | |
| 5411 | - Op::SetColumnWidth(change) => layout.set_column_width(change), | |
| 5412 | - Op::SetWindowWidth { id, change } => { | |
| 5413 | - let id = id.filter(|id| layout.has_window(id)); | |
| 5414 | - layout.set_window_width(id.as_ref(), change); | |
| 5415 | - } | |
| 5416 | - Op::SetWindowHeight { id, change } => { | |
| 5417 | - let id = id.filter(|id| layout.has_window(id)); | |
| 5418 | - layout.set_window_height(id.as_ref(), change); | |
| 5419 | - } | |
| 5420 | - Op::ResetWindowHeight { id } => { | |
| 5421 | - let id = id.filter(|id| layout.has_window(id)); | |
| 5422 | - layout.reset_window_height(id.as_ref()); | |
| 5423 | - } | |
| 5424 | - Op::ToggleWindowFloating { id } => { | |
| 5425 | - let id = id.filter(|id| layout.has_window(id)); | |
| 5426 | - layout.toggle_window_floating(id.as_ref()); | |
| 5427 | - } | |
| 5428 | - Op::SetWindowFloating { id, floating } => { | |
| 5429 | - let id = id.filter(|id| layout.has_window(id)); | |
| 5430 | - layout.set_window_floating(id.as_ref(), floating); | |
| 5431 | - } | |
| 5432 | - Op::FocusFloating => { | |
| 5433 | - layout.focus_floating(); | |
| 5434 | - } | |
| 5435 | - Op::FocusTiling => { | |
| 5436 | - layout.focus_tiling(); | |
| 5437 | - } | |
| 5438 | - Op::SwitchFocusFloatingTiling => { | |
| 5439 | - layout.switch_focus_floating_tiling(); | |
| 5440 | - } | |
| 5441 | - Op::MoveFloatingWindow { id, x, y, animate } => { | |
| 5442 | - let id = id.filter(|id| layout.has_window(id)); | |
| 5443 | - layout.move_floating_window(id.as_ref(), x, y, animate); | |
| 5444 | - } | |
| 5445 | - Op::SetParent { | |
| 5446 | - id, | |
| 5447 | - mut new_parent_id, | |
| 5448 | - } => { | |
| 5449 | - if !layout.has_window(&id) { | |
| 5450 | - return; | |
| 5451 | - } | |
| 5452 | - | |
| 5453 | - if let Some(parent_id) = new_parent_id { | |
| 5454 | - if parent_id_causes_loop(layout, id, parent_id) { | |
| 5455 | - new_parent_id = None; | |
| 5456 | - } | |
| 5457 | - } | |
| 5458 | - | |
| 5459 | - let mut update = false; | |
| 5460 | - | |
| 5461 | - if let Some(InteractiveMoveState::Moving(move_)) = &layout.interactive_move { | |
| 5462 | - if move_.tile.window().0.id == id { | |
| 5463 | - move_.tile.window().0.parent_id.set(new_parent_id); | |
| 5464 | - update = true; | |
| 5465 | - } | |
| 5466 | - } | |
| 5467 | - | |
| 5468 | - match &mut layout.monitor_set { | |
| 5469 | - MonitorSet::Normal { monitors, .. } => { | |
| 5470 | - 'outer: for mon in monitors { | |
| 5471 | - for ws in &mut mon.workspaces { | |
| 5472 | - for win in ws.windows() { | |
| 5473 | - if win.0.id == id { | |
| 5474 | - win.0.parent_id.set(new_parent_id); | |
| 5475 | - update = true; | |
| 5476 | - break 'outer; | |
| 5477 | - } | |
| 5478 | - } | |
| 5479 | - } | |
| 5480 | - } | |
| 5481 | - } | |
| 5482 | - MonitorSet::NoOutputs { workspaces, .. } => { | |
| 5483 | - 'outer: for ws in workspaces { | |
| 5484 | - for win in ws.windows() { | |
| 5485 | - if win.0.id == id { | |
| 5486 | - win.0.parent_id.set(new_parent_id); | |
| 5487 | - update = true; | |
| 5488 | - break 'outer; | |
| 5489 | - } | |
| 5490 | - } | |
| 5491 | - } | |
| 5492 | - } | |
| 5493 | - } | |
| 5494 | - | |
| 5495 | - if update { | |
| 5496 | - if let Some(new_parent_id) = new_parent_id { | |
| 5497 | - layout.descendants_added(&new_parent_id); | |
| 5498 | - } | |
| 5499 | - } | |
| 5500 | - } | |
| 5501 | - Op::Communicate(id) => { | |
| 5502 | - let mut update = false; | |
| 5503 | - | |
| 5504 | - if let Some(InteractiveMoveState::Moving(move_)) = &layout.interactive_move { | |
| 5505 | - if move_.tile.window().0.id == id { | |
| 5506 | - if move_.tile.window().communicate() { | |
| 5507 | - update = true; | |
| 5508 | - } | |
| 5509 | - | |
| 5510 | - if update { | |
| 5511 | - // FIXME: serial. | |
| 5512 | - layout.update_window(&id, None); | |
| 5513 | - } | |
| 5514 | - return; | |
| 5515 | - } | |
| 5516 | - } | |
| 5517 | - | |
| 5518 | - match &mut layout.monitor_set { | |
| 5519 | - MonitorSet::Normal { monitors, .. } => { | |
| 5520 | - 'outer: for mon in monitors { | |
| 5521 | - for ws in &mut mon.workspaces { | |
| 5522 | - for win in ws.windows() { | |
| 5523 | - if win.0.id == id { | |
| 5524 | - if win.communicate() { | |
| 5525 | - update = true; | |
| 5526 | - } | |
| 5527 | - break 'outer; | |
| 5528 | - } | |
| 5529 | - } | |
| 5530 | - } | |
| 5531 | - } | |
| 5532 | - } | |
| 5533 | - MonitorSet::NoOutputs { workspaces, .. } => { | |
| 5534 | - 'outer: for ws in workspaces { | |
| 5535 | - for win in ws.windows() { | |
| 5536 | - if win.0.id == id { | |
| 5537 | - if win.communicate() { | |
| 5538 | - update = true; | |
| 5539 | - } | |
| 5540 | - break 'outer; | |
| 5541 | - } | |
| 5542 | - } | |
| 5543 | - } | |
| 5544 | - } | |
| 5545 | - } | |
| 5546 | - | |
| 5547 | - if update { | |
| 5548 | - // FIXME: serial. | |
| 5549 | - layout.update_window(&id, None); | |
| 5550 | - } | |
| 5551 | - } | |
| 5552 | - Op::Refresh { is_active } => { | |
| 5553 | - layout.refresh(is_active); | |
| 5554 | - } | |
| 5555 | - Op::AdvanceAnimations { msec_delta } => { | |
| 5556 | - let mut now = layout.clock.now_unadjusted(); | |
| 5557 | - if msec_delta >= 0 { | |
| 5558 | - now = now.saturating_add(Duration::from_millis(msec_delta as u64)); | |
| 5559 | - } else { | |
| 5560 | - now = now.saturating_sub(Duration::from_millis(-msec_delta as u64)); | |
| 5561 | - } | |
| 5562 | - layout.clock.set_unadjusted(now); | |
| 5563 | - layout.advance_animations(); | |
| 5564 | - } | |
| 5565 | - Op::MoveWorkspaceToOutput(id) => { | |
| 5566 | - let name = format!("output{id}"); | |
| 5567 | - let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 5568 | - return; | |
| 5569 | - }; | |
| 5570 | - | |
| 5571 | - layout.move_workspace_to_output(&output); | |
| 5572 | - } | |
| 5573 | - Op::ViewOffsetGestureBegin { | |
| 5574 | - output_idx: id, | |
| 5575 | - is_touchpad: normalize, | |
| 5576 | - } => { | |
| 5577 | - let name = format!("output{id}"); | |
| 5578 | - let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 5579 | - return; | |
| 5580 | - }; | |
| 5581 | - | |
| 5582 | - layout.view_offset_gesture_begin(&output, normalize); | |
| 5583 | - } | |
| 5584 | - Op::ViewOffsetGestureUpdate { | |
| 5585 | - delta, | |
| 5586 | - timestamp, | |
| 5587 | - is_touchpad, | |
| 5588 | - } => { | |
| 5589 | - layout.view_offset_gesture_update(delta, timestamp, is_touchpad); | |
| 5590 | - } | |
| 5591 | - Op::ViewOffsetGestureEnd { is_touchpad } => { | |
| 5592 | - // We don't handle cancels in this gesture. | |
| 5593 | - layout.view_offset_gesture_end(false, is_touchpad); | |
| 5594 | - } | |
| 5595 | - Op::WorkspaceSwitchGestureBegin { | |
| 5596 | - output_idx: id, | |
| 5597 | - is_touchpad, | |
| 5598 | - } => { | |
| 5599 | - let name = format!("output{id}"); | |
| 5600 | - let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 5601 | - return; | |
| 5602 | - }; | |
| 5603 | - | |
| 5604 | - layout.workspace_switch_gesture_begin(&output, is_touchpad); | |
| 5605 | - } | |
| 5606 | - Op::WorkspaceSwitchGestureUpdate { | |
| 5607 | - delta, | |
| 5608 | - timestamp, | |
| 5609 | - is_touchpad, | |
| 5610 | - } => { | |
| 5611 | - layout.workspace_switch_gesture_update(delta, timestamp, is_touchpad); | |
| 5612 | - } | |
| 5613 | - Op::WorkspaceSwitchGestureEnd { | |
| 5614 | - cancelled, | |
| 5615 | - is_touchpad, | |
| 5616 | - } => { | |
| 5617 | - layout.workspace_switch_gesture_end(cancelled, is_touchpad); | |
| 5618 | - } | |
| 5619 | - Op::InteractiveMoveBegin { | |
| 5620 | - window, | |
| 5621 | - output_idx, | |
| 5622 | - px, | |
| 5623 | - py, | |
| 5624 | - } => { | |
| 5625 | - let name = format!("output{output_idx}"); | |
| 5626 | - let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 5627 | - return; | |
| 5628 | - }; | |
| 5629 | - layout.interactive_move_begin(window, &output, Point::from((px, py))); | |
| 5630 | - } | |
| 5631 | - Op::InteractiveMoveUpdate { | |
| 5632 | - window, | |
| 5633 | - dx, | |
| 5634 | - dy, | |
| 5635 | - output_idx, | |
| 5636 | - px, | |
| 5637 | - py, | |
| 5638 | - } => { | |
| 5639 | - let name = format!("output{output_idx}"); | |
| 5640 | - let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 5641 | - return; | |
| 5642 | - }; | |
| 5643 | - layout.interactive_move_update( | |
| 5644 | - &window, | |
| 5645 | - Point::from((dx, dy)), | |
| 5646 | - output, | |
| 5647 | - Point::from((px, py)), | |
| 5648 | - ); | |
| 5649 | - } | |
| 5650 | - Op::InteractiveMoveEnd { window } => { | |
| 5651 | - layout.interactive_move_end(&window); | |
| 5652 | - } | |
| 5653 | - Op::InteractiveResizeBegin { window, edges } => { | |
| 5654 | - layout.interactive_resize_begin(window, edges); | |
| 5655 | - } | |
| 5656 | - Op::InteractiveResizeUpdate { window, dx, dy } => { | |
| 5657 | - layout.interactive_resize_update(&window, Point::from((dx, dy))); | |
| 5658 | - } | |
| 5659 | - Op::InteractiveResizeEnd { window } => { | |
| 5660 | - layout.interactive_resize_end(&window); | |
| 5661 | - } | |
| 5662 | - } | |
| 5663 | - } | |
| 5664 | - } | |
| 5665 | - | |
| 5666 | - #[track_caller] | |
| 5667 | - fn check_ops(ops: &[Op]) -> Layout<TestWindow> { | |
| 5668 | - let mut layout = Layout::default(); | |
| 5669 | - for op in ops { | |
| 5670 | - op.apply(&mut layout); | |
| 5671 | - layout.verify_invariants(); | |
| 5672 | - } | |
| 5673 | - layout | |
| 5674 | - } | |
| 5675 | - | |
| 5676 | - #[track_caller] | |
| 5677 | - fn check_ops_with_options(options: Options, ops: &[Op]) -> Layout<TestWindow> { | |
| 5678 | - let mut layout = Layout::with_options(Clock::with_time(Duration::ZERO), options); | |
| 5679 | - | |
| 5680 | - for op in ops { | |
| 5681 | - op.apply(&mut layout); | |
| 5682 | - layout.verify_invariants(); | |
| 5683 | - } | |
| 5684 | - | |
| 5685 | - layout | |
| 5686 | - } | |
| 5687 | - | |
| 5688 | - #[test] | |
| 5689 | - fn operations_dont_panic() { | |
| 5690 | - let every_op = [ | |
| 5691 | - Op::AddOutput(0), | |
| 5692 | - Op::AddOutput(1), | |
| 5693 | - Op::AddOutput(2), | |
| 5694 | - Op::RemoveOutput(0), | |
| 5695 | - Op::RemoveOutput(1), | |
| 5696 | - Op::RemoveOutput(2), | |
| 5697 | - Op::FocusOutput(0), | |
| 5698 | - Op::FocusOutput(1), | |
| 5699 | - Op::FocusOutput(2), | |
| 5700 | - Op::AddNamedWorkspace { | |
| 5701 | - ws_name: 1, | |
| 5702 | - output_name: Some(1), | |
| 5703 | - }, | |
| 5704 | - Op::UnnameWorkspace { ws_name: 1 }, | |
| 5705 | - Op::AddWindow { | |
| 5706 | - params: TestWindowParams::new(0), | |
| 5707 | - }, | |
| 5708 | - Op::AddWindow { | |
| 5709 | - params: TestWindowParams::new(1), | |
| 5710 | - }, | |
| 5711 | - Op::AddWindowNextTo { | |
| 5712 | - params: TestWindowParams::new(2), | |
| 5713 | - next_to_id: 1, | |
| 5714 | - }, | |
| 5715 | - Op::AddWindowToNamedWorkspace { | |
| 5716 | - params: TestWindowParams::new(3), | |
| 5717 | - ws_name: 1, | |
| 5718 | - }, | |
| 5719 | - Op::CloseWindow(0), | |
| 5720 | - Op::CloseWindow(1), | |
| 5721 | - Op::CloseWindow(2), | |
| 5722 | - Op::FullscreenWindow(1), | |
| 5723 | - Op::FullscreenWindow(2), | |
| 5724 | - Op::FullscreenWindow(3), | |
| 5725 | - Op::FocusColumnLeft, | |
| 5726 | - Op::FocusColumnRight, | |
| 5727 | - Op::FocusColumnRightOrFirst, | |
| 5728 | - Op::FocusColumnLeftOrLast, | |
| 5729 | - Op::FocusWindowOrMonitorUp(0), | |
| 5730 | - Op::FocusWindowOrMonitorDown(1), | |
| 5731 | - Op::FocusColumnOrMonitorLeft(0), | |
| 5732 | - Op::FocusColumnOrMonitorRight(1), | |
| 5733 | - Op::FocusWindowUp, | |
| 5734 | - Op::FocusWindowUpOrColumnLeft, | |
| 5735 | - Op::FocusWindowUpOrColumnRight, | |
| 5736 | - Op::FocusWindowOrWorkspaceUp, | |
| 5737 | - Op::FocusWindowDown, | |
| 5738 | - Op::FocusWindowDownOrColumnLeft, | |
| 5739 | - Op::FocusWindowDownOrColumnRight, | |
| 5740 | - Op::FocusWindowOrWorkspaceDown, | |
| 5741 | - Op::MoveColumnLeft, | |
| 5742 | - Op::MoveColumnRight, | |
| 5743 | - Op::MoveColumnLeftOrToMonitorLeft(0), | |
| 5744 | - Op::MoveColumnRightOrToMonitorRight(1), | |
| 5745 | - Op::ConsumeWindowIntoColumn, | |
| 5746 | - Op::ExpelWindowFromColumn, | |
| 5747 | - Op::CenterColumn, | |
| 5748 | - Op::FocusWorkspaceDown, | |
| 5749 | - Op::FocusWorkspaceUp, | |
| 5750 | - Op::FocusWorkspace(1), | |
| 5751 | - Op::FocusWorkspace(2), | |
| 5752 | - Op::MoveWindowToWorkspaceDown, | |
| 5753 | - Op::MoveWindowToWorkspaceUp, | |
| 5754 | - Op::MoveWindowToWorkspace { | |
| 5755 | - window_id: None, | |
| 5756 | - workspace_idx: 1, | |
| 5757 | - }, | |
| 5758 | - Op::MoveWindowToWorkspace { | |
| 5759 | - window_id: None, | |
| 5760 | - workspace_idx: 2, | |
| 5761 | - }, | |
| 5762 | - Op::MoveColumnToWorkspaceDown, | |
| 5763 | - Op::MoveColumnToWorkspaceUp, | |
| 5764 | - Op::MoveColumnToWorkspace(1), | |
| 5765 | - Op::MoveColumnToWorkspace(2), | |
| 5766 | - Op::MoveWindowDown, | |
| 5767 | - Op::MoveWindowDownOrToWorkspaceDown, | |
| 5768 | - Op::MoveWindowUp, | |
| 5769 | - Op::MoveWindowUpOrToWorkspaceUp, | |
| 5770 | - Op::ConsumeOrExpelWindowLeft { id: None }, | |
| 5771 | - Op::ConsumeOrExpelWindowRight { id: None }, | |
| 5772 | - Op::MoveWorkspaceToOutput(1), | |
| 5773 | - ]; | |
| 5774 | - | |
| 5775 | - for third in every_op { | |
| 5776 | - for second in every_op { | |
| 5777 | - for first in every_op { | |
| 5778 | - // eprintln!("{first:?}, {second:?}, {third:?}"); | |
| 5779 | - | |
| 5780 | - let mut layout = Layout::default(); | |
| 5781 | - first.apply(&mut layout); | |
| 5782 | - layout.verify_invariants(); | |
| 5783 | - second.apply(&mut layout); | |
| 5784 | - layout.verify_invariants(); | |
| 5785 | - third.apply(&mut layout); | |
| 5786 | - layout.verify_invariants(); | |
| 5787 | - } | |
| 5788 | - } | |
| 5789 | - } | |
| 5790 | - } | |
| 5791 | - | |
| 5792 | - #[test] | |
| 5793 | - fn operations_from_starting_state_dont_panic() { | |
| 5794 | - if std::env::var_os("RUN_SLOW_TESTS").is_none() { | |
| 5795 | - eprintln!("ignoring slow test"); | |
| 5796 | - return; | |
| 5797 | - } | |
| 5798 | - | |
| 5799 | - // Running every op from an empty state doesn't get us to all the interesting states. So, | |
| 5800 | - // also run it from a manually-created starting state with more things going on to exercise | |
| 5801 | - // more code paths. | |
| 5802 | - let setup_ops = [ | |
| 5803 | - Op::AddOutput(1), | |
| 5804 | - Op::AddWindow { | |
| 5805 | - params: TestWindowParams::new(1), | |
| 5806 | - }, | |
| 5807 | - Op::MoveWindowToWorkspaceDown, | |
| 5808 | - Op::AddWindow { | |
| 5809 | - params: TestWindowParams::new(2), | |
| 5810 | - }, | |
| 5811 | - Op::AddWindow { | |
| 5812 | - params: TestWindowParams::new(3), | |
| 5813 | - }, | |
| 5814 | - Op::FocusColumnLeft, | |
| 5815 | - Op::ConsumeWindowIntoColumn, | |
| 5816 | - Op::AddWindow { | |
| 5817 | - params: TestWindowParams::new(4), | |
| 5818 | - }, | |
| 5819 | - Op::AddOutput(2), | |
| 5820 | - Op::AddWindow { | |
| 5821 | - params: TestWindowParams::new(5), | |
| 5822 | - }, | |
| 5823 | - Op::MoveWindowToOutput { | |
| 5824 | - window_id: None, | |
| 5825 | - output_id: 2, | |
| 5826 | - target_ws_idx: None, | |
| 5827 | - }, | |
| 5828 | - Op::FocusOutput(1), | |
| 5829 | - Op::Communicate(1), | |
| 5830 | - Op::Communicate(2), | |
| 5831 | - Op::Communicate(3), | |
| 5832 | - Op::Communicate(4), | |
| 5833 | - Op::Communicate(5), | |
| 5834 | - ]; | |
| 5835 | - | |
| 5836 | - let every_op = [ | |
| 5837 | - Op::AddOutput(0), | |
| 5838 | - Op::AddOutput(1), | |
| 5839 | - Op::AddOutput(2), | |
| 5840 | - Op::RemoveOutput(0), | |
| 5841 | - Op::RemoveOutput(1), | |
| 5842 | - Op::RemoveOutput(2), | |
| 5843 | - Op::FocusOutput(0), | |
| 5844 | - Op::FocusOutput(1), | |
| 5845 | - Op::FocusOutput(2), | |
| 5846 | - Op::AddNamedWorkspace { | |
| 5847 | - ws_name: 1, | |
| 5848 | - output_name: Some(1), | |
| 5849 | - }, | |
| 5850 | - Op::UnnameWorkspace { ws_name: 1 }, | |
| 5851 | - Op::AddWindow { | |
| 5852 | - params: TestWindowParams::new(0), | |
| 5853 | - }, | |
| 5854 | - Op::AddWindow { | |
| 5855 | - params: TestWindowParams::new(1), | |
| 5856 | - }, | |
| 5857 | - Op::AddWindow { | |
| 5858 | - params: TestWindowParams::new(2), | |
| 5859 | - }, | |
| 5860 | - Op::AddWindowNextTo { | |
| 5861 | - params: TestWindowParams::new(6), | |
| 5862 | - next_to_id: 0, | |
| 5863 | - }, | |
| 5864 | - Op::AddWindowNextTo { | |
| 5865 | - params: TestWindowParams::new(7), | |
| 5866 | - next_to_id: 1, | |
| 5867 | - }, | |
| 5868 | - Op::AddWindowToNamedWorkspace { | |
| 5869 | - params: TestWindowParams::new(5), | |
| 5870 | - ws_name: 1, | |
| 5871 | - }, | |
| 5872 | - Op::CloseWindow(0), | |
| 5873 | - Op::CloseWindow(1), | |
| 5874 | - Op::CloseWindow(2), | |
| 5875 | - Op::FullscreenWindow(1), | |
| 5876 | - Op::FullscreenWindow(2), | |
| 5877 | - Op::FullscreenWindow(3), | |
| 5878 | - Op::SetFullscreenWindow { | |
| 5879 | - window: 1, | |
| 5880 | - is_fullscreen: false, | |
| 5881 | - }, | |
| 5882 | - Op::SetFullscreenWindow { | |
| 5883 | - window: 1, | |
| 5884 | - is_fullscreen: true, | |
| 5885 | - }, | |
| 5886 | - Op::SetFullscreenWindow { | |
| 5887 | - window: 2, | |
| 5888 | - is_fullscreen: false, | |
| 5889 | - }, | |
| 5890 | - Op::SetFullscreenWindow { | |
| 5891 | - window: 2, | |
| 5892 | - is_fullscreen: true, | |
| 5893 | - }, | |
| 5894 | - Op::FocusColumnLeft, | |
| 5895 | - Op::FocusColumnRight, | |
| 5896 | - Op::FocusColumnRightOrFirst, | |
| 5897 | - Op::FocusColumnLeftOrLast, | |
| 5898 | - Op::FocusWindowOrMonitorUp(0), | |
| 5899 | - Op::FocusWindowOrMonitorDown(1), | |
| 5900 | - Op::FocusColumnOrMonitorLeft(0), | |
| 5901 | - Op::FocusColumnOrMonitorRight(1), | |
| 5902 | - Op::FocusWindowUp, | |
| 5903 | - Op::FocusWindowUpOrColumnLeft, | |
| 5904 | - Op::FocusWindowUpOrColumnRight, | |
| 5905 | - Op::FocusWindowOrWorkspaceUp, | |
| 5906 | - Op::FocusWindowDown, | |
| 5907 | - Op::FocusWindowDownOrColumnLeft, | |
| 5908 | - Op::FocusWindowDownOrColumnRight, | |
| 5909 | - Op::FocusWindowOrWorkspaceDown, | |
| 5910 | - Op::MoveColumnLeft, | |
| 5911 | - Op::MoveColumnRight, | |
| 5912 | - Op::MoveColumnLeftOrToMonitorLeft(0), | |
| 5913 | - Op::MoveColumnRightOrToMonitorRight(1), | |
| 5914 | - Op::ConsumeWindowIntoColumn, | |
| 5915 | - Op::ExpelWindowFromColumn, | |
| 5916 | - Op::CenterColumn, | |
| 5917 | - Op::FocusWorkspaceDown, | |
| 5918 | - Op::FocusWorkspaceUp, | |
| 5919 | - Op::FocusWorkspace(1), | |
| 5920 | - Op::FocusWorkspace(2), | |
| 5921 | - Op::FocusWorkspace(3), | |
| 5922 | - Op::MoveWindowToWorkspaceDown, | |
| 5923 | - Op::MoveWindowToWorkspaceUp, | |
| 5924 | - Op::MoveWindowToWorkspace { | |
| 5925 | - window_id: None, | |
| 5926 | - workspace_idx: 1, | |
| 5927 | - }, | |
| 5928 | - Op::MoveWindowToWorkspace { | |
| 5929 | - window_id: None, | |
| 5930 | - workspace_idx: 2, | |
| 5931 | - }, | |
| 5932 | - Op::MoveWindowToWorkspace { | |
| 5933 | - window_id: None, | |
| 5934 | - workspace_idx: 3, | |
| 5935 | - }, | |
| 5936 | - Op::MoveColumnToWorkspaceDown, | |
| 5937 | - Op::MoveColumnToWorkspaceUp, | |
| 5938 | - Op::MoveColumnToWorkspace(1), | |
| 5939 | - Op::MoveColumnToWorkspace(2), | |
| 5940 | - Op::MoveColumnToWorkspace(3), | |
| 5941 | - Op::MoveWindowDown, | |
| 5942 | - Op::MoveWindowDownOrToWorkspaceDown, | |
| 5943 | - Op::MoveWindowUp, | |
| 5944 | - Op::MoveWindowUpOrToWorkspaceUp, | |
| 5945 | - Op::ConsumeOrExpelWindowLeft { id: None }, | |
| 5946 | - Op::ConsumeOrExpelWindowRight { id: None }, | |
| 5947 | - ]; | |
| 5948 | - | |
| 5949 | - for third in every_op { | |
| 5950 | - for second in every_op { | |
| 5951 | - for first in every_op { | |
| 5952 | - // eprintln!("{first:?}, {second:?}, {third:?}"); | |
| 5953 | - | |
| 5954 | - let mut layout = Layout::default(); | |
| 5955 | - for op in setup_ops { | |
| 5956 | - op.apply(&mut layout); | |
| 5957 | - } | |
| 5958 | - | |
| 5959 | - first.apply(&mut layout); | |
| 5960 | - layout.verify_invariants(); | |
| 5961 | - second.apply(&mut layout); | |
| 5962 | - layout.verify_invariants(); | |
| 5963 | - third.apply(&mut layout); | |
| 5964 | - layout.verify_invariants(); | |
| 5965 | - } | |
| 5966 | - } | |
| 5967 | - } | |
| 5968 | - } | |
| 5969 | - | |
| 5970 | - #[test] | |
| 5971 | - fn primary_active_workspace_idx_not_updated_on_output_add() { | |
| 5972 | - let ops = [ | |
| 5973 | - Op::AddOutput(1), | |
| 5974 | - Op::AddOutput(2), | |
| 5975 | - Op::FocusOutput(1), | |
| 5976 | - Op::AddWindow { | |
| 5977 | - params: TestWindowParams::new(0), | |
| 5978 | - }, | |
| 5979 | - Op::FocusOutput(2), | |
| 5980 | - Op::AddWindow { | |
| 5981 | - params: TestWindowParams::new(1), | |
| 5982 | - }, | |
| 5983 | - Op::RemoveOutput(2), | |
| 5984 | - Op::FocusWorkspace(3), | |
| 5985 | - Op::AddOutput(2), | |
| 5986 | - ]; | |
| 5987 | - | |
| 5988 | - check_ops(&ops); | |
| 5989 | - } | |
| 5990 | - | |
| 5991 | - #[test] | |
| 5992 | - fn window_closed_on_previous_workspace() { | |
| 5993 | - let ops = [ | |
| 5994 | - Op::AddOutput(1), | |
| 5995 | - Op::AddWindow { | |
| 5996 | - params: TestWindowParams::new(0), | |
| 5997 | - }, | |
| 5998 | - Op::FocusWorkspaceDown, | |
| 5999 | - Op::CloseWindow(0), | |
| 6000 | - ]; | |
| 6001 | - | |
| 6002 | - check_ops(&ops); | |
| 6003 | - } | |
| 6004 | - | |
| 6005 | - #[test] | |
| 6006 | - fn removing_output_must_keep_empty_focus_on_primary() { | |
| 6007 | - let ops = [ | |
| 6008 | - Op::AddOutput(1), | |
| 6009 | - Op::AddWindow { | |
| 6010 | - params: TestWindowParams::new(0), | |
| 6011 | - }, | |
| 6012 | - Op::AddOutput(2), | |
| 6013 | - Op::RemoveOutput(1), | |
| 6014 | - ]; | |
| 6015 | - | |
| 6016 | - let layout = check_ops(&ops); | |
| 6017 | - | |
| 6018 | - let MonitorSet::Normal { monitors, .. } = layout.monitor_set else { | |
| 6019 | - unreachable!() | |
| 6020 | - }; | |
| 6021 | - | |
| 6022 | - // The workspace from the removed output was inserted at position 0, so the active workspace | |
| 6023 | - // must change to 1 to keep the focus on the empty workspace. | |
| 6024 | - assert_eq!(monitors[0].active_workspace_idx, 1); | |
| 6025 | - } | |
| 6026 | - | |
| 6027 | - #[test] | |
| 6028 | - fn move_to_workspace_by_idx_does_not_leave_empty_workspaces() { | |
| 6029 | - let ops = [ | |
| 6030 | - Op::AddOutput(1), | |
| 6031 | - Op::AddWindow { | |
| 6032 | - params: TestWindowParams::new(0), | |
| 6033 | - }, | |
| 6034 | - Op::AddOutput(2), | |
| 6035 | - Op::FocusOutput(2), | |
| 6036 | - Op::AddWindow { | |
| 6037 | - params: TestWindowParams::new(1), | |
| 6038 | - }, | |
| 6039 | - Op::RemoveOutput(1), | |
| 6040 | - Op::MoveWindowToWorkspace { | |
| 6041 | - window_id: Some(0), | |
| 6042 | - workspace_idx: 2, | |
| 6043 | - }, | |
| 6044 | - ]; | |
| 6045 | - | |
| 6046 | - let layout = check_ops(&ops); | |
| 6047 | - | |
| 6048 | - let MonitorSet::Normal { monitors, .. } = layout.monitor_set else { | |
| 6049 | - unreachable!() | |
| 6050 | - }; | |
| 6051 | - | |
| 6052 | - assert!(monitors[0].workspaces[1].has_windows()); | |
| 6053 | - } | |
| 6054 | - | |
| 6055 | - #[test] | |
| 6056 | - fn empty_workspaces_dont_move_back_to_original_output() { | |
| 6057 | - let ops = [ | |
| 6058 | - Op::AddOutput(1), | |
| 6059 | - Op::AddWindow { | |
| 6060 | - params: TestWindowParams::new(1), | |
| 6061 | - }, | |
| 6062 | - Op::FocusWorkspaceDown, | |
| 6063 | - Op::AddWindow { | |
| 6064 | - params: TestWindowParams::new(2), | |
| 6065 | - }, | |
| 6066 | - Op::AddOutput(2), | |
| 6067 | - Op::RemoveOutput(1), | |
| 6068 | - Op::FocusWorkspace(1), | |
| 6069 | - Op::CloseWindow(1), | |
| 6070 | - Op::AddOutput(1), | |
| 6071 | - ]; | |
| 6072 | - | |
| 6073 | - check_ops(&ops); | |
| 6074 | - } | |
| 6075 | - | |
| 6076 | - #[test] | |
| 6077 | - fn named_workspaces_dont_update_original_output_on_adding_window() { | |
| 6078 | - let ops = [ | |
| 6079 | - Op::AddOutput(1), | |
| 6080 | - Op::SetWorkspaceName { | |
| 6081 | - new_ws_name: 1, | |
| 6082 | - ws_name: None, | |
| 6083 | - }, | |
| 6084 | - Op::AddOutput(2), | |
| 6085 | - Op::RemoveOutput(1), | |
| 6086 | - Op::FocusWorkspaceUp, | |
| 6087 | - // Adding a window updates the original output for unnamed workspaces. | |
| 6088 | - Op::AddWindow { | |
| 6089 | - params: TestWindowParams::new(1), | |
| 6090 | - }, | |
| 6091 | - // Connecting the previous output should move the named workspace back since its | |
| 6092 | - // original output wasn't updated. | |
| 6093 | - Op::AddOutput(1), | |
| 6094 | - ]; | |
| 6095 | - | |
| 6096 | - let layout = check_ops(&ops); | |
| 6097 | - let (mon, _, ws) = layout | |
| 6098 | - .workspaces() | |
| 6099 | - .find(|(_, _, ws)| ws.name().is_some()) | |
| 6100 | - .unwrap(); | |
| 6101 | - assert!(ws.name().is_some()); // Sanity check. | |
| 6102 | - let mon = mon.unwrap(); | |
| 6103 | - assert_eq!(mon.output_name(), "output1"); | |
| 6104 | - } | |
| 6105 | - | |
| 6106 | - #[test] | |
| 6107 | - fn workspaces_update_original_output_on_moving_to_same_output() { | |
| 6108 | - let ops = [ | |
| 6109 | - Op::AddOutput(1), | |
| 6110 | - Op::SetWorkspaceName { | |
| 6111 | - new_ws_name: 1, | |
| 6112 | - ws_name: None, | |
| 6113 | - }, | |
| 6114 | - Op::AddOutput(2), | |
| 6115 | - Op::RemoveOutput(1), | |
| 6116 | - Op::FocusWorkspaceUp, | |
| 6117 | - Op::MoveWorkspaceToOutput(2), | |
| 6118 | - Op::AddOutput(1), | |
| 6119 | - ]; | |
| 6120 | - | |
| 6121 | - let layout = check_ops(&ops); | |
| 6122 | - let (mon, _, ws) = layout | |
| 6123 | - .workspaces() | |
| 6124 | - .find(|(_, _, ws)| ws.name().is_some()) | |
| 6125 | - .unwrap(); | |
| 6126 | - assert!(ws.name().is_some()); // Sanity check. | |
| 6127 | - let mon = mon.unwrap(); | |
| 6128 | - assert_eq!(mon.output_name(), "output2"); | |
| 6129 | - } | |
| 6130 | - | |
| 6131 | - #[test] | |
| 6132 | - fn workspaces_update_original_output_on_moving_to_same_monitor() { | |
| 6133 | - let ops = [ | |
| 6134 | - Op::AddOutput(1), | |
| 6135 | - Op::SetWorkspaceName { | |
| 6136 | - new_ws_name: 1, | |
| 6137 | - ws_name: None, | |
| 6138 | - }, | |
| 6139 | - Op::AddOutput(2), | |
| 6140 | - Op::RemoveOutput(1), | |
| 6141 | - Op::FocusWorkspaceUp, | |
| 6142 | - Op::MoveWorkspaceToMonitor { | |
| 6143 | - ws_name: Some(1), | |
| 6144 | - output_id: 2, | |
| 6145 | - }, | |
| 6146 | - Op::AddOutput(1), | |
| 6147 | - ]; | |
| 6148 | - | |
| 6149 | - let layout = check_ops(&ops); | |
| 6150 | - let (mon, _, ws) = layout | |
| 6151 | - .workspaces() | |
| 6152 | - .find(|(_, _, ws)| ws.name().is_some()) | |
| 6153 | - .unwrap(); | |
| 6154 | - assert!(ws.name().is_some()); // Sanity check. | |
| 6155 | - let mon = mon.unwrap(); | |
| 6156 | - assert_eq!(mon.output_name(), "output2"); | |
| 6157 | - } | |
| 6158 | - | |
| 6159 | - #[test] | |
| 6160 | - fn large_negative_height_change() { | |
| 6161 | - let ops = [ | |
| 6162 | - Op::AddOutput(1), | |
| 6163 | - Op::AddWindow { | |
| 6164 | - params: TestWindowParams::new(1), | |
| 6165 | - }, | |
| 6166 | - Op::SetWindowHeight { | |
| 6167 | - id: None, | |
| 6168 | - change: SizeChange::AdjustProportion(-1e129), | |
| 6169 | - }, | |
| 6170 | - ]; | |
| 6171 | - | |
| 6172 | - let mut options = Options::default(); | |
| 6173 | - options.border.off = false; | |
| 6174 | - options.border.width = FloatOrInt(1.); | |
| 6175 | - | |
| 6176 | - check_ops_with_options(options, &ops); | |
| 6177 | - } | |
| 6178 | - | |
| 6179 | - #[test] | |
| 6180 | - fn large_max_size() { | |
| 6181 | - let ops = [ | |
| 6182 | - Op::AddOutput(1), | |
| 6183 | - Op::AddWindow { | |
| 6184 | - params: TestWindowParams { | |
| 6185 | - min_max_size: (Size::from((0, 0)), Size::from((i32::MAX, i32::MAX))), | |
| 6186 | - ..TestWindowParams::new(1) | |
| 6187 | - }, | |
| 6188 | - }, | |
| 6189 | - ]; | |
| 6190 | - | |
| 6191 | - let mut options = Options::default(); | |
| 6192 | - options.border.off = false; | |
| 6193 | - options.border.width = FloatOrInt(1.); | |
| 6194 | - | |
| 6195 | - check_ops_with_options(options, &ops); | |
| 6196 | - } | |
| 6197 | - | |
| 6198 | - #[test] | |
| 6199 | - fn workspace_cleanup_during_switch() { | |
| 6200 | - let ops = [ | |
| 6201 | - Op::AddOutput(1), | |
| 6202 | - Op::AddWindow { | |
| 6203 | - params: TestWindowParams::new(1), | |
| 6204 | - }, | |
| 6205 | - Op::FocusWorkspaceDown, | |
| 6206 | - Op::CloseWindow(1), | |
| 6207 | - ]; | |
| 6208 | - | |
| 6209 | - check_ops(&ops); | |
| 6210 | - } | |
| 6211 | - | |
| 6212 | - #[test] | |
| 6213 | - fn workspace_transfer_during_switch() { | |
| 6214 | - let ops = [ | |
| 6215 | - Op::AddOutput(1), | |
| 6216 | - Op::AddWindow { | |
| 6217 | - params: TestWindowParams::new(1), | |
| 6218 | - }, | |
| 6219 | - Op::AddOutput(2), | |
| 6220 | - Op::FocusOutput(2), | |
| 6221 | - Op::AddWindow { | |
| 6222 | - params: TestWindowParams::new(2), | |
| 6223 | - }, | |
| 6224 | - Op::RemoveOutput(1), | |
| 6225 | - Op::FocusWorkspaceDown, | |
| 6226 | - Op::FocusWorkspaceDown, | |
| 6227 | - Op::AddOutput(1), | |
| 6228 | - ]; | |
| 6229 | - | |
| 6230 | - check_ops(&ops); | |
| 6231 | - } | |
| 6232 | - | |
| 6233 | - #[test] | |
| 6234 | - fn workspace_transfer_during_switch_from_last() { | |
| 6235 | - let ops = [ | |
| 6236 | - Op::AddOutput(1), | |
| 6237 | - Op::AddWindow { | |
| 6238 | - params: TestWindowParams::new(1), | |
| 6239 | - }, | |
| 6240 | - Op::AddOutput(2), | |
| 6241 | - Op::RemoveOutput(1), | |
| 6242 | - Op::FocusWorkspaceUp, | |
| 6243 | - Op::AddOutput(1), | |
| 6244 | - ]; | |
| 6245 | - | |
| 6246 | - check_ops(&ops); | |
| 6247 | - } | |
| 6248 | - | |
| 6249 | - #[test] | |
| 6250 | - fn workspace_transfer_during_switch_gets_cleaned_up() { | |
| 6251 | - let ops = [ | |
| 6252 | - Op::AddOutput(1), | |
| 6253 | - Op::AddWindow { | |
| 6254 | - params: TestWindowParams::new(1), | |
| 6255 | - }, | |
| 6256 | - Op::RemoveOutput(1), | |
| 6257 | - Op::AddOutput(2), | |
| 6258 | - Op::MoveColumnToWorkspaceDown, | |
| 6259 | - Op::MoveColumnToWorkspaceDown, | |
| 6260 | - Op::AddOutput(1), | |
| 6261 | - ]; | |
| 6262 | - | |
| 6263 | - check_ops(&ops); | |
| 6264 | - } | |
| 6265 | - | |
| 6266 | - #[test] | |
| 6267 | - fn move_workspace_to_output() { | |
| 6268 | - let ops = [ | |
| 6269 | - Op::AddOutput(1), | |
| 6270 | - Op::AddOutput(2), | |
| 6271 | - Op::FocusOutput(1), | |
| 6272 | - Op::AddWindow { | |
| 6273 | - params: TestWindowParams::new(0), | |
| 6274 | - }, | |
| 6275 | - Op::MoveWorkspaceToOutput(2), | |
| 6276 | - ]; | |
| 6277 | - | |
| 6278 | - let layout = check_ops(&ops); | |
| 6279 | - | |
| 6280 | - let MonitorSet::Normal { | |
| 6281 | - monitors, | |
| 6282 | - active_monitor_idx, | |
| 6283 | - .. | |
| 6284 | - } = layout.monitor_set | |
| 6285 | - else { | |
| 6286 | - unreachable!() | |
| 6287 | - }; | |
| 6288 | - | |
| 6289 | - assert_eq!(active_monitor_idx, 1); | |
| 6290 | - assert_eq!(monitors[0].workspaces.len(), 1); | |
| 6291 | - assert!(!monitors[0].workspaces[0].has_windows()); | |
| 6292 | - assert_eq!(monitors[1].active_workspace_idx, 0); | |
| 6293 | - assert_eq!(monitors[1].workspaces.len(), 2); | |
| 6294 | - assert!(monitors[1].workspaces[0].has_windows()); | |
| 6295 | - } | |
| 6296 | - | |
| 6297 | - #[test] | |
| 6298 | - fn fullscreen() { | |
| 6299 | - let ops = [ | |
| 6300 | - Op::AddOutput(1), | |
| 6301 | - Op::AddWindow { |
src/layout/tests.rsadded+3163 -0
Diff too large; view file
| @@ -0,0 +1,3163 @@ | ||
| 1 | +use std::cell::Cell; | |
| 2 | + | |
| 3 | +use niri_config::{FloatOrInt, OutputName, WorkspaceName, WorkspaceReference}; | |
| 4 | +use proptest::prelude::*; | |
| 5 | +use proptest_derive::Arbitrary; | |
| 6 | +use smithay::output::{Mode, PhysicalProperties, Subpixel}; | |
| 7 | +use smithay::utils::Rectangle; | |
| 8 | + | |
| 9 | +use super::*; | |
| 10 | + | |
| 11 | +impl<W: LayoutElement> Default for Layout<W> { | |
| 12 | + fn default() -> Self { | |
| 13 | + Self::with_options(Clock::with_time(Duration::ZERO), Default::default()) | |
| 14 | + } | |
| 15 | +} | |
| 16 | + | |
| 17 | +#[derive(Debug)] | |
| 18 | +struct TestWindowInner { | |
| 19 | + id: usize, | |
| 20 | + parent_id: Cell<Option<usize>>, | |
| 21 | + bbox: Cell<Rectangle<i32, Logical>>, | |
| 22 | + initial_bbox: Rectangle<i32, Logical>, | |
| 23 | + requested_size: Cell<Option<Size<i32, Logical>>>, | |
| 24 | + min_size: Size<i32, Logical>, | |
| 25 | + max_size: Size<i32, Logical>, | |
| 26 | + pending_fullscreen: Cell<bool>, | |
| 27 | + pending_activated: Cell<bool>, | |
| 28 | +} | |
| 29 | + | |
| 30 | +#[derive(Debug, Clone)] | |
| 31 | +struct TestWindow(Rc<TestWindowInner>); | |
| 32 | + | |
| 33 | +#[derive(Debug, Clone, Copy, Arbitrary)] | |
| 34 | +struct TestWindowParams { | |
| 35 | + #[proptest(strategy = "1..=5usize")] | |
| 36 | + id: usize, | |
| 37 | + #[proptest(strategy = "arbitrary_parent_id()")] | |
| 38 | + parent_id: Option<usize>, | |
| 39 | + is_floating: bool, | |
| 40 | + #[proptest(strategy = "arbitrary_bbox()")] | |
| 41 | + bbox: Rectangle<i32, Logical>, | |
| 42 | + #[proptest(strategy = "arbitrary_min_max_size()")] | |
| 43 | + min_max_size: (Size<i32, Logical>, Size<i32, Logical>), | |
| 44 | +} | |
| 45 | + | |
| 46 | +impl TestWindowParams { | |
| 47 | + pub fn new(id: usize) -> Self { | |
| 48 | + Self { | |
| 49 | + id, | |
| 50 | + parent_id: None, | |
| 51 | + is_floating: false, | |
| 52 | + bbox: Rectangle::from_size(Size::from((100, 200))), | |
| 53 | + min_max_size: Default::default(), | |
| 54 | + } | |
| 55 | + } | |
| 56 | +} | |
| 57 | + | |
| 58 | +impl TestWindow { | |
| 59 | + fn new(params: TestWindowParams) -> Self { | |
| 60 | + Self(Rc::new(TestWindowInner { | |
| 61 | + id: params.id, | |
| 62 | + parent_id: Cell::new(params.parent_id), | |
| 63 | + bbox: Cell::new(params.bbox), | |
| 64 | + initial_bbox: params.bbox, | |
| 65 | + requested_size: Cell::new(None), | |
| 66 | + min_size: params.min_max_size.0, | |
| 67 | + max_size: params.min_max_size.1, | |
| 68 | + pending_fullscreen: Cell::new(false), | |
| 69 | + pending_activated: Cell::new(false), | |
| 70 | + })) | |
| 71 | + } | |
| 72 | + | |
| 73 | + fn communicate(&self) -> bool { | |
| 74 | + if let Some(size) = self.0.requested_size.get() { | |
| 75 | + assert!(size.w >= 0); | |
| 76 | + assert!(size.h >= 0); | |
| 77 | + | |
| 78 | + let mut new_bbox = self.0.initial_bbox; | |
| 79 | + if size.w != 0 { | |
| 80 | + new_bbox.size.w = size.w; | |
| 81 | + } | |
| 82 | + if size.h != 0 { | |
| 83 | + new_bbox.size.h = size.h; | |
| 84 | + } | |
| 85 | + | |
| 86 | + if self.0.bbox.get() != new_bbox { | |
| 87 | + self.0.bbox.set(new_bbox); | |
| 88 | + return true; | |
| 89 | + } | |
| 90 | + } | |
| 91 | + | |
| 92 | + false | |
| 93 | + } | |
| 94 | +} | |
| 95 | + | |
| 96 | +impl LayoutElement for TestWindow { | |
| 97 | + type Id = usize; | |
| 98 | + | |
| 99 | + fn id(&self) -> &Self::Id { | |
| 100 | + &self.0.id | |
| 101 | + } | |
| 102 | + | |
| 103 | + fn size(&self) -> Size<i32, Logical> { | |
| 104 | + self.0.bbox.get().size | |
| 105 | + } | |
| 106 | + | |
| 107 | + fn buf_loc(&self) -> Point<i32, Logical> { | |
| 108 | + (0, 0).into() | |
| 109 | + } | |
| 110 | + | |
| 111 | + fn is_in_input_region(&self, _point: Point<f64, Logical>) -> bool { | |
| 112 | + false | |
| 113 | + } | |
| 114 | + | |
| 115 | + fn render<R: NiriRenderer>( | |
| 116 | + &self, | |
| 117 | + _renderer: &mut R, | |
| 118 | + _location: Point<f64, Logical>, | |
| 119 | + _scale: Scale<f64>, | |
| 120 | + _alpha: f32, | |
| 121 | + _target: RenderTarget, | |
| 122 | + ) -> SplitElements<LayoutElementRenderElement<R>> { | |
| 123 | + SplitElements::default() | |
| 124 | + } | |
| 125 | + | |
| 126 | + fn request_size( | |
| 127 | + &mut self, | |
| 128 | + size: Size<i32, Logical>, | |
| 129 | + _animate: bool, | |
| 130 | + _transaction: Option<Transaction>, | |
| 131 | + ) { | |
| 132 | + self.0.requested_size.set(Some(size)); | |
| 133 | + self.0.pending_fullscreen.set(false); | |
| 134 | + } | |
| 135 | + | |
| 136 | + fn request_fullscreen(&mut self, _size: Size<i32, Logical>) { | |
| 137 | + self.0.pending_fullscreen.set(true); | |
| 138 | + } | |
| 139 | + | |
| 140 | + fn min_size(&self) -> Size<i32, Logical> { | |
| 141 | + self.0.min_size | |
| 142 | + } | |
| 143 | + | |
| 144 | + fn max_size(&self) -> Size<i32, Logical> { | |
| 145 | + self.0.max_size | |
| 146 | + } | |
| 147 | + | |
| 148 | + fn is_wl_surface(&self, _wl_surface: &WlSurface) -> bool { | |
| 149 | + false | |
| 150 | + } | |
| 151 | + | |
| 152 | + fn set_preferred_scale_transform(&self, _scale: output::Scale, _transform: Transform) {} | |
| 153 | + | |
| 154 | + fn has_ssd(&self) -> bool { | |
| 155 | + false | |
| 156 | + } | |
| 157 | + | |
| 158 | + fn output_enter(&self, _output: &Output) {} | |
| 159 | + | |
| 160 | + fn output_leave(&self, _output: &Output) {} | |
| 161 | + | |
| 162 | + fn set_offscreen_element_id(&self, _id: Option<Id>) {} | |
| 163 | + | |
| 164 | + fn set_activated(&mut self, active: bool) { | |
| 165 | + self.0.pending_activated.set(active); | |
| 166 | + } | |
| 167 | + | |
| 168 | + fn set_bounds(&self, _bounds: Size<i32, Logical>) {} | |
| 169 | + | |
| 170 | + fn is_ignoring_opacity_window_rule(&self) -> bool { | |
| 171 | + false | |
| 172 | + } | |
| 173 | + | |
| 174 | + fn configure_intent(&self) -> ConfigureIntent { | |
| 175 | + ConfigureIntent::CanSend | |
| 176 | + } | |
| 177 | + | |
| 178 | + fn send_pending_configure(&mut self) {} | |
| 179 | + | |
| 180 | + fn set_active_in_column(&mut self, _active: bool) {} | |
| 181 | + | |
| 182 | + fn set_floating(&mut self, _floating: bool) {} | |
| 183 | + | |
| 184 | + fn is_fullscreen(&self) -> bool { | |
| 185 | + false | |
| 186 | + } | |
| 187 | + | |
| 188 | + fn is_pending_fullscreen(&self) -> bool { | |
| 189 | + self.0.pending_fullscreen.get() | |
| 190 | + } | |
| 191 | + | |
| 192 | + fn requested_size(&self) -> Option<Size<i32, Logical>> { | |
| 193 | + self.0.requested_size.get() | |
| 194 | + } | |
| 195 | + | |
| 196 | + fn is_child_of(&self, parent: &Self) -> bool { | |
| 197 | + self.0.parent_id.get() == Some(parent.0.id) | |
| 198 | + } | |
| 199 | + | |
| 200 | + fn refresh(&self) {} | |
| 201 | + | |
| 202 | + fn rules(&self) -> &ResolvedWindowRules { | |
| 203 | + static EMPTY: ResolvedWindowRules = ResolvedWindowRules::empty(); | |
| 204 | + &EMPTY | |
| 205 | + } | |
| 206 | + | |
| 207 | + fn animation_snapshot(&self) -> Option<&LayoutElementRenderSnapshot> { | |
| 208 | + None | |
| 209 | + } | |
| 210 | + | |
| 211 | + fn take_animation_snapshot(&mut self) -> Option<LayoutElementRenderSnapshot> { | |
| 212 | + None | |
| 213 | + } | |
| 214 | + | |
| 215 | + fn set_interactive_resize(&mut self, _data: Option<InteractiveResizeData>) {} | |
| 216 | + | |
| 217 | + fn cancel_interactive_resize(&mut self) {} | |
| 218 | + | |
| 219 | + fn on_commit(&mut self, _serial: Serial) {} | |
| 220 | + | |
| 221 | + fn interactive_resize_data(&self) -> Option<InteractiveResizeData> { | |
| 222 | + None | |
| 223 | + } | |
| 224 | +} | |
| 225 | + | |
| 226 | +fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> { | |
| 227 | + any::<(i16, i16, u16, u16)>().prop_map(|(x, y, w, h)| { | |
| 228 | + let loc: Point<i32, _> = Point::from((x.into(), y.into())); | |
| 229 | + let size: Size<i32, _> = Size::from((w.max(1).into(), h.max(1).into())); | |
| 230 | + Rectangle::new(loc, size) | |
| 231 | + }) | |
| 232 | +} | |
| 233 | + | |
| 234 | +fn arbitrary_size_change() -> impl Strategy<Value = SizeChange> { | |
| 235 | + prop_oneof![ | |
| 236 | + (0..).prop_map(SizeChange::SetFixed), | |
| 237 | + (0f64..).prop_map(SizeChange::SetProportion), | |
| 238 | + any::<i32>().prop_map(SizeChange::AdjustFixed), | |
| 239 | + any::<f64>().prop_map(SizeChange::AdjustProportion), | |
| 240 | + // Interactive resize can have negative values here. | |
| 241 | + Just(SizeChange::SetFixed(-100)), | |
| 242 | + ] | |
| 243 | +} | |
| 244 | + | |
| 245 | +fn arbitrary_position_change() -> impl Strategy<Value = PositionChange> { | |
| 246 | + prop_oneof![ | |
| 247 | + (-1000f64..1000f64).prop_map(PositionChange::SetFixed), | |
| 248 | + (-1000f64..1000f64).prop_map(PositionChange::AdjustFixed), | |
| 249 | + any::<f64>().prop_map(PositionChange::SetFixed), | |
| 250 | + any::<f64>().prop_map(PositionChange::AdjustFixed), | |
| 251 | + ] | |
| 252 | +} | |
| 253 | + | |
| 254 | +fn arbitrary_min_max() -> impl Strategy<Value = (i32, i32)> { | |
| 255 | + prop_oneof![ | |
| 256 | + Just((0, 0)), | |
| 257 | + (1..65536).prop_map(|n| (n, n)), | |
| 258 | + (1..65536).prop_map(|min| (min, 0)), | |
| 259 | + (1..).prop_map(|max| (0, max)), | |
| 260 | + (1..65536, 1..).prop_map(|(min, max): (i32, i32)| (min, max.max(min))), | |
| 261 | + ] | |
| 262 | +} | |
| 263 | + | |
| 264 | +fn arbitrary_min_max_size() -> impl Strategy<Value = (Size<i32, Logical>, Size<i32, Logical>)> { | |
| 265 | + prop_oneof![ | |
| 266 | + 5 => (arbitrary_min_max(), arbitrary_min_max()).prop_map( | |
| 267 | + |((min_w, max_w), (min_h, max_h))| { | |
| 268 | + let min_size = Size::from((min_w, min_h)); | |
| 269 | + let max_size = Size::from((max_w, max_h)); | |
| 270 | + (min_size, max_size) | |
| 271 | + }, | |
| 272 | + ), | |
| 273 | + 1 => arbitrary_min_max().prop_map(|(w, h)| { | |
| 274 | + let size = Size::from((w, h)); | |
| 275 | + (size, size) | |
| 276 | + }), | |
| 277 | + ] | |
| 278 | +} | |
| 279 | + | |
| 280 | +fn arbitrary_view_offset_gesture_delta() -> impl Strategy<Value = f64> { | |
| 281 | + prop_oneof![(-10f64..10f64), (-50000f64..50000f64),] | |
| 282 | +} | |
| 283 | + | |
| 284 | +fn arbitrary_resize_edge() -> impl Strategy<Value = ResizeEdge> { | |
| 285 | + prop_oneof![ | |
| 286 | + Just(ResizeEdge::RIGHT), | |
| 287 | + Just(ResizeEdge::BOTTOM), | |
| 288 | + Just(ResizeEdge::LEFT), | |
| 289 | + Just(ResizeEdge::TOP), | |
| 290 | + Just(ResizeEdge::BOTTOM_RIGHT), | |
| 291 | + Just(ResizeEdge::BOTTOM_LEFT), | |
| 292 | + Just(ResizeEdge::TOP_RIGHT), | |
| 293 | + Just(ResizeEdge::TOP_LEFT), | |
| 294 | + Just(ResizeEdge::empty()), | |
| 295 | + ] | |
| 296 | +} | |
| 297 | + | |
| 298 | +fn arbitrary_scale() -> impl Strategy<Value = f64> { | |
| 299 | + prop_oneof![Just(1.), Just(1.5), Just(2.),] | |
| 300 | +} | |
| 301 | + | |
| 302 | +fn arbitrary_msec_delta() -> impl Strategy<Value = i32> { | |
| 303 | + prop_oneof![ | |
| 304 | + 1 => Just(-1000), | |
| 305 | + 2 => Just(-10), | |
| 306 | + 1 => Just(0), | |
| 307 | + 2 => Just(10), | |
| 308 | + 6 => Just(1000), | |
| 309 | + ] | |
| 310 | +} | |
| 311 | + | |
| 312 | +fn arbitrary_parent_id() -> impl Strategy<Value = Option<usize>> { | |
| 313 | + prop_oneof![ | |
| 314 | + 5 => Just(None), | |
| 315 | + 1 => prop::option::of(1..=5usize), | |
| 316 | + ] | |
| 317 | +} | |
| 318 | + | |
| 319 | +fn arbitrary_scroll_direction() -> impl Strategy<Value = ScrollDirection> { | |
| 320 | + prop_oneof![Just(ScrollDirection::Left), Just(ScrollDirection::Right)] | |
| 321 | +} | |
| 322 | + | |
| 323 | +#[derive(Debug, Clone, Copy, Arbitrary)] | |
| 324 | +enum Op { | |
| 325 | + AddOutput(#[proptest(strategy = "1..=5usize")] usize), | |
| 326 | + AddScaledOutput { | |
| 327 | + #[proptest(strategy = "1..=5usize")] | |
| 328 | + id: usize, | |
| 329 | + #[proptest(strategy = "arbitrary_scale()")] | |
| 330 | + scale: f64, | |
| 331 | + }, | |
| 332 | + RemoveOutput(#[proptest(strategy = "1..=5usize")] usize), | |
| 333 | + FocusOutput(#[proptest(strategy = "1..=5usize")] usize), | |
| 334 | + AddNamedWorkspace { | |
| 335 | + #[proptest(strategy = "1..=5usize")] | |
| 336 | + ws_name: usize, | |
| 337 | + #[proptest(strategy = "prop::option::of(1..=5usize)")] | |
| 338 | + output_name: Option<usize>, | |
| 339 | + }, | |
| 340 | + UnnameWorkspace { | |
| 341 | + #[proptest(strategy = "1..=5usize")] | |
| 342 | + ws_name: usize, | |
| 343 | + }, | |
| 344 | + AddWindow { | |
| 345 | + params: TestWindowParams, | |
| 346 | + }, | |
| 347 | + AddWindowNextTo { | |
| 348 | + params: TestWindowParams, | |
| 349 | + #[proptest(strategy = "1..=5usize")] | |
| 350 | + next_to_id: usize, | |
| 351 | + }, | |
| 352 | + AddWindowToNamedWorkspace { | |
| 353 | + params: TestWindowParams, | |
| 354 | + #[proptest(strategy = "1..=5usize")] | |
| 355 | + ws_name: usize, | |
| 356 | + }, | |
| 357 | + CloseWindow(#[proptest(strategy = "1..=5usize")] usize), | |
| 358 | + FullscreenWindow(#[proptest(strategy = "1..=5usize")] usize), | |
| 359 | + SetFullscreenWindow { | |
| 360 | + #[proptest(strategy = "1..=5usize")] | |
| 361 | + window: usize, | |
| 362 | + is_fullscreen: bool, | |
| 363 | + }, | |
| 364 | + FocusColumnLeft, | |
| 365 | + FocusColumnRight, | |
| 366 | + FocusColumnFirst, | |
| 367 | + FocusColumnLast, | |
| 368 | + FocusColumnRightOrFirst, | |
| 369 | + FocusColumnLeftOrLast, | |
| 370 | + FocusWindowOrMonitorUp(#[proptest(strategy = "1..=2u8")] u8), | |
| 371 | + FocusWindowOrMonitorDown(#[proptest(strategy = "1..=2u8")] u8), | |
| 372 | + FocusColumnOrMonitorLeft(#[proptest(strategy = "1..=2u8")] u8), | |
| 373 | + FocusColumnOrMonitorRight(#[proptest(strategy = "1..=2u8")] u8), | |
| 374 | + FocusWindowDown, | |
| 375 | + FocusWindowUp, | |
| 376 | + FocusWindowDownOrColumnLeft, | |
| 377 | + FocusWindowDownOrColumnRight, | |
| 378 | + FocusWindowUpOrColumnLeft, | |
| 379 | + FocusWindowUpOrColumnRight, | |
| 380 | + FocusWindowOrWorkspaceDown, | |
| 381 | + FocusWindowOrWorkspaceUp, | |
| 382 | + FocusWindow(#[proptest(strategy = "1..=5usize")] usize), | |
| 383 | + MoveColumnLeft, | |
| 384 | + MoveColumnRight, | |
| 385 | + MoveColumnToFirst, | |
| 386 | + MoveColumnToLast, | |
| 387 | + MoveColumnLeftOrToMonitorLeft(#[proptest(strategy = "1..=2u8")] u8), | |
| 388 | + MoveColumnRightOrToMonitorRight(#[proptest(strategy = "1..=2u8")] u8), | |
| 389 | + MoveWindowDown, | |
| 390 | + MoveWindowUp, | |
| 391 | + MoveWindowDownOrToWorkspaceDown, | |
| 392 | + MoveWindowUpOrToWorkspaceUp, | |
| 393 | + ConsumeOrExpelWindowLeft { | |
| 394 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 395 | + id: Option<usize>, | |
| 396 | + }, | |
| 397 | + ConsumeOrExpelWindowRight { | |
| 398 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 399 | + id: Option<usize>, | |
| 400 | + }, | |
| 401 | + ConsumeWindowIntoColumn, | |
| 402 | + ExpelWindowFromColumn, | |
| 403 | + SwapWindowInDirection(#[proptest(strategy = "arbitrary_scroll_direction()")] ScrollDirection), | |
| 404 | + CenterColumn, | |
| 405 | + CenterWindow { | |
| 406 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 407 | + id: Option<usize>, | |
| 408 | + }, | |
| 409 | + FocusWorkspaceDown, | |
| 410 | + FocusWorkspaceUp, | |
| 411 | + FocusWorkspace(#[proptest(strategy = "0..=4usize")] usize), | |
| 412 | + FocusWorkspaceAutoBackAndForth(#[proptest(strategy = "0..=4usize")] usize), | |
| 413 | + FocusWorkspacePrevious, | |
| 414 | + MoveWindowToWorkspaceDown, | |
| 415 | + MoveWindowToWorkspaceUp, | |
| 416 | + MoveWindowToWorkspace { | |
| 417 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 418 | + window_id: Option<usize>, | |
| 419 | + #[proptest(strategy = "0..=4usize")] | |
| 420 | + workspace_idx: usize, | |
| 421 | + }, | |
| 422 | + MoveColumnToWorkspaceDown, | |
| 423 | + MoveColumnToWorkspaceUp, | |
| 424 | + MoveColumnToWorkspace(#[proptest(strategy = "0..=4usize")] usize), | |
| 425 | + MoveWorkspaceDown, | |
| 426 | + MoveWorkspaceUp, | |
| 427 | + MoveWorkspaceToIndex { | |
| 428 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 429 | + ws_name: Option<usize>, | |
| 430 | + #[proptest(strategy = "0..=4usize")] | |
| 431 | + target_idx: usize, | |
| 432 | + }, | |
| 433 | + MoveWorkspaceToMonitor { | |
| 434 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 435 | + ws_name: Option<usize>, | |
| 436 | + #[proptest(strategy = "0..=5usize")] | |
| 437 | + output_id: usize, | |
| 438 | + }, | |
| 439 | + SetWorkspaceName { | |
| 440 | + #[proptest(strategy = "1..=5usize")] | |
| 441 | + new_ws_name: usize, | |
| 442 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 443 | + ws_name: Option<usize>, | |
| 444 | + }, | |
| 445 | + UnsetWorkspaceName { | |
| 446 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 447 | + ws_name: Option<usize>, | |
| 448 | + }, | |
| 449 | + MoveWindowToOutput { | |
| 450 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 451 | + window_id: Option<usize>, | |
| 452 | + #[proptest(strategy = "1..=5usize")] | |
| 453 | + output_id: usize, | |
| 454 | + #[proptest(strategy = "proptest::option::of(0..=4usize)")] | |
| 455 | + target_ws_idx: Option<usize>, | |
| 456 | + }, | |
| 457 | + MoveColumnToOutput(#[proptest(strategy = "1..=5usize")] usize), | |
| 458 | + SwitchPresetColumnWidth, | |
| 459 | + SwitchPresetWindowWidth { | |
| 460 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 461 | + id: Option<usize>, | |
| 462 | + }, | |
| 463 | + SwitchPresetWindowHeight { | |
| 464 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 465 | + id: Option<usize>, | |
| 466 | + }, | |
| 467 | + MaximizeColumn, | |
| 468 | + SetColumnWidth(#[proptest(strategy = "arbitrary_size_change()")] SizeChange), | |
| 469 | + SetWindowWidth { | |
| 470 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 471 | + id: Option<usize>, | |
| 472 | + #[proptest(strategy = "arbitrary_size_change()")] | |
| 473 | + change: SizeChange, | |
| 474 | + }, | |
| 475 | + SetWindowHeight { | |
| 476 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 477 | + id: Option<usize>, | |
| 478 | + #[proptest(strategy = "arbitrary_size_change()")] | |
| 479 | + change: SizeChange, | |
| 480 | + }, | |
| 481 | + ResetWindowHeight { | |
| 482 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 483 | + id: Option<usize>, | |
| 484 | + }, | |
| 485 | + ToggleWindowFloating { | |
| 486 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 487 | + id: Option<usize>, | |
| 488 | + }, | |
| 489 | + SetWindowFloating { | |
| 490 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 491 | + id: Option<usize>, | |
| 492 | + floating: bool, | |
| 493 | + }, | |
| 494 | + FocusFloating, | |
| 495 | + FocusTiling, | |
| 496 | + SwitchFocusFloatingTiling, | |
| 497 | + MoveFloatingWindow { | |
| 498 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | |
| 499 | + id: Option<usize>, | |
| 500 | + #[proptest(strategy = "arbitrary_position_change()")] | |
| 501 | + x: PositionChange, | |
| 502 | + #[proptest(strategy = "arbitrary_position_change()")] | |
| 503 | + y: PositionChange, | |
| 504 | + animate: bool, | |
| 505 | + }, | |
| 506 | + SetParent { | |
| 507 | + #[proptest(strategy = "1..=5usize")] | |
| 508 | + id: usize, | |
| 509 | + #[proptest(strategy = "prop::option::of(1..=5usize)")] | |
| 510 | + new_parent_id: Option<usize>, | |
| 511 | + }, | |
| 512 | + Communicate(#[proptest(strategy = "1..=5usize")] usize), | |
| 513 | + Refresh { | |
| 514 | + is_active: bool, | |
| 515 | + }, | |
| 516 | + AdvanceAnimations { | |
| 517 | + #[proptest(strategy = "arbitrary_msec_delta()")] | |
| 518 | + msec_delta: i32, | |
| 519 | + }, | |
| 520 | + MoveWorkspaceToOutput(#[proptest(strategy = "1..=5usize")] usize), | |
| 521 | + ViewOffsetGestureBegin { | |
| 522 | + #[proptest(strategy = "1..=5usize")] | |
| 523 | + output_idx: usize, | |
| 524 | + is_touchpad: bool, | |
| 525 | + }, | |
| 526 | + ViewOffsetGestureUpdate { | |
| 527 | + #[proptest(strategy = "arbitrary_view_offset_gesture_delta()")] | |
| 528 | + delta: f64, | |
| 529 | + timestamp: Duration, | |
| 530 | + is_touchpad: bool, | |
| 531 | + }, | |
| 532 | + ViewOffsetGestureEnd { | |
| 533 | + is_touchpad: Option<bool>, | |
| 534 | + }, | |
| 535 | + WorkspaceSwitchGestureBegin { | |
| 536 | + #[proptest(strategy = "1..=5usize")] | |
| 537 | + output_idx: usize, | |
| 538 | + is_touchpad: bool, | |
| 539 | + }, | |
| 540 | + WorkspaceSwitchGestureUpdate { | |
| 541 | + #[proptest(strategy = "-400f64..400f64")] | |
| 542 | + delta: f64, | |
| 543 | + timestamp: Duration, | |
| 544 | + is_touchpad: bool, | |
| 545 | + }, | |
| 546 | + WorkspaceSwitchGestureEnd { | |
| 547 | + cancelled: bool, | |
| 548 | + is_touchpad: Option<bool>, | |
| 549 | + }, | |
| 550 | + InteractiveMoveBegin { | |
| 551 | + #[proptest(strategy = "1..=5usize")] | |
| 552 | + window: usize, | |
| 553 | + #[proptest(strategy = "1..=5usize")] | |
| 554 | + output_idx: usize, | |
| 555 | + #[proptest(strategy = "-20000f64..20000f64")] | |
| 556 | + px: f64, | |
| 557 | + #[proptest(strategy = "-20000f64..20000f64")] | |
| 558 | + py: f64, | |
| 559 | + }, | |
| 560 | + InteractiveMoveUpdate { | |
| 561 | + #[proptest(strategy = "1..=5usize")] | |
| 562 | + window: usize, | |
| 563 | + #[proptest(strategy = "-20000f64..20000f64")] | |
| 564 | + dx: f64, | |
| 565 | + #[proptest(strategy = "-20000f64..20000f64")] | |
| 566 | + dy: f64, | |
| 567 | + #[proptest(strategy = "1..=5usize")] | |
| 568 | + output_idx: usize, | |
| 569 | + #[proptest(strategy = "-20000f64..20000f64")] | |
| 570 | + px: f64, | |
| 571 | + #[proptest(strategy = "-20000f64..20000f64")] | |
| 572 | + py: f64, | |
| 573 | + }, | |
| 574 | + InteractiveMoveEnd { | |
| 575 | + #[proptest(strategy = "1..=5usize")] | |
| 576 | + window: usize, | |
| 577 | + }, | |
| 578 | + InteractiveResizeBegin { | |
| 579 | + #[proptest(strategy = "1..=5usize")] | |
| 580 | + window: usize, | |
| 581 | + #[proptest(strategy = "arbitrary_resize_edge()")] | |
| 582 | + edges: ResizeEdge, | |
| 583 | + }, | |
| 584 | + InteractiveResizeUpdate { | |
| 585 | + #[proptest(strategy = "1..=5usize")] | |
| 586 | + window: usize, | |
| 587 | + #[proptest(strategy = "-20000f64..20000f64")] | |
| 588 | + dx: f64, | |
| 589 | + #[proptest(strategy = "-20000f64..20000f64")] | |
| 590 | + dy: f64, | |
| 591 | + }, | |
| 592 | + InteractiveResizeEnd { | |
| 593 | + #[proptest(strategy = "1..=5usize")] | |
| 594 | + window: usize, | |
| 595 | + }, | |
| 596 | +} | |
| 597 | + | |
| 598 | +impl Op { | |
| 599 | + fn apply(self, layout: &mut Layout<TestWindow>) { | |
| 600 | + match self { | |
| 601 | + Op::AddOutput(id) => { | |
| 602 | + let name = format!("output{id}"); | |
| 603 | + if layout.outputs().any(|o| o.name() == name) { | |
| 604 | + return; | |
| 605 | + } | |
| 606 | + | |
| 607 | + let output = Output::new( | |
| 608 | + name.clone(), | |
| 609 | + PhysicalProperties { | |
| 610 | + size: Size::from((1280, 720)), | |
| 611 | + subpixel: Subpixel::Unknown, | |
| 612 | + make: String::new(), | |
| 613 | + model: String::new(), | |
| 614 | + }, | |
| 615 | + ); | |
| 616 | + output.change_current_state( | |
| 617 | + Some(Mode { | |
| 618 | + size: Size::from((1280, 720)), | |
| 619 | + refresh: 60000, | |
| 620 | + }), | |
| 621 | + None, | |
| 622 | + None, | |
| 623 | + None, | |
| 624 | + ); | |
| 625 | + output.user_data().insert_if_missing(|| OutputName { | |
| 626 | + connector: name, | |
| 627 | + make: None, | |
| 628 | + model: None, | |
| 629 | + serial: None, | |
| 630 | + }); | |
| 631 | + layout.add_output(output.clone()); | |
| 632 | + } | |
| 633 | + Op::AddScaledOutput { id, scale } => { | |
| 634 | + let name = format!("output{id}"); | |
| 635 | + if layout.outputs().any(|o| o.name() == name) { | |
| 636 | + return; | |
| 637 | + } | |
| 638 | + | |
| 639 | + let output = Output::new( | |
| 640 | + name.clone(), | |
| 641 | + PhysicalProperties { | |
| 642 | + size: Size::from((1280, 720)), | |
| 643 | + subpixel: Subpixel::Unknown, | |
| 644 | + make: String::new(), | |
| 645 | + model: String::new(), | |
| 646 | + }, | |
| 647 | + ); | |
| 648 | + output.change_current_state( | |
| 649 | + Some(Mode { | |
| 650 | + size: Size::from((1280, 720)), | |
| 651 | + refresh: 60000, | |
| 652 | + }), | |
| 653 | + None, | |
| 654 | + Some(smithay::output::Scale::Fractional(scale)), | |
| 655 | + None, | |
| 656 | + ); | |
| 657 | + output.user_data().insert_if_missing(|| OutputName { | |
| 658 | + connector: name, | |
| 659 | + make: None, | |
| 660 | + model: None, | |
| 661 | + serial: None, | |
| 662 | + }); | |
| 663 | + layout.add_output(output.clone()); | |
| 664 | + } | |
| 665 | + Op::RemoveOutput(id) => { | |
| 666 | + let name = format!("output{id}"); | |
| 667 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 668 | + return; | |
| 669 | + }; | |
| 670 | + | |
| 671 | + layout.remove_output(&output); | |
| 672 | + } | |
| 673 | + Op::FocusOutput(id) => { | |
| 674 | + let name = format!("output{id}"); | |
| 675 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 676 | + return; | |
| 677 | + }; | |
| 678 | + | |
| 679 | + layout.focus_output(&output); | |
| 680 | + } | |
| 681 | + Op::AddNamedWorkspace { | |
| 682 | + ws_name, | |
| 683 | + output_name, | |
| 684 | + } => { | |
| 685 | + layout.ensure_named_workspace(&WorkspaceConfig { | |
| 686 | + name: WorkspaceName(format!("ws{ws_name}")), | |
| 687 | + open_on_output: output_name.map(|name| format!("output{name}")), | |
| 688 | + }); | |
| 689 | + } | |
| 690 | + Op::UnnameWorkspace { ws_name } => { | |
| 691 | + layout.unname_workspace(&format!("ws{ws_name}")); | |
| 692 | + } | |
| 693 | + Op::SetWorkspaceName { | |
| 694 | + new_ws_name, | |
| 695 | + ws_name, | |
| 696 | + } => { | |
| 697 | + let ws_ref = | |
| 698 | + ws_name.map(|ws_name| WorkspaceReference::Name(format!("ws{ws_name}"))); | |
| 699 | + layout.set_workspace_name(format!("ws{new_ws_name}"), ws_ref); | |
| 700 | + } | |
| 701 | + Op::UnsetWorkspaceName { ws_name } => { | |
| 702 | + let ws_ref = | |
| 703 | + ws_name.map(|ws_name| WorkspaceReference::Name(format!("ws{ws_name}"))); | |
| 704 | + layout.unset_workspace_name(ws_ref); | |
| 705 | + } | |
| 706 | + Op::AddWindow { mut params } => { | |
| 707 | + if layout.has_window(¶ms.id) { | |
| 708 | + return; | |
| 709 | + } | |
| 710 | + if let Some(parent_id) = params.parent_id { | |
| 711 | + if parent_id_causes_loop(layout, params.id, parent_id) { | |
| 712 | + params.parent_id = None; | |
| 713 | + } | |
| 714 | + } | |
| 715 | + | |
| 716 | + let win = TestWindow::new(params); | |
| 717 | + layout.add_window( | |
| 718 | + win, | |
| 719 | + AddWindowTarget::Auto, | |
| 720 | + None, | |
| 721 | + None, | |
| 722 | + false, | |
| 723 | + params.is_floating, | |
| 724 | + ActivateWindow::default(), | |
| 725 | + ); | |
| 726 | + } | |
| 727 | + Op::AddWindowNextTo { | |
| 728 | + mut params, | |
| 729 | + next_to_id, | |
| 730 | + } => { | |
| 731 | + let mut found_next_to = false; | |
| 732 | + | |
| 733 | + if let Some(InteractiveMoveState::Moving(move_)) = &layout.interactive_move { | |
| 734 | + let win_id = move_.tile.window().0.id; | |
| 735 | + if win_id == params.id { | |
| 736 | + return; | |
| 737 | + } | |
| 738 | + if win_id == next_to_id { | |
| 739 | + found_next_to = true; | |
| 740 | + } | |
| 741 | + } | |
| 742 | + | |
| 743 | + match &mut layout.monitor_set { | |
| 744 | + MonitorSet::Normal { monitors, .. } => { | |
| 745 | + for mon in monitors { | |
| 746 | + for ws in &mut mon.workspaces { | |
| 747 | + for win in ws.windows() { | |
| 748 | + if win.0.id == params.id { | |
| 749 | + return; | |
| 750 | + } | |
| 751 | + | |
| 752 | + if win.0.id == next_to_id { | |
| 753 | + found_next_to = true; | |
| 754 | + } | |
| 755 | + } | |
| 756 | + } | |
| 757 | + } | |
| 758 | + } | |
| 759 | + MonitorSet::NoOutputs { workspaces, .. } => { | |
| 760 | + for ws in workspaces { | |
| 761 | + for win in ws.windows() { | |
| 762 | + if win.0.id == params.id { | |
| 763 | + return; | |
| 764 | + } | |
| 765 | + | |
| 766 | + if win.0.id == next_to_id { | |
| 767 | + found_next_to = true; | |
| 768 | + } | |
| 769 | + } | |
| 770 | + } | |
| 771 | + } | |
| 772 | + } | |
| 773 | + | |
| 774 | + if !found_next_to { | |
| 775 | + return; | |
| 776 | + } | |
| 777 | + | |
| 778 | + if let Some(parent_id) = params.parent_id { | |
| 779 | + if parent_id_causes_loop(layout, params.id, parent_id) { | |
| 780 | + params.parent_id = None; | |
| 781 | + } | |
| 782 | + } | |
| 783 | + | |
| 784 | + let win = TestWindow::new(params); | |
| 785 | + layout.add_window( | |
| 786 | + win, | |
| 787 | + AddWindowTarget::NextTo(&next_to_id), | |
| 788 | + None, | |
| 789 | + None, | |
| 790 | + false, | |
| 791 | + params.is_floating, | |
| 792 | + ActivateWindow::default(), | |
| 793 | + ); | |
| 794 | + } | |
| 795 | + Op::AddWindowToNamedWorkspace { | |
| 796 | + mut params, | |
| 797 | + ws_name, | |
| 798 | + } => { | |
| 799 | + let ws_name = format!("ws{ws_name}"); | |
| 800 | + let mut ws_id = None; | |
| 801 | + | |
| 802 | + if let Some(InteractiveMoveState::Moving(move_)) = &layout.interactive_move { | |
| 803 | + if move_.tile.window().0.id == params.id { | |
| 804 | + return; | |
| 805 | + } | |
| 806 | + } | |
| 807 | + | |
| 808 | + match &mut layout.monitor_set { | |
| 809 | + MonitorSet::Normal { monitors, .. } => { | |
| 810 | + for mon in monitors { | |
| 811 | + for ws in &mut mon.workspaces { | |
| 812 | + for win in ws.windows() { | |
| 813 | + if win.0.id == params.id { | |
| 814 | + return; | |
| 815 | + } | |
| 816 | + } | |
| 817 | + | |
| 818 | + if ws | |
| 819 | + .name | |
| 820 | + .as_ref() | |
| 821 | + .is_some_and(|name| name.eq_ignore_ascii_case(&ws_name)) | |
| 822 | + { | |
| 823 | + ws_id = Some(ws.id()); | |
| 824 | + } | |
| 825 | + } | |
| 826 | + } | |
| 827 | + } | |
| 828 | + MonitorSet::NoOutputs { workspaces, .. } => { | |
| 829 | + for ws in workspaces { | |
| 830 | + for win in ws.windows() { | |
| 831 | + if win.0.id == params.id { | |
| 832 | + return; | |
| 833 | + } | |
| 834 | + } | |
| 835 | + | |
| 836 | + if ws | |
| 837 | + .name | |
| 838 | + .as_ref() | |
| 839 | + .is_some_and(|name| name.eq_ignore_ascii_case(&ws_name)) | |
| 840 | + { | |
| 841 | + ws_id = Some(ws.id()); | |
| 842 | + } | |
| 843 | + } | |
| 844 | + } | |
| 845 | + } | |
| 846 | + | |
| 847 | + let Some(ws_id) = ws_id else { | |
| 848 | + return; | |
| 849 | + }; | |
| 850 | + | |
| 851 | + if let Some(parent_id) = params.parent_id { | |
| 852 | + if parent_id_causes_loop(layout, params.id, parent_id) { | |
| 853 | + params.parent_id = None; | |
| 854 | + } | |
| 855 | + } | |
| 856 | + | |
| 857 | + let win = TestWindow::new(params); | |
| 858 | + layout.add_window( | |
| 859 | + win, | |
| 860 | + AddWindowTarget::Workspace(ws_id), | |
| 861 | + None, | |
| 862 | + None, | |
| 863 | + false, | |
| 864 | + params.is_floating, | |
| 865 | + ActivateWindow::default(), | |
| 866 | + ); | |
| 867 | + } | |
| 868 | + Op::CloseWindow(id) => { | |
| 869 | + layout.remove_window(&id, Transaction::new()); | |
| 870 | + } | |
| 871 | + Op::FullscreenWindow(id) => { | |
| 872 | + layout.toggle_fullscreen(&id); | |
| 873 | + } | |
| 874 | + Op::SetFullscreenWindow { | |
| 875 | + window, | |
| 876 | + is_fullscreen, | |
| 877 | + } => { | |
| 878 | + layout.set_fullscreen(&window, is_fullscreen); | |
| 879 | + } | |
| 880 | + Op::FocusColumnLeft => layout.focus_left(), | |
| 881 | + Op::FocusColumnRight => layout.focus_right(), | |
| 882 | + Op::FocusColumnFirst => layout.focus_column_first(), | |
| 883 | + Op::FocusColumnLast => layout.focus_column_last(), | |
| 884 | + Op::FocusColumnRightOrFirst => layout.focus_column_right_or_first(), | |
| 885 | + Op::FocusColumnLeftOrLast => layout.focus_column_left_or_last(), | |
| 886 | + Op::FocusWindowOrMonitorUp(id) => { | |
| 887 | + let name = format!("output{id}"); | |
| 888 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 889 | + return; | |
| 890 | + }; | |
| 891 | + | |
| 892 | + layout.focus_window_up_or_output(&output); | |
| 893 | + } | |
| 894 | + Op::FocusWindowOrMonitorDown(id) => { | |
| 895 | + let name = format!("output{id}"); | |
| 896 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 897 | + return; | |
| 898 | + }; | |
| 899 | + | |
| 900 | + layout.focus_window_down_or_output(&output); | |
| 901 | + } | |
| 902 | + Op::FocusColumnOrMonitorLeft(id) => { | |
| 903 | + let name = format!("output{id}"); | |
| 904 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 905 | + return; | |
| 906 | + }; | |
| 907 | + | |
| 908 | + layout.focus_column_left_or_output(&output); | |
| 909 | + } | |
| 910 | + Op::FocusColumnOrMonitorRight(id) => { | |
| 911 | + let name = format!("output{id}"); | |
| 912 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 913 | + return; | |
| 914 | + }; | |
| 915 | + | |
| 916 | + layout.focus_column_right_or_output(&output); | |
| 917 | + } | |
| 918 | + Op::FocusWindowDown => layout.focus_down(), | |
| 919 | + Op::FocusWindowUp => layout.focus_up(), | |
| 920 | + Op::FocusWindowDownOrColumnLeft => layout.focus_down_or_left(), | |
| 921 | + Op::FocusWindowDownOrColumnRight => layout.focus_down_or_right(), | |
| 922 | + Op::FocusWindowUpOrColumnLeft => layout.focus_up_or_left(), | |
| 923 | + Op::FocusWindowUpOrColumnRight => layout.focus_up_or_right(), | |
| 924 | + Op::FocusWindowOrWorkspaceDown => layout.focus_window_or_workspace_down(), | |
| 925 | + Op::FocusWindowOrWorkspaceUp => layout.focus_window_or_workspace_up(), | |
| 926 | + Op::FocusWindow(id) => layout.activate_window(&id), | |
| 927 | + Op::MoveColumnLeft => layout.move_left(), | |
| 928 | + Op::MoveColumnRight => layout.move_right(), | |
| 929 | + Op::MoveColumnToFirst => layout.move_column_to_first(), | |
| 930 | + Op::MoveColumnToLast => layout.move_column_to_last(), | |
| 931 | + Op::MoveColumnLeftOrToMonitorLeft(id) => { | |
| 932 | + let name = format!("output{id}"); | |
| 933 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 934 | + return; | |
| 935 | + }; | |
| 936 | + | |
| 937 | + layout.move_column_left_or_to_output(&output); | |
| 938 | + } | |
| 939 | + Op::MoveColumnRightOrToMonitorRight(id) => { | |
| 940 | + let name = format!("output{id}"); | |
| 941 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 942 | + return; | |
| 943 | + }; | |
| 944 | + | |
| 945 | + layout.move_column_right_or_to_output(&output); | |
| 946 | + } | |
| 947 | + Op::MoveWindowDown => layout.move_down(), | |
| 948 | + Op::MoveWindowUp => layout.move_up(), | |
| 949 | + Op::MoveWindowDownOrToWorkspaceDown => layout.move_down_or_to_workspace_down(), | |
| 950 | + Op::MoveWindowUpOrToWorkspaceUp => layout.move_up_or_to_workspace_up(), | |
| 951 | + Op::ConsumeOrExpelWindowLeft { id } => { | |
| 952 | + let id = id.filter(|id| layout.has_window(id)); | |
| 953 | + layout.consume_or_expel_window_left(id.as_ref()); | |
| 954 | + } | |
| 955 | + Op::ConsumeOrExpelWindowRight { id } => { | |
| 956 | + let id = id.filter(|id| layout.has_window(id)); | |
| 957 | + layout.consume_or_expel_window_right(id.as_ref()); | |
| 958 | + } | |
| 959 | + Op::ConsumeWindowIntoColumn => layout.consume_into_column(), | |
| 960 | + Op::ExpelWindowFromColumn => layout.expel_from_column(), | |
| 961 | + Op::SwapWindowInDirection(direction) => layout.swap_window_in_direction(direction), | |
| 962 | + Op::CenterColumn => layout.center_column(), | |
| 963 | + Op::CenterWindow { id } => { | |
| 964 | + let id = id.filter(|id| layout.has_window(id)); | |
| 965 | + layout.center_window(id.as_ref()); | |
| 966 | + } | |
| 967 | + Op::FocusWorkspaceDown => layout.switch_workspace_down(), | |
| 968 | + Op::FocusWorkspaceUp => layout.switch_workspace_up(), | |
| 969 | + Op::FocusWorkspace(idx) => layout.switch_workspace(idx), | |
| 970 | + Op::FocusWorkspaceAutoBackAndForth(idx) => { | |
| 971 | + layout.switch_workspace_auto_back_and_forth(idx) | |
| 972 | + } | |
| 973 | + Op::FocusWorkspacePrevious => layout.switch_workspace_previous(), | |
| 974 | + Op::MoveWindowToWorkspaceDown => layout.move_to_workspace_down(), | |
| 975 | + Op::MoveWindowToWorkspaceUp => layout.move_to_workspace_up(), | |
| 976 | + Op::MoveWindowToWorkspace { | |
| 977 | + window_id, | |
| 978 | + workspace_idx, | |
| 979 | + } => { | |
| 980 | + let window_id = window_id.filter(|id| layout.has_window(id)); | |
| 981 | + layout.move_to_workspace(window_id.as_ref(), workspace_idx); | |
| 982 | + } | |
| 983 | + Op::MoveColumnToWorkspaceDown => layout.move_column_to_workspace_down(), | |
| 984 | + Op::MoveColumnToWorkspaceUp => layout.move_column_to_workspace_up(), | |
| 985 | + Op::MoveColumnToWorkspace(idx) => layout.move_column_to_workspace(idx), | |
| 986 | + Op::MoveWindowToOutput { | |
| 987 | + window_id, | |
| 988 | + output_id: id, | |
| 989 | + target_ws_idx, | |
| 990 | + } => { | |
| 991 | + let name = format!("output{id}"); | |
| 992 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 993 | + return; | |
| 994 | + }; | |
| 995 | + let mon = layout.monitor_for_output(&output).unwrap(); | |
| 996 | + | |
| 997 | + let window_id = window_id.filter(|id| layout.has_window(id)); | |
| 998 | + let target_ws_idx = target_ws_idx.filter(|idx| mon.workspaces.len() > *idx); | |
| 999 | + layout.move_to_output(window_id.as_ref(), &output, target_ws_idx); | |
| 1000 | + } | |
| 1001 | + Op::MoveColumnToOutput(id) => { | |
| 1002 | + let name = format!("output{id}"); | |
| 1003 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 1004 | + return; | |
| 1005 | + }; | |
| 1006 | + | |
| 1007 | + layout.move_column_to_output(&output); | |
| 1008 | + } | |
| 1009 | + Op::MoveWorkspaceDown => layout.move_workspace_down(), | |
| 1010 | + Op::MoveWorkspaceUp => layout.move_workspace_up(), | |
| 1011 | + Op::MoveWorkspaceToIndex { | |
| 1012 | + ws_name: Some(ws_name), | |
| 1013 | + target_idx, | |
| 1014 | + } => { | |
| 1015 | + let MonitorSet::Normal { monitors, .. } = &mut layout.monitor_set else { | |
| 1016 | + return; | |
| 1017 | + }; | |
| 1018 | + | |
| 1019 | + let Some((old_idx, old_output)) = monitors.iter().find_map(|monitor| { | |
| 1020 | + monitor | |
| 1021 | + .workspaces | |
| 1022 | + .iter() | |
| 1023 | + .enumerate() | |
| 1024 | + .find_map(|(i, ws)| { | |
| 1025 | + if ws.name == Some(format!("ws{ws_name}")) { | |
| 1026 | + Some(i) | |
| 1027 | + } else { | |
| 1028 | + None | |
| 1029 | + } | |
| 1030 | + }) | |
| 1031 | + .map(|i| (i, monitor.output.clone())) | |
| 1032 | + }) else { | |
| 1033 | + return; | |
| 1034 | + }; | |
| 1035 | + | |
| 1036 | + layout.move_workspace_to_idx(Some((Some(old_output), old_idx)), target_idx) | |
| 1037 | + } | |
| 1038 | + Op::MoveWorkspaceToIndex { | |
| 1039 | + ws_name: None, | |
| 1040 | + target_idx, | |
| 1041 | + } => layout.move_workspace_to_idx(None, target_idx), | |
| 1042 | + Op::MoveWorkspaceToMonitor { | |
| 1043 | + ws_name: None, | |
| 1044 | + output_id: id, | |
| 1045 | + } => { | |
| 1046 | + let name = format!("output{id}"); | |
| 1047 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 1048 | + return; | |
| 1049 | + }; | |
| 1050 | + layout.move_workspace_to_output(&output); | |
| 1051 | + } | |
| 1052 | + Op::MoveWorkspaceToMonitor { | |
| 1053 | + ws_name: Some(ws_name), | |
| 1054 | + output_id: id, | |
| 1055 | + } => { | |
| 1056 | + let name = format!("output{id}"); | |
| 1057 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 1058 | + return; | |
| 1059 | + }; | |
| 1060 | + let MonitorSet::Normal { monitors, .. } = &mut layout.monitor_set else { | |
| 1061 | + return; | |
| 1062 | + }; | |
| 1063 | + | |
| 1064 | + let Some((old_idx, old_output)) = monitors.iter().find_map(|monitor| { | |
| 1065 | + monitor | |
| 1066 | + .workspaces | |
| 1067 | + .iter() | |
| 1068 | + .enumerate() | |
| 1069 | + .find_map(|(i, ws)| { | |
| 1070 | + if ws.name == Some(format!("ws{ws_name}")) { | |
| 1071 | + Some(i) | |
| 1072 | + } else { | |
| 1073 | + None | |
| 1074 | + } | |
| 1075 | + }) | |
| 1076 | + .map(|i| (i, monitor.output.clone())) | |
| 1077 | + }) else { | |
| 1078 | + return; | |
| 1079 | + }; | |
| 1080 | + | |
| 1081 | + layout.move_workspace_to_output_by_id(old_idx, Some(old_output), output); | |
| 1082 | + } | |
| 1083 | + Op::SwitchPresetColumnWidth => layout.toggle_width(), | |
| 1084 | + Op::SwitchPresetWindowWidth { id } => { | |
| 1085 | + let id = id.filter(|id| layout.has_window(id)); | |
| 1086 | + layout.toggle_window_width(id.as_ref()); | |
| 1087 | + } | |
| 1088 | + Op::SwitchPresetWindowHeight { id } => { | |
| 1089 | + let id = id.filter(|id| layout.has_window(id)); | |
| 1090 | + layout.toggle_window_height(id.as_ref()); | |
| 1091 | + } | |
| 1092 | + Op::MaximizeColumn => layout.toggle_full_width(), | |
| 1093 | + Op::SetColumnWidth(change) => layout.set_column_width(change), | |
| 1094 | + Op::SetWindowWidth { id, change } => { | |
| 1095 | + let id = id.filter(|id| layout.has_window(id)); | |
| 1096 | + layout.set_window_width(id.as_ref(), change); | |
| 1097 | + } | |
| 1098 | + Op::SetWindowHeight { id, change } => { | |
| 1099 | + let id = id.filter(|id| layout.has_window(id)); | |
| 1100 | + layout.set_window_height(id.as_ref(), change); | |
| 1101 | + } | |
| 1102 | + Op::ResetWindowHeight { id } => { | |
| 1103 | + let id = id.filter(|id| layout.has_window(id)); | |
| 1104 | + layout.reset_window_height(id.as_ref()); | |
| 1105 | + } | |
| 1106 | + Op::ToggleWindowFloating { id } => { | |
| 1107 | + let id = id.filter(|id| layout.has_window(id)); | |
| 1108 | + layout.toggle_window_floating(id.as_ref()); | |
| 1109 | + } | |
| 1110 | + Op::SetWindowFloating { id, floating } => { | |
| 1111 | + let id = id.filter(|id| layout.has_window(id)); | |
| 1112 | + layout.set_window_floating(id.as_ref(), floating); | |
| 1113 | + } | |
| 1114 | + Op::FocusFloating => { | |
| 1115 | + layout.focus_floating(); | |
| 1116 | + } | |
| 1117 | + Op::FocusTiling => { | |
| 1118 | + layout.focus_tiling(); | |
| 1119 | + } | |
| 1120 | + Op::SwitchFocusFloatingTiling => { | |
| 1121 | + layout.switch_focus_floating_tiling(); | |
| 1122 | + } | |
| 1123 | + Op::MoveFloatingWindow { id, x, y, animate } => { | |
| 1124 | + let id = id.filter(|id| layout.has_window(id)); | |
| 1125 | + layout.move_floating_window(id.as_ref(), x, y, animate); | |
| 1126 | + } | |
| 1127 | + Op::SetParent { | |
| 1128 | + id, | |
| 1129 | + mut new_parent_id, | |
| 1130 | + } => { | |
| 1131 | + if !layout.has_window(&id) { | |
| 1132 | + return; | |
| 1133 | + } | |
| 1134 | + | |
| 1135 | + if let Some(parent_id) = new_parent_id { | |
| 1136 | + if parent_id_causes_loop(layout, id, parent_id) { | |
| 1137 | + new_parent_id = None; | |
| 1138 | + } | |
| 1139 | + } | |
| 1140 | + | |
| 1141 | + let mut update = false; | |
| 1142 | + | |
| 1143 | + if let Some(InteractiveMoveState::Moving(move_)) = &layout.interactive_move { | |
| 1144 | + if move_.tile.window().0.id == id { | |
| 1145 | + move_.tile.window().0.parent_id.set(new_parent_id); | |
| 1146 | + update = true; | |
| 1147 | + } | |
| 1148 | + } | |
| 1149 | + | |
| 1150 | + match &mut layout.monitor_set { | |
| 1151 | + MonitorSet::Normal { monitors, .. } => { | |
| 1152 | + 'outer: for mon in monitors { | |
| 1153 | + for ws in &mut mon.workspaces { | |
| 1154 | + for win in ws.windows() { | |
| 1155 | + if win.0.id == id { | |
| 1156 | + win.0.parent_id.set(new_parent_id); | |
| 1157 | + update = true; | |
| 1158 | + break 'outer; | |
| 1159 | + } | |
| 1160 | + } | |
| 1161 | + } | |
| 1162 | + } | |
| 1163 | + } | |
| 1164 | + MonitorSet::NoOutputs { workspaces, .. } => { | |
| 1165 | + 'outer: for ws in workspaces { | |
| 1166 | + for win in ws.windows() { | |
| 1167 | + if win.0.id == id { | |
| 1168 | + win.0.parent_id.set(new_parent_id); | |
| 1169 | + update = true; | |
| 1170 | + break 'outer; | |
| 1171 | + } | |
| 1172 | + } | |
| 1173 | + } | |
| 1174 | + } | |
| 1175 | + } | |
| 1176 | + | |
| 1177 | + if update { | |
| 1178 | + if let Some(new_parent_id) = new_parent_id { | |
| 1179 | + layout.descendants_added(&new_parent_id); | |
| 1180 | + } | |
| 1181 | + } | |
| 1182 | + } | |
| 1183 | + Op::Communicate(id) => { | |
| 1184 | + let mut update = false; | |
| 1185 | + | |
| 1186 | + if let Some(InteractiveMoveState::Moving(move_)) = &layout.interactive_move { | |
| 1187 | + if move_.tile.window().0.id == id { | |
| 1188 | + if move_.tile.window().communicate() { | |
| 1189 | + update = true; | |
| 1190 | + } | |
| 1191 | + | |
| 1192 | + if update { | |
| 1193 | + // FIXME: serial. | |
| 1194 | + layout.update_window(&id, None); | |
| 1195 | + } | |
| 1196 | + return; | |
| 1197 | + } | |
| 1198 | + } | |
| 1199 | + | |
| 1200 | + match &mut layout.monitor_set { | |
| 1201 | + MonitorSet::Normal { monitors, .. } => { | |
| 1202 | + 'outer: for mon in monitors { | |
| 1203 | + for ws in &mut mon.workspaces { | |
| 1204 | + for win in ws.windows() { | |
| 1205 | + if win.0.id == id { | |
| 1206 | + if win.communicate() { | |
| 1207 | + update = true; | |
| 1208 | + } | |
| 1209 | + break 'outer; | |
| 1210 | + } | |
| 1211 | + } | |
| 1212 | + } | |
| 1213 | + } | |
| 1214 | + } | |
| 1215 | + MonitorSet::NoOutputs { workspaces, .. } => { | |
| 1216 | + 'outer: for ws in workspaces { | |
| 1217 | + for win in ws.windows() { | |
| 1218 | + if win.0.id == id { | |
| 1219 | + if win.communicate() { | |
| 1220 | + update = true; | |
| 1221 | + } | |
| 1222 | + break 'outer; | |
| 1223 | + } | |
| 1224 | + } | |
| 1225 | + } | |
| 1226 | + } | |
| 1227 | + } | |
| 1228 | + | |
| 1229 | + if update { | |
| 1230 | + // FIXME: serial. | |
| 1231 | + layout.update_window(&id, None); | |
| 1232 | + } | |
| 1233 | + } | |
| 1234 | + Op::Refresh { is_active } => { | |
| 1235 | + layout.refresh(is_active); | |
| 1236 | + } | |
| 1237 | + Op::AdvanceAnimations { msec_delta } => { | |
| 1238 | + let mut now = layout.clock.now_unadjusted(); | |
| 1239 | + if msec_delta >= 0 { | |
| 1240 | + now = now.saturating_add(Duration::from_millis(msec_delta as u64)); | |
| 1241 | + } else { | |
| 1242 | + now = now.saturating_sub(Duration::from_millis(-msec_delta as u64)); | |
| 1243 | + } | |
| 1244 | + layout.clock.set_unadjusted(now); | |
| 1245 | + layout.advance_animations(); | |
| 1246 | + } | |
| 1247 | + Op::MoveWorkspaceToOutput(id) => { | |
| 1248 | + let name = format!("output{id}"); | |
| 1249 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 1250 | + return; | |
| 1251 | + }; | |
| 1252 | + | |
| 1253 | + layout.move_workspace_to_output(&output); | |
| 1254 | + } | |
| 1255 | + Op::ViewOffsetGestureBegin { | |
| 1256 | + output_idx: id, | |
| 1257 | + is_touchpad: normalize, | |
| 1258 | + } => { | |
| 1259 | + let name = format!("output{id}"); | |
| 1260 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 1261 | + return; | |
| 1262 | + }; | |
| 1263 | + | |
| 1264 | + layout.view_offset_gesture_begin(&output, normalize); | |
| 1265 | + } | |
| 1266 | + Op::ViewOffsetGestureUpdate { | |
| 1267 | + delta, | |
| 1268 | + timestamp, | |
| 1269 | + is_touchpad, | |
| 1270 | + } => { | |
| 1271 | + layout.view_offset_gesture_update(delta, timestamp, is_touchpad); | |
| 1272 | + } | |
| 1273 | + Op::ViewOffsetGestureEnd { is_touchpad } => { | |
| 1274 | + // We don't handle cancels in this gesture. | |
| 1275 | + layout.view_offset_gesture_end(false, is_touchpad); | |
| 1276 | + } | |
| 1277 | + Op::WorkspaceSwitchGestureBegin { | |
| 1278 | + output_idx: id, | |
| 1279 | + is_touchpad, | |
| 1280 | + } => { | |
| 1281 | + let name = format!("output{id}"); | |
| 1282 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 1283 | + return; | |
| 1284 | + }; | |
| 1285 | + | |
| 1286 | + layout.workspace_switch_gesture_begin(&output, is_touchpad); | |
| 1287 | + } | |
| 1288 | + Op::WorkspaceSwitchGestureUpdate { | |
| 1289 | + delta, | |
| 1290 | + timestamp, | |
| 1291 | + is_touchpad, | |
| 1292 | + } => { | |
| 1293 | + layout.workspace_switch_gesture_update(delta, timestamp, is_touchpad); | |
| 1294 | + } | |
| 1295 | + Op::WorkspaceSwitchGestureEnd { | |
| 1296 | + cancelled, | |
| 1297 | + is_touchpad, | |
| 1298 | + } => { | |
| 1299 | + layout.workspace_switch_gesture_end(cancelled, is_touchpad); | |
| 1300 | + } | |
| 1301 | + Op::InteractiveMoveBegin { | |
| 1302 | + window, | |
| 1303 | + output_idx, | |
| 1304 | + px, | |
| 1305 | + py, | |
| 1306 | + } => { | |
| 1307 | + let name = format!("output{output_idx}"); | |
| 1308 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 1309 | + return; | |
| 1310 | + }; | |
| 1311 | + layout.interactive_move_begin(window, &output, Point::from((px, py))); | |
| 1312 | + } | |
| 1313 | + Op::InteractiveMoveUpdate { | |
| 1314 | + window, | |
| 1315 | + dx, | |
| 1316 | + dy, | |
| 1317 | + output_idx, | |
| 1318 | + px, | |
| 1319 | + py, | |
| 1320 | + } => { | |
| 1321 | + let name = format!("output{output_idx}"); | |
| 1322 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 1323 | + return; | |
| 1324 | + }; | |
| 1325 | + layout.interactive_move_update( | |
| 1326 | + &window, | |
| 1327 | + Point::from((dx, dy)), | |
| 1328 | + output, | |
| 1329 | + Point::from((px, py)), | |
| 1330 | + ); | |
| 1331 | + } | |
| 1332 | + Op::InteractiveMoveEnd { window } => { | |
| 1333 | + layout.interactive_move_end(&window); | |
| 1334 | + } | |
| 1335 | + Op::InteractiveResizeBegin { window, edges } => { | |
| 1336 | + layout.interactive_resize_begin(window, edges); | |
| 1337 | + } | |
| 1338 | + Op::InteractiveResizeUpdate { window, dx, dy } => { | |
| 1339 | + layout.interactive_resize_update(&window, Point::from((dx, dy))); | |
| 1340 | + } | |
| 1341 | + Op::InteractiveResizeEnd { window } => { | |
| 1342 | + layout.interactive_resize_end(&window); | |
| 1343 | + } | |
| 1344 | + } | |
| 1345 | + } | |
| 1346 | +} | |
| 1347 | + | |
| 1348 | +#[track_caller] | |
| 1349 | +fn check_ops(ops: &[Op]) -> Layout<TestWindow> { | |
| 1350 | + let mut layout = Layout::default(); | |
| 1351 | + for op in ops { | |
| 1352 | + op.apply(&mut layout); | |
| 1353 | + layout.verify_invariants(); | |
| 1354 | + } | |
| 1355 | + layout | |
| 1356 | +} | |
| 1357 | + | |
| 1358 | +#[track_caller] | |
| 1359 | +fn check_ops_with_options(options: Options, ops: &[Op]) -> Layout<TestWindow> { | |
| 1360 | + let mut layout = Layout::with_options(Clock::with_time(Duration::ZERO), options); | |
| 1361 | + | |
| 1362 | + for op in ops { | |
| 1363 | + op.apply(&mut layout); | |
| 1364 | + layout.verify_invariants(); | |
| 1365 | + } | |
| 1366 | + | |
| 1367 | + layout | |
| 1368 | +} | |
| 1369 | + | |
| 1370 | +#[test] | |
| 1371 | +fn operations_dont_panic() { | |
| 1372 | + let every_op = [ | |
| 1373 | + Op::AddOutput(0), | |
| 1374 | + Op::AddOutput(1), | |
| 1375 | + Op::AddOutput(2), | |
| 1376 | + Op::RemoveOutput(0), | |
| 1377 | + Op::RemoveOutput(1), | |
| 1378 | + Op::RemoveOutput(2), | |
| 1379 | + Op::FocusOutput(0), | |
| 1380 | + Op::FocusOutput(1), | |
| 1381 | + Op::FocusOutput(2), | |
| 1382 | + Op::AddNamedWorkspace { | |
| 1383 | + ws_name: 1, | |
| 1384 | + output_name: Some(1), | |
| 1385 | + }, | |
| 1386 | + Op::UnnameWorkspace { ws_name: 1 }, | |
| 1387 | + Op::AddWindow { | |
| 1388 | + params: TestWindowParams::new(0), | |
| 1389 | + }, | |
| 1390 | + Op::AddWindow { | |
| 1391 | + params: TestWindowParams::new(1), | |
| 1392 | + }, | |
| 1393 | + Op::AddWindowNextTo { | |
| 1394 | + params: TestWindowParams::new(2), | |
| 1395 | + next_to_id: 1, | |
| 1396 | + }, | |
| 1397 | + Op::AddWindowToNamedWorkspace { | |
| 1398 | + params: TestWindowParams::new(3), | |
| 1399 | + ws_name: 1, | |
| 1400 | + }, | |
| 1401 | + Op::CloseWindow(0), | |
| 1402 | + Op::CloseWindow(1), | |
| 1403 | + Op::CloseWindow(2), | |
| 1404 | + Op::FullscreenWindow(1), | |
| 1405 | + Op::FullscreenWindow(2), | |
| 1406 | + Op::FullscreenWindow(3), | |
| 1407 | + Op::FocusColumnLeft, | |
| 1408 | + Op::FocusColumnRight, | |
| 1409 | + Op::FocusColumnRightOrFirst, | |
| 1410 | + Op::FocusColumnLeftOrLast, | |
| 1411 | + Op::FocusWindowOrMonitorUp(0), | |
| 1412 | + Op::FocusWindowOrMonitorDown(1), | |
| 1413 | + Op::FocusColumnOrMonitorLeft(0), | |
| 1414 | + Op::FocusColumnOrMonitorRight(1), | |
| 1415 | + Op::FocusWindowUp, | |
| 1416 | + Op::FocusWindowUpOrColumnLeft, | |
| 1417 | + Op::FocusWindowUpOrColumnRight, | |
| 1418 | + Op::FocusWindowOrWorkspaceUp, | |
| 1419 | + Op::FocusWindowDown, | |
| 1420 | + Op::FocusWindowDownOrColumnLeft, | |
| 1421 | + Op::FocusWindowDownOrColumnRight, | |
| 1422 | + Op::FocusWindowOrWorkspaceDown, | |
| 1423 | + Op::MoveColumnLeft, | |
| 1424 | + Op::MoveColumnRight, | |
| 1425 | + Op::MoveColumnLeftOrToMonitorLeft(0), | |
| 1426 | + Op::MoveColumnRightOrToMonitorRight(1), | |
| 1427 | + Op::ConsumeWindowIntoColumn, | |
| 1428 | + Op::ExpelWindowFromColumn, | |
| 1429 | + Op::CenterColumn, | |
| 1430 | + Op::FocusWorkspaceDown, | |
| 1431 | + Op::FocusWorkspaceUp, | |
| 1432 | + Op::FocusWorkspace(1), | |
| 1433 | + Op::FocusWorkspace(2), | |
| 1434 | + Op::MoveWindowToWorkspaceDown, | |
| 1435 | + Op::MoveWindowToWorkspaceUp, | |
| 1436 | + Op::MoveWindowToWorkspace { | |
| 1437 | + window_id: None, | |
| 1438 | + workspace_idx: 1, | |
| 1439 | + }, | |
| 1440 | + Op::MoveWindowToWorkspace { | |
| 1441 | + window_id: None, | |
| 1442 | + workspace_idx: 2, | |
| 1443 | + }, | |
| 1444 | + Op::MoveColumnToWorkspaceDown, | |
| 1445 | + Op::MoveColumnToWorkspaceUp, | |
| 1446 | + Op::MoveColumnToWorkspace(1), | |
| 1447 | + Op::MoveColumnToWorkspace(2), | |
| 1448 | + Op::MoveWindowDown, | |
| 1449 | + Op::MoveWindowDownOrToWorkspaceDown, | |
| 1450 | + Op::MoveWindowUp, | |
| 1451 | + Op::MoveWindowUpOrToWorkspaceUp, | |
| 1452 | + Op::ConsumeOrExpelWindowLeft { id: None }, | |
| 1453 | + Op::ConsumeOrExpelWindowRight { id: None }, | |
| 1454 | + Op::MoveWorkspaceToOutput(1), | |
| 1455 | + ]; | |
| 1456 | + | |
| 1457 | + for third in every_op { | |
| 1458 | + for second in every_op { | |
| 1459 | + for first in every_op { | |
| 1460 | + // eprintln!("{first:?}, {second:?}, {third:?}"); | |
| 1461 | + | |
| 1462 | + let mut layout = Layout::default(); | |
| 1463 | + first.apply(&mut layout); | |
| 1464 | + layout.verify_invariants(); | |
| 1465 | + second.apply(&mut layout); | |
| 1466 | + layout.verify_invariants(); | |
| 1467 | + third.apply(&mut layout); | |
| 1468 | + layout.verify_invariants(); | |
| 1469 | + } | |
| 1470 | + } | |
| 1471 | + } | |
| 1472 | +} | |
| 1473 | + | |
| 1474 | +#[test] | |
| 1475 | +fn operations_from_starting_state_dont_panic() { | |
| 1476 | + if std::env::var_os("RUN_SLOW_TESTS").is_none() { | |
| 1477 | + eprintln!("ignoring slow test"); | |
| 1478 | + return; | |
| 1479 | + } | |
| 1480 | + | |
| 1481 | + // Running every op from an empty state doesn't get us to all the interesting states. So, | |
| 1482 | + // also run it from a manually-created starting state with more things going on to exercise | |
| 1483 | + // more code paths. | |
| 1484 | + let setup_ops = [ | |
| 1485 | + Op::AddOutput(1), | |
| 1486 | + Op::AddWindow { | |
| 1487 | + params: TestWindowParams::new(1), | |
| 1488 | + }, | |
| 1489 | + Op::MoveWindowToWorkspaceDown, | |
| 1490 | + Op::AddWindow { | |
| 1491 | + params: TestWindowParams::new(2), | |
| 1492 | + }, | |
| 1493 | + Op::AddWindow { | |
| 1494 | + params: TestWindowParams::new(3), | |
| 1495 | + }, | |
| 1496 | + Op::FocusColumnLeft, | |
| 1497 | + Op::ConsumeWindowIntoColumn, | |
| 1498 | + Op::AddWindow { | |
| 1499 | + params: TestWindowParams::new(4), | |
| 1500 | + }, | |
| 1501 | + Op::AddOutput(2), | |
| 1502 | + Op::AddWindow { | |
| 1503 | + params: TestWindowParams::new(5), | |
| 1504 | + }, | |
| 1505 | + Op::MoveWindowToOutput { | |
| 1506 | + window_id: None, | |
| 1507 | + output_id: 2, | |
| 1508 | + target_ws_idx: None, | |
| 1509 | + }, | |
| 1510 | + Op::FocusOutput(1), | |
| 1511 | + Op::Communicate(1), | |
| 1512 | + Op::Communicate(2), | |
| 1513 | + Op::Communicate(3), | |
| 1514 | + Op::Communicate(4), | |
| 1515 | + Op::Communicate(5), | |
| 1516 | + ]; | |
| 1517 | + | |
| 1518 | + let every_op = [ | |
| 1519 | + Op::AddOutput(0), | |
| 1520 | + Op::AddOutput(1), | |
| 1521 | + Op::AddOutput(2), | |
| 1522 | + Op::RemoveOutput(0), | |
| 1523 | + Op::RemoveOutput(1), | |
| 1524 | + Op::RemoveOutput(2), | |
| 1525 | + Op::FocusOutput(0), | |
| 1526 | + Op::FocusOutput(1), | |
| 1527 | + Op::FocusOutput(2), | |
| 1528 | + Op::AddNamedWorkspace { | |
| 1529 | + ws_name: 1, | |
| 1530 | + output_name: Some(1), | |
| 1531 | + }, | |
| 1532 | + Op::UnnameWorkspace { ws_name: 1 }, | |
| 1533 | + Op::AddWindow { | |
| 1534 | + params: TestWindowParams::new(0), | |
| 1535 | + }, | |
| 1536 | + Op::AddWindow { | |
| 1537 | + params: TestWindowParams::new(1), | |
| 1538 | + }, | |
| 1539 | + Op::AddWindow { | |
| 1540 | + params: TestWindowParams::new(2), | |
| 1541 | + }, | |
| 1542 | + Op::AddWindowNextTo { | |
| 1543 | + params: TestWindowParams::new(6), | |
| 1544 | + next_to_id: 0, | |
| 1545 | + }, | |
| 1546 | + Op::AddWindowNextTo { | |
| 1547 | + params: TestWindowParams::new(7), | |
| 1548 | + next_to_id: 1, | |
| 1549 | + }, | |
| 1550 | + Op::AddWindowToNamedWorkspace { | |
| 1551 | + params: TestWindowParams::new(5), | |
| 1552 | + ws_name: 1, | |
| 1553 | + }, | |
| 1554 | + Op::CloseWindow(0), | |
| 1555 | + Op::CloseWindow(1), | |
| 1556 | + Op::CloseWindow(2), | |
| 1557 | + Op::FullscreenWindow(1), | |
| 1558 | + Op::FullscreenWindow(2), | |
| 1559 | + Op::FullscreenWindow(3), | |
| 1560 | + Op::SetFullscreenWindow { | |
| 1561 | + window: 1, | |
| 1562 | + is_fullscreen: false, | |
| 1563 | + }, | |
| 1564 | + Op::SetFullscreenWindow { | |
| 1565 | + window: 1, | |
| 1566 | + is_fullscreen: true, | |
| 1567 | + }, | |
| 1568 | + Op::SetFullscreenWindow { | |
| 1569 | + window: 2, | |
| 1570 | + is_fullscreen: false, | |
| 1571 | + }, | |
| 1572 | + Op::SetFullscreenWindow { | |
| 1573 | + window: 2, | |
| 1574 | + is_fullscreen: true, | |
| 1575 | + }, | |
| 1576 | + Op::FocusColumnLeft, | |
| 1577 | + Op::FocusColumnRight, | |
| 1578 | + Op::FocusColumnRightOrFirst, | |
| 1579 | + Op::FocusColumnLeftOrLast, | |
| 1580 | + Op::FocusWindowOrMonitorUp(0), | |
| 1581 | + Op::FocusWindowOrMonitorDown(1), | |
| 1582 | + Op::FocusColumnOrMonitorLeft(0), | |
| 1583 | + Op::FocusColumnOrMonitorRight(1), | |
| 1584 | + Op::FocusWindowUp, | |
| 1585 | + Op::FocusWindowUpOrColumnLeft, | |
| 1586 | + Op::FocusWindowUpOrColumnRight, | |
| 1587 | + Op::FocusWindowOrWorkspaceUp, | |
| 1588 | + Op::FocusWindowDown, | |
| 1589 | + Op::FocusWindowDownOrColumnLeft, | |
| 1590 | + Op::FocusWindowDownOrColumnRight, | |
| 1591 | + Op::FocusWindowOrWorkspaceDown, | |
| 1592 | + Op::MoveColumnLeft, | |
| 1593 | + Op::MoveColumnRight, | |
| 1594 | + Op::MoveColumnLeftOrToMonitorLeft(0), | |
| 1595 | + Op::MoveColumnRightOrToMonitorRight(1), | |
| 1596 | + Op::ConsumeWindowIntoColumn, | |
| 1597 | + Op::ExpelWindowFromColumn, | |
| 1598 | + Op::CenterColumn, | |
| 1599 | + Op::FocusWorkspaceDown, | |
| 1600 | + Op::FocusWorkspaceUp, | |
| 1601 | + Op::FocusWorkspace(1), | |
| 1602 | + Op::FocusWorkspace(2), | |
| 1603 | + Op::FocusWorkspace(3), | |
| 1604 | + Op::MoveWindowToWorkspaceDown, | |
| 1605 | + Op::MoveWindowToWorkspaceUp, | |
| 1606 | + Op::MoveWindowToWorkspace { | |
| 1607 | + window_id: None, | |
| 1608 | + workspace_idx: 1, | |
| 1609 | + }, | |
| 1610 | + Op::MoveWindowToWorkspace { | |
| 1611 | + window_id: None, | |
| 1612 | + workspace_idx: 2, | |
| 1613 | + }, | |
| 1614 | + Op::MoveWindowToWorkspace { | |
| 1615 | + window_id: None, | |
| 1616 | + workspace_idx: 3, | |
| 1617 | + }, | |
| 1618 | + Op::MoveColumnToWorkspaceDown, | |
| 1619 | + Op::MoveColumnToWorkspaceUp, | |
| 1620 | + Op::MoveColumnToWorkspace(1), | |
| 1621 | + Op::MoveColumnToWorkspace(2), | |
| 1622 | + Op::MoveColumnToWorkspace(3), | |
| 1623 | + Op::MoveWindowDown, | |
| 1624 | + Op::MoveWindowDownOrToWorkspaceDown, | |
| 1625 | + Op::MoveWindowUp, | |
| 1626 | + Op::MoveWindowUpOrToWorkspaceUp, | |
| 1627 | + Op::ConsumeOrExpelWindowLeft { id: None }, | |
| 1628 | + Op::ConsumeOrExpelWindowRight { id: None }, | |
| 1629 | + ]; | |
| 1630 | + | |
| 1631 | + for third in every_op { | |
| 1632 | + for second in every_op { | |
| 1633 | + for first in every_op { | |
| 1634 | + // eprintln!("{first:?}, {second:?}, {third:?}"); | |
| 1635 | + | |
| 1636 | + let mut layout = Layout::default(); | |
| 1637 | + for op in setup_ops { | |
| 1638 | + op.apply(&mut layout); | |
| 1639 | + } | |
| 1640 | + | |
| 1641 | + first.apply(&mut layout); | |
| 1642 | + layout.verify_invariants(); | |
| 1643 | + second.apply(&mut layout); | |
| 1644 | + layout.verify_invariants(); | |
| 1645 | + third.apply(&mut layout); | |
| 1646 | + layout.verify_invariants(); | |
| 1647 | + } | |
| 1648 | + } | |
| 1649 | + } | |
| 1650 | +} | |
| 1651 | + | |
| 1652 | +#[test] | |
| 1653 | +fn primary_active_workspace_idx_not_updated_on_output_add() { | |
| 1654 | + let ops = [ | |
| 1655 | + Op::AddOutput(1), | |
| 1656 | + Op::AddOutput(2), | |
| 1657 | + Op::FocusOutput(1), | |
| 1658 | + Op::AddWindow { | |
| 1659 | + params: TestWindowParams::new(0), | |
| 1660 | + }, | |
| 1661 | + Op::FocusOutput(2), | |
| 1662 | + Op::AddWindow { | |
| 1663 | + params: TestWindowParams::new(1), | |
| 1664 | + }, | |
| 1665 | + Op::RemoveOutput(2), | |
| 1666 | + Op::FocusWorkspace(3), | |
| 1667 | + Op::AddOutput(2), | |
| 1668 | + ]; | |
| 1669 | + | |
| 1670 | + check_ops(&ops); | |
| 1671 | +} | |
| 1672 | + | |
| 1673 | +#[test] | |
| 1674 | +fn window_closed_on_previous_workspace() { | |
| 1675 | + let ops = [ | |
| 1676 | + Op::AddOutput(1), | |
| 1677 | + Op::AddWindow { | |
| 1678 | + params: TestWindowParams::new(0), | |
| 1679 | + }, | |
| 1680 | + Op::FocusWorkspaceDown, | |
| 1681 | + Op::CloseWindow(0), | |
| 1682 | + ]; | |
| 1683 | + | |
| 1684 | + check_ops(&ops); | |
| 1685 | +} | |
| 1686 | + | |
| 1687 | +#[test] | |
| 1688 | +fn removing_output_must_keep_empty_focus_on_primary() { | |
| 1689 | + let ops = [ | |
| 1690 | + Op::AddOutput(1), | |
| 1691 | + Op::AddWindow { | |
| 1692 | + params: TestWindowParams::new(0), | |
| 1693 | + }, | |
| 1694 | + Op::AddOutput(2), | |
| 1695 | + Op::RemoveOutput(1), | |
| 1696 | + ]; | |
| 1697 | + | |
| 1698 | + let layout = check_ops(&ops); | |
| 1699 | + | |
| 1700 | + let MonitorSet::Normal { monitors, .. } = layout.monitor_set else { | |
| 1701 | + unreachable!() | |
| 1702 | + }; | |
| 1703 | + | |
| 1704 | + // The workspace from the removed output was inserted at position 0, so the active workspace | |
| 1705 | + // must change to 1 to keep the focus on the empty workspace. | |
| 1706 | + assert_eq!(monitors[0].active_workspace_idx, 1); | |
| 1707 | +} | |
| 1708 | + | |
| 1709 | +#[test] | |
| 1710 | +fn move_to_workspace_by_idx_does_not_leave_empty_workspaces() { | |
| 1711 | + let ops = [ | |
| 1712 | + Op::AddOutput(1), | |
| 1713 | + Op::AddWindow { | |
| 1714 | + params: TestWindowParams::new(0), | |
| 1715 | + }, | |
| 1716 | + Op::AddOutput(2), | |
| 1717 | + Op::FocusOutput(2), | |
| 1718 | + Op::AddWindow { | |
| 1719 | + params: TestWindowParams::new(1), | |
| 1720 | + }, | |
| 1721 | + Op::RemoveOutput(1), | |
| 1722 | + Op::MoveWindowToWorkspace { | |
| 1723 | + window_id: Some(0), | |
| 1724 | + workspace_idx: 2, | |
| 1725 | + }, | |
| 1726 | + ]; | |
| 1727 | + | |
| 1728 | + let layout = check_ops(&ops); | |
| 1729 | + | |
| 1730 | + let MonitorSet::Normal { monitors, .. } = layout.monitor_set else { | |
| 1731 | + unreachable!() | |
| 1732 | + }; | |
| 1733 | + | |
| 1734 | + assert!(monitors[0].workspaces[1].has_windows()); | |
| 1735 | +} | |
| 1736 | + | |
| 1737 | +#[test] | |
| 1738 | +fn empty_workspaces_dont_move_back_to_original_output() { | |
| 1739 | + let ops = [ | |
| 1740 | + Op::AddOutput(1), | |
| 1741 | + Op::AddWindow { | |
| 1742 | + params: TestWindowParams::new(1), | |
| 1743 | + }, | |
| 1744 | + Op::FocusWorkspaceDown, | |
| 1745 | + Op::AddWindow { | |
| 1746 | + params: TestWindowParams::new(2), | |
| 1747 | + }, | |
| 1748 | + Op::AddOutput(2), | |
| 1749 | + Op::RemoveOutput(1), | |
| 1750 | + Op::FocusWorkspace(1), | |
| 1751 | + Op::CloseWindow(1), | |
| 1752 | + Op::AddOutput(1), | |
| 1753 | + ]; | |
| 1754 | + | |
| 1755 | + check_ops(&ops); | |
| 1756 | +} | |
| 1757 | + | |
| 1758 | +#[test] | |
| 1759 | +fn named_workspaces_dont_update_original_output_on_adding_window() { | |
| 1760 | + let ops = [ | |
| 1761 | + Op::AddOutput(1), | |
| 1762 | + Op::SetWorkspaceName { | |
| 1763 | + new_ws_name: 1, | |
| 1764 | + ws_name: None, | |
| 1765 | + }, | |
| 1766 | + Op::AddOutput(2), | |
| 1767 | + Op::RemoveOutput(1), | |
| 1768 | + Op::FocusWorkspaceUp, | |
| 1769 | + // Adding a window updates the original output for unnamed workspaces. | |
| 1770 | + Op::AddWindow { | |
| 1771 | + params: TestWindowParams::new(1), | |
| 1772 | + }, | |
| 1773 | + // Connecting the previous output should move the named workspace back since its | |
| 1774 | + // original output wasn't updated. | |
| 1775 | + Op::AddOutput(1), | |
| 1776 | + ]; | |
| 1777 | + | |
| 1778 | + let layout = check_ops(&ops); | |
| 1779 | + let (mon, _, ws) = layout | |
| 1780 | + .workspaces() | |
| 1781 | + .find(|(_, _, ws)| ws.name().is_some()) | |
| 1782 | + .unwrap(); | |
| 1783 | + assert!(ws.name().is_some()); // Sanity check. | |
| 1784 | + let mon = mon.unwrap(); | |
| 1785 | + assert_eq!(mon.output_name(), "output1"); | |
| 1786 | +} | |
| 1787 | + | |
| 1788 | +#[test] | |
| 1789 | +fn workspaces_update_original_output_on_moving_to_same_output() { | |
| 1790 | + let ops = [ | |
| 1791 | + Op::AddOutput(1), | |
| 1792 | + Op::SetWorkspaceName { | |
| 1793 | + new_ws_name: 1, | |
| 1794 | + ws_name: None, | |
| 1795 | + }, | |
| 1796 | + Op::AddOutput(2), | |
| 1797 | + Op::RemoveOutput(1), | |
| 1798 | + Op::FocusWorkspaceUp, | |
| 1799 | + Op::MoveWorkspaceToOutput(2), | |
| 1800 | + Op::AddOutput(1), | |
| 1801 | + ]; | |
| 1802 | + | |
| 1803 | + let layout = check_ops(&ops); | |
| 1804 | + let (mon, _, ws) = layout | |
| 1805 | + .workspaces() | |
| 1806 | + .find(|(_, _, ws)| ws.name().is_some()) | |
| 1807 | + .unwrap(); | |
| 1808 | + assert!(ws.name().is_some()); // Sanity check. | |
| 1809 | + let mon = mon.unwrap(); | |
| 1810 | + assert_eq!(mon.output_name(), "output2"); | |
| 1811 | +} | |
| 1812 | + | |
| 1813 | +#[test] | |
| 1814 | +fn workspaces_update_original_output_on_moving_to_same_monitor() { | |
| 1815 | + let ops = [ | |
| 1816 | + Op::AddOutput(1), | |
| 1817 | + Op::SetWorkspaceName { | |
| 1818 | + new_ws_name: 1, | |
| 1819 | + ws_name: None, | |
| 1820 | + }, | |
| 1821 | + Op::AddOutput(2), | |
| 1822 | + Op::RemoveOutput(1), | |
| 1823 | + Op::FocusWorkspaceUp, | |
| 1824 | + Op::MoveWorkspaceToMonitor { | |
| 1825 | + ws_name: Some(1), | |
| 1826 | + output_id: 2, | |
| 1827 | + }, | |
| 1828 | + Op::AddOutput(1), | |
| 1829 | + ]; | |
| 1830 | + | |
| 1831 | + let layout = check_ops(&ops); | |
| 1832 | + let (mon, _, ws) = layout | |
| 1833 | + .workspaces() | |
| 1834 | + .find(|(_, _, ws)| ws.name().is_some()) | |
| 1835 | + .unwrap(); | |
| 1836 | + assert!(ws.name().is_some()); // Sanity check. | |
| 1837 | + let mon = mon.unwrap(); | |
| 1838 | + assert_eq!(mon.output_name(), "output2"); | |
| 1839 | +} | |
| 1840 | + | |
| 1841 | +#[test] | |
| 1842 | +fn large_negative_height_change() { | |
| 1843 | + let ops = [ | |
| 1844 | + Op::AddOutput(1), | |
| 1845 | + Op::AddWindow { | |
| 1846 | + params: TestWindowParams::new(1), | |
| 1847 | + }, | |
| 1848 | + Op::SetWindowHeight { | |
| 1849 | + id: None, | |
| 1850 | + change: SizeChange::AdjustProportion(-1e129), | |
| 1851 | + }, | |
| 1852 | + ]; | |
| 1853 | + | |
| 1854 | + let mut options = Options::default(); | |
| 1855 | + options.border.off = false; | |
| 1856 | + options.border.width = FloatOrInt(1.); | |
| 1857 | + | |
| 1858 | + check_ops_with_options(options, &ops); | |
| 1859 | +} | |
| 1860 | + | |
| 1861 | +#[test] | |
| 1862 | +fn large_max_size() { | |
| 1863 | + let ops = [ | |
| 1864 | + Op::AddOutput(1), | |
| 1865 | + Op::AddWindow { | |
| 1866 | + params: TestWindowParams { | |
| 1867 | + min_max_size: (Size::from((0, 0)), Size::from((i32::MAX, i32::MAX))), | |
| 1868 | + ..TestWindowParams::new(1) | |
| 1869 | + }, | |
| 1870 | + }, | |
| 1871 | + ]; | |
| 1872 | + | |
| 1873 | + let mut options = Options::default(); | |
| 1874 | + options.border.off = false; | |
| 1875 | + options.border.width = FloatOrInt(1.); | |
| 1876 | + | |
| 1877 | + check_ops_with_options(options, &ops); | |
| 1878 | +} | |
| 1879 | + | |
| 1880 | +#[test] | |
| 1881 | +fn workspace_cleanup_during_switch() { | |
| 1882 | + let ops = [ | |
| 1883 | + Op::AddOutput(1), | |
| 1884 | + Op::AddWindow { | |
| 1885 | + params: TestWindowParams::new(1), | |
| 1886 | + }, | |
| 1887 | + Op::FocusWorkspaceDown, | |
| 1888 | + Op::CloseWindow(1), | |
| 1889 | + ]; | |
| 1890 | + | |
| 1891 | + check_ops(&ops); | |
| 1892 | +} | |
| 1893 | + | |
| 1894 | +#[test] | |
| 1895 | +fn workspace_transfer_during_switch() { | |
| 1896 | + let ops = [ | |
| 1897 | + Op::AddOutput(1), | |
| 1898 | + Op::AddWindow { | |
| 1899 | + params: TestWindowParams::new(1), | |
| 1900 | + }, | |
| 1901 | + Op::AddOutput(2), | |
| 1902 | + Op::FocusOutput(2), | |
| 1903 | + Op::AddWindow { | |
| 1904 | + params: TestWindowParams::new(2), | |
| 1905 | + }, | |
| 1906 | + Op::RemoveOutput(1), | |
| 1907 | + Op::FocusWorkspaceDown, | |
| 1908 | + Op::FocusWorkspaceDown, | |
| 1909 | + Op::AddOutput(1), | |
| 1910 | + ]; | |
| 1911 | + | |
| 1912 | + check_ops(&ops); | |
| 1913 | +} | |
| 1914 | + | |
| 1915 | +#[test] | |
| 1916 | +fn workspace_transfer_during_switch_from_last() { | |
| 1917 | + let ops = [ | |
| 1918 | + Op::AddOutput(1), | |
| 1919 | + Op::AddWindow { | |
| 1920 | + params: TestWindowParams::new(1), | |
| 1921 | + }, | |
| 1922 | + Op::AddOutput(2), | |
| 1923 | + Op::RemoveOutput(1), | |
| 1924 | + Op::FocusWorkspaceUp, | |
| 1925 | + Op::AddOutput(1), | |
| 1926 | + ]; | |
| 1927 | + | |
| 1928 | + check_ops(&ops); | |
| 1929 | +} | |
| 1930 | + | |
| 1931 | +#[test] | |
| 1932 | +fn workspace_transfer_during_switch_gets_cleaned_up() { | |
| 1933 | + let ops = [ | |
| 1934 | + Op::AddOutput(1), | |
| 1935 | + Op::AddWindow { | |
| 1936 | + params: TestWindowParams::new(1), | |
| 1937 | + }, | |
| 1938 | + Op::RemoveOutput(1), | |
| 1939 | + Op::AddOutput(2), | |
| 1940 | + Op::MoveColumnToWorkspaceDown, | |
| 1941 | + Op::MoveColumnToWorkspaceDown, | |
| 1942 | + Op::AddOutput(1), | |
| 1943 | + ]; | |
| 1944 | + | |
| 1945 | + check_ops(&ops); | |
| 1946 | +} | |
| 1947 | + | |
| 1948 | +#[test] | |
| 1949 | +fn move_workspace_to_output() { | |
| 1950 | + let ops = [ | |
| 1951 | + Op::AddOutput(1), | |
| 1952 | + Op::AddOutput(2), | |
| 1953 | + Op::FocusOutput(1), | |
| 1954 | + Op::AddWindow { | |
| 1955 | + params: TestWindowParams::new(0), | |
| 1956 | + }, | |
| 1957 | + Op::MoveWorkspaceToOutput(2), | |
| 1958 | + ]; | |
| 1959 | + | |
| 1960 | + let layout = check_ops(&ops); | |
| 1961 | + | |
| 1962 | + let MonitorSet::Normal { | |
| 1963 | + monitors, | |
| 1964 | + active_monitor_idx, | |
| 1965 | + .. | |
| 1966 | + } = layout.monitor_set | |
| 1967 | + else { | |
| 1968 | + unreachable!() | |
| 1969 | + }; | |
| 1970 | + | |
| 1971 | + assert_eq!(active_monitor_idx, 1); | |
| 1972 | + assert_eq!(monitors[0].workspaces.len(), 1); | |
| 1973 | + assert!(!monitors[0].workspaces[0].has_windows()); | |
| 1974 | + assert_eq!(monitors[1].active_workspace_idx, 0); | |
| 1975 | + assert_eq!(monitors[1].workspaces.len(), 2); | |
| 1976 | + assert!(monitors[1].workspaces[0].has_windows()); | |
| 1977 | +} | |
| 1978 | + | |
| 1979 | +#[test] | |
| 1980 | +fn fullscreen() { | |
| 1981 | + let ops = [ | |
| 1982 | + Op::AddOutput(1), | |
| 1983 | + Op::AddWindow { | |
| 1984 | + params: TestWindowParams::new(1), | |
| 1985 | + }, | |
| 1986 | + Op::FullscreenWindow(1), | |
| 1987 | + ]; | |
| 1988 | + | |
| 1989 | + check_ops(&ops); | |
| 1990 | +} | |
| 1991 | + | |
| 1992 | +#[test] | |
| 1993 | +fn unfullscreen_window_in_column() { | |
| 1994 | + let ops = [ | |
| 1995 | + Op::AddOutput(1), | |
| 1996 | + Op::AddWindow { | |
| 1997 | + params: TestWindowParams::new(1), | |
| 1998 | + }, | |
| 1999 | + Op::AddWindow { | |
| 2000 | + params: TestWindowParams::new(2), |