niri
Clone
https://git.tahinli.com/Tahinli/niri.git
0 watching·0 forks·Rust·GPL-3.0·12.1 MiB·055a94d·Ivan Molodetskikh·1 year ago·2247 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 | let mut f = Fixture::new(); |
| 13 | f.add_output(1, (1920, 1080)); |
| 14 | f.add_output(2, (1280, 720)); |
| 15 | |
| 16 | let id = f.add_client(); |
| 17 | let window = f.client(id).create_window(); |
| 18 | let surface = window.surface.clone(); |
| 19 | window.commit(); |
| 20 | f.roundtrip(id); |
| 21 | |
| 22 | let window = f.client(id).window(&surface); |
| 23 | window.attach_new_buffer(); |
| 24 | window.set_size(100, 100); |
| 25 | window.ack_last_and_commit(); |
| 26 | f.double_roundtrip(id); |
| 27 | |
| 28 | (f, id, surface) |
| 29 | } |
| 30 | |
| 31 | #[test] |
| 32 | fn unfocus_preserves_current_size() { |
| 33 | let (mut f, id, surface) = set_up(); |
| 34 | |
| 35 | f.niri().layout.toggle_window_floating(None); |
| 36 | f.roundtrip(id); |
| 37 | |
| 38 | // Change window size while it's floating. |
| 39 | let window = f.client(id).window(&surface); |
| 40 | window.set_size(200, 200); |
| 41 | window.ack_last_and_commit(); |
| 42 | f.double_roundtrip(id); |
| 43 | |
| 44 | let _ = f.client(id).window(&surface).recent_configures(); |
| 45 | |
| 46 | // Focus a different output which should drop the Activated state. |
| 47 | f.niri_focus_output(2); |
| 48 | |
| 49 | f.double_roundtrip(id); |
| 50 | |
| 51 | // This should request 200 × 200 because that's the current window size. |
| 52 | let window = f.client(id).window(&surface); |
| 53 | assert_snapshot!( |
| 54 | window.format_recent_configures(), |
| 55 | @"size: 200 × 200, bounds: 1920 × 1080, states: []" |
| 56 | ); |
| 57 | |
| 58 | // Change window size again. |
| 59 | let window = f.client(id).window(&surface); |
| 60 | window.set_size(300, 300); |
| 61 | window.ack_last_and_commit(); |
| 62 | f.roundtrip(id); |
| 63 | |
| 64 | // Focus the first output which should add back the Activated state. |
| 65 | f.niri_focus_output(1); |
| 66 | |
| 67 | f.double_roundtrip(id); |
| 68 | |
| 69 | // This should request 300 × 300 because that's the current window size. |
| 70 | let window = f.client(id).window(&surface); |
| 71 | assert_snapshot!( |
| 72 | window.format_recent_configures(), |
| 73 | @"size: 300 × 300, bounds: 1920 × 1080, states: [Activated]" |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | #[test] |
| 78 | fn resize_to_different_size() { |
| 79 | let (mut f, id, surface) = set_up(); |
| 80 | let _ = f.client(id).window(&surface).recent_configures(); |
| 81 | |
| 82 | // Commit in response to the Activated state change configure. |
| 83 | f.client(id).window(&surface).ack_last_and_commit(); |
| 84 | f.double_roundtrip(id); |
| 85 | |
| 86 | f.niri().layout.toggle_window_floating(None); |
| 87 | f.niri().layout.set_column_width(SizeChange::SetFixed(500)); |
| 88 | f.double_roundtrip(id); |
| 89 | |
| 90 | // This should request the new size, 500 × 100. |
| 91 | assert_snapshot!( |
| 92 | f.client(id).window(&surface).format_recent_configures(), |
| 93 | @"size: 500 × 100, bounds: 1920 × 1080, states: [Activated]" |
| 94 | ); |
| 95 | |
| 96 | // Focus a different output which should drop the Activated state. |
| 97 | f.niri_focus_output(2); |
| 98 | f.double_roundtrip(id); |
| 99 | // This should request the new size since the window hasn't committed yet. |
| 100 | assert_snapshot!( |
| 101 | f.client(id).window(&surface).format_recent_configures(), |
| 102 | @"size: 500 × 100, bounds: 1920 × 1080, states: []" |
| 103 | ); |
| 104 | |
| 105 | // Ack but don't commit yet. |
| 106 | let window = f.client(id).window(&surface); |
| 107 | window.ack_last(); |
| 108 | f.roundtrip(id); |
| 109 | // Add the activated state. |
| 110 | f.niri_focus_output(1); |
| 111 | f.double_roundtrip(id); |
| 112 | // This should request the new size since the window hasn't committed yet. |
| 113 | assert_snapshot!( |
| 114 | f.client(id).window(&surface).format_recent_configures(), |
| 115 | @"size: 500 × 100, bounds: 1920 × 1080, states: [Activated]" |
| 116 | ); |
| 117 | |
| 118 | // Commit but with some different size. |
| 119 | let window = f.client(id).window(&surface); |
| 120 | window.set_size(200, 200); |
| 121 | window.commit(); |
| 122 | f.double_roundtrip(id); |
| 123 | // This shouldn't request anything. |
| 124 | assert_snapshot!( |
| 125 | f.client(id).window(&surface).format_recent_configures(), |
| 126 | @"" |
| 127 | ); |
| 128 | |
| 129 | // Drop the Activated state. |
| 130 | f.niri_focus_output(2); |
| 131 | f.double_roundtrip(id); |
| 132 | // This should request the current window size rather than keep requesting 500 × 100. |
| 133 | assert_snapshot!( |
| 134 | f.client(id).window(&surface).format_recent_configures(), |
| 135 | @"size: 200 × 200, bounds: 1920 × 1080, states: []" |
| 136 | ); |
| 137 | } |
| 138 | |
| 139 | #[test] |
| 140 | fn set_window_width_uses_current_height() { |
| 141 | let (mut f, id, surface) = set_up(); |
| 142 | |
| 143 | f.niri().layout.toggle_window_floating(None); |
| 144 | f.double_roundtrip(id); |
| 145 | let _ = f.client(id).window(&surface).recent_configures(); |
| 146 | |
| 147 | // Resize to something different on both axes. |
| 148 | let window = f.client(id).window(&surface); |
| 149 | window.set_size(200, 200); |
| 150 | window.ack_last_and_commit(); |
| 151 | f.roundtrip(id); |
| 152 | |
| 153 | // Request a width change. |
| 154 | f.niri().layout.set_column_width(SizeChange::SetFixed(500)); |
| 155 | |
| 156 | f.double_roundtrip(id); |
| 157 | |
| 158 | // This should use the current window height (200), rather than the initial window height (100). |
| 159 | assert_snapshot!( |
| 160 | f.client(id).window(&surface).format_recent_configures(), |
| 161 | @"size: 500 × 200, bounds: 1920 × 1080, states: [Activated]" |
| 162 | ); |
| 163 | } |
| 164 | |
| 165 | #[test] |
| 166 | fn set_window_height_uses_current_width() { |
| 167 | let (mut f, id, surface) = set_up(); |
| 168 | |
| 169 | f.niri().layout.toggle_window_floating(None); |
| 170 | f.double_roundtrip(id); |
| 171 | let _ = f.client(id).window(&surface).recent_configures(); |
| 172 | |
| 173 | // Resize to something different on both axes. |
| 174 | let window = f.client(id).window(&surface); |
| 175 | window.set_size(200, 200); |
| 176 | window.ack_last_and_commit(); |
| 177 | f.roundtrip(id); |
| 178 | |
| 179 | // Request a width change. |
| 180 | f.niri() |
| 181 | .layout |
| 182 | .set_window_height(None, SizeChange::SetFixed(500)); |
| 183 | |
| 184 | f.double_roundtrip(id); |
| 185 | |
| 186 | // This should use the current window width (200), rather than the initial window width (100). |
| 187 | assert_snapshot!( |
| 188 | f.client(id).window(&surface).format_recent_configures(), |
| 189 | @"size: 200 × 500, bounds: 1920 × 1080, states: [Activated]" |
| 190 | ); |
| 191 | } |
| 192 | |
| 193 | #[test] |
| 194 | fn resize_to_same_size() { |
| 195 | let (mut f, id, surface) = set_up(); |
| 196 | |
| 197 | f.niri().layout.toggle_window_floating(None); |
| 198 | f.double_roundtrip(id); |
| 199 | let _ = f.client(id).window(&surface).recent_configures(); |
| 200 | |
| 201 | // Resize to something different. |
| 202 | let window = f.client(id).window(&surface); |
| 203 | window.set_size(200, 200); |
| 204 | window.ack_last_and_commit(); |
| 205 | f.roundtrip(id); |
| 206 | |
| 207 | // Request a size change to the same size. |
| 208 | f.niri().layout.set_column_width(SizeChange::SetFixed(200)); |
| 209 | |
| 210 | f.double_roundtrip(id); |
| 211 | |
| 212 | // This needn't request anything because we're already that size; the size in the current |
| 213 | // server state matches the requested size. |
| 214 | // |
| 215 | // FIXME: However, currently it will request the size anyway because the code checks the |
| 216 | // current server state, and the last size niri requested of the window was 100×100 (even if |
| 217 | // the window already acked and committed in response). |
| 218 | assert_snapshot!( |
| 219 | f.client(id).window(&surface).format_recent_configures(), |
| 220 | @"size: 200 × 200, bounds: 1920 × 1080, states: [Activated]" |
| 221 | ); |
| 222 | } |
| 223 | |
| 224 | #[test] |
| 225 | fn resize_to_different_then_same() { |
| 226 | let (mut f, id, surface) = set_up(); |
| 227 | |
| 228 | f.niri().layout.toggle_window_floating(None); |
| 229 | f.double_roundtrip(id); |
| 230 | let _ = f.client(id).window(&surface).recent_configures(); |
| 231 | |
| 232 | // Commit in response to any configure from the floating change. |
| 233 | let window = f.client(id).window(&surface); |
| 234 | window.ack_last_and_commit(); |
| 235 | f.roundtrip(id); |
| 236 | |
| 237 | // Request a size change to a different size. |
| 238 | f.niri().layout.set_column_width(SizeChange::SetFixed(500)); |
| 239 | |
| 240 | f.double_roundtrip(id); |
| 241 | |
| 242 | // This should request the new size. |
| 243 | assert_snapshot!( |
| 244 | f.client(id).window(&surface).format_recent_configures(), |
| 245 | @"size: 500 × 100, bounds: 1920 × 1080, states: [Activated]" |
| 246 | ); |
| 247 | |
| 248 | // Before the window has a chance to respond, request a size change to the same, new size. |
| 249 | f.niri().layout.set_column_width(SizeChange::SetFixed(500)); |
| 250 | |
| 251 | // And also drop the Activated state to have some pending change. |
| 252 | f.niri_focus_output(2); |
| 253 | |
| 254 | f.double_roundtrip(id); |
| 255 | |
| 256 | // This should keep requesting the new size (500 × 100) since the window has not responded to |
| 257 | // it yet. |
| 258 | assert_snapshot!( |
| 259 | f.client(id).window(&surface).format_recent_configures(), |
| 260 | @"size: 500 × 100, bounds: 1920 × 1080, states: []" |
| 261 | ); |
| 262 | |
| 263 | // Commit in response to the size change request. |
| 264 | let window = f.client(id).window(&surface); |
| 265 | window.set_size(300, 300); |
| 266 | window.ack_last_and_commit(); |
| 267 | f.roundtrip(id); |
| 268 | |
| 269 | // And also add the Activated state to have some pending change. |
| 270 | f.niri_focus_output(1); |
| 271 | |
| 272 | f.double_roundtrip(id); |
| 273 | |
| 274 | // This should request the current window size (300 × 300) since the window has committed in |
| 275 | // response to the size change. |
| 276 | assert_snapshot!( |
| 277 | f.client(id).window(&surface).format_recent_configures(), |
| 278 | @"size: 300 × 300, bounds: 1920 × 1080, states: [Activated]" |
| 279 | ); |
| 280 | } |
| 281 | |
| 282 | #[test] |
| 283 | fn restore_floating_size() { |
| 284 | let (mut f, id, surface) = set_up(); |
| 285 | |
| 286 | f.niri().layout.toggle_window_floating(None); |
| 287 | f.double_roundtrip(id); |
| 288 | |
| 289 | // Change size while we're floating and commit in response to the floating configure. |
| 290 | let window = f.client(id).window(&surface); |
| 291 | window.set_size(200, 200); |
| 292 | window.ack_last_and_commit(); |
| 293 | f.double_roundtrip(id); |
| 294 | |
| 295 | let _ = f.client(id).window(&surface).recent_configures(); |
| 296 | |
| 297 | // Change back to tiling. |
| 298 | f.niri().layout.toggle_window_floating(None); |
| 299 | f.double_roundtrip(id); |
| 300 | |
| 301 | // We should get a tiling size configure. |
| 302 | assert_snapshot!( |
| 303 | f.client(id).window(&surface).format_recent_configures(), |
| 304 | @"size: 200 × 1048, bounds: 1888 × 1048, states: [Activated]" |
| 305 | ); |
| 306 | |
| 307 | // Resize as requested. |
| 308 | let window = f.client(id).window(&surface); |
| 309 | let (_, configure) = window.configures_received.last().unwrap(); |
| 310 | window.set_size(configure.size.0 as u16, configure.size.1 as u16); |
| 311 | window.ack_last_and_commit(); |
| 312 | f.roundtrip(id); |
| 313 | |
| 314 | // Change back to floating. |
| 315 | f.niri().layout.toggle_window_floating(None); |
| 316 | f.double_roundtrip(id); |
| 317 | |
| 318 | // We should get a configure restoring out previous 200 × 200 size. |
| 319 | assert_snapshot!( |
| 320 | f.client(id).window(&surface).format_recent_configures(), |
| 321 | @"size: 200 × 200, bounds: 1920 × 1080, states: [Activated]" |
| 322 | ); |
| 323 | } |
| 324 | |
| 325 | #[test] |
| 326 | fn moving_across_workspaces_doesnt_cancel_resize() { |
| 327 | let (mut f, id, surface) = set_up(); |
| 328 | |
| 329 | f.niri().layout.toggle_window_floating(None); |
| 330 | f.double_roundtrip(id); |
| 331 | |
| 332 | // Change size while we're floating and commit in response to the floating configure. |
| 333 | let window = f.client(id).window(&surface); |
| 334 | window.set_size(200, 200); |
| 335 | window.ack_last_and_commit(); |
| 336 | f.double_roundtrip(id); |
| 337 | |
| 338 | let _ = f.client(id).window(&surface).recent_configures(); |
| 339 | |
| 340 | // Request a size change to a different size. |
| 341 | f.niri().layout.set_column_width(SizeChange::SetFixed(500)); |
| 342 | f.double_roundtrip(id); |
| 343 | |
| 344 | // This should request the new size. |
| 345 | assert_snapshot!( |
| 346 | f.client(id).window(&surface).format_recent_configures(), |
| 347 | @"size: 500 × 200, bounds: 1920 × 1080, states: [Activated]" |
| 348 | ); |
| 349 | |
| 350 | // Move to a different workspace before the window has a chance to respond. This will remove it |
| 351 | // from one floating layout and add into a different one, potentially causing a size request. |
| 352 | f.niri().layout.move_to_workspace_down(); |
| 353 | // Drop the Activated state to force a configure. |
| 354 | f.niri_focus_output(2); |
| 355 | f.double_roundtrip(id); |
| 356 | |
| 357 | // This should request the new size again (500 × 200) since the window hasn't responded to it. |
| 358 | assert_snapshot!( |
| 359 | f.client(id).window(&surface).format_recent_configures(), |
| 360 | @"size: 500 × 200, bounds: 1920 × 1080, states: []" |
| 361 | ); |
| 362 | |
| 363 | // Respond to the resize with a different size. |
| 364 | let window = f.client(id).window(&surface); |
| 365 | window.set_size(300, 300); |
| 366 | window.ack_last_and_commit(); |
| 367 | f.roundtrip(id); |
| 368 | |
| 369 | // Focus, adding Activated, and move to workspace down, causing removing and adding to a |
| 370 | // floating layout. |
| 371 | f.niri_focus_output(1); |
| 372 | f.niri().layout.move_to_workspace_down(); |
| 373 | f.double_roundtrip(id); |
| 374 | |
| 375 | // This should request the current size (300 × 300) since the window responded to the change. |
| 376 | assert_snapshot!( |
| 377 | f.client(id).window(&surface).format_recent_configures(), |
| 378 | @"size: 300 × 300, bounds: 1920 × 1080, states: [Activated]" |
| 379 | ); |
| 380 | } |
| 381 | |
| 382 | #[test] |
| 383 | fn moving_to_floating_doesnt_cancel_resize() { |
| 384 | let (mut f, id, surface) = set_up(); |
| 385 | let _ = f.client(id).window(&surface).recent_configures(); |
| 386 | |
| 387 | // Request a size change to a different size. |
| 388 | f.niri().layout.set_column_width(SizeChange::SetFixed(500)); |
| 389 | f.double_roundtrip(id); |
| 390 | |
| 391 | // This should request the new size (500 ×). |
| 392 | assert_snapshot!( |
| 393 | f.client(id).window(&surface).format_recent_configures(), |
| 394 | @"size: 500 × 1048, bounds: 1888 × 1048, states: [Activated]" |
| 395 | ); |
| 396 | |
| 397 | // Before the window has a chance to respond, make it floating. |
| 398 | f.niri().layout.toggle_window_floating(None); |
| 399 | f.double_roundtrip(id); |
| 400 | |
| 401 | // This should keep requesting the new size (500 ×). |
| 402 | assert_snapshot!( |
| 403 | f.client(id).window(&surface).format_recent_configures(), |
| 404 | @"size: 500 × 1048, bounds: 1920 × 1080, states: [Activated]" |
| 405 | ); |
| 406 | } |
| 407 | |
| 408 | #[test] |
| 409 | fn interactive_move_unfullscreen_to_floating_restores_size() { |
| 410 | let (mut f, id, surface) = set_up(); |
| 411 | |
| 412 | f.niri().layout.toggle_window_floating(None); |
| 413 | f.double_roundtrip(id); |
| 414 | |
| 415 | // Change size while we're floating and commit. |
| 416 | let window = f.client(id).window(&surface); |
| 417 | window.set_size(200, 200); |
| 418 | window.ack_last_and_commit(); |
| 419 | f.double_roundtrip(id); |
| 420 | |
| 421 | let _ = f.client(id).window(&surface).recent_configures(); |
| 422 | |
| 423 | let niri = f.niri(); |
| 424 | let mapped = niri.layout.windows().next().unwrap().1; |
| 425 | let window = mapped.window.clone(); |
| 426 | niri.layout.set_fullscreen(&window, true); |
| 427 | f.double_roundtrip(id); |
| 428 | |
| 429 | // This should request a fullscreen size. |
| 430 | assert_snapshot!( |
| 431 | f.client(id).window(&surface).format_recent_configures(), |
| 432 | @"size: 1920 × 1080, bounds: 1888 × 1048, states: [Activated, Fullscreen]" |
| 433 | ); |
| 434 | |
| 435 | // Start an interactive move which causes an unfullscreen into floating. |
| 436 | let output = f.niri_output(1); |
| 437 | let niri = f.niri(); |
| 438 | let mapped = niri.layout.windows().next().unwrap().1; |
| 439 | let window = mapped.window.clone(); |
| 440 | niri.layout |
| 441 | .interactive_move_begin(window.clone(), &output, Point::default()); |
| 442 | niri.layout.interactive_move_update( |
| 443 | &window, |
| 444 | Point::from((1000., 0.)), |
| 445 | output, |
| 446 | Point::default(), |
| 447 | ); |
| 448 | f.double_roundtrip(id); |
| 449 | |
| 450 | // This should request the stored floating size (200 × 200). |
| 451 | assert_snapshot!( |
| 452 | f.client(id).window(&surface).format_recent_configures(), |
| 453 | @"size: 200 × 200, bounds: 1920 × 1080, states: [Activated]" |
| 454 | ); |
| 455 | } |
| 456 | |
| 457 | #[test] |
| 458 | fn resize_during_interactive_move_propagates_to_floating() { |
| 459 | let (mut f, id, surface) = set_up(); |
| 460 | |
| 461 | f.niri().layout.toggle_window_floating(None); |
| 462 | f.double_roundtrip(id); |
| 463 | |
| 464 | // Change size while we're floating and commit. |
| 465 | let window = f.client(id).window(&surface); |
| 466 | window.set_size(200, 200); |
| 467 | window.ack_last_and_commit(); |
| 468 | f.double_roundtrip(id); |
| 469 | |
| 470 | let _ = f.client(id).window(&surface).recent_configures(); |
| 471 | |
| 472 | // Start an interactive move. |
| 473 | let output = f.niri_output(1); |
| 474 | let niri = f.niri(); |
| 475 | let mapped = niri.layout.windows().next().unwrap().1; |
| 476 | let window_id = mapped.window.clone(); |
| 477 | niri.layout |
| 478 | .interactive_move_begin(window_id.clone(), &output, Point::default()); |
| 479 | niri.layout.interactive_move_update( |
| 480 | &window_id, |
| 481 | Point::from((1000., 0.)), |
| 482 | output, |
| 483 | Point::default(), |
| 484 | ); |
| 485 | f.double_roundtrip(id); |
| 486 | |
| 487 | // This shouldn't request any new size. |
| 488 | assert_snapshot!( |
| 489 | f.client(id).window(&surface).format_recent_configures(), |
| 490 | @"" |
| 491 | ); |
| 492 | |
| 493 | // Change size while we're being interactively moved. |
| 494 | let window = f.client(id).window(&surface); |
| 495 | window.set_size(300, 300); |
| 496 | window.commit(); |
| 497 | f.double_roundtrip(id); |
| 498 | |
| 499 | // This shouldn't request any new size. |
| 500 | assert_snapshot!( |
| 501 | f.client(id).window(&surface).format_recent_configures(), |
| 502 | @"" |
| 503 | ); |
| 504 | |
| 505 | // End the interactive move, placing the window into floating. |
| 506 | f.niri().layout.interactive_move_end(&window_id); |
| 507 | f.double_roundtrip(id); |
| 508 | |
| 509 | // This should keep the new 300 × 300 size. |
| 510 | assert_snapshot!( |
| 511 | f.client(id).window(&surface).format_recent_configures(), |
| 512 | @"size: 300 × 300, bounds: 1920 × 1080, states: [Activated]" |
| 513 | ); |
| 514 | } |
| 515 | |
| 516 | #[test] |
| 517 | fn resize_in_steps() { |
| 518 | let (mut f, id, surface) = set_up(); |
| 519 | |
| 520 | f.niri().layout.toggle_window_floating(None); |
| 521 | f.double_roundtrip(id); |
| 522 | let _ = f.client(id).window(&surface).recent_configures(); |
| 523 | |
| 524 | // Commit in response to the floating bounds state change configure. |
| 525 | f.client(id).window(&surface).ack_last_and_commit(); |
| 526 | f.double_roundtrip(id); |
| 527 | |
| 528 | // Request a size change to a different size in two steps. |
| 529 | f.niri().layout.set_column_width(SizeChange::SetFixed(500)); |
| 530 | f.niri() |
| 531 | .layout |
| 532 | .set_window_height(None, SizeChange::SetFixed(500)); |
| 533 | f.double_roundtrip(id); |
| 534 | |
| 535 | // This should request the full new size (500 × 500) once. |
| 536 | assert_snapshot!( |
| 537 | f.client(id).window(&surface).format_recent_configures(), |
| 538 | @"size: 500 × 500, bounds: 1920 × 1080, states: [Activated]" |
| 539 | ); |
| 540 | |
| 541 | let window = f.client(id).window(&surface); |
| 542 | let serial = window.configures_received.last().unwrap().0; |
| 543 | |
| 544 | // Request a size change now that the previous one is pending-but-not-acked. |
| 545 | f.niri().layout.set_column_width(SizeChange::SetFixed(600)); |
| 546 | // Drop Activated to work around resize throttling. |
| 547 | f.niri_focus_output(2); |
| 548 | f.double_roundtrip(id); |
| 549 | |
| 550 | // This should request the new size (600 × 500) once. |
| 551 | assert_snapshot!( |
| 552 | f.client(id).window(&surface).format_recent_configures(), |
| 553 | @"size: 600 × 500, bounds: 1920 × 1080, states: []" |
| 554 | ); |
| 555 | |
| 556 | // Commit in response to the previous configure. |
| 557 | let window = f.client(id).window(&surface); |
| 558 | window.xdg_surface.ack_configure(serial); |
| 559 | window.set_size(500, 500); |
| 560 | window.commit(); |
| 561 | |
| 562 | f.double_roundtrip(id); |
| 563 | |
| 564 | // This shouldn't request anything. |
| 565 | assert_snapshot!( |
| 566 | f.client(id).window(&surface).format_recent_configures(), |
| 567 | @"" |
| 568 | ); |
| 569 | |
| 570 | // Request a height change now that the first one is committed-to, but the second isn't. |
| 571 | let niri = f.niri(); |
| 572 | let mapped = niri.layout.windows().next().unwrap().1; |
| 573 | let window = mapped.window.clone(); |
| 574 | f.niri() |
| 575 | .layout |
| 576 | .set_window_height(Some(&window), SizeChange::SetFixed(600)); |
| 577 | // Add Activated to work around resize throttling. |
| 578 | f.niri_focus_output(1); |
| 579 | f.double_roundtrip(id); |
| 580 | |
| 581 | // This should request the latest sizes (600 × 600). |
| 582 | assert_snapshot!( |
| 583 | f.client(id).window(&surface).format_recent_configures(), |
| 584 | @"size: 600 × 600, bounds: 1920 × 1080, states: [Activated]" |
| 585 | ); |
| 586 | } |
| 587 | |
| 588 | #[test] |
| 589 | fn state_change_doesnt_break_use_window_size() { |
| 590 | let (mut f, id, surface) = set_up(); |
| 591 | |
| 592 | f.niri().layout.toggle_window_floating(None); |
| 593 | f.double_roundtrip(id); |
| 594 | let _ = f.client(id).window(&surface).recent_configures(); |
| 595 | |
| 596 | // Commit in response to the bounds change that comes with toggling floating. |
| 597 | f.client(id).window(&surface).ack_last_and_commit(); |
| 598 | f.roundtrip(id); |
| 599 | |
| 600 | // Request a size change to a different size. |
| 601 | f.niri().layout.set_column_width(SizeChange::SetFixed(500)); |
| 602 | f.double_roundtrip(id); |
| 603 | |
| 604 | // This should request the new size (500 × 100). |
| 605 | assert_snapshot!( |
| 606 | f.client(id).window(&surface).format_recent_configures(), |
| 607 | @"size: 500 × 100, bounds: 1920 × 1080, states: [Activated]" |
| 608 | ); |
| 609 | |
| 610 | let window = f.client(id).window(&surface); |
| 611 | let serial = window.configures_received.last().unwrap().0; |
| 612 | |
| 613 | // Request a state change by dropping Activated. |
| 614 | f.niri_focus_output(2); |
| 615 | f.double_roundtrip(id); |
| 616 | |
| 617 | // This should request the new size (500 × 100). |
| 618 | assert_snapshot!( |
| 619 | f.client(id).window(&surface).format_recent_configures(), |
| 620 | @"size: 500 × 100, bounds: 1920 × 1080, states: []" |
| 621 | ); |
| 622 | |
| 623 | // Commit in response to the previous configure with a different size. |
| 624 | let window = f.client(id).window(&surface); |
| 625 | window.xdg_surface.ack_configure(serial); |
| 626 | window.set_size(300, 300); |
| 627 | window.commit(); |
| 628 | |
| 629 | f.double_roundtrip(id); |
| 630 | |
| 631 | // This shouldn't request anything. |
| 632 | assert_snapshot!( |
| 633 | f.client(id).window(&surface).format_recent_configures(), |
| 634 | @"" |
| 635 | ); |
| 636 | |
| 637 | // Request a height change now that the first one is committed-to, but the second isn't. |
| 638 | let niri = f.niri(); |
| 639 | let mapped = niri.layout.windows().next().unwrap().1; |
| 640 | let window = mapped.window.clone(); |
| 641 | f.niri() |
| 642 | .layout |
| 643 | .set_window_height(Some(&window), SizeChange::SetFixed(600)); |
| 644 | // Add Activated state to force a configure. |
| 645 | f.niri_focus_output(1); |
| 646 | f.double_roundtrip(id); |
| 647 | |
| 648 | // This should already request the current width (300 × 600) rather than the pending previous |
| 649 | // width (500 × 600) from the state change configure. |
| 650 | assert_snapshot!( |
| 651 | f.client(id).window(&surface).format_recent_configures(), |
| 652 | @"size: 300 × 600, bounds: 1920 × 1080, states: [Activated]" |
| 653 | ); |
| 654 | } |
| 655 | |
| 656 | #[test] |
| 657 | fn interactive_move_restores_floating_size_when_set_to_floating() { |
| 658 | let (mut f, id, surface) = set_up(); |
| 659 | |
| 660 | f.niri().layout.toggle_window_floating(None); |
| 661 | f.double_roundtrip(id); |
| 662 | |
| 663 | // Change size while we're floating and commit to make niri remember it. |
| 664 | let window = f.client(id).window(&surface); |
| 665 | window.set_size(200, 200); |
| 666 | window.ack_last_and_commit(); |
| 667 | f.double_roundtrip(id); |
| 668 | |
| 669 | let _ = f.client(id).window(&surface).recent_configures(); |
| 670 | |
| 671 | // Change back to tiling. |
| 672 | f.niri().layout.toggle_window_floating(None); |
| 673 | f.double_roundtrip(id); |
| 674 | |
| 675 | // We should get a tiled size configure. |
| 676 | assert_snapshot!( |
| 677 | f.client(id).window(&surface).format_recent_configures(), |
| 678 | @"size: 200 × 1048, bounds: 1888 × 1048, states: [Activated]" |
| 679 | ); |
| 680 | |
| 681 | // Resize as requested. |
| 682 | let window = f.client(id).window(&surface); |
| 683 | let (_, configure) = window.configures_received.last().unwrap(); |
| 684 | window.set_size(configure.size.0 as u16, configure.size.1 as u16); |
| 685 | window.ack_last_and_commit(); |
| 686 | f.roundtrip(id); |
| 687 | |
| 688 | // Start an interactive move. |
| 689 | let output = f.niri_output(1); |
| 690 | let niri = f.niri(); |
| 691 | let mapped = niri.layout.windows().next().unwrap().1; |
| 692 | let window_id = mapped.window.clone(); |
| 693 | niri.layout |
| 694 | .interactive_move_begin(window_id.clone(), &output, Point::default()); |
| 695 | niri.layout.interactive_move_update( |
| 696 | &window_id, |
| 697 | Point::from((1000., 0.)), |
| 698 | output, |
| 699 | Point::default(), |
| 700 | ); |
| 701 | f.double_roundtrip(id); |
| 702 | |
| 703 | // This shouldn't request any new size because interactive move targets tiling. |
| 704 | assert_snapshot!( |
| 705 | f.client(id).window(&surface).format_recent_configures(), |
| 706 | @"size: 200 × 1048, bounds: 1920 × 1080, states: [Activated]" |
| 707 | ); |
| 708 | |
| 709 | // Change interactive move to target floating. |
| 710 | f.niri().layout.toggle_window_floating(None); |
| 711 | f.double_roundtrip(id); |
| 712 | |
| 713 | // This should restore the floating window size (200 × 200). |
| 714 | assert_snapshot!( |
| 715 | f.client(id).window(&surface).format_recent_configures(), |
| 716 | @"size: 200 × 200, bounds: 1920 × 1080, states: [Activated]" |
| 717 | ); |
| 718 | |
| 719 | // End the interactive move, placing the window into floating. |
| 720 | f.niri().layout.interactive_move_end(&window_id); |
| 721 | f.double_roundtrip(id); |
| 722 | |
| 723 | // This should keep the floating window size (200 × 200). |
| 724 | assert_snapshot!( |
| 725 | f.client(id).window(&surface).format_recent_configures(), |
| 726 | @"" |
| 727 | ); |
| 728 | } |
| 729 | |
| 730 | #[test] |
| 731 | fn floating_doesnt_store_fullscreen_size() { |
| 732 | let mut f = Fixture::new(); |
| 733 | f.add_output(1, (1920, 1080)); |
| 734 | f.add_output(2, (1280, 720)); |
| 735 | |
| 736 | // Open a window fullscreen. |
| 737 | let id = f.add_client(); |
| 738 | let window = f.client(id).create_window(); |
| 739 | let surface = window.surface.clone(); |
| 740 | window.set_fullscreen(None); |
| 741 | window.commit(); |
| 742 | f.roundtrip(id); |
| 743 | |
| 744 | let window = f.client(id).window(&surface); |
| 745 | window.attach_new_buffer(); |
| 746 | window.set_size(1920, 1080); |
| 747 | window.ack_last_and_commit(); |
| 748 | f.double_roundtrip(id); |
| 749 | |
| 750 | let _ = f.client(id).window(&surface).recent_configures(); |
| 751 | |
| 752 | // Make it floating. |
| 753 | f.niri().layout.toggle_window_floating(None); |
| 754 | f.double_roundtrip(id); |
| 755 | |
| 756 | // This should request 0 × 0 to unfullscreen. |
| 757 | assert_snapshot!( |
| 758 | f.client(id).window(&surface).format_recent_configures(), |
| 759 | @"size: 0 × 0, bounds: 1920 × 1080, states: [Activated]" |
| 760 | ); |
| 761 | |
| 762 | // Without committing, make it tiling again. We never committed while floating, so there's no |
| 763 | // floating size to remember. |
| 764 | f.niri().layout.toggle_window_floating(None); |
| 765 | f.double_roundtrip(id); |
| 766 | |
| 767 | // This should request the tiled size. |
| 768 | assert_snapshot!( |
| 769 | f.client(id).window(&surface).format_recent_configures(), |
| 770 | @"size: 1920 × 1048, bounds: 1888 × 1048, states: [Activated]" |
| 771 | ); |
| 772 | |
| 773 | // Commit in response. |
| 774 | let window = f.client(id).window(&surface); |
| 775 | window.set_size(100, 100); |
| 776 | window.ack_last_and_commit(); |
| 777 | f.roundtrip(id); |
| 778 | |
| 779 | // Make the window floating again. |
| 780 | f.niri().layout.toggle_window_floating(None); |
| 781 | f.double_roundtrip(id); |
| 782 | |
| 783 | // This shouldn't request any size change, particularly not the fullscreen size. |
| 784 | assert_snapshot!( |
| 785 | f.client(id).window(&surface).format_recent_configures(), |
| 786 | @"size: 100 × 100, bounds: 1920 × 1080, states: [Activated]" |
| 787 | ); |
| 788 | } |
| 789 | |
| 790 | #[test] |
| 791 | fn floating_respects_non_fixed_min_max_rule() { |
| 792 | let config = r##" |
| 793 | window-rule { |
| 794 | min-width 200 |
| 795 | max-width 300 |
| 796 | } |
| 797 | "##; |
| 798 | let config = Config::parse("test.kdl", config).unwrap(); |
| 799 | let mut f = Fixture::with_config(config); |
| 800 | f.add_output(1, (1920, 1080)); |
| 801 | f.add_output(2, (1280, 720)); |
| 802 | |
| 803 | let id = f.add_client(); |
| 804 | let window = f.client(id).create_window(); |
| 805 | let surface = window.surface.clone(); |
| 806 | window.commit(); |
| 807 | f.roundtrip(id); |
| 808 | |
| 809 | // Open with smaller width than min. |
| 810 | let window = f.client(id).window(&surface); |
| 811 | window.attach_new_buffer(); |
| 812 | window.set_size(100, 100); |
| 813 | window.ack_last_and_commit(); |
| 814 | f.double_roundtrip(id); |
| 815 | |
| 816 | // Commit to the Activated state configure. |
| 817 | f.client(id).window(&surface).ack_last_and_commit(); |
| 818 | f.double_roundtrip(id); |
| 819 | |
| 820 | let _ = f.client(id).window(&surface).recent_configures(); |
| 821 | |
| 822 | // Make it floating. |
| 823 | f.niri().layout.toggle_window_floating(None); |
| 824 | f.double_roundtrip(id); |
| 825 | |
| 826 | // This should clamp to min-width and request 200 × 100. |
| 827 | assert_snapshot!( |
| 828 | f.client(id).window(&surface).format_recent_configures(), |
| 829 | @"size: 200 × 100, bounds: 1920 × 1080, states: [Activated]" |
| 830 | ); |
| 831 | |
| 832 | // Commit with a bigger width than max. |
| 833 | let window = f.client(id).window(&surface); |
| 834 | window.set_size(400, 100); |
| 835 | window.ack_last_and_commit(); |
| 836 | f.roundtrip(id); |
| 837 | |
| 838 | // Make it tiling. |
| 839 | f.niri().layout.toggle_window_floating(None); |
| 840 | f.double_roundtrip(id); |
| 841 | |
| 842 | let _ = f.client(id).window(&surface).recent_configures(); |
| 843 | |
| 844 | f.client(id).window(&surface).ack_last_and_commit(); |
| 845 | f.roundtrip(id); |
| 846 | |
| 847 | // Make it floating. |
| 848 | f.niri().layout.toggle_window_floating(None); |
| 849 | f.double_roundtrip(id); |
| 850 | |
| 851 | // This should clamp to max-width and request 300 × 100. |
| 852 | assert_snapshot!( |
| 853 | f.client(id).window(&surface).format_recent_configures(), |
| 854 | @"size: 300 × 100, bounds: 1920 × 1080, states: [Activated]" |
| 855 | ); |
| 856 | } |
| 857 | |
| 858 | #[test] |
| 859 | fn unfullscreen_to_floating_doesnt_send_extra_configure() { |
| 860 | let (mut f, id, surface) = set_up(); |
| 861 | |
| 862 | // Make it floating. |
| 863 | f.niri().layout.toggle_window_floating(None); |
| 864 | f.roundtrip(id); |
| 865 | |
| 866 | // Fullscreen. |
| 867 | let window = f.client(id).window(&surface); |
| 868 | window.set_fullscreen(None); |
| 869 | f.double_roundtrip(id); |
| 870 | |
| 871 | let _ = f.client(id).window(&surface).recent_configures(); |
| 872 | |
| 873 | // Unfullscreen via the window request which requires a configure response. |
| 874 | let window = f.client(id).window(&surface); |
| 875 | window.unset_fullscreen(); |
| 876 | f.double_roundtrip(id); |
| 877 | |
| 878 | // This should configure only once and not twice. |
| 879 | assert_snapshot!( |
| 880 | f.client(id).window(&surface).format_recent_configures(), |
| 881 | @"size: 936 × 1048, bounds: 1920 × 1080, states: [Activated]" |
| 882 | ); |
| 883 | } |