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