Skip to content

feat(wayland): add Go client and protocol scanner - #211

Merged
mhduiy merged 2 commits into
linuxdeepin:develop/2500u3from
mhduiy:wayland-client-generator-bug377251-u3
Dec 2, 2026
Merged

mhduiy merged 2 commits into
linuxdeepin:develop/2500u3from
mhduiy:wayland-client-generator-bug377251-u3

Conversation

@mhduiy

@mhduiy mhduiy commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Cherry-pick of #210 for the develop/2500u3 packaging branch. Adds the pure Go Wayland client, protocol scanner, and standalone binding generation. The dde-api-dev package includes the Wayland runtime and core bindings required to build dde-daemon.

Validation: built dde-api and dde-api-dev 6.2.2 with dpkg-buildpackage; checked the packaged Go sources; built dde-session-daemon and ran inputdevices1 and inputmanager tests against the extracted development package. The libwayland interoperability test and REUSE lint passed.

PMS: BUG-377251

Summary by Sourcery

Provide a Go Wayland client and protocol binding generation for applications and package developers.

New Features:

  • Add a pure Go Wayland client runtime and core protocol bindings for connecting to a display and handling input-related Wayland events.
  • Add a command-line scanner that generates Go client bindings from Wayland protocol XML, with optional interface selection.
  • Add CMake support for generating core and optional extension bindings from protocol XML.

Enhancements:

  • Include Wayland runtime and core bindings in the development build and package installation.

Build:

  • Add Wayland runtime and core packages and the protocol scanner to the Makefile build and test targets.

Tests:

  • Add unit tests for scanner validation and output replacement, runtime event and descriptor handling, and a libwayland interoperability test.

Chores:

  • Add MIT license and reuse/debian copyright metadata for the included Wayland protocol bindings.

1. Add a pure Go Wayland client with core bindings and opt-in protocol tracing.
2. Generate Go client bindings from protocol XML and replace output files atomically.
3. Add standalone CMake generation and cover wire interoperability and object lifecycle.

Log: Add the Go Wayland client runtime and protocol scanner.
Influence: Go clients can connect to Wayland compositors.

feat(wayland): 新增 Go 客户端和协议生成器

1. 新增纯 Go Wayland 客户端,提供核心协议绑定和可选的协议日志。
2. 从协议 XML 生成 Go 客户端绑定,并原子替换输出文件。
3. 提供独立的 CMake 生成入口,覆盖协议互通和对象生命周期测试。

Log: 新增 Go Wayland 客户端运行时和协议生成器。
PMS: BUG-377251
Influence: Go 客户端可连接 Wayland 合成器。
@sourcery-ai

sourcery-ai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Define the runtime’s protocol metadata, object and connection state, and wire encoder/decoder data structures that the client and generated bindings rely on.

  • wayland/conn_linux.go L35-90
  • wayland/wire_linux.go L1-106

API

Expose the Go client’s connection, object, dispatch, and wire APIs alongside the core protocol bindings and display helpers that clients call.

  • wayland/conn_linux.go L1-34, L91-245
  • wayland/core/client.go L1-57
  • wayland/core/wayland-client-protocol.go L1-625

Implementation

Implement protocol XML parsing and binding generation, transport and object lifecycle behavior, and opt-in protocol tracing.

  • cmd/go-wayland-scanner/main.go L1-442
  • wayland/conn_linux.go L246-334
  • wayland/debug_linux.go L1-96
  • wayland/wire_linux.go L107-223

Configuration

Register the Wayland runtime and scanner in the project build and packaging, and add a standalone CMake entry point for generating protocol bindings.

  • .reuse/dep5 L71-76
  • Makefile L41-44, L58, L137
  • debian/copyright L22-46
  • wayland/CMakeLists.txt L1-40

Documentation

Add the MIT license text needed by the imported Wayland core protocol copyright notice.

  • LICENSES/MIT.txt L1-21

Tests

