Skip to content

fix: set XDG_CURRENT_DESKTOP=DDE before Xsession.d runs - #250

Merged
mhduiy merged 1 commit into
masterfrom
fix/xsession-desktop-names
Nov 23, 2026
Merged

mhduiy merged 1 commit into
masterfrom
fix/xsession-desktop-names

Conversation

@hualet

@hualet hualet commented Nov 22, 2026 •

Copy link
Copy Markdown

问题现象

在 X11 会话下完成系统升级并重启登录后,依赖 XDG Desktop Portal(org.freedesktop.portal.Settings -> org.freedesktop.appearance / color-scheme)的 Electron / Chromium 应用(如 ChatGPT 桌面端、Chrome 等)不再跟随系统深色/浅色主题设置:

  • 查询 org.freedesktop.portal.Desktop 的 org.freedesktop.portal.Settings.Read('org.freedesktop.appearance', 'color-scheme') 始终返回 uint32 0(No Preference),切换系统深浅色也没有 SettingChanged 通知;
  • 同期检查 org.deepin.dde.Appearance1(GtkTheme="deepin-dark")、org.deepin.dde.XSettings1(Net/ThemeName="deepin-dark"),以及直接调用 org.freedesktop.impl.portal.desktop.dde,均正常返回 uint32 1(Prefer Dark);
  • xdg-desktop-portal-dde.service 处于 inactive (dead),而 xdg-desktop-portal-gtk.service 被拉起并接管了 Settings / FileChooser 等接口(其读取 GNOME gsettings org.gnome.desktop.interface color-scheme,在 deepin 下始终为 'default')。

手动执行 systemctl --user restart xdg-desktop-portal 后立即恢复正常。

根因分析

