detached 7535410

test(wayland): sync constraint region and geometry tests

commit
7535410710eae169ef2a3312152fff9bfda1bbab
author
brice · · 2026-09-25 12:49 UTC
parent
d2ed99b
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · 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 (
88 "github.com/bnema/purego-libwayland/protocol/pointerconstraints"
99 "github.com/bnema/purego-libwayland/protocol/relativepointer"
1010 "github.com/bnema/purego-libwayland/protocol/wayland"
11+ "github.com/bnema/purego-libwayland/protocol/xdgshell"
1112 "github.com/bnema/wlturbo"
1213 )
1314
@@ -76,7 +77,7 @@ func TestPointerLockAndRelativeMotion(t *testing.T) {
7677 rel := c.AllocateID()
7778 relEvents := logProxy(t, c, rel)
7879 requestProtocol(t, c, relManager, relativepointer.ZwpRelativePointerManagerV1RequestGetRelativePointer, rel, pointer)
79- w, surf := surfaceMapper(t, c, events)()
80+ w, surf, _ := surfaceMapper(t, c, events)()
8081
8182 constraints := bindProtocol(t, c, "zwp_pointer_constraints_v1")
8283 lock := c.AllocateID()
@@ -135,10 +136,10 @@ func TestPointerConfineOneshotRegion(t *testing.T) {
135136 seat := bindProtocol(t, c, "wl_seat")
136137 registerProtocol(t, c, seat)
137138 pointer := c.AllocateID()
138- registerProtocol(t, c, pointer)
139+ pointerEvents := logProxy(t, c, pointer)
139140 requestProtocol(t, c, seat, wayland.SeatRequestGetPointer, pointer)
140141 comp := bindProtocol(t, c, "wl_compositor")
141- w, surf := surfaceMapper(t, c, events)()
142+ w, surf, xdgID := surfaceMapper(t, c, events)()
142143 region := c.AllocateID()
143144 registerProtocol(t, c, region)
144145 requestProtocol(t, c, comp, wayland.CompositorRequestCreateRegion, region)
@@ -154,8 +155,9 @@ func TestPointerConfineOneshotRegion(t *testing.T) {
154155 // Outside the region the constraint waits for the pointer.
155156 commands <- ports.FocusWindow{ID: w.ID}
156157 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) {
159161 }
160162 if len(confineEvents) > 0 {
161163 t.Fatal("confined outside the region")
@@ -169,6 +171,13 @@ func TestPointerConfineOneshotRegion(t *testing.T) {
169171 t.Fatalf("constrained %+v, want %+v", got, want)
170172 }
171173
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+
172181 // A new region applies on commit.
173182 requestProtocol(t, c, confine, pointerconstraints.ZwpConfinedPointerV1RequestSetRegion, uint32(0))
174183 requestProtocol(t, c, surf, wayland.SurfaceRequestCommit)
@@ -207,7 +216,7 @@ func TestPointerLockDestroyed(t *testing.T) {
207216 pointer := c.AllocateID()
208217 registerProtocol(t, c, pointer)
209218 requestProtocol(t, c, seat, wayland.SeatRequestGetPointer, pointer)
210- w, surf := surfaceMapper(t, c, events)()
219+ w, surf, _ := surfaceMapper(t, c, events)()
211220 constraints := bindProtocol(t, c, "zwp_pointer_constraints_v1")
212221 lock := c.AllocateID()
213222 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) {
592592 func toplevelMapper(t *testing.T, c *wlturbo.Display, events <-chan ports.ClientEvent) func() ports.WindowMapped {
593593 t.Helper()
594594 m := surfaceMapper(t, c, events)
595- return func() ports.WindowMapped { w, _ := m(); return w }
595+ return func() ports.WindowMapped { w, _, _ := m(); return w }
596596 }
597597
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) {
600601 t.Helper()
601602 comp := bindProtocol(t, c, "wl_compositor")
602603 wm := bindProtocol(t, c, "xdg_wm_base")
@@ -617,7 +618,7 @@ func surfaceMapper(t *testing.T, c *wlturbo.Display, events <-chan ports.ClientE
617618 t.Fatal(err)
618619 }
619620 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) {
621622 surf, xdg, top := c.AllocateID(), c.AllocateID(), c.AllocateID()
622623 requestProtocol(t, c, comp, wayland.CompositorRequestCreateSurface, surf)
623624 registerProtocol(t, c, surf)
@@ -643,6 +644,6 @@ func surfaceMapper(t *testing.T, c *wlturbo.Display, events <-chan ports.ClientE
643644 if err := c.Roundtrip(); err != nil {
644645 t.Fatal(err)
645646 }
646- return mapped(t, events, 2*time.Second), surf
647+ return mapped(t, events, 2*time.Second), surf, xdg
647648 }
648649 }
@@ -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), surf647+ return mapped(t, events, 2*time.Second), surf, xdg
647 }648 }
648 }649 }

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 23

Tags 10

↑↓ moveenter openesc close