Check scanner input validation and atomic output replacement, and exercise runtime behavior and wire interoperability against a Wayland server.

  • cmd/go-wayland-scanner/main_test.go L1-67
  • wayland/conn_linux_test.go L1-213
  • wayland/testdata/interop/client.go L1-148
  • wayland/testdata/interop/probe.xml L1-49
  • wayland/testdata/interop/run.sh L1-59
  • wayland/testdata/interop/server.c L1-146

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 7 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="wayland/conn_linux.go" line_range="93" />
<code_context>
+}
+
+func Dial(ctx context.Context, display *Interface) (*Conn, *Object, error) {
+	name := os.Getenv("WAYLAND_DISPLAY")
+	if name == "" {
+		name = "wayland-0"
</code_context>
<issue_to_address>
**Inherited Wayland socket ignored**

When the client is launched with a connected compositor socket in `WAYLAND_SOCKET`, `Dial` ignores the inherited `WAYLAND_SOCKET` file descriptor and instead tries to connect to a socket path; clients launched with a pre-opened Wayland connection therefore fail to connect when that path is unavailable.

Have `Dial` detect and use the inherited socket descriptor before falling back to the `WAYLAND_DISPLAY` path.
</issue_to_address>

### Comment 2
<location path="wayland/conn_linux.go" line_range="102" />
<code_context>
+		if dir == "" {
+			return nil, nil, fmt.Errorf("XDG_RUNTIME_DIR is unset")
+		}
+		name = filepath.Join(dir, name)
+	}
+	var dialer net.Dialer
</code_context>
<issue_to_address>
**Abstract Wayland sockets cannot connect**

When `WAYLAND_DISPLAY` names an abstract Unix socket, such as `@wayland-0`, `Dial` joins the abstract socket name to `XDG_RUNTIME_DIR`, so `net.DialContext` looks for a filesystem socket and fails to connect.

Recognize abstract socket names and pass them to the Unix dialer without joining them to `XDG_RUNTIME_DIR`.
</issue_to_address>

### Comment 3
<location path="wayland/CMakeLists.txt" line_range="28" />
<code_context>
+
+set(core "${CMAKE_CURRENT_BINARY_DIR}/core/wayland-client-protocol.go")
+dde_generate_wayland_client("${core}" core "${WAYLAND_CORE_XML}"
+    -interfaces wl_display,wl_registry,wl_callback,wl_seat,wl_pointer,wl_keyboard,wl_touch)
+set(bindings "${core}")
+if(WAYLAND_PROTOCOL_XML)
</code_context>
<issue_to_address>
**Core input events reject surface references**

When a client using these core bindings receives a keyboard or pointer event referring to a surface it cannot create through the generated interfaces, `Decoder.Object` rejects the surface ID as unknown, so dispatch closes the connection before delivering the event. The generated keyboard and pointer bindings decode surface-bearing events, but the selected core bindings omit `wl_surface` and the interfaces needed to create one.

Include the required surface-creating interfaces and `wl_surface` in the core bindings, or otherwise ensure those surface objects are registered before such events are decoded.
</issue_to_address>

### Comment 4
<location path="cmd/go-wayland-scanner/main.go" line_range="217" />
<code_context>
+		}
+	}
+	fmt.Fprintf(&b, "\npackage %s\n\nimport wl \"github.com/linuxdeepin/dde-api/wayland\"\n\n", pkg)
+	fmt.Fprintln(&b, "func Register(c *wl.Conn) { c.Register(")
+	for _, i := range interfaces {
+		fmt.Fprintf(&b, "&%sInterface,\n", exported(i.Name))
</code_context>
<issue_to_address>
**Filtered bindings cannot create child objects**

When the `-interfaces` filter selects an interface with a typed `new_id` constructor but omits that constructor's target interface, `Register` registers only emitted interfaces, while generated constructor methods require the child interface to be registered. For example, generating only `wl_display` leaves `Sync` and `GetRegistry` unable to create their objects, so callers receive an “unregistered Wayland interface” error.

Include referenced constructor interfaces in the generated registration set, or reject filters that omit those dependencies.
</issue_to_address>

### Comment 5
<location path="Makefile" line_range="137" />
<code_context>

 build-dev: prepare
-	${GOBUILD} $(addprefix ${GOPKG_PREFIX}/, ${LIBRARIES})
+	${GOBUILD} $(addprefix ${GOPKG_PREFIX}/, ${LIBRARIES}) ${GOPKG_PREFIX}/wayland/core

 install/lib/%:
</code_context>
<issue_to_address>
**Installed sources omit core bindings**

When a consumer installs the development sources through `install-dev`, `install-dev` derives its copy targets from `ININSTALLS`/`LIBRARIES`, which includes `wayland` but not `wayland/core`, so the installed source tree lacks the core bindings and downstream imports fail to build.

Include `wayland/core` in the source-copy targets used by `install-dev`.
</issue_to_address>

### Comment 6
<location path="wayland/core/client.go" line_range="27" />
<code_context>
+	}
+	Register(conn)
+	d := &Display{WlDisplay: WlDisplay{root}, Conn: conn}
+	d.OnError(func(_ *wayland.Object, code uint32, message string) {
+		d.protocolError = fmt.Errorf("Wayland protocol error %d: %s", code, message)
+	})
</code_context>
<issue_to_address>
**Custom listeners disable bookkeeping**