通过开机登录阶段的 journalctl --user 与 /proc/<pid>/environ 还原完整时序:

  1. /usr/share/xsessions/deepin.desktop 缺少 DesktopNames=DDE
    LightDM 启动 X11 会话执行 /etc/X11/Xsession.d/* 时,环境变量中尚未设置 XDG_CURRENT_DESKTOP(要等到最后的 99x11-common_start 启动 dde-session 后,由 EnvironmentsManager::init() 才注入)。
  2. 20dbus_xdg-runtime 与 95dbus_update-activation-env 同步时缺少 XDG_CURRENT_DESKTOP
    此时执行 dbus-update-activation-environment --systemd ... 导入到 D-Bus activation environment 和 systemd --user 的环境中不包含 XDG_CURRENT_DESKTOP。
  3. 升级后首次登录,98deepin-upgrade-check 抢在 dde-session 之前激活了 xdg-desktop-portal
    /etc/X11/Xsession.d/98deepin-upgrade-check(deepin-update-ui)在检测到 /tmp/deepin_update_option.json 后,会阻塞执行 /usr/bin/dde-update --wait(Qt 应用)。dde-update 启动即通过 D-Bus 激活 org.freedesktop.portal.Desktop(xdg-desktop-portal.service):
    dbus-daemon: Activating via systemd: service name='org.freedesktop.portal.Desktop' unit='xdg-desktop-portal.service' requested by ... comm="/usr/libexec/deepin/dde-update --notify-fifo /tmp/"
    
  4. xdg-desktop-portal 启动环境缺少 XDG_CURRENT_DESKTOP,永久回退至 gtk.portal
    因为 xdg-desktop-portal 进程环境中没有 XDG_CURRENT_DESKTOP,无法匹配 /usr/share/xdg-desktop-portal/dde-portals.conf(default=dde)及 dde.portal 中的 UseIn=DDE,于是记录:
    xdg-desktop-portal: Choosing gtk.portal for org.freedesktop.impl.portal.Settings as a last-resort fallback
    
    并将 Settings / FileChooser 等后端永久绑定到 xdg-desktop-portal-gtk。
  5. 随后 dde-session 启动再导入 XDG_CURRENT_DESKTOP=DDE 为时已晚
    虽然 systemctl --user show-environment 事后已经包含 XDG_CURRENT_DESKTOP=DDE,但常驻的 xdg-desktop-portal 不会重载 backend,导致整个会话期间一直走错误的 portal 后端。

解决思路与变更内容

采用标准 XDG/Xsession 机制,在进入 Xsession.d 的最早期即确立 XDG_CURRENT_DESKTOP=DDE,确保后续已有的 20dbus_xdg-runtime 和 95dbus_update-activation-env 自动将其同步给 D-Bus 与 systemd --user:

  1. misc/xsessions/deepin.desktop.in
    • 补充 Type=Application 和 DesktopNames=DDE(符合 freedesktop Desktop Entry 规范;LightDM/GDM/SDDM 等显示管理器会据此在进入 /etc/X11/Xsession 之前即设置 XDG_CURRENT_DESKTOP=DDE,且仅作用于 DDE 会话,不污染同机其他桌面环境)。
  2. misc/Xsession.d/00deepin-dde-env
    • 将 XDG_CURRENT_DESKTOP 加入 EXCLUDED_ENV,避免从 systemd --user 导入环境时被上一次会话残留的旧值覆盖;
    • 在 if [ "$1" = "/usr/bin/dde-session" ] 分支中增加兜底:若 XDG_CURRENT_DESKTOP 为空则导出 XDG_CURRENT_DESKTOP="DDE",兼容不支持 DesktopNames 的显示管理器或启动方式。

关于 #245 的补充说明

#245 试图通过 graphical-session-pre.target.wants 新增 dde-session-environment.service 注入 XDG_CURRENT_DESKTOP=DDE,存在两点局限:

  1. 在上述 98deepin-upgrade-check(dde-update)场景下,D-Bus 按需激活 xdg-desktop-portal.service 发生在 dde-session 启动之前,此时 graphical-session-pre.target 尚未被拉起,因此该 service 仍来不及执行;
  2. 挂载在全局 graphical-session-pre.target.wants 下会在用户登录同机的其他非 DDE 桌面环境时也强制写入 XDG_CURRENT_DESKTOP=DDE。

本 PR 直接从 deepin.desktop + 00deepin-dde-env 源头解决,无需新增额外 systemd unit,既覆盖 Xsession.d 阶段的早期 portal 激活,又严格限定在 DDE 会话内生效。

验证

  • sh -n misc/Xsession.d/00deepin-dde-env 语法检查通过;
  • 00deepin-dde-env 导出的变量(如原有的 QT_QPA_PLATFORM="dxcb;xcb")已实测在 98deepin-upgrade-check 激活的 xdg-desktop-portal 进程 /proc/<pid>/environ 中可见,确认 20dbus_xdg-runtime / 95dbus_update-activation-env 在 98deepin-upgrade-check 之前完成同步。

Summary by Sourcery

Set XDG_CURRENT_DESKTOP to DDE early in X11 sessions so XDG Desktop Portal consistently selects the DDE backend.

Bug Fixes:

  • Ensure XDG_CURRENT_DESKTOP is set to DDE before Xsession.d scripts and early portal activation, preventing XDG Desktop Portal from selecting the GTK backend instead of the DDE backend.

Enhancements:

  • Scope the desktop environment configuration to DDE sessions and add a fallback for display managers that do not provide DesktopNames.

Tests:

  • Validate the updated Xsession environment script syntax and confirm the environment is propagated to early portal processes.

Ref: #251 — 同步到 U3 分支(develop/2500u3)

@sourcery-ai

sourcery-ai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Configuration

Set the DDE desktop identity through session metadata and an early Xsession fallback so portal services receive it before activation-environment synchronization.

  • misc/Xsession.d/00deepin-dde-env L8, L64-66
  • misc/xsessions/deepin.desktop.in L6-7

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 reviewed your changes and they look great!


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

@mhduiy mhduiy left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

原BUG未复现,问题确实存在,验证修复有效

尾注不符合规范,我们需要带 Log: 和 pms / Issue: 尾注

1. Declare DesktopNames=DDE so LightDM sets the desktop identity before Xsession.
2. Prevent stale values from the systemd user environment from overriding it.
3. Default to DDE when launching dde-session without a desktop identity.

Log: Set the DDE desktop identity before Xsession syncs the activation environment.
Influence: Early portals can use the DDE FileChooser.

fix(session): 在 Xsession 前设置桌面标识

1. 声明 DesktopNames=DDE,让 LightDM 在进入 Xsession 前设置桌面标识。
2. 防止 systemd 用户环境中的旧值覆盖当前桌面标识。
3. 启动 dde-session 时若桌面标识为空,则补为 DDE。

Log: 在 Xsession 同步激活环境前设置 DDE 桌面标识。
PMS: BUG-382063
Influence: 提前启动的门户可使用 DDE 文件选择器。
@mhduiy
mhduiy force-pushed the fix/xsession-desktop-names branch from c2a12e1 to 72fd401 Compare November 23, 2026 05:32
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: hualet, 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 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@hualet commit msg 我直接修改了,修复验证没问题,直接合并了

@mhduiy
mhduiy merged commit 4cf1b19 into master Nov 23, 2026
28 of 29 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