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.

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

Log:
@deepin-ci-robot
Copy link

deepin pr auto review

我来对这段代码变更进行详细审查:

  1. 代码逻辑改进:
  • 原代码只在非Wayland环境下初始化X连接,新代码添加了enableTraySelectionManager标志来控制初始化
  • 添加了清晰的注释说明支持Wayland下的XWayland
  • 使用了#region/#endregion标记来组织代码块,提高了可读性
  1. 潜在问题:
  • enableTraySelectionManager变量被定义为false,这意味着X连接的初始化实际上永远不会执行
  • 如果意图是支持XWayland,应该根据实际需求设置enableTraySelectionManager的值,或者完全移除这个变量
  1. 建议改进:
// 建议方案1:如果确实需要支持XWayland,直接移除enableTraySelectionManager变量
if os.Getenv("XDG_SESSION_TYPE") != "wayland" || os.Getenv("XDG_SESSION_TYPE") == "wayland" {
    // init x conn
    XConn, err = x.NewConn()
    // ... 其余代码
}

// 建议方案2:如果需要更精确的控制,可以通过环境变量来控制
enableTraySelectionManager := os.Getenv("ENABLE_TRAY_SELECTION_MANAGER") == "1"
if (os.Getenv("XDG_SESSION_TYPE") != "wayland" || os.Getenv("XDG_SESSION_TYPE") == "wayland") && enableTraySelectionManager {
    // init x conn
    XConn, err = x.NewConn()
    // ... 其余代码
}
  1. 安全性考虑:
  • 当前代码没有明显的安全问题
  • 建议添加对XConn的错误处理,确保在连接失败时能够优雅地处理
  1. 性能考虑:
  • X连接的初始化是一个相对昂贵的操作,建议只在确实需要时才进行初始化
  • 可以考虑延迟初始化,即在实际需要使用X连接时再进行初始化
  1. 代码风格:
  • 注释风格良好,但建议使用统一的注释格式
  • 建议将enableTraySelectionManager定义为常量而不是变量,因为它的值在运行时不会改变

总结:这个改动的主要目的是支持Wayland下的XWayland,但当前的实现可能无法达到预期效果。建议根据实际需求调整enableTraySelectionManager的使用方式,或者采用更直接的方式来实现XWayland支持。

@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

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