When a caller registers its own `OnDeleteId` or `OnError` handler after `Connect`, a caller registering its own `OnDeleteId` or `OnError` handler overwrites the handler installed by `Connect` because `Object.On` stores only one handler per opcode. Delete events then stop recycling object IDs, and error events stop setting `protocolError`, so `Dispatch` loses the protocol-error detail.

Keep required internal bookkeeping separate from user listeners, or chain the internal handler whenever a user registers one.

Also at `wayland/core/client.go:30`.
</issue_to_address>

### Comment 7
<location path="cmd/go-wayland-scanner/main.go" line_range="310-312" />
<code_context>
+		if a.Type == "new_id" {
+			result = "(*wl.Object, error)"
+			if a.Interface == "" {
+				params = append(params, "interfaceName string", "version uint32")
+				binding, version = "interfaceName", "version"
+				enc = append(enc, "e.String(interfaceName)", "e.Uint(version)")
+			} else {
+				binding = fmt.Sprintf("%q", a.Interface)
</code_context>
<issue_to_address>
**Generated bind requests duplicate arguments**

When the scanner generates `wl_registry.bind` or another untyped-`new_id` message with explicit interface and version XML arguments, `emitRequest` encodes the XML interface and version arguments in the ordinary loop, then appends them again before the ID, so the request has the wrong wire shape and the compositor rejects it; `debugMessage` also duplicates these fields in trace metadata.

Encode the interface and version only once, in the required wire order, and use that same argument list for trace metadata.

Also at `cmd/go-wayland-scanner/main.go:313-316`, `cmd/go-wayland-scanner/main.go:358-359`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread wayland/conn_linux.go Resolved
Comment thread wayland/conn_linux.go Resolved
Comment thread wayland/CMakeLists.txt Resolved
Comment thread cmd/go-wayland-scanner/main.go Resolved
Comment thread Makefile Resolved
Comment thread wayland/core/client.go Resolved
Comment thread cmd/go-wayland-scanner/main.go Resolved
1. Keep protocol error reporting and object ID recycling when registering listeners.
2. Test that user listeners still run and bookkeeping is preserved.

Log: Preserve internal display event handling when clients register listeners.
Influence: Listeners retain error and ID handling.

fix(wayland): 保留显示对象的内部事件处理

1. 注册监听器时保留协议错误上报与对象 ID 回收。
2. 验证用户回调和内部处理都能执行。

Log: 注册监听器时保留显示对象的内部事件处理。
PMS: BUG-377251
Influence: 监听器不会覆盖错误上报和 ID 回收。
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fly602, mhduiy

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@mhduiy
mhduiy merged commit df51589 into linuxdeepin:develop/2500u3 Dec 2, 2026
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants