Skip to content

Conversation

@BLumia
Copy link
Member

@BLumia BLumia commented Dec 3, 2025

为 wayland 会话也初始化 Xembed 托盘支持.

Summary by Sourcery

Enhancements:

  • Gate X connection and tray selection manager initialization behind an internal flag instead of disabling it entirely on Wayland sessions.

@BLumia BLumia requested a review from fly602 December 3, 2025 08:56
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia

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

@sourcery-ai
Copy link

sourcery-ai bot commented Dec 3, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Enable the tray daemon’s Xembed/Xwayland-related X connection initialization path to be present in both X11 and Wayland sessions while effectively disabling the tray selection manager logic for now via a feature flag variable, and add region markers around the X connection setup block.

Flow diagram for updated X connection initialization in Daemon.Start

flowchart TD
    A[Daemon.Start] --> B[Create sessionBus]
    B --> C[Create sigLoop and start]
    C --> D[Set enableTraySelectionManager = false]
    D --> E{XDG_SESSION_TYPE != wayland?}
    E -->|no| G[Skip XConn initialization]
    E -->|yes| F{enableTraySelectionManager == true?}
    F -->|no| G
    F -->|yes| H[Call x.NewConn and assign to XConn]
    H --> I[Initialize tray selection manager on X]
    G --> J{DDE_DISABLE_STATUS_NOTIFIER_WATCHER != 1?}
    I --> J
    J -->|yes| K[Create StatusNotifierWatcher]
    J -->|no| L[Skip StatusNotifierWatcher]
    K --> M[Return from Daemon.Start]
    L --> M
Loading

File-Level Changes

Change Details Files
Gate X connection initialization behind a temporary boolean flag and relax the session-type check to conceptually support Xwayland in Wayland sessions.
  • Replace the Wayland-only early return condition so that the X connection block is no longer skipped solely based on XDG_SESSION_TYPE being wayland.
  • Introduce a local enableTraySelectionManager boolean flag defaulting to false to control whether the X connection and tray selection manager code actually runs.
  • Keep the existing tray selection manager logic intact but now conditionally executed based on the new flag rather than session type.
trayicon1/daemon.go
Improve code organization and clarity for the X connection setup section.
  • Add a comment explaining that the logic is intended to run on both X11 and Wayland for Xwayland support.
  • Wrap the X connection setup and related code with region markers to delineate the initialization section.
trayicon1/daemon.go

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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and found some issues that need to be addressed.

  • By unconditionally calling x.NewConn() you now hard-fail the daemon on sessions without an X server/Xwayland; consider keeping an environment-based guard or gracefully degrading if the X connection cannot be established so Wayland-only sessions still work.
  • The // #region / // #endregion markers are non-idiomatic in Go and inconsistent with typical comment style in this file; consider removing them or replacing with a simple explanatory comment block if needed.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- By unconditionally calling `x.NewConn()` you now hard-fail the daemon on sessions without an X server/Xwayland; consider keeping an environment-based guard or gracefully degrading if the X connection cannot be established so Wayland-only sessions still work.
- The `// #region` / `// #endregion` markers are non-idiomatic in Go and inconsistent with typical comment style in this file; consider removing them or replacing with a simple explanatory comment block if needed.

## Individual Comments

