test(wayland): wait for the output change before counting surface enters
- commit
- 43a1ce78d2548a6da57c936293bf1e3437901330
- author
- brice · · 2026-10-22 15:42 UTC
- committer
- brice · · 2026-10-22 17:54 UTC
- parent
- 1b0bfc7
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +18 -5
M internal/adapters/wayland/x11window_test.go +18 -5
| @@ -533,6 +533,22 @@ func TestX11ConfineRegionHasNoOffset(t *testing.T) { | |||
| 533 | 533 | } | |
| 534 | 534 | } | |
| 535 | 535 | ||
| 536 | + | // waitOn waits until window id's surface is on output name: commands reach | |
| 537 | + | // the display goroutine asynchronously. | |
| 538 | + | func (r *x11Rig) waitOn(id ports.WindowID, name string) { | |
| 539 | + | r.t.Helper() | |
| 540 | + | waitTrue(r.t, "surface on "+name, func() bool { | |
| 541 | + | ok := false | |
| 542 | + | r.state(func() { | |
| 543 | + | if w := r.s.windows[id]; w != nil { | |
| 544 | + | on := w.surf().on | |
| 545 | + | ok = on != nil && on.name() == name | |
| 546 | + | } | |
| 547 | + | }) | |
| 548 | + | return ok | |
| 549 | + | }) | |
| 550 | + | } | |
| 551 | + | ||
| 536 | 552 | // An X11 window is on one output only, even straddling two: a single | |
| 537 | 553 | // wl_surface.enter, and a leave only when its output changes. | |
| 538 | 554 | func TestX11WindowEntersOneOutput(t *testing.T) { | |
| @@ -575,10 +591,7 @@ func TestX11WindowEntersOneOutput(t *testing.T) { | |||
| 575 | 591 | // Straddling both outputs, configured on A. | |
| 576 | 592 | r.commands <- ports.PlaceWindow{ID: m.ID, X: 1900, Y: 0} | |
| 577 | 593 | r.commands <- ports.ConfigureWindow{ID: m.ID, Width: 200, Height: 100, Visible: true, Output: "A"} | |
| 578 | - | if err := r.xc.Roundtrip(); err != nil { | |
| 579 | - | t.Fatal(err) | |
| 580 | - | } | |
| 581 | - | r.state(func() {}) | |
| 594 | + | r.waitOn(m.ID, "A") | |
| 582 | 595 | if err := r.xc.Roundtrip(); err != nil { | |
| 583 | 596 | t.Fatal(err) | |
| 584 | 597 | } | |
| @@ -604,7 +617,7 @@ func TestX11WindowEntersOneOutput(t *testing.T) { | |||
| 604 | 617 | ||
| 605 | 618 | // Moving to B leaves A and enters B once. | |
| 606 | 619 | r.commands <- ports.ConfigureWindow{ID: m.ID, Width: 200, Height: 100, Visible: true, Output: "B"} | |
| 607 | - | r.state(func() {}) | |
| 620 | + | r.waitOn(m.ID, "B") | |
| 608 | 621 | if err := r.xc.Roundtrip(); err != nil { | |
| 609 | 622 | t.Fatal(err) | |
| 610 | 623 | } | |
| @@ -533,6 +533,22 @@ func TestX11ConfineRegionHasNoOffset(t *testing.T) { | |||||
| 533 | } | 533 | } | ||
| 534 | } | 534 | } | ||
| 535 | 535 | ||||
| 536 | + | // waitOn waits until window id's surface is on output name: commands reach | |||
| 537 | + | // the display goroutine asynchronously. | |||
| 538 | + | func (r *x11Rig) waitOn(id ports.WindowID, name string) { | |||
| 539 | + | r.t.Helper() | |||
| 540 | + | waitTrue(r.t, "surface on "+name, func() bool { | |||
| 541 | + | ok := false | |||
| 542 | + | r.state(func() { | |||
| 543 | + | if w := r.s.windows[id]; w != nil { | |||
| 544 | + | on := w.surf().on | |||
| 545 | + | ok = on != nil && on.name() == name | |||
| 546 | + | } | |||
| 547 | + | }) | |||
| 548 | + | return ok | |||
| 549 | + | }) | |||
| 550 | + | } | |||
| 551 | + | ||||
| 536 | // An X11 window is on one output only, even straddling two: a single | 552 | // An X11 window is on one output only, even straddling two: a single | ||
| 537 | // wl_surface.enter, and a leave only when its output changes. | 553 | // wl_surface.enter, and a leave only when its output changes. | ||
| 538 | func TestX11WindowEntersOneOutput(t *testing.T) { | 554 | func TestX11WindowEntersOneOutput(t *testing.T) { | ||
| @@ -575,10 +591,7 @@ func TestX11WindowEntersOneOutput(t *testing.T) { | |||||
| 575 | // Straddling both outputs, configured on A. | 591 | // Straddling both outputs, configured on A. | ||
| 576 | r.commands <- ports.PlaceWindow{ID: m.ID, X: 1900, Y: 0} | 592 | r.commands <- ports.PlaceWindow{ID: m.ID, X: 1900, Y: 0} | ||
| 577 | r.commands <- ports.ConfigureWindow{ID: m.ID, Width: 200, Height: 100, Visible: true, Output: "A"} | 593 | r.commands <- ports.ConfigureWindow{ID: m.ID, Width: 200, Height: 100, Visible: true, Output: "A"} | ||
| 578 | - | if err := r.xc.Roundtrip(); err != nil { | 594 | + | r.waitOn(m.ID, "A") |
| 579 | - | t.Fatal(err) | |||
| 580 | - | } | |||
| 581 | - | r.state(func() {}) | |||
| 582 | if err := r.xc.Roundtrip(); err != nil { | 595 | if err := r.xc.Roundtrip(); err != nil { | ||
| 583 | t.Fatal(err) | 596 | t.Fatal(err) | ||
| 584 | } | 597 | } | ||
| @@ -604,7 +617,7 @@ func TestX11WindowEntersOneOutput(t *testing.T) { | |||||
| 604 | 617 | ||||
| 605 | // Moving to B leaves A and enters B once. | 618 | // Moving to B leaves A and enters B once. | ||
| 606 | r.commands <- ports.ConfigureWindow{ID: m.ID, Width: 200, Height: 100, Visible: true, Output: "B"} | 619 | r.commands <- ports.ConfigureWindow{ID: m.ID, Width: 200, Height: 100, Visible: true, Output: "B"} | ||
| 607 | - | r.state(func() {}) | 620 | + | r.waitOn(m.ID, "B") |
| 608 | if err := r.xc.Roundtrip(); err != nil { | 621 | if err := r.xc.Roundtrip(); err != nil { | ||
| 609 | t.Fatal(err) | 622 | t.Fatal(err) | ||
| 610 | } | 623 | } | ||