test(wayland): sync constraint region and geometry tests
- commit
- 7535410710eae169ef2a3312152fff9bfda1bbab
- author
- brice · · 2026-09-25 12:49 UTC
- parent
- d2ed99b
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +21 -11
M internal/adapters/wayland/constraints_test.go +15 -6
| @@ -8,6 +8,7 @@ import ( | |||
| 8 | 8 | "github.com/bnema/purego-libwayland/protocol/pointerconstraints" | |
| 9 | 9 | "github.com/bnema/purego-libwayland/protocol/relativepointer" | |
| 10 | 10 | "github.com/bnema/purego-libwayland/protocol/wayland" | |
| 11 | + | "github.com/bnema/purego-libwayland/protocol/xdgshell" | |
| 11 | 12 | "github.com/bnema/wlturbo" | |
| 12 | 13 | ) | |
| 13 | 14 | ||
| @@ -76,7 +77,7 @@ func TestPointerLockAndRelativeMotion(t *testing.T) { | |||
| 76 | 77 | rel := c.AllocateID() | |
| 77 | 78 | relEvents := logProxy(t, c, rel) | |
| 78 | 79 | requestProtocol(t, c, relManager, relativepointer.ZwpRelativePointerManagerV1RequestGetRelativePointer, rel, pointer) | |
| 79 | - | w, surf := surfaceMapper(t, c, events)() | |
| 80 | + | w, surf, _ := surfaceMapper(t, c, events)() | |
| 80 | 81 | ||
| 81 | 82 | constraints := bindProtocol(t, c, "zwp_pointer_constraints_v1") | |
| 82 | 83 | lock := c.AllocateID() | |
| @@ -135,10 +136,10 @@ func TestPointerConfineOneshotRegion(t *testing.T) { | |||
| 135 | 136 | seat := bindProtocol(t, c, "wl_seat") | |
| 136 | 137 | registerProtocol(t, c, seat) | |
| 137 | 138 | pointer := c.AllocateID() | |
| 138 | - | registerProtocol(t, c, pointer) | |
| 139 | + | pointerEvents := logProxy(t, c, pointer) | |
| 139 | 140 | requestProtocol(t, c, seat, wayland.SeatRequestGetPointer, pointer) | |
| 140 | 141 | comp := bindProtocol(t, c, "wl_compositor") | |
| 141 | - | w, surf := surfaceMapper(t, c, events)() | |
| 142 | + | w, surf, xdgID := surfaceMapper(t, c, events)() | |
| 142 | 143 | region := c.AllocateID() | |
| 143 | 144 | registerProtocol(t, c, region) | |
| 144 | 145 | requestProtocol(t, c, comp, wayland.CompositorRequestCreateRegion, region) | |
| @@ -154,8 +155,9 @@ func TestPointerConfineOneshotRegion(t *testing.T) { | |||
| 154 | 155 | // Outside the region the constraint waits for the pointer. | |
| 155 | 156 | commands <- ports.FocusWindow{ID: w.ID} | |
| 156 | 157 | commands <- ports.PointerFocus{ID: w.ID} | |
| 157 | - | if err := c.Roundtrip(); err != nil { | |
| 158 | - | t.Fatal(err) | |
| 158 | + | commands <- ports.PointerMotionTo{ID: w.ID, X: 50, Y: 50} | |
| 159 | + | // Sync on the motion reaching the client before checking. | |
| 160 | + | for ev := next(t, c, pointerEvents); ev[0] != float64(wayland.PointerEventMotion); ev = next(t, c, pointerEvents) { | |
| 159 | 161 | } | |
| 160 | 162 | if len(confineEvents) > 0 { | |
| 161 | 163 | t.Fatal("confined outside the region") | |
| @@ -169,6 +171,13 @@ func TestPointerConfineOneshotRegion(t *testing.T) { | |||
| 169 | 171 | t.Fatalf("constrained %+v, want %+v", got, want) | |
| 170 | 172 | } | |
| 171 | 173 | ||
| 174 | + | // A geometry change moves the window-local region. | |
| 175 | + | requestProtocol(t, c, xdgID, xdgshell.SurfaceRequestSetWindowGeometry, int32(1), int32(1), int32(1), int32(1)) | |
| 176 | + | requestProtocol(t, c, surf, wayland.SurfaceRequestCommit) | |
| 177 | + | if got := constrained(t, events); got.Rect != (ports.Rect{X: 1, Y: 2, W: 23, H: 20}) { | |
| 178 | + | t.Fatalf("after geometry %+v", got) | |
| 179 | + | } | |
| 180 | + | ||
| 172 | 181 | // A new region applies on commit. | |
| 173 | 182 | requestProtocol(t, c, confine, pointerconstraints.ZwpConfinedPointerV1RequestSetRegion, uint32(0)) | |
| 174 | 183 | requestProtocol(t, c, surf, wayland.SurfaceRequestCommit) | |
| @@ -207,7 +216,7 @@ func TestPointerLockDestroyed(t *testing.T) { | |||
| 207 | 216 | pointer := c.AllocateID() | |
| 208 | 217 | registerProtocol(t, c, pointer) | |
| 209 | 218 | requestProtocol(t, c, seat, wayland.SeatRequestGetPointer, pointer) | |
| 210 | - | w, surf := surfaceMapper(t, c, events)() | |
| 219 | + | w, surf, _ := surfaceMapper(t, c, events)() | |
| 211 | 220 | constraints := bindProtocol(t, c, "zwp_pointer_constraints_v1") | |
| 212 | 221 | lock := c.AllocateID() | |
| 213 | 222 | lockEvents := logProxy(t, c, lock) | |
| @@ -8,6 +8,7 @@ import ( | |||||
| 8 | "github.com/bnema/purego-libwayland/protocol/pointerconstraints" | 8 | "github.com/bnema/purego-libwayland/protocol/pointerconstraints" | ||
| 9 | "github.com/bnema/purego-libwayland/protocol/relativepointer" | 9 | "github.com/bnema/purego-libwayland/protocol/relativepointer" | ||
| 10 | "github.com/bnema/purego-libwayland/protocol/wayland" | 10 | "github.com/bnema/purego-libwayland/protocol/wayland" | ||
| 11 | + | "github.com/bnema/purego-libwayland/protocol/xdgshell" | |||
| 11 | "github.com/bnema/wlturbo" | 12 | "github.com/bnema/wlturbo" | ||
| 12 | ) | 13 | ) | ||
| 13 | 14 | ||||
| @@ -76,7 +77,7 @@ func TestPointerLockAndRelativeMotion(t *testing.T) { | |||||
| 76 | rel := c.AllocateID() | 77 | rel := c.AllocateID() | ||
| 77 | relEvents := logProxy(t, c, rel) | 78 | relEvents := logProxy(t, c, rel) | ||
| 78 | requestProtocol(t, c, relManager, relativepointer.ZwpRelativePointerManagerV1RequestGetRelativePointer, rel, pointer) | 79 | requestProtocol(t, c, relManager, relativepointer.ZwpRelativePointerManagerV1RequestGetRelativePointer, rel, pointer) | ||
| 79 | - | w, surf := surfaceMapper(t, c, events)() | 80 | + | w, surf, _ := surfaceMapper(t, c, events)() |
| 80 | 81 | ||||
| 81 | constraints := bindProtocol(t, c, "zwp_pointer_constraints_v1") | 82 | constraints := bindProtocol(t, c, "zwp_pointer_constraints_v1") | ||
| 82 | lock := c.AllocateID() | 83 | lock := c.AllocateID() | ||
| @@ -135,10 +136,10 @@ func TestPointerConfineOneshotRegion(t *testing.T) { | |||||
| 135 | seat := bindProtocol(t, c, "wl_seat") | 136 | seat := bindProtocol(t, c, "wl_seat") | ||
| 136 | registerProtocol(t, c, seat) | 137 | registerProtocol(t, c, seat) | ||
| 137 | pointer := c.AllocateID() | 138 | pointer := c.AllocateID() | ||
| 138 | - | registerProtocol(t, c, pointer) | 139 | + | pointerEvents := logProxy(t, c, pointer) |
| 139 | requestProtocol(t, c, seat, wayland.SeatRequestGetPointer, pointer) | 140 | requestProtocol(t, c, seat, wayland.SeatRequestGetPointer, pointer) | ||
| 140 | comp := bindProtocol(t, c, "wl_compositor") | 141 | comp := bindProtocol(t, c, "wl_compositor") | ||
| 141 | - | w, surf := surfaceMapper(t, c, events)() | 142 | + | w, surf, xdgID := surfaceMapper(t, c, events)() |
| 142 | region := c.AllocateID() | 143 | region := c.AllocateID() | ||
| 143 | registerProtocol(t, c, region) | 144 | registerProtocol(t, c, region) | ||
| 144 | requestProtocol(t, c, comp, wayland.CompositorRequestCreateRegion, region) | 145 | requestProtocol(t, c, comp, wayland.CompositorRequestCreateRegion, region) | ||
| @@ -154,8 +155,9 @@ func TestPointerConfineOneshotRegion(t *testing.T) { | |||||
| 154 | // Outside the region the constraint waits for the pointer. | 155 | // Outside the region the constraint waits for the pointer. | ||
| 155 | commands <- ports.FocusWindow{ID: w.ID} | 156 | commands <- ports.FocusWindow{ID: w.ID} | ||
| 156 | commands <- ports.PointerFocus{ID: w.ID} | 157 | commands <- ports.PointerFocus{ID: w.ID} | ||
| 157 | - | if err := c.Roundtrip(); err != nil { | 158 | + | commands <- ports.PointerMotionTo{ID: w.ID, X: 50, Y: 50} |
| 158 | - | t.Fatal(err) | 159 | + | // Sync on the motion reaching the client before checking. |
| 160 | + | for ev := next(t, c, pointerEvents); ev[0] != float64(wayland.PointerEventMotion); ev = next(t, c, pointerEvents) { | |||
| 159 | } | 161 | } | ||
| 160 | if len(confineEvents) > 0 { | 162 | if len(confineEvents) > 0 { | ||
| 161 | t.Fatal("confined outside the region") | 163 | t.Fatal("confined outside the region") | ||
| @@ -169,6 +171,13 @@ func TestPointerConfineOneshotRegion(t *testing.T) { | |||||
| 169 | t.Fatalf("constrained %+v, want %+v", got, want) | 171 | t.Fatalf("constrained %+v, want %+v", got, want) | ||
| 170 | } | 172 | } | ||
| 171 | 173 | ||||
| 174 | + | // A geometry change moves the window-local region. | |||
| 175 | + | requestProtocol(t, c, xdgID, xdgshell.SurfaceRequestSetWindowGeometry, int32(1), int32(1), int32(1), int32(1)) | |||
| 176 | + | requestProtocol(t, c, surf, wayland.SurfaceRequestCommit) | |||
| 177 | + | if got := constrained(t, events); got.Rect != (ports.Rect{X: 1, Y: 2, W: 23, H: 20}) { | |||
| 178 | + | t.Fatalf("after geometry %+v", got) | |||
| 179 | + | } | |||
| 180 | + | ||||
| 172 | // A new region applies on commit. | 181 | // A new region applies on commit. | ||
| 173 | requestProtocol(t, c, confine, pointerconstraints.ZwpConfinedPointerV1RequestSetRegion, uint32(0)) | 182 | requestProtocol(t, c, confine, pointerconstraints.ZwpConfinedPointerV1RequestSetRegion, uint32(0)) | ||
| 174 | requestProtocol(t, c, surf, wayland.SurfaceRequestCommit) | 183 | requestProtocol(t, c, surf, wayland.SurfaceRequestCommit) | ||
| @@ -207,7 +216,7 @@ func TestPointerLockDestroyed(t *testing.T) { | |||||
| 207 | pointer := c.AllocateID() | 216 | pointer := c.AllocateID() | ||
| 208 | registerProtocol(t, c, pointer) | 217 | registerProtocol(t, c, pointer) | ||
| 209 | requestProtocol(t, c, seat, wayland.SeatRequestGetPointer, pointer) | 218 | requestProtocol(t, c, seat, wayland.SeatRequestGetPointer, pointer) | ||
| 210 | - | w, surf := surfaceMapper(t, c, events)() | 219 | + | w, surf, _ := surfaceMapper(t, c, events)() |
| 211 | constraints := bindProtocol(t, c, "zwp_pointer_constraints_v1") | 220 | constraints := bindProtocol(t, c, "zwp_pointer_constraints_v1") | ||
| 212 | lock := c.AllocateID() | 221 | lock := c.AllocateID() | ||
| 213 | lockEvents := logProxy(t, c, lock) | 222 | lockEvents := logProxy(t, c, lock) | ||
M internal/adapters/wayland/protocol_test.go +6 -5
| @@ -592,11 +592,12 @@ func TestHeldKeyOnKeyboardFocusTransfer(t *testing.T) { | |||
| 592 | 592 | func toplevelMapper(t *testing.T, c *wlturbo.Display, events <-chan ports.ClientEvent) func() ports.WindowMapped { | |
| 593 | 593 | t.Helper() | |
| 594 | 594 | m := surfaceMapper(t, c, events) | |
| 595 | - | return func() ports.WindowMapped { w, _ := m(); return w } | |
| 595 | + | return func() ports.WindowMapped { w, _, _ := m(); return w } | |
| 596 | 596 | } | |
| 597 | 597 | ||
| 598 | - | // surfaceMapper is toplevelMapper also returning the wl_surface ID. | |
| 599 | - | func surfaceMapper(t *testing.T, c *wlturbo.Display, events <-chan ports.ClientEvent) func() (ports.WindowMapped, uint32) { | |
| 598 | + | // surfaceMapper is toplevelMapper also returning the wl_surface and | |
| 599 | + | // xdg_surface IDs. | |
| 600 | + | func surfaceMapper(t *testing.T, c *wlturbo.Display, events <-chan ports.ClientEvent) func() (ports.WindowMapped, uint32, uint32) { | |
| 600 | 601 | t.Helper() | |
| 601 | 602 | comp := bindProtocol(t, c, "wl_compositor") | |
| 602 | 603 | wm := bindProtocol(t, c, "xdg_wm_base") | |
| @@ -617,7 +618,7 @@ func surfaceMapper(t *testing.T, c *wlturbo.Display, events <-chan ports.ClientE | |||
| 617 | 618 | t.Fatal(err) | |
| 618 | 619 | } | |
| 619 | 620 | requestProtocol(t, c, pool, wayland.ShmPoolRequestCreateBuffer, buffer, int32(0), int32(1), int32(1), int32(4), uint32(0)) | |
| 620 | - | return func() (ports.WindowMapped, uint32) { | |
| 621 | + | return func() (ports.WindowMapped, uint32, uint32) { | |
| 621 | 622 | surf, xdg, top := c.AllocateID(), c.AllocateID(), c.AllocateID() | |
| 622 | 623 | requestProtocol(t, c, comp, wayland.CompositorRequestCreateSurface, surf) | |
| 623 | 624 | registerProtocol(t, c, surf) | |
| @@ -643,6 +644,6 @@ func surfaceMapper(t *testing.T, c *wlturbo.Display, events <-chan ports.ClientE | |||
| 643 | 644 | if err := c.Roundtrip(); err != nil { | |
| 644 | 645 | t.Fatal(err) | |
| 645 | 646 | } | |
| 646 | - | return mapped(t, events, 2*time.Second), surf | |
| 647 | + | return mapped(t, events, 2*time.Second), surf, xdg | |
| 647 | 648 | } | |
| 648 | 649 | } | |
| @@ -592,11 +592,12 @@ func TestHeldKeyOnKeyboardFocusTransfer(t *testing.T) { | |||||
| 592 | func toplevelMapper(t *testing.T, c *wlturbo.Display, events <-chan ports.ClientEvent) func() ports.WindowMapped { | 592 | func toplevelMapper(t *testing.T, c *wlturbo.Display, events <-chan ports.ClientEvent) func() ports.WindowMapped { | ||
| 593 | t.Helper() | 593 | t.Helper() | ||
| 594 | m := surfaceMapper(t, c, events) | 594 | m := surfaceMapper(t, c, events) | ||
| 595 | - | return func() ports.WindowMapped { w, _ := m(); return w } | 595 | + | return func() ports.WindowMapped { w, _, _ := m(); return w } |
| 596 | } | 596 | } | ||
| 597 | 597 | ||||
| 598 | - | // surfaceMapper is toplevelMapper also returning the wl_surface ID. | 598 | + | // surfaceMapper is toplevelMapper also returning the wl_surface and |
| 599 | - | func surfaceMapper(t *testing.T, c *wlturbo.Display, events <-chan ports.ClientEvent) func() (ports.WindowMapped, uint32) { | 599 | + | // xdg_surface IDs. |
| 600 | + | func surfaceMapper(t *testing.T, c *wlturbo.Display, events <-chan ports.ClientEvent) func() (ports.WindowMapped, uint32, uint32) { | |||
| 600 | t.Helper() | 601 | t.Helper() | ||
| 601 | comp := bindProtocol(t, c, "wl_compositor") | 602 | comp := bindProtocol(t, c, "wl_compositor") | ||
| 602 | wm := bindProtocol(t, c, "xdg_wm_base") | 603 | wm := bindProtocol(t, c, "xdg_wm_base") | ||
| @@ -617,7 +618,7 @@ func surfaceMapper(t *testing.T, c *wlturbo.Display, events <-chan ports.ClientE | |||||
| 617 | t.Fatal(err) | 618 | t.Fatal(err) | ||
| 618 | } | 619 | } | ||
| 619 | requestProtocol(t, c, pool, wayland.ShmPoolRequestCreateBuffer, buffer, int32(0), int32(1), int32(1), int32(4), uint32(0)) | 620 | requestProtocol(t, c, pool, wayland.ShmPoolRequestCreateBuffer, buffer, int32(0), int32(1), int32(1), int32(4), uint32(0)) | ||
| 620 | - | return func() (ports.WindowMapped, uint32) { | 621 | + | return func() (ports.WindowMapped, uint32, uint32) { |
| 621 | surf, xdg, top := c.AllocateID(), c.AllocateID(), c.AllocateID() | 622 | surf, xdg, top := c.AllocateID(), c.AllocateID(), c.AllocateID() | ||
| 622 | requestProtocol(t, c, comp, wayland.CompositorRequestCreateSurface, surf) | 623 | requestProtocol(t, c, comp, wayland.CompositorRequestCreateSurface, surf) | ||
| 623 | registerProtocol(t, c, surf) | 624 | registerProtocol(t, c, surf) | ||
| @@ -643,6 +644,6 @@ func surfaceMapper(t *testing.T, c *wlturbo.Display, events <-chan ports.ClientE | |||||
| 643 | if err := c.Roundtrip(); err != nil { | 644 | if err := c.Roundtrip(); err != nil { | ||
| 644 | t.Fatal(err) | 645 | t.Fatal(err) | ||
| 645 | } | 646 | } | ||
| 646 | - | return mapped(t, events, 2*time.Second), surf | 647 | + | return mapped(t, events, 2*time.Second), surf, xdg |
| 647 | } | 648 | } | ||
| 648 | } | 649 | } | ||