niri
Clone
https://git.tahinli.com/Tahinli/niri.git
0 watching·0 forks·Rust·GPL-3.0·12.1 MiB·b0eb8ad·Ivan Molodetskikh·3 months ago·2857 commits
| 1 | use client::ClientId; |
| 2 | use insta::assert_snapshot; |
| 3 | use niri_config::Config; |
| 4 | use niri_ipc::SizeChange; |
| 5 | use smithay::utils::Point; |
| 6 | use wayland_client::protocol::wl_surface::WlSurface; |
| 7 | |
| 8 | use super::*; |
| 9 | |
| 10 | // Sets up a fixture with two outputs and 100×100 window. |
| 11 | fn set_up() -> (Fixture, ClientId, WlSurface) { |
| 12 | set_up_with_config(Config::default()) |
| 13 | } |
| 14 | |
| 15 | fn set_up_with_config(config: Config) -> (Fixture, ClientId, WlSurface) { |
| 16 | let mut f = Fixture::with_config(config); |
| 17 | f.add_output(1, (1920, 1080)); |
| 18 | f.add_output(2, (1280, 720)); |
| 19 | |
| 20 | let id = f.add_client(); |
| 21 | let window = f.client(id).create_window(); |
| 22 | let surface = window.surface.clone(); |
| 23 | window.commit(); |
| 24 | f.roundtrip(id); |
| 25 | |
| 26 | let window = f.client(id).window(&surface); |
| 27 | window.attach_new_buffer(); |
| 28 | window.set_size(100, 100); |
| 29 | window.ack_last_and_commit(); |
| 30 | f.double_roundtrip(id); |
| 31 | |
| 32 | (f, id, surface) |
| 33 | } |
| 34 | |
| 35 | #[test] |
| 36 | fn unfocus_preserves_current_size() { |
| 37 | let (mut f, id, surface) = set_up(); |
| 38 | |
| 39 | f.niri().layout.toggle_window_floating(None); |
| 40 | f.roundtrip(id); |
| 41 | |
| 42 | // Change window size while it's floating. |
| 43 | let window = f.client(id).window(&surface); |
| 44 | window.set_size(200, 200); |
| 45 | window.ack_last_and_commit(); |
| 46 | f.double_roundtrip(id); |
| 47 | |
| 48 | let _ = f.client(id).window(&surface).recent_configures(); |
| 49 | |
| 50 | // Focus a different output which should drop the Activated state. |
| 51 | f.niri_focus_output(2); |
| 52 | |
| 53 | f.double_roundtrip(id); |
| 54 | |
| 55 | // This should request 200 × 200 because that's the current window size. |
| 56 | let window = f.client(id).window(&surface); |
| 57 | assert_snapshot!( |
| 58 | window.format_recent_configures(), |
| 59 | @"size: 200 × 200, bounds: 1920 × 1080, states: []" |
| 60 | ); |
| 61 | |
| 62 | // Change window size again. |
| 63 | let window = f.client(id).window(&surface); |
| 64 | window.set_size(300, 300); |
| 65 | window.ack_last_and_commit(); |
| 66 | f.roundtrip(id); |
| 67 | |
| 68 | // Focus the first output which should add back the Activated state. |
| 69 | f.niri_focus_output(1); |
| 70 | |
| 71 | f.double_roundtrip(id); |
| 72 | |
| 73 | // This should request 300 × 300 because that's the current window size. |
| 74 | let window = f.client(id).window(&surface); |
| 75 | assert_snapshot!( |
| 76 | window.format_recent_configures(), |
| 77 | @"size: 300 × 300, bounds: 1920 × 1080, states: [Activated]" |
| 78 | ); |
| 79 | } |
| 80 | |
| 81 | #[test] |
| 82 | fn resize_to_different_size() { |
| 83 | let (mut f, id, surface) = set_up(); |
| 84 | let _ = f.client(id).window(&surface).recent_configures(); |
| 85 | |
| 86 | // Commit in response to the Activated state change configure. |
| 87 | f.client(id).window(&surface).ack_last_and_commit(); |
| 88 | f.double_roundtrip(id); |
| 89 | |
| 90 | f.niri().layout.toggle_window_floating(None); |
| 91 | f.niri().layout.set_column_width(SizeChange::SetFixed(500)); |
| 92 | f.double_roundtrip(id); |
| 93 | |
| 94 | // This should request the new size, 500 × 100. |
| 95 | assert_snapshot!( |
| 96 | f.client(id).window(&surface).format_recent_configures(), |
| 97 | @"size: 500 × 100, bounds: 1920 × 1080, states: [Activated]" |
| 98 | ); |
| 99 | |
| 100 | // Focus a different output which should drop the Activated state. |
| 101 | f.niri_focus_output(2); |
| 102 | f.double_roundtrip(id); |
| 103 | // This should request the new size since the window hasn't committed yet. |
| 104 | assert_snapshot!( |
| 105 | f.client(id).window(&surface).format_recent_configures(), |
| 106 | @"size: 500 × 100, bounds: 1920 × 1080, states: []" |
| 107 | ); |
| 108 | |
| 109 | // Ack but don't commit yet. |
| 110 | let window = f.client(id).window(&surface); |
| 111 | window.ack_last(); |
| 112 | f.roundtrip(id); |
| 113 | // Add the activated state. |
| 114 | f.niri_focus_output(1); |
| 115 | f.double_roundtrip(id); |
| 116 | // This should request the new size since the window hasn't committed yet. |
| 117 | assert_snapshot!( |
| 118 | f.client(id).window(&surface).format_recent_configures(), |
| 119 | @"size: 500 × 100, bounds: 1920 × 1080, states: [Activated]" |
| 120 | ); |
| 121 | |
| 122 | // Commit but with some different size. |
| 123 | let window = f.client(id).window(&surface); |
| 124 | window.set_size(200, 200); |
| 125 | window.commit(); |
| 126 | f.double_roundtrip(id); |
| 127 | // This shouldn't request anything. |
| 128 | assert_snapshot!( |
| 129 | f.client(id).window(&surface).format_recent_configures(), |
| 130 | @"" |
| 131 | ); |
| 132 | |
| 133 | // Drop the Activated state. |
| 134 | f.niri_focus_output(2); |
| 135 | f.double_roundtrip(id); |
| 136 | // This should request the current window size rather than keep requesting 500 × 100. |
| 137 | assert_snapshot!( |
| 138 | f.client(id).window(&surface).format_recent_configures(), |
| 139 | @"size: 200 × 200, bounds: 1920 × 1080, states: []" |
| 140 | ); |
| 141 | } |
| 142 | |
| 143 | #[test] |
| 144 | fn set_window_width_uses_current_height() { |
| 145 | let (mut f, id, surface) = set_up(); |
| 146 | |
| 147 | f.niri().layout.toggle_window_floating(None); |
| 148 | f.double_roundtrip(id); |
| 149 | let _ = f.client(id).window(&surface).recent_configures(); |
| 150 | |
| 151 | // Resize to something different on both axes. |
| 152 | let window = f.client(id).window(&surface); |
| 153 | window.set_size(200, 200); |
| 154 | window.ack_last_and_commit(); |
| 155 | f.roundtrip(id); |
| 156 | |
| 157 | // Request a width change. |
| 158 | f.niri().layout.set_column_width(SizeChange::SetFixed(500)); |
| 159 | |
| 160 | f.double_roundtrip(id); |
| 161 | |
| 162 | // This should use the current window height (200), rather than the initial window height (100). |
| 163 | assert_snapshot!( |
| 164 | f.client(id).window(&surface).format_recent_configures(), |
| 165 | @"size: 500 × 200, bounds: 1920 × 1080, states: [Activated]" |
| 166 | ); |
| 167 | } |
| 168 | |
| 169 | #[test] |
| 170 | fn set_window_height_uses_current_width() { |
| 171 | let (mut f, id, surface) = set_up(); |
| 172 | |
| 173 | f.niri().layout.toggle_window_floating(None); |
| 174 | f.double_roundtrip(id); |
| 175 | let _ = f.client(id).window(&surface).recent_configures(); |
| 176 | |
| 177 | // Resize to something different on both axes. |
| 178 | let window = f.client(id).window(&surface); |
| 179 | window.set_size(200, 200); |
| 180 | window.ack_last_and_commit(); |
| 181 | f.roundtrip(id); |
| 182 | |
| 183 | // Request a width change. |
| 184 | f.niri() |
| 185 | .layout |
| 186 | .set_window_height(None, SizeChange::SetFixed(500)); |
| 187 | |
| 188 | f.double_roundtrip(id); |
| 189 | |
| 190 | // This should use the current window width (200), rather than the initial window width (100). |
| 191 | assert_snapshot!( |
| 192 | f.client(id).window(&surface).format_recent_configures(), |
| 193 | @"size: 200 × 500, bounds: 1920 × 1080, states: [Activated]" |
| 194 | ); |
| 195 | } |
| 196 | |
| 197 | #[test] |
| 198 | fn resize_to_same_size() { |
| 199 | let (mut f, id, surface) = set_up(); |
| 200 | |
| 201 | f.niri().layout.toggle_window_floating(None); |
| 202 | f.double_roundtrip(id); |
| 203 | let _ = f.client(id).window(&surface).recent_configures(); |
| 204 | |
| 205 | // Resize to something different. |
| 206 | let window = f.client(id).window(&surface); |
| 207 | window.set_size(200, 200); |
| 208 | window.ack_last_and_commit(); |
| 209 | f.roundtrip(id); |
| 210 | |
| 211 | // Request a size change to the same size. |
| 212 | f.niri().layout.set_column_width(SizeChange::SetFixed(200)); |
| 213 | |
| 214 | f.double_roundtrip(id); |
| 215 | |
| 216 | // This needn't request anything because we're already that size; the size in the current |
| 217 | // server state matches the requested size. |
| 218 | // |
| 219 | // FIXME: However, currently it will request the size anyway because the code checks the |
| 220 | // current server state, and the last size niri requested of the window was 100×100 (even if |
| 221 | // the window already acked and committed in response). |
| 222 | assert_snapshot!( |
| 223 | f.client(id).window(&surface).format_recent_configures(), |
| 224 | @"size: 200 × 200, bounds: 1920 × 1080, states: [Activated]" |
| 225 | ); |
| 226 | } |
| 227 | |
| 228 | #[test] |
| 229 | fn resize_to_different_then_same() { |
| 230 | let (mut f, id, surface) = set_up(); |
| 231 | |
| 232 | f.niri().layout.toggle_window_floating(None); |
| 233 | f.double_roundtrip(id); |
| 234 | let _ = f.client(id).window(&surface).recent_configures(); |
| 235 | |
| 236 | // Commit in response to any configure from the floating change. |
| 237 | let window = f.client(id).window(&surface); |
| 238 | window.ack_last_and_commit(); |
| 239 | f.roundtrip(id); |
| 240 | |
| 241 | // Request a size change to a different size. |
| 242 | f.niri().layout.set_column_width(SizeChange::SetFixed(500)); |
| 243 | |
| 244 | f.double_roundtrip(id); |
| 245 | |
| 246 | // This should request the new size. |
| 247 | assert_snapshot!( |
| 248 | f.client(id).window(&surface).format_recent_configures(), |
| 249 | @"size: 500 × 100, bounds: 1920 × 1080, states: [Activated]" |
| 250 | ); |
| 251 | |
| 252 | // Before the window has a chance to respond, request a size change to the same, new size. |
| 253 | f.niri().layout.set_column_width(SizeChange::SetFixed(500)); |
| 254 | |
| 255 | // And also drop the Activated state to have some pending change. |
| 256 | f.niri_focus_output(2); |
| 257 | |
| 258 | f.double_roundtrip(id); |
| 259 | |
| 260 | // This should keep requesting the new size (500 × 100) since the window has not responded to |
| 261 | // it yet. |
| 262 | assert_snapshot!( |
| 263 | f.client(id).window(&surface).format_recent_configures(), |
| 264 | @"size: 500 × 100, bounds: 1920 × 1080, states: []" |
| 265 | ); |
| 266 | |
| 267 | // Commit in response to the size change request. |
| 268 | let window = f.client(id).window(&surface); |
| 269 | window.set_size(300, 300); |
| 270 | window.ack_last_and_commit(); |
| 271 | f.roundtrip(id); |
| 272 | |
| 273 | // And also add the Activated state to have some pending change. |
| 274 | f.niri_focus_output(1); |
| 275 | |
| 276 | f.double_roundtrip(id); |
| 277 | |
| 278 | // This should request the current window size (300 × 300) since the window has committed in |
| 279 | // response to the size change. |
| 280 | assert_snapshot!( |
| 281 | f.client(id).window(&surface).format_recent_configures(), |
| 282 | @"size: 300 × 300, bounds: 1920 × 1080, states: [Activated]" |
| 283 | ); |
| 284 | } |
| 285 | |
| 286 | #[test] |
| 287 | fn restore_floating_size() { |
| 288 | let (mut f, id, surface) = set_up(); |
| 289 | |
| 290 | f.niri().layout.toggle_window_floating(None); |
| 291 | f.double_roundtrip(id); |
| 292 | |
| 293 | // Change size while we're floating and commit in response to the floating configure. |
| 294 | let window = f.client(id).window(&surface); |
| 295 | window.set_size(200, 200); |
| 296 | window.ack_last_and_commit(); |
| 297 | f.double_roundtrip(id); |
| 298 | |
| 299 | let _ = f.client(id).window(&surface).recent_configures(); |
| 300 | |
| 301 | // Change back to tiling. |
| 302 | f.niri().layout.toggle_window_floating(None); |
| 303 | f.double_roundtrip(id); |
| 304 | |
| 305 | // We should get a tiling size configure. |
| 306 | assert_snapshot!( |
| 307 | f.client(id).window(&surface).format_recent_configures(), |
| 308 | @"size: 200 × 1048, bounds: 1888 × 1048, states: [Activated]" |
| 309 | ); |
| 310 | |
| 311 | // Resize as requested. |
| 312 | let window = f.client(id).window(&surface); |
| 313 | let (_, configure) = window.configures_received.last().unwrap(); |
| 314 | window.set_size(configure.size.0 as u16, configure.size.1 as u16); |
| 315 | window.ack_last_and_commit(); |
| 316 | f.roundtrip(id); |
| 317 | |
| 318 | // Change back to floating. |
| 319 | f.niri().layout.toggle_window_floating(None); |
| 320 | f.double_roundtrip(id); |
| 321 | |
| 322 | // We should get a configure restoring out previous 200 × 200 size. |
| 323 | assert_snapshot!( |
| 324 | f.client(id).window(&surface).format_recent_configures(), |
| 325 | @"size: 200 × 200, bounds: 1920 × 1080, states: [Activated]" |
| 326 | ); |
| 327 | } |
| 328 | |
| 329 | #[test] |
| 330 | fn moving_across_workspaces_doesnt_cancel_resize() { |
| 331 | let (mut f, id, surface) = set_up(); |
| 332 | |
| 333 | f.niri().layout.toggle_window_floating(None); |
| 334 | f.double_roundtrip(id); |
| 335 | |
| 336 | // Change size while we're floating and commit in response to the floating configure. |
| 337 | let window = f.client(id).window(&surface); |
| 338 | window.set_size(200, 200); |
| 339 | window.ack_last_and_commit(); |
| 340 | f.double_roundtrip(id); |
| 341 | |
| 342 | let _ = f.client(id).window(&surface).recent_configures(); |
| 343 | |
| 344 | // Request a size change to a different size. |
| 345 | f.niri().layout.set_column_width(SizeChange::SetFixed(500)); |
| 346 | f.double_roundtrip(id); |
| 347 | |
| 348 | // This should request the new size. |
| 349 | assert_snapshot!( |
| 350 | f.client(id).window(&surface).format_recent_configures(), |
| 351 | @"size: 500 × 200, bounds: 1920 × 1080, states: [Activated]" |
| 352 | ); |
| 353 | |
| 354 | // Move to a different workspace before the window has a chance to respond. This will remove it |
| 355 | // from one floating layout and add into a different one, potentially causing a size request. |
| 356 | f.niri().layout.move_to_workspace_down(true); |
| 357 | // Drop the Activated state to force a configure. |
| 358 | f.niri_focus_output(2); |
| 359 | f.double_roundtrip(id); |
| 360 | |
| 361 | // This should request the new size again (500 × 200) since the window hasn't responded to it. |
| 362 | assert_snapshot!( |
| 363 | f.client(id).window(&surface).format_recent_configures(), |
| 364 | @"size: 500 × 200, bounds: 1920 × 1080, states: []" |
| 365 | ); |
| 366 | |
| 367 | // Respond to the resize with a different size. |
| 368 | let window = f.client(id).window(&surface); |
| 369 | window.set_size(300, 300); |
| 370 | window.ack_last_and_commit(); |
| 371 | f.roundtrip(id); |
| 372 | |
| 373 | // Focus, adding Activated, and move to workspace down, causing removing and adding to a |
| 374 | // floating layout. |
| 375 | f.niri_focus_output(1); |
| 376 | f.niri().layout.move_to_workspace_down(true); |
| 377 | f.double_roundtrip(id); |
| 378 | |
| 379 | // This should request the current size (300 × 300) since the window responded to the change. |
| 380 | assert_snapshot!( |
| 381 | f.client(id).window(&surface).format_recent_configures(), |
| 382 | @"size: 300 × 300, bounds: 1920 × 1080, states: [Activated]" |
| 383 | ); |
| 384 | } |
| 385 | |
| 386 | #[test] |
| 387 | fn moving_to_floating_doesnt_cancel_resize() { |
| 388 | let (mut f, id, surface) = set_up(); |
| 389 | let _ = f.client(id).window(&surface).recent_configures(); |
| 390 | |
| 391 | // Request a size change to a different size. |
| 392 | f.niri().layout.set_column_width(SizeChange::SetFixed(500)); |
| 393 | f.double_roundtrip(id); |
| 394 | |
| 395 | // This should request the new size (500 ×). |
| 396 | assert_snapshot!( |
| 397 | f.client(id).window(&surface).format_recent_configures(), |
| 398 | @"size: 500 × 1048, bounds: 1888 × 1048, states: [Activated]" |
| 399 | ); |
| 400 | |
| 401 | // Before the window has a chance to respond, make it floating. |
| 402 | f.niri().layout.toggle_window_floating(None); |
| 403 | f.double_roundtrip(id); |
| 404 | |
| 405 | // This should keep requesting the new size (500 ×). |
| 406 | assert_snapshot!( |
| 407 | f.client(id).window(&surface).format_recent_configures(), |
| 408 | @"size: 500 × 1048, bounds: 1920 × 1080, states: [Activated]" |
| 409 | ); |
| 410 | } |
| 411 | |
| 412 | #[test] |
| 413 | fn interactive_move_unfullscreen_to_floating_restores_size() { |
| 414 | let (mut f, id, surface) = set_up(); |
| 415 | |
| 416 | f.niri().layout.toggle_window_floating(None); |
| 417 | f.double_roundtrip(id); |
| 418 | |
| 419 | // Change size while we're floating and commit. |
| 420 | let window = f.client(id).window(&surface); |
| 421 | window.set_size(200, 200); |
| 422 | window.ack_last_and_commit(); |
| 423 | f.double_roundtrip(id); |
| 424 | |
| 425 | let _ = f.client(id).window(&surface).recent_configures(); |
| 426 | |
| 427 | let niri = f.niri(); |
| 428 | let mapped = niri.layout.windows().next().unwrap().1; |
| 429 | let window = mapped.window.clone(); |
| 430 | niri.layout.set_fullscreen(&window, true); |
| 431 | f.double_roundtrip(id); |
| 432 | |
| 433 | // This should request a fullscreen size. |
| 434 | assert_snapshot!( |
| 435 | f.client(id).window(&surface).format_recent_configures(), |
| 436 | @"size: 1920 × 1080, bounds: 1888 × 1048, states: [Activated, Fullscreen]" |
| 437 | ); |
| 438 | |
| 439 | // Start an interactive move which causes an unfullscreen into floating. |
| 440 | let output = f.niri_output(1); |
| 441 | let niri = f.niri(); |
| 442 | let mapped = niri.layout.windows().next().unwrap().1; |
| 443 | let window = mapped.window.clone(); |
| 444 | niri.layout |
| 445 | .interactive_move_begin(window.clone(), &output, Point::default()); |
| 446 | niri.layout.interactive_move_update( |
| 447 | &window, |
| 448 | Point::from((1000., 0.)), |
| 449 | output, |
| 450 | Point::default(), |
| 451 | ); |
| 452 | f.double_roundtrip(id); |
| 453 | |
| 454 | // This should request the stored floating size (200 × 200). |
| 455 | assert_snapshot!( |
| 456 | f.client(id).window(&surface).format_recent_configures(), |
| 457 | @"size: 200 × 200, bounds: 1920 × 1080, states: [Activated]" |
| 458 | ); |
| 459 | } |
| 460 | |
| 461 | #[test] |
| 462 | fn interactive_move_unmaximize_to_floating_restores_size() { |
| 463 | let (mut f, id, surface) = set_up(); |
| 464 | |
| 465 | f.niri().layout.toggle_window_floating(None); |
| 466 | f.double_roundtrip(id); |
| 467 | |
| 468 | // Change size while we're floating and commit. |
| 469 | let window = f.client(id).window(&surface); |
| 470 | window.set_size(200, 200); |
| 471 | window.ack_last_and_commit(); |
| 472 | f.double_roundtrip(id); |
| 473 | |
| 474 | let _ = f.client(id).window(&surface).recent_configures(); |
| 475 | |
| 476 | let niri = f.niri(); |
| 477 | let mapped = niri.layout.windows().next().unwrap().1; |
| 478 | let window = mapped.window.clone(); |
| 479 | niri.layout.set_maximized(&window, true); |
| 480 | f.double_roundtrip(id); |
| 481 | |
| 482 | // This should request a maximized size. |
| 483 | assert_snapshot!( |
| 484 | f.client(id).window(&surface).format_recent_configures(), |
| 485 | @"size: 1920 × 1080, bounds: 1888 × 1048, states: [Activated, Maximized]" |
| 486 | ); |
| 487 | |
| 488 | // Start an interactive move which causes an unmaximize into floating. |
| 489 | let output = f.niri_output(1); |
| 490 | let niri = f.niri(); |
| 491 | let mapped = niri.layout.windows().next().unwrap().1; |
| 492 | let window = mapped.window.clone(); |
| 493 | niri.layout |
| 494 | .interactive_move_begin(window.clone(), &output, Point::default()); |
| 495 | niri.layout.interactive_move_update( |
| 496 | &window, |
| 497 | Point::from((1000., 0.)), |
| 498 | output, |
| 499 | Point::default(), |
| 500 | ); |
| 501 | f.double_roundtrip(id); |
| 502 | |
| 503 | // This should request the stored floating size (200 × 200). |
| 504 | assert_snapshot!( |
| 505 | f.client(id).window(&surface).format_recent_configures(), |
| 506 | @"size: 200 × 200, bounds: 1920 × 1080, states: [Activated]" |
| 507 | ); |
| 508 | } |
| 509 | |
| 510 | #[test] |
| 511 | fn resize_during_interactive_move_propagates_to_floating() { |
| 512 | let (mut f, id, surface) = set_up(); |
| 513 | |
| 514 | f.niri().layout.toggle_window_floating(None); |
| 515 | f.double_roundtrip(id); |
| 516 | |
| 517 | // Change size while we're floating and commit. |
| 518 | let window = f.client(id).window(&surface); |
| 519 | window.set_size(200, 200); |
| 520 | window.ack_last_and_commit(); |
| 521 | f.double_roundtrip(id); |
| 522 | |
| 523 | let _ = f.client(id).window(&surface).recent_configures(); |
| 524 | |
| 525 | // Start an interactive move. |
| 526 | let output = f.niri_output(1); |
| 527 | let niri = f.niri(); |
| 528 | let mapped = niri.layout.windows().next().unwrap().1; |
| 529 | let window_id = mapped.window.clone(); |
| 530 | niri.layout |
| 531 | .interactive_move_begin(window_id.clone(), &output, Point::default()); |
| 532 | niri.layout.interactive_move_update( |
| 533 | &window_id, |
| 534 | Point::from((1000., 0.)), |
| 535 | output, |
| 536 | Point::default(), |
| 537 | ); |
| 538 | f.double_roundtrip(id); |
| 539 | |
| 540 | // This shouldn't request any new size. |
| 541 | assert_snapshot!( |
| 542 | f.client(id).window(&surface).format_recent_configures(), |
| 543 | @"" |
| 544 | ); |
| 545 | |
| 546 | // Change size while we're being interactively moved. |
| 547 | let window = f.client(id).window(&surface); |
| 548 | window.set_size(300, 300); |
| 549 | window.commit(); |
| 550 | f.double_roundtrip(id); |
| 551 | |
| 552 | // This shouldn't request any new size. |
| 553 | assert_snapshot!( |
| 554 | f.client(id).window(&surface).format_recent_configures(), |
| 555 | @"" |
| 556 | ); |
| 557 | |
| 558 | // End the interactive move, placing the window into floating. |
| 559 | f.niri().layout.interactive_move_end(&window_id); |
| 560 | f.double_roundtrip(id); |
| 561 | |
| 562 | // This should keep the new 300 × 300 size. |
| 563 | assert_snapshot!( |
| 564 | f.client(id).window(&surface).format_recent_configures(), |
| 565 | @"size: 300 × 300, bounds: 1920 × 1080, states: [Activated]" |
| 566 | ); |
| 567 | } |
| 568 | |
| 569 | #[test] |
| 570 | fn resize_in_steps() { |
| 571 | let (mut f, id, surface) = set_up(); |
| 572 | |
| 573 | f.niri().layout.toggle_window_floating(None); |
| 574 | f.double_roundtrip(id); |
| 575 | let _ = f.client(id).window(&surface).recent_configures(); |
| 576 | |
| 577 | // Commit in response to the floating bounds state change configure. |
| 578 | f.client(id).window(&surface).ack_last_and_commit(); |
| 579 | f.double_roundtrip(id); |
| 580 | |
| 581 | // Request a size change to a different size in two steps. |
| 582 | f.niri().layout.set_column_width(SizeChange::SetFixed(500)); |
| 583 | f.niri() |
| 584 | .layout |
| 585 | .set_window_height(None, SizeChange::SetFixed(500)); |
| 586 | f.double_roundtrip(id); |
| 587 | |
| 588 | // This should request the full new size (500 × 500) once. |
| 589 | assert_snapshot!( |
| 590 | f.client(id).window(&surface).format_recent_configures(), |
| 591 | @"size: 500 × 500, bounds: 1920 × 1080, states: [Activated]" |
| 592 | ); |
| 593 | |
| 594 | let window = f.client(id).window(&surface); |
| 595 | let serial = window.configures_received.last().unwrap().0; |
| 596 | |
| 597 | // Request a size change now that the previous one is pending-but-not-acked. |
| 598 | f.niri().layout.set_column_width(SizeChange::SetFixed(600)); |
| 599 | // Drop Activated to work around resize throttling. |
| 600 | f.niri_focus_output(2); |
| 601 | f.double_roundtrip(id); |
| 602 | |
| 603 | // This should request the new size (600 × 500) once. |
| 604 | assert_snapshot!( |
| 605 | f.client(id).window(&surface).format_recent_configures(), |
| 606 | @"size: 600 × 500, bounds: 1920 × 1080, states: []" |
| 607 | ); |
| 608 | |
| 609 | // Commit in response to the previous configure. |
| 610 | let window = f.client(id).window(&surface); |
| 611 | window.xdg_surface.ack_configure(serial); |
| 612 | window.set_size(500, 500); |
| 613 | window.commit(); |
| 614 | |
| 615 | f.double_roundtrip(id); |
| 616 | |
| 617 | // This shouldn't request anything. |
| 618 | assert_snapshot!( |
| 619 | f.client(id).window(&surface).format_recent_configures(), |
| 620 | @"" |
| 621 | ); |
| 622 | |
| 623 | // Request a height change now that the first one is committed-to, but the second isn't. |
| 624 | let niri = f.niri(); |
| 625 | let mapped = niri.layout.windows().next().unwrap().1; |
| 626 | let window = mapped.window.clone(); |
| 627 | f.niri() |
| 628 | .layout |
| 629 | .set_window_height(Some(&window), SizeChange::SetFixed(600)); |
| 630 | // Add Activated to work around resize throttling. |
| 631 | f.niri_focus_output(1); |
| 632 | f.double_roundtrip(id); |
| 633 | |
| 634 | // This should request the latest sizes (600 × 600). |
| 635 | assert_snapshot!( |
| 636 | f.client(id).window(&surface).format_recent_configures(), |
| 637 | @"size: 600 × 600, bounds: 1920 × 1080, states: [Activated]" |
| 638 | ); |
| 639 | } |
| 640 | |
| 641 | #[test] |
| 642 | fn state_change_doesnt_break_use_window_size() { |
| 643 | let (mut f, id, surface) = set_up(); |
| 644 | |
| 645 | f.niri().layout.toggle_window_floating(None); |
| 646 | f.double_roundtrip(id); |
| 647 | let _ = f.client(id).window(&surface).recent_configures(); |
| 648 | |
| 649 | // Commit in response to the bounds change that comes with toggling floating. |
| 650 | f.client(id).window(&surface).ack_last_and_commit(); |
| 651 | f.roundtrip(id); |
| 652 | |
| 653 | // Request a size change to a different size. |
| 654 | f.niri().layout.set_column_width(SizeChange::SetFixed(500)); |
| 655 | f.double_roundtrip(id); |
| 656 | |
| 657 | // This should request the new size (500 × 100). |
| 658 | assert_snapshot!( |
| 659 | f.client(id).window(&surface).format_recent_configures(), |
| 660 | @"size: 500 × 100, bounds: 1920 × 1080, states: [Activated]" |
| 661 | ); |
| 662 | |
| 663 | let window = f.client(id).window(&surface); |
| 664 | let serial = window.configures_received.last().unwrap().0; |
| 665 | |
| 666 | // Request a state change by dropping Activated. |
| 667 | f.niri_focus_output(2); |
| 668 | f.double_roundtrip(id); |
| 669 | |
| 670 | // This should request the new size (500 × 100). |
| 671 | assert_snapshot!( |
| 672 | f.client(id).window(&surface).format_recent_configures(), |
| 673 | @"size: 500 × 100, bounds: 1920 × 1080, states: []" |
| 674 | ); |
| 675 | |
| 676 | // Commit in response to the previous configure with a different size. |
| 677 | let window = f.client(id).window(&surface); |
| 678 | window.xdg_surface.ack_configure(serial); |
| 679 | window.set_size(300, 300); |
| 680 | window.commit(); |
| 681 | |
| 682 | f.double_roundtrip(id); |
| 683 | |
| 684 | // This shouldn't request anything. |
| 685 | assert_snapshot!( |
| 686 | f.client(id).window(&surface).format_recent_configures(), |
| 687 | @"" |
| 688 | ); |
| 689 | |
| 690 | // Request a height change now that the first one is committed-to, but the second isn't. |
| 691 | let niri = f.niri(); |
| 692 | let mapped = niri.layout.windows().next().unwrap().1; |
| 693 | let window = mapped.window.clone(); |
| 694 | f.niri() |
| 695 | .layout |
| 696 | .set_window_height(Some(&window), SizeChange::SetFixed(600)); |
| 697 | // Add Activated state to force a configure. |
| 698 | f.niri_focus_output(1); |
| 699 | f.double_roundtrip(id); |
| 700 | |
| 701 | // This should already request the current width (300 × 600) rather than the pending previous |
| 702 | // width (500 × 600) from the state change configure. |
| 703 | assert_snapshot!( |
| 704 | f.client(id).window(&surface).format_recent_configures(), |
| 705 | @"size: 300 × 600, bounds: 1920 × 1080, states: [Activated]" |
| 706 | ); |
| 707 | } |
| 708 | |
| 709 | #[test] |
| 710 | fn interactive_move_restores_floating_size_when_set_to_floating() { |
| 711 | let (mut f, id, surface) = set_up(); |
| 712 | |
| 713 | f.niri().layout.toggle_window_floating(None); |
| 714 | f.double_roundtrip(id); |
| 715 | |
| 716 | // Change size while we're floating and commit to make niri remember it. |
| 717 | let window = f.client(id).window(&surface); |
| 718 | window.set_size(200, 200); |
| 719 | window.ack_last_and_commit(); |
| 720 | f.double_roundtrip(id); |
| 721 | |
| 722 | let _ = f.client(id).window(&surface).recent_configures(); |
| 723 | |
| 724 | // Change back to tiling. |
| 725 | f.niri().layout.toggle_window_floating(None); |
| 726 | f.double_roundtrip(id); |
| 727 | |
| 728 | // We should get a tiled size configure. |
| 729 | assert_snapshot!( |
| 730 | f.client(id).window(&surface).format_recent_configures(), |
| 731 | @"size: 200 × 1048, bounds: 1888 × 1048, states: [Activated]" |
| 732 | ); |
| 733 | |
| 734 | // Resize as requested. |
| 735 | let window = f.client(id).window(&surface); |
| 736 | let (_, configure) = window.configures_received.last().unwrap(); |
| 737 | window.set_size(configure.size.0 as u16, configure.size.1 as u16); |
| 738 | window.ack_last_and_commit(); |
| 739 | f.roundtrip(id); |
| 740 | |
| 741 | // Start an interactive move. |
| 742 | let output = f.niri_output(1); |
| 743 | let niri = f.niri(); |
| 744 | let mapped = niri.layout.windows().next().unwrap().1; |
| 745 | let window_id = mapped.window.clone(); |
| 746 | niri.layout |
| 747 | .interactive_move_begin(window_id.clone(), &output, Point::default()); |
| 748 | niri.layout.interactive_move_update( |
| 749 | &window_id, |
| 750 | Point::from((1000., 0.)), |
| 751 | output, |
| 752 | Point::default(), |
| 753 | ); |
| 754 | f.double_roundtrip(id); |
| 755 | |
| 756 | // This shouldn't request any new size because interactive move targets tiling. |
| 757 | assert_snapshot!( |
| 758 | f.client(id).window(&surface).format_recent_configures(), |
| 759 | @"size: 200 × 1048, bounds: 1920 × 1080, states: [Activated]" |
| 760 | ); |
| 761 | |
| 762 | // Change interactive move to target floating. |
| 763 | f.niri().layout.toggle_window_floating(None); |
| 764 | f.double_roundtrip(id); |
| 765 | |
| 766 | // This should restore the floating window size (200 × 200). |
| 767 | assert_snapshot!( |
| 768 | f.client(id).window(&surface).format_recent_configures(), |
| 769 | @"size: 200 × 200, bounds: 1920 × 1080, states: [Activated]" |
| 770 | ); |
| 771 | |
| 772 | // End the interactive move, placing the window into floating. |
| 773 | f.niri().layout.interactive_move_end(&window_id); |
| 774 | f.double_roundtrip(id); |
| 775 | |
| 776 | // This should keep the floating window size (200 × 200). |
| 777 | assert_snapshot!( |
| 778 | f.client(id).window(&surface).format_recent_configures(), |
| 779 | @"" |
| 780 | ); |
| 781 | } |
| 782 | |
| 783 | #[test] |
| 784 | fn floating_doesnt_store_fullscreen_size() { |
| 785 | let mut f = Fixture::new(); |
| 786 | f.add_output(1, (1920, 1080)); |
| 787 | f.add_output(2, (1280, 720)); |
| 788 | |
| 789 | // Open a window fullscreen. |
| 790 | let id = f.add_client(); |
| 791 | let window = f.client(id).create_window(); |
| 792 | let surface = window.surface.clone(); |
| 793 | window.set_fullscreen(None); |
| 794 | window.commit(); |
| 795 | f.roundtrip(id); |
| 796 | |
| 797 | let window = f.client(id).window(&surface); |
| 798 | window.attach_new_buffer(); |
| 799 | window.set_size(1920, 1080); |
| 800 | window.ack_last_and_commit(); |
| 801 | f.double_roundtrip(id); |
| 802 | |
| 803 | let _ = f.client(id).window(&surface).recent_configures(); |
| 804 | |
| 805 | // Make it floating. |
| 806 | f.niri().layout.toggle_window_floating(None); |
| 807 | f.double_roundtrip(id); |
| 808 | |
| 809 | // This should request 0 × 0 to unfullscreen. |
| 810 | assert_snapshot!( |
| 811 | f.client(id).window(&surface).format_recent_configures(), |
| 812 | @"size: 0 × 0, bounds: 1920 × 1080, states: [Activated]" |
| 813 | ); |
| 814 | |
| 815 | // Without committing, make it tiling again. We never committed while floating, so there's no |
| 816 | // floating size to remember. |
| 817 | f.niri().layout.toggle_window_floating(None); |
| 818 | f.double_roundtrip(id); |
| 819 | |
| 820 | // This should request the tiled size. |
| 821 | assert_snapshot!( |
| 822 | f.client(id).window(&surface).format_recent_configures(), |
| 823 | @"size: 1920 × 1048, bounds: 1888 × 1048, states: [Activated]" |
| 824 | ); |
| 825 | |
| 826 | // Commit in response. |
| 827 | let window = f.client(id).window(&surface); |
| 828 | window.set_size(100, 100); |
| 829 | window.ack_last_and_commit(); |
| 830 | f.roundtrip(id); |
| 831 | |
| 832 | // Make the window floating again. |
| 833 | f.niri().layout.toggle_window_floating(None); |
| 834 | f.double_roundtrip(id); |
| 835 | |
| 836 | // This shouldn't request any size change, particularly not the fullscreen size. |
| 837 | assert_snapshot!( |
| 838 | f.client(id).window(&surface).format_recent_configures(), |
| 839 | @"size: 100 × 100, bounds: 1920 × 1080, states: [Activated]" |
| 840 | ); |
| 841 | } |
| 842 | |
| 843 | #[test] |
| 844 | fn floating_doesnt_store_maximized_size() { |
| 845 | let mut f = Fixture::new(); |
| 846 | f.add_output(1, (1920, 1080)); |
| 847 | f.add_output(2, (1280, 720)); |
| 848 | |
| 849 | // Open a window maximized. |
| 850 | let id = f.add_client(); |
| 851 | let window = f.client(id).create_window(); |
| 852 | let surface = window.surface.clone(); |
| 853 | window.set_maximized(); |
| 854 | window.commit(); |
| 855 | f.roundtrip(id); |
| 856 | |
| 857 | let window = f.client(id).window(&surface); |
| 858 | window.attach_new_buffer(); |
| 859 | window.set_size(1920, 1080); |
| 860 | window.ack_last_and_commit(); |
| 861 | f.double_roundtrip(id); |
| 862 | |
| 863 | let _ = f.client(id).window(&surface).recent_configures(); |
| 864 | |
| 865 | // Make it floating. |
| 866 | f.niri().layout.toggle_window_floating(None); |
| 867 | f.double_roundtrip(id); |
| 868 | |
| 869 | // This should request 0 × 0 to unmaximize. |
| 870 | assert_snapshot!( |
| 871 | f.client(id).window(&surface).format_recent_configures(), |
| 872 | @"size: 0 × 0, bounds: 1920 × 1080, states: [Activated]" |
| 873 | ); |
| 874 | |
| 875 | // Without committing, make it tiling again. We never committed while floating, so there's no |
| 876 | // floating size to remember. |
| 877 | f.niri().layout.toggle_window_floating(None); |
| 878 | f.double_roundtrip(id); |
| 879 | |
| 880 | // This should request the tiled size. |
| 881 | assert_snapshot!( |
| 882 | f.client(id).window(&surface).format_recent_configures(), |
| 883 | @"size: 1920 × 1048, bounds: 1888 × 1048, states: [Activated]" |
| 884 | ); |
| 885 | |
| 886 | // Commit in response. |
| 887 | let window = f.client(id).window(&surface); |
| 888 | window.set_size(100, 100); |
| 889 | window.ack_last_and_commit(); |
| 890 | f.roundtrip(id); |
| 891 | |
| 892 | // Make the window floating again. |
| 893 | f.niri().layout.toggle_window_floating(None); |
| 894 | f.double_roundtrip(id); |
| 895 | |
| 896 | // This shouldn't request any size change, particularly not the maximized size. |
| 897 | assert_snapshot!( |
| 898 | f.client(id).window(&surface).format_recent_configures(), |
| 899 | @"size: 100 × 100, bounds: 1920 × 1080, states: [Activated]" |
| 900 | ); |
| 901 | } |
| 902 | |
| 903 | #[test] |
| 904 | fn floating_respects_non_fixed_min_max_rule() { |
| 905 | let config = r##" |
| 906 | window-rule { |
| 907 | min-width 200 |
| 908 | max-width 300 |
| 909 | } |
| 910 | "##; |
| 911 | let config = Config::parse_mem(config).unwrap(); |
| 912 | let (mut f, id, surface) = set_up_with_config(config); |
| 913 | |
| 914 | // Commit to the Activated state configure. |
| 915 | f.client(id).window(&surface).ack_last_and_commit(); |
| 916 | f.double_roundtrip(id); |
| 917 | |
| 918 | let _ = f.client(id).window(&surface).recent_configures(); |
| 919 | |
| 920 | // Make it floating. |
| 921 | f.niri().layout.toggle_window_floating(None); |
| 922 | f.double_roundtrip(id); |
| 923 | |
| 924 | // This should clamp to min-width and request 200 × 100. |
| 925 | assert_snapshot!( |
| 926 | f.client(id).window(&surface).format_recent_configures(), |
| 927 | @"size: 200 × 100, bounds: 1920 × 1080, states: [Activated]" |
| 928 | ); |
| 929 | |
| 930 | // Commit with a bigger width than max. |
| 931 | let window = f.client(id).window(&surface); |
| 932 | window.set_size(400, 100); |
| 933 | window.ack_last_and_commit(); |
| 934 | f.roundtrip(id); |
| 935 | |
| 936 | // Make it tiling. |
| 937 | f.niri().layout.toggle_window_floating(None); |
| 938 | f.double_roundtrip(id); |
| 939 | |
| 940 | let _ = f.client(id).window(&surface).recent_configures(); |
| 941 | |
| 942 | f.client(id).window(&surface).ack_last_and_commit(); |
| 943 | f.roundtrip(id); |
| 944 | |
| 945 | // Make it floating. |
| 946 | f.niri().layout.toggle_window_floating(None); |
| 947 | f.double_roundtrip(id); |
| 948 | |
| 949 | // This should clamp to max-width and request 300 × 100. |
| 950 | assert_snapshot!( |
| 951 | f.client(id).window(&surface).format_recent_configures(), |
| 952 | @"size: 300 × 100, bounds: 1920 × 1080, states: [Activated]" |
| 953 | ); |
| 954 | } |
| 955 | |
| 956 | #[test] |
| 957 | fn unmap_from_floating() { |
| 958 | let (mut f, id, surface) = set_up(); |
| 959 | |
| 960 | f.niri().layout.toggle_window_floating(None); |
| 961 | f.double_roundtrip(id); |
| 962 | let _ = f.client(id).window(&surface).recent_configures(); |
| 963 | |
| 964 | // Resize to something different on both axes. |
| 965 | let window = f.client(id).window(&surface); |
| 966 | window.attach_null(); |
| 967 | window.commit(); |
| 968 | |
| 969 | // Shouldn't panic. |
| 970 | f.double_roundtrip(id); |
| 971 | } |
| 972 | |
| 973 | #[test] |
| 974 | fn unfullscreen_to_floating_doesnt_send_extra_configure() { |
| 975 | let (mut f, id, surface) = set_up(); |
| 976 | |
| 977 | // Make it floating. |
| 978 | f.niri().layout.toggle_window_floating(None); |
| 979 | f.roundtrip(id); |
| 980 | |
| 981 | // Fullscreen. |
| 982 | let window = f.client(id).window(&surface); |
| 983 | window.set_fullscreen(None); |
| 984 | f.double_roundtrip(id); |
| 985 | |
| 986 | let _ = f.client(id).window(&surface).recent_configures(); |
| 987 | |
| 988 | // Unfullscreen via the window request which requires a configure response. |
| 989 | let window = f.client(id).window(&surface); |
| 990 | window.unset_fullscreen(); |
| 991 | f.double_roundtrip(id); |
| 992 | |
| 993 | // This should configure only once and not twice. |
| 994 | assert_snapshot!( |
| 995 | f.client(id).window(&surface).format_recent_configures(), |
| 996 | @"size: 936 × 1048, bounds: 1920 × 1080, states: [Activated]" |
| 997 | ); |
| 998 | } |
| 999 | |
| 1000 | #[test] |
| 1001 | fn unmaximize_to_floating_doesnt_send_extra_configure() { |
| 1002 | let (mut f, id, surface) = set_up(); |
| 1003 | |
| 1004 | // Make it floating. |
| 1005 | f.niri().layout.toggle_window_floating(None); |
| 1006 | f.roundtrip(id); |
| 1007 | |
| 1008 | // Maximize. |
| 1009 | let window = f.client(id).window(&surface); |
| 1010 | window.set_maximized(); |
| 1011 | f.double_roundtrip(id); |
| 1012 | |
| 1013 | let _ = f.client(id).window(&surface).recent_configures(); |
| 1014 | |
| 1015 | // Unmaximzie via the window request which requires a configure response. |
| 1016 | let window = f.client(id).window(&surface); |
| 1017 | window.unset_maximized(); |
| 1018 | f.double_roundtrip(id); |
| 1019 | |
| 1020 | // This should configure only once and not twice. |
| 1021 | assert_snapshot!( |
| 1022 | f.client(id).window(&surface).format_recent_configures(), |
| 1023 | @"size: 936 × 1048, bounds: 1920 × 1080, states: [Activated]" |
| 1024 | ); |
| 1025 | } |
| 1026 | |
| 1027 | #[test] |
| 1028 | fn unfullscreen_to_same_size_floating() { |
| 1029 | let (mut f, id, surface) = set_up(); |
| 1030 | |
| 1031 | // Make it floating. |
| 1032 | f.niri().layout.toggle_window_floating(None); |
| 1033 | f.double_roundtrip(id); |
| 1034 | |
| 1035 | // Change size to the same as fullscreen, make niri remember it. |
| 1036 | let window = f.client(id).window(&surface); |
| 1037 | window.set_size(1920, 1080); |
| 1038 | window.ack_last_and_commit(); |
| 1039 | f.double_roundtrip(id); |
| 1040 | |
| 1041 | let _ = f.client(id).window(&surface).recent_configures(); |
| 1042 | |
| 1043 | // Fullscreen. |
| 1044 | let window = f.client(id).window(&surface); |
| 1045 | window.set_fullscreen(None); |
| 1046 | f.double_roundtrip(id); |
| 1047 | |
| 1048 | // The fullscreen configure. |
| 1049 | assert_snapshot!( |
| 1050 | f.client(id).window(&surface).format_recent_configures(), |
| 1051 | @"size: 1920 × 1080, bounds: 1888 × 1048, states: [Activated, Fullscreen]" |
| 1052 | ); |
| 1053 | |
| 1054 | // Unfullscreen into floating. |
| 1055 | f.niri().layout.toggle_window_floating(None); |
| 1056 | f.double_roundtrip(id); |
| 1057 | |
| 1058 | // We should see a configure with the same size and no Fullscreen state. |
| 1059 | assert_snapshot!( |
| 1060 | f.client(id).window(&surface).format_recent_configures(), |
| 1061 | @"size: 1920 × 1080, bounds: 1920 × 1080, states: [Activated]" |
| 1062 | ); |
| 1063 | } |
| 1064 | |
| 1065 | #[test] |
| 1066 | fn unmaximize_to_same_size_floating() { |
| 1067 | let (mut f, id, surface) = set_up(); |
| 1068 | |
| 1069 | // Make it floating. |
| 1070 | f.niri().layout.toggle_window_floating(None); |
| 1071 | f.double_roundtrip(id); |
| 1072 | |
| 1073 | // Change size to the same as maximized, make niri remember it. |
| 1074 | let window = f.client(id).window(&surface); |
| 1075 | window.set_size(1920, 1080); |
| 1076 | window.ack_last_and_commit(); |
| 1077 | f.double_roundtrip(id); |
| 1078 | |
| 1079 | let _ = f.client(id).window(&surface).recent_configures(); |
| 1080 | |
| 1081 | // Maximize. |
| 1082 | let window = f.client(id).window(&surface); |
| 1083 | window.set_maximized(); |
| 1084 | f.double_roundtrip(id); |
| 1085 | |
| 1086 | // The maximize configure. |
| 1087 | assert_snapshot!( |
| 1088 | f.client(id).window(&surface).format_recent_configures(), |
| 1089 | @"size: 1920 × 1080, bounds: 1888 × 1048, states: [Activated, Maximized]" |
| 1090 | ); |
| 1091 | |
| 1092 | // Unmaximize into floating. |
| 1093 | f.niri().layout.toggle_window_floating(None); |
| 1094 | f.double_roundtrip(id); |
| 1095 | |
| 1096 | // We should see a configure with the same size and no maximized state. |
| 1097 | assert_snapshot!( |
| 1098 | f.client(id).window(&surface).format_recent_configures(), |
| 1099 | @"size: 1920 × 1080, bounds: 1920 × 1080, states: [Activated]" |
| 1100 | ); |
| 1101 | } |
| 1102 | |
| 1103 | #[test] |
| 1104 | fn unfullscreen_to_same_size_windowed_fullscreen_floating() { |
| 1105 | let (mut f, id, surface) = set_up(); |
| 1106 | |
| 1107 | let mapped = f.niri().layout.windows().next().unwrap().1; |
| 1108 | let window_id = mapped.window.clone(); |
| 1109 | |
| 1110 | // Make it floating. |
| 1111 | f.niri().layout.toggle_window_floating(None); |
| 1112 | f.double_roundtrip(id); |
| 1113 | |
| 1114 | // Change size to the same as fullscreen, make niri remember it. |
| 1115 | let window = f.client(id).window(&surface); |
| 1116 | window.set_size(1920, 1080); |
| 1117 | window.ack_last_and_commit(); |
| 1118 | f.double_roundtrip(id); |
| 1119 | |
| 1120 | let _ = f.client(id).window(&surface).recent_configures(); |
| 1121 | |
| 1122 | // Fullscreen. |
| 1123 | let window = f.client(id).window(&surface); |
| 1124 | window.set_fullscreen(None); |
| 1125 | f.double_roundtrip(id); |
| 1126 | |
| 1127 | // The fullscreen configure. |
| 1128 | assert_snapshot!( |
| 1129 | f.client(id).window(&surface).format_recent_configures(), |
| 1130 | @"size: 1920 × 1080, bounds: 1888 × 1048, states: [Activated, Fullscreen]" |
| 1131 | ); |
| 1132 | |
| 1133 | // Unfullscreen into windowed-fullscreen floating. |
| 1134 | f.niri().layout.toggle_windowed_fullscreen(&window_id); |
| 1135 | f.double_roundtrip(id); |
| 1136 | |
| 1137 | // Should send configure because the bounds have changed. |
| 1138 | assert_snapshot!( |
| 1139 | f.client(id).window(&surface).format_recent_configures(), |
| 1140 | @"size: 1920 × 1080, bounds: 1920 × 1080, states: [Activated, Fullscreen]" |
| 1141 | ); |
| 1142 | } |
| 1143 | |
| 1144 | #[test] |
| 1145 | fn unmaximize_to_same_size_windowed_fullscreen_floating() { |
| 1146 | let (mut f, id, surface) = set_up(); |
| 1147 | |
| 1148 | let mapped = f.niri().layout.windows().next().unwrap().1; |
| 1149 | let window_id = mapped.window.clone(); |
| 1150 | |
| 1151 | // Make it floating. |
| 1152 | f.niri().layout.toggle_window_floating(None); |
| 1153 | f.double_roundtrip(id); |
| 1154 | |
| 1155 | // Change size to the same as maximized, make niri remember it. |
| 1156 | let window = f.client(id).window(&surface); |
| 1157 | window.set_size(1920, 1080); |
| 1158 | window.ack_last_and_commit(); |
| 1159 | f.double_roundtrip(id); |
| 1160 | |
| 1161 | let _ = f.client(id).window(&surface).recent_configures(); |
| 1162 | |
| 1163 | // Maximize. |
| 1164 | let window = f.client(id).window(&surface); |
| 1165 | window.set_maximized(); |
| 1166 | f.double_roundtrip(id); |
| 1167 | |
| 1168 | // The maximize configure. |
| 1169 | assert_snapshot!( |
| 1170 | f.client(id).window(&surface).format_recent_configures(), |
| 1171 | @"size: 1920 × 1080, bounds: 1888 × 1048, states: [Activated, Maximized]" |
| 1172 | ); |
| 1173 | |
| 1174 | // Enable windowed-fullscreen. |
| 1175 | f.niri().layout.toggle_windowed_fullscreen(&window_id); |
| 1176 | f.double_roundtrip(id); |
| 1177 | |
| 1178 | // The windowed-fullscreen configure. |
| 1179 | assert_snapshot!( |
| 1180 | f.client(id).window(&surface).format_recent_configures(), |
| 1181 | @"size: 1920 × 1080, bounds: 1888 × 1048, states: [Activated, Fullscreen]" |
| 1182 | ); |
| 1183 | |
| 1184 | // Go back to windowed-fullscreen floating. |
| 1185 | f.niri().layout.toggle_window_floating(None); |
| 1186 | f.double_roundtrip(id); |
| 1187 | |
| 1188 | // Should send configure because the bounds have changed. |
| 1189 | assert_snapshot!( |
| 1190 | f.client(id).window(&surface).format_recent_configures(), |
| 1191 | @"size: 1920 × 1080, bounds: 1920 × 1080, states: [Activated, Fullscreen]" |
| 1192 | ); |
| 1193 | |
| 1194 | // Disable windowed-fullscreen. |
| 1195 | f.niri().layout.toggle_windowed_fullscreen(&window_id); |
| 1196 | f.double_roundtrip(id); |
| 1197 | |
| 1198 | // Should send configure dropping the Fullscreen state. |
| 1199 | assert_snapshot!( |
| 1200 | f.client(id).window(&surface).format_recent_configures(), |
| 1201 | @"size: 1920 × 1080, bounds: 1920 × 1080, states: [Activated]" |
| 1202 | ); |
| 1203 | } |
| 1204 | |
| 1205 | #[test] |
| 1206 | fn unfullscreen_to_same_size_same_bounds_floating() { |
| 1207 | let config = r##" |
| 1208 | layout { |
| 1209 | gaps 0 |
| 1210 | } |
| 1211 | "##; |
| 1212 | let config = Config::parse_mem(config).unwrap(); |
| 1213 | let (mut f, id, surface) = set_up_with_config(config); |
| 1214 | |
| 1215 | // Make it floating. |
| 1216 | f.niri().layout.toggle_window_floating(None); |
| 1217 | f.double_roundtrip(id); |
| 1218 | |
| 1219 | // Change size to the same as fullscreen, make niri remember it. |
| 1220 | let window = f.client(id).window(&surface); |
| 1221 | window.set_size(1920, 1080); |
| 1222 | window.ack_last_and_commit(); |
| 1223 | f.double_roundtrip(id); |
| 1224 | |
| 1225 | let _ = f.client(id).window(&surface).recent_configures(); |
| 1226 | |
| 1227 | // Fullscreen. |
| 1228 | let window = f.client(id).window(&surface); |
| 1229 | window.set_fullscreen(None); |
| 1230 | f.double_roundtrip(id); |
| 1231 | |
| 1232 | // The fullscreen configure. |
| 1233 | assert_snapshot!( |
| 1234 | f.client(id).window(&surface).format_recent_configures(), |
| 1235 | @"size: 1920 × 1080, bounds: 1920 × 1080, states: [Activated, Fullscreen]" |
| 1236 | ); |
| 1237 | |
| 1238 | // Unfullscreen into floating. |
| 1239 | f.niri().layout.toggle_window_floating(None); |
| 1240 | f.double_roundtrip(id); |
| 1241 | |
| 1242 | // We should see a configure with the same size and no Fullscreen state. |
| 1243 | assert_snapshot!( |
| 1244 | f.client(id).window(&surface).format_recent_configures(), |
| 1245 | @"size: 1920 × 1080, bounds: 1920 × 1080, states: [Activated]" |
| 1246 | ); |
| 1247 | } |
| 1248 | |
| 1249 | #[test] |
| 1250 | fn unmaximize_to_same_size_same_bounds_floating() { |
| 1251 | let config = r##" |
| 1252 | layout { |
| 1253 | gaps 0 |
| 1254 | } |
| 1255 | "##; |
| 1256 | let config = Config::parse_mem(config).unwrap(); |
| 1257 | let (mut f, id, surface) = set_up_with_config(config); |
| 1258 | |
| 1259 | // Make it floating. |
| 1260 | f.niri().layout.toggle_window_floating(None); |
| 1261 | f.double_roundtrip(id); |
| 1262 | |
| 1263 | // Change size to the same as fullscreen, make niri remember it. |
| 1264 | let window = f.client(id).window(&surface); |
| 1265 | window.set_size(1920, 1080); |
| 1266 | window.ack_last_and_commit(); |
| 1267 | f.double_roundtrip(id); |
| 1268 | |
| 1269 | let _ = f.client(id).window(&surface).recent_configures(); |
| 1270 | |
| 1271 | // Maximize. |
| 1272 | let window = f.client(id).window(&surface); |
| 1273 | window.set_maximized(); |
| 1274 | f.double_roundtrip(id); |
| 1275 | |
| 1276 | // The maximize configure. |
| 1277 | assert_snapshot!( |
| 1278 | f.client(id).window(&surface).format_recent_configures(), |
| 1279 | @"size: 1920 × 1080, bounds: 1920 × 1080, states: [Activated, Maximized]" |
| 1280 | ); |
| 1281 | |
| 1282 | // Unmaximize into floating. |
| 1283 | f.niri().layout.toggle_window_floating(None); |
| 1284 | f.double_roundtrip(id); |
| 1285 | |
| 1286 | // We should see a configure with the same size and no Maximized state. |
| 1287 | assert_snapshot!( |
| 1288 | f.client(id).window(&surface).format_recent_configures(), |
| 1289 | @"size: 1920 × 1080, bounds: 1920 × 1080, states: [Activated]" |
| 1290 | ); |
| 1291 | } |
| 1292 | |
| 1293 | #[test] |
| 1294 | fn repeated_size_request() { |
| 1295 | let (mut f, id, surface) = set_up(); |
| 1296 | let _ = f.client(id).window(&surface).recent_configures(); |
| 1297 | |
| 1298 | // Make it floating. |
| 1299 | f.niri().layout.toggle_window_floating(None); |
| 1300 | f.double_roundtrip(id); |
| 1301 | |
| 1302 | // The floating configure. |
| 1303 | assert_snapshot!( |
| 1304 | f.client(id).window(&surface).format_recent_configures(), |
| 1305 | @"size: 936 × 1048, bounds: 1920 × 1080, states: [Activated]" |
| 1306 | ); |
| 1307 | |
| 1308 | // Request a different width (200x100). |
| 1309 | f.niri() |
| 1310 | .layout |
| 1311 | .set_window_width(None, SizeChange::SetFixed(200)); |
| 1312 | f.niri() |
| 1313 | .layout |
| 1314 | .set_window_height(None, SizeChange::SetFixed(100)); |
| 1315 | f.double_roundtrip(id); |
| 1316 | |
| 1317 | // The 200x100 request. |
| 1318 | assert_snapshot!( |
| 1319 | f.client(id).window(&surface).format_recent_configures(), |
| 1320 | @"size: 200 × 100, bounds: 1920 × 1080, states: [Activated]" |
| 1321 | ); |
| 1322 | |
| 1323 | // Request a size change to the same size as we have just requested. |
| 1324 | f.niri().layout.set_column_width(SizeChange::SetFixed(200)); |
| 1325 | f.double_roundtrip(id); |
| 1326 | |
| 1327 | // Should request nothing as this is a repeated same-size request in floating and the surface |
| 1328 | // hasn't committed to it yet. |
| 1329 | assert_snapshot!( |
| 1330 | f.client(id).window(&surface).format_recent_configures(), |
| 1331 | @"" |
| 1332 | ); |
| 1333 | |
| 1334 | // Ack but don't commit yet. |
| 1335 | let window = f.client(id).window(&surface); |
| 1336 | window.ack_last(); |
| 1337 | f.double_roundtrip(id); |
| 1338 | |
| 1339 | // Request a size change to the same size as we have just requested. |
| 1340 | f.niri().layout.set_column_width(SizeChange::SetFixed(200)); |
| 1341 | f.double_roundtrip(id); |
| 1342 | |
| 1343 | // Should request nothing as this is a repeated same-size request in floating and the surface |
| 1344 | // hasn't committed to it yet. |
| 1345 | assert_snapshot!( |
| 1346 | f.client(id).window(&surface).format_recent_configures(), |
| 1347 | @"" |
| 1348 | ); |
| 1349 | |
| 1350 | // Commit. |
| 1351 | let window = f.client(id).window(&surface); |
| 1352 | window.commit(); |
| 1353 | f.double_roundtrip(id); |
| 1354 | |
| 1355 | // Request the size change again. |
| 1356 | f.niri().layout.set_column_width(SizeChange::SetFixed(200)); |
| 1357 | f.double_roundtrip(id); |
| 1358 | |
| 1359 | // This should send a new configure since the window had committed. |
| 1360 | // |
| 1361 | // FIXME: doesn't request that currently. |
| 1362 | assert_snapshot!( |
| 1363 | f.client(id).window(&surface).format_recent_configures(), |
| 1364 | @"" |
| 1365 | ); |
| 1366 | } |