### Comment 1
<location> `trayicon1/daemon.go:51-53` </location>
<code_context>
-		if err != nil {
-			return err
-		}
+	// Enable this on both x11 and wayland(for xwayland support)
+	// #region init x conn
+	XConn, err = x.NewConn()
+	if err != nil {
+		return err
</code_context>

<issue_to_address>
**issue (bug_risk):** Unconditionally creating the X connection may cause Start() to fail on pure Wayland setups without Xwayland.

This used to be guarded by `XDG_SESSION_TYPE != "wayland"`, so the daemon could start on Wayland even without X. With `x.NewConn()` now unconditional, a failure (e.g., Wayland without Xwayland or DISPLAY) causes `Start()` to error and the daemon to fail to start. If X is meant to be optional, consider treating connection failures as non-fatal (e.g., log and continue without the tray manager, or only require a successful X connection when you know X should be available) to preserve the previous behavior while still enabling Xwayland when present.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@BLumia BLumia marked this pull request as draft December 3, 2025 09:20
@deepin-bot
Copy link
Contributor

deepin-bot bot commented Dec 4, 2025

TAG Bot

New tag: 6.1.66
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #972

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Dec 11, 2025

TAG Bot

New tag: 6.1.67
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #976

@BLumia BLumia marked this pull request as ready for review December 15, 2025 10:07
@BLumia BLumia changed the title feat: enable xembed support for xwayland 【不要合并!!!】feat: enable xembed support for xwayland Dec 15, 2025
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and found some issues that need to be addressed.

  • The new enableTraySelectionManager flag is hardcoded to false, which means the X connection (and thus tray selection manager) is never initialized on any session type; if this is meant to be configurable, wire it to a real config/env option or remove the flag and keep the previous behavior adjusted for Wayland/Xwayland as intended.
  • The comment // Enable this on both x11 and wayland(for xwayland support) does not match the current logic (guarded by enableTraySelectionManager and still checking XDG_SESSION_TYPE); please align the condition with the intended behavior or update the comment to avoid confusion.
  • The // #region / // #endregion markers are not idiomatic in Go and may not be recognized by all editors; consider using a regular comment block or extracting the X initialization into a small helper function to make the intent clearer.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `enableTraySelectionManager` flag is hardcoded to `false`, which means the X connection (and thus tray selection manager) is never initialized on any session type; if this is meant to be configurable, wire it to a real config/env option or remove the flag and keep the previous behavior adjusted for Wayland/Xwayland as intended.
- The comment `// Enable this on both x11 and wayland(for xwayland support)` does not match the current logic (guarded by `enableTraySelectionManager` and still checking `XDG_SESSION_TYPE`); please align the condition with the intended behavior or update the comment to avoid confusion.
- The `// #region` / `// #endregion` markers are not idiomatic in Go and may not be recognized by all editors; consider using a regular comment block or extracting the X initialization into a small helper function to make the intent clearer.

## Individual Comments

### Comment 1
<location> `trayicon1/daemon.go:51-54` </location>
<code_context>

-	if os.Getenv("XDG_SESSION_TYPE") != "wayland" {
-		// init x conn
+	// Enable this on both x11 and wayland(for xwayland support)
+	// #region init x conn
+	var enableTraySelectionManager = false
+	if os.Getenv("XDG_SESSION_TYPE") != "wayland" && enableTraySelectionManager {
 		XConn, err = x.NewConn()
 		if err != nil {
</code_context>

<issue_to_address>
**issue (bug_risk):** The new flag and condition effectively disable the X connection everywhere and conflict with the comment about enabling on both X11 and Wayland.

Because `enableTraySelectionManager` is hardcoded to `false`, this block will never run on any session type. The condition also still excludes `XDG_SESSION_TYPE == "wayland"`, which conflicts with the comment about supporting both X11 and Wayland (via Xwayland).

If the goal is to gate this behind a flag while allowing Xwayland, consider either:
- Removing the `XDG_SESSION_TYPE != "wayland"` check and relying only on the flag, or
- Making `enableTraySelectionManager` configurable (env/config) and updating the condition so Xwayland sessions are actually included.

As it stands, the tray selection manager is effectively disabled everywhere.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +51 to +54
// Enable this on both x11 and wayland(for xwayland support)
// #region init x conn
var enableTraySelectionManager = false
if os.Getenv("XDG_SESSION_TYPE") != "wayland" && enableTraySelectionManager {
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): The new flag and condition effectively disable the X connection everywhere and conflict with the comment about enabling on both X11 and Wayland.

Because enableTraySelectionManager is hardcoded to false, this block will never run on any session type. The condition also still excludes XDG_SESSION_TYPE == "wayland", which conflicts with the comment about supporting both X11 and Wayland (via Xwayland).

If the goal is to gate this behind a flag while allowing Xwayland, consider either:

  • Removing the XDG_SESSION_TYPE != "wayland" check and relying only on the flag, or
  • Making enableTraySelectionManager configurable (env/config) and updating the condition so Xwayland sessions are actually included.

As it stands, the tray selection manager is effectively disabled everywhere.

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Dec 18, 2025

TAG Bot

New tag: 6.1.68
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #982

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Dec 25, 2025

TAG Bot

New tag: 6.1.69
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #986

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Jan 7, 2026

TAG Bot

New tag: 6.1.70
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #991

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Jan 15, 2026

TAG Bot

New tag: 6.1.71
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #998

不再由 dde-daemon 的 trayicon1 模块注册 xembed selectionmanager

Log:
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码修改的目的是在 Wayland 会话下支持 XWayland,从而扩展托盘图标的兼容性。以下是对该代码修改的详细审查意见:

1. 语法与逻辑审查

  • 逻辑错误:变量永远为 false

    • 问题:代码中定义了 var enableTraySelectionManager = false,紧接着在 if 条件中使用了 && enableTraySelectionManager
    • 后果:由于 enableTraySelectionManager 始终为 false,且是逻辑“与”关系,导致整个 if 语句块内的 X11 连接初始化代码(x.NewConn() 等)永远不会被执行。
    • 修正:如果目的是启用该功能,应将其改为 true,或者将其作为一个可配置的开关(例如通过环境变量读取)。
  • 逻辑矛盾:注释与代码不符

    • 问题:注释写道 // Enable this on both x11 and wayland(for xwayland support)(在 X11 和 Wayland 上都启用此功能以支持 XWayland),但代码逻辑是 os.Getenv("XDG_SESSION_TYPE") != "wayland"
    • 后果:这意味着只有在非 Wayland(即 X11)环境下才会进入此分支。这与“在 Wayland 上启用以支持 XWayland”的意图是相反的。在纯 Wayland 环境下,XDG_SESSION_TYPE 为 "wayland",条件不满足,X11 连接不会建立,因此无法支持 XWayland 托盘应用。
    • 修正:如果是为了支持 XWayland,通常需要在 Wayland 环境下也建立 X11 连接。条件判断可能需要移除或修改。

2. 代码质量与规范审查

  • 注释风格

    • 问题:使用了 // #region// #endregion 这种标记。
    • 建议:Go 语言的标准惯例并不常用这种折叠标记。虽然这有助于编辑器折叠代码,但在 Go 代码中并不常见。建议保持简洁,或者如果团队统一使用此风格则保留。
  • 错误处理

    • 观察XConn, err = x.NewConn() 后直接 return err,这是符合 Go 语言习惯的,没有问题。

3. 性能审查

  • 环境变量读取
    • 观察os.Getenv("XDG_SESSION_TYPE") 被调用。
    • 建议os.Getenv 开销很小,但在高频调用的循环中应避免。在 Start() 这种初始化函数中调用一次是完全可接受的。

4. 安全性审查

  • 环境变量依赖
    • 观察:代码逻辑严重依赖 XDG_SESSION_TYPE 环境变量。
    • 风险:如果该环境变量未设置或被篡改,程序可能无法按预期运行(例如在 Wayland 下误判为 X11,或反之)。
    • 建议:虽然通常由显示管理器设置该变量,但在关键逻辑中,增加防御性检查(例如尝试连接 X Server 失败后的降级处理)会更健壮。

改进建议代码示例

假设你的目的是无条件启用 X11 连接初始化(为了同时支持 X11 和 XWayland),建议修改如下:

func (d *Daemon) Start() error {
	d.sigLoop = dbusutil.NewSignalLoop(sessionBus, 10)
	d.sigLoop.Start()

	// Init X connection for X11 or XWayland support
	// 尝试建立 X 连接,如果失败则返回错误(或者根据需求决定是否忽略错误)
	XConn, err = x.NewConn()
	if err != nil {
		// 如果是在纯 Wayland 环境且不需要 XWayland 支持,这里可能需要只记录日志而不返回错误
		// 但根据原代码逻辑,连接失败是致命错误
		logger.Warningf("Failed to connect to X server: %v", err)
		// return err // 根据实际需求决定是否直接退出
	} else {
		// 原有的初始化逻辑...
		// ...
	}

	if os.Getenv("DDE_DISABLE_STATUS_NOTIFIER_WATCHER") != "1" {
		d.snw = newStatusNotifierWatcher(service, d.sigLoop)
        // ...
	}
    // ...
}

或者,如果你确实需要通过一个开关来控制是否初始化 X 连接,建议使用环境变量:

// 使用环境变量控制是否启用 X11 托盘管理器
enableX11Tray := os.Getenv("DDE_ENABLE_X11_TRAY") != "0"

if enableX11Tray {
    XConn, err = x.NewConn()
    // ...
}

总结

这段代码目前的修改存在致命的逻辑错误(变量为 false 导致代码不执行)以及逻辑与注释不符的问题。建议根据实际需求(是否在 Wayland 下启用 XWayland 支持)重新设计 if 条件判断。

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Jan 23, 2026

TAG Bot

New tag: 6.1.72
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1001

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.

2 participants