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

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

Log:
@deepin-ci-robot
Copy link

deepin pr auto review

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

  1. 语法逻辑:
  • 语法上没有明显错误,代码结构清晰
  • 新增的 enableTraySelectionManager 变量目前被硬编码为 false,这会导致 X11 相关的初始化代码永远不会执行,这可能不是预期行为
  1. 代码质量:
  • 注释风格良好,解释了代码的意图
  • 使用了 #region 标记来组织代码块,提高了可读性
  • 变量命名清晰,符合 Go 语言规范
  • 但是 enableTraySelectionManager 变量应该考虑:
    • 改为可配置的参数而不是硬编码
    • 或者如果暂时不需要,直接移除相关代码
  1. 代码性能:
  • 代码变更对性能影响很小
  • X11 连接的初始化被条件控制,避免了不必要的资源消耗
  1. 代码安全:
  • 没有发现明显安全隐患
  • 建议改进:
    • enableTraySelectionManager 应该通过配置文件或环境变量来控制,而不是硬编码
    • 可以考虑添加错误日志,帮助调试 X11 连接问题

改进建议:

// #region init x conn
// 通过环境变量控制是否启用托盘选择管理器
enableTraySelectionManager := os.Getenv("DDE_ENABLE_TRAY_SELECTION_MANAGER") == "1"
if (os.Getenv("XDG_SESSION_TYPE") != "wayland" || os.Getenv("XDG_SESSION_TYPE") == "wayland") && enableTraySelectionManager {
    XConn, err = x.NewConn()
    if err != nil {
        logger.Warning("Failed to initialize X connection:", err)
        return err
    }
    // ... 其余代码保持不变
}
// #endregion

主要改进点:

  1. 将硬编码的布尔值改为通过环境变量控制
  2. 添加了错误日志记录
  3. 简化了 Wayland 的判断条件
  4. 保持了原有的代码结构和功能

这样的改进会让代码更加灵活和可维护,同时保持了原有的功能和安全性。

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