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