detached 72a8075

fix(server): read the id libwayland allocates for server-created resources

commit
72a807532e3358cfb95e9a2a116c7c318f62d1c8
author
brice · · 2026-09-27 16:34 UTC
committer
brice · · 2026-09-27 18:47 UTC
parent
f0a709a
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
3 files · +29 -2
M server/display.go +4 -0
@@ -226,6 +226,10 @@ func (c Client) CreateResource(iface *Interface, version int32, id uint32, h Han
226226 if rc == 0 {
227227 return nil, fmt.Errorf("purego-libwayland: wl_resource_create(%s) failed", iface.Name)
228228 }
229+ // id 0 asks libwayland to allocate a server-side ID.
230+ if id == 0 {
231+ id = wlResourceGetID(rc)
232+ }
229233 r := &Resource{c: rc, id: id, version: version, client: c.c, iface: iface, handler: h}
230234 live.resources[rc] = r
231235 wlResourceSetDispatcher(rc, cbDispatcher, implMarker(), 0, cbDestroy)
@@ -226,6 +226,10 @@ func (c Client) CreateResource(iface *Interface, version int32, id uint32, h Han
226 if rc == 0 {226 if rc == 0 {
227 return nil, fmt.Errorf("purego-libwayland: wl_resource_create(%s) failed", iface.Name)227 return nil, fmt.Errorf("purego-libwayland: wl_resource_create(%s) failed", iface.Name)
228 }228 }
229+ // id 0 asks libwayland to allocate a server-side ID.
230+ if id == 0 {
231+ id = wlResourceGetID(rc)
232+ }
229 r := &Resource{c: rc, id: id, version: version, client: c.c, iface: iface, handler: h}233 r := &Resource{c: rc, id: id, version: version, client: c.c, iface: iface, handler: h}
230 live.resources[rc] = r234 live.resources[rc] = r
231 wlResourceSetDispatcher(rc, cbDispatcher, implMarker(), 0, cbDestroy)235 wlResourceSetDispatcher(rc, cbDispatcher, implMarker(), 0, cbDestroy)
M server/hotpath_test.go +17 -0
@@ -64,6 +64,23 @@ func hotDisplay(t testing.TB, iface *Interface, h Handler) (*Display, *Resource)
6464 return d, hotResource(t, d, iface, h)
6565 }
6666
67+func TestServerAllocatedResourceID(t *testing.T) {
68+ iface := &Interface{Name: "server_allocated_id_test", Version: 1}
69+ d, existing := hotDisplay(t, iface, nil)
70+ if !d.Do(func() {
71+ r, err := (Client{existing.client}).CreateResource(iface, 1, 0, nil)
72+ if err != nil {
73+ t.Errorf("create server-side resource: %v", err)
74+ return
75+ }
76+ if r.ID() == 0 || r.ID() != wlResourceGetID(r.c) {
77+ t.Errorf("resource ID = %d, libwayland ID = %d", r.ID(), wlResourceGetID(r.c))
78+ }
79+ }) {
80+ t.Fatal("display stopped")
81+ }
82+}
83+
6784 func requestMessage(iface *Interface) unsafe.Pointer {
6885 return *(*unsafe.Pointer)(unsafe.Add(unsafe.Pointer(&tables.mem[0]), iface.c-tables.base+16))
6986 }
@@ -64,6 +64,23 @@ func hotDisplay(t testing.TB, iface *Interface, h Handler) (*Display, *Resource)
64 return d, hotResource(t, d, iface, h)64 return d, hotResource(t, d, iface, h)
65 }65 }
66 66
67+func TestServerAllocatedResourceID(t *testing.T) {
68+ iface := &Interface{Name: "server_allocated_id_test", Version: 1}
69+ d, existing := hotDisplay(t, iface, nil)
70+ if !d.Do(func() {
71+ r, err := (Client{existing.client}).CreateResource(iface, 1, 0, nil)
72+ if err != nil {
73+ t.Errorf("create server-side resource: %v", err)
74+ return
75+ }
76+ if r.ID() == 0 || r.ID() != wlResourceGetID(r.c) {
77+ t.Errorf("resource ID = %d, libwayland ID = %d", r.ID(), wlResourceGetID(r.c))
78+ }
79+ }) {
80+ t.Fatal("display stopped")
81+ }
82+}
83+
67 func requestMessage(iface *Interface) unsafe.Pointer {84 func requestMessage(iface *Interface) unsafe.Pointer {
68 return *(*unsafe.Pointer)(unsafe.Add(unsafe.Pointer(&tables.mem[0]), iface.c-tables.base+16))85 return *(*unsafe.Pointer)(unsafe.Add(unsafe.Pointer(&tables.mem[0]), iface.c-tables.base+16))
69 }86 }
M server/lib.go +8 -2
@@ -28,8 +28,8 @@ var (
2828 loadOnce sync.Once
2929 loadErr error
3030
31- symDisplayFlushClients, symEventLoopDispatch, symResourceCreate uintptr
32- symResourceSetDispatcher, symResourcePostEventArr, symResourceDestroy uintptr
31+ symDisplayFlushClients, symEventLoopDispatch, symResourceCreate uintptr
32+ symResourceSetDispatcher, symResourcePostEventArr, symResourceDestroy, symResourceGetID uintptr
3333
3434 // Shared C callbacks. purego callbacks are never freed, so there is one
3535 // of each for the whole process.
@@ -71,6 +71,7 @@ func load() error {
7171 {"wl_display_flush_clients", &symDisplayFlushClients},
7272 {"wl_event_loop_dispatch", &symEventLoopDispatch},
7373 {"wl_resource_create", &symResourceCreate},
74+ {"wl_resource_get_id", &symResourceGetID},
7475 {"wl_resource_set_dispatcher", &symResourceSetDispatcher},
7576 {"wl_resource_post_event_array", &symResourcePostEventArr},
7677 {"wl_resource_destroy", &symResourceDestroy},
@@ -109,6 +110,11 @@ func wlResourceCreate(client, iface uintptr, version int32, id uint32) uintptr {
109110 r, _, _ := purego.SyscallN(symResourceCreate, callArgs[:4]...)
110111 return r
111112 }
113+func wlResourceGetID(resource uintptr) uint32 {
114+ callArgs[0] = resource
115+ r, _, _ := purego.SyscallN(symResourceGetID, callArgs[:1]...)
116+ return uint32(r)
117+}
112118 func wlResourceSetDispatcher(resource, dispatcher, impl, data, destroy uintptr) {
113119 callArgs[0], callArgs[1], callArgs[2], callArgs[3], callArgs[4] = resource, dispatcher, impl, data, destroy
114120 purego.SyscallN(symResourceSetDispatcher, callArgs[:5]...)
@@ -28,8 +28,8 @@ var (
28 loadOnce sync.Once28 loadOnce sync.Once
29 loadErr error29 loadErr error
30 30
31- symDisplayFlushClients, symEventLoopDispatch, symResourceCreate uintptr31+ symDisplayFlushClients, symEventLoopDispatch, symResourceCreate uintptr
32- symResourceSetDispatcher, symResourcePostEventArr, symResourceDestroy uintptr32+ symResourceSetDispatcher, symResourcePostEventArr, symResourceDestroy, symResourceGetID uintptr
33 33
34 // Shared C callbacks. purego callbacks are never freed, so there is one34 // Shared C callbacks. purego callbacks are never freed, so there is one
35 // of each for the whole process.35 // of each for the whole process.
@@ -71,6 +71,7 @@ func load() error {
71 {"wl_display_flush_clients", &symDisplayFlushClients},71 {"wl_display_flush_clients", &symDisplayFlushClients},
72 {"wl_event_loop_dispatch", &symEventLoopDispatch},72 {"wl_event_loop_dispatch", &symEventLoopDispatch},
73 {"wl_resource_create", &symResourceCreate},73 {"wl_resource_create", &symResourceCreate},
74+ {"wl_resource_get_id", &symResourceGetID},
74 {"wl_resource_set_dispatcher", &symResourceSetDispatcher},75 {"wl_resource_set_dispatcher", &symResourceSetDispatcher},
75 {"wl_resource_post_event_array", &symResourcePostEventArr},76 {"wl_resource_post_event_array", &symResourcePostEventArr},
76 {"wl_resource_destroy", &symResourceDestroy},77 {"wl_resource_destroy", &symResourceDestroy},
@@ -109,6 +110,11 @@ func wlResourceCreate(client, iface uintptr, version int32, id uint32) uintptr {
109 r, _, _ := purego.SyscallN(symResourceCreate, callArgs[:4]...)110 r, _, _ := purego.SyscallN(symResourceCreate, callArgs[:4]...)
110 return r111 return r
111 }112 }
113+func wlResourceGetID(resource uintptr) uint32 {
114+ callArgs[0] = resource
115+ r, _, _ := purego.SyscallN(symResourceGetID, callArgs[:1]...)
116+ return uint32(r)
117+}
112 func wlResourceSetDispatcher(resource, dispatcher, impl, data, destroy uintptr) {118 func wlResourceSetDispatcher(resource, dispatcher, impl, data, destroy uintptr) {
113 callArgs[0], callArgs[1], callArgs[2], callArgs[3], callArgs[4] = resource, dispatcher, impl, data, destroy119 callArgs[0], callArgs[1], callArgs[2], callArgs[3], callArgs[4] = resource, dispatcher, impl, data, destroy
114 purego.SyscallN(symResourceSetDispatcher, callArgs[:5]...)120 purego.SyscallN(symResourceSetDispatcher, callArgs[:5]...)

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 1

Tags 14

↑↓ moveenter openesc close