Skip to content

feat: force QT_IM_MODULE=wayland for plugin process to enable Chinese…#433

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
yixinshark:fix-inputChinese
Mar 5, 2026
Merged

feat: force QT_IM_MODULE=wayland for plugin process to enable Chinese…#433
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
yixinshark:fix-inputChinese

Conversation

@yixinshark
Copy link
Contributor

@yixinshark yixinshark commented Mar 5, 2026

… input

The plugin process connects to the internal dockplugin compositor and cannot directly access the system fcitx/ibus DBus interfaces. Force the use of the native Wayland text_input protocol so that IME requests are properly proxied by the dockplugin compositor (via zwp_text_input) to the outer real compositor, enabling Chinese input in plugin windows.

feat: force QT_IM_MODULE=wayland for plugin process to enable Chinese input
Pms: BUG-323547

Summary by Sourcery

Bug Fixes:

  • Ensure input method events (including Chinese IME) in plugin windows are correctly routed via the Wayland text_input protocol instead of relying on unavailable system fcitx/ibus DBus interfaces.

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 5, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR ensures the tray plugin process always uses Qt’s native Wayland input method backend so IME (e.g., Chinese input) can be proxied correctly through the dockplugin compositor, while preserving and later restoring the original QT_IM_MODULE environment variable.

Sequence diagram for plugin IME handling via Wayland text_input

sequenceDiagram
    actor User
    participant PluginProcess
    participant DockpluginCompositor
    participant OuterCompositor
    participant IMEServer

    User->>PluginProcess: Start tray plugin
    PluginProcess->>PluginProcess: Save old QT_IM_MODULE
    PluginProcess->>PluginProcess: qputenv QT_IM_MODULE=wayland

    User->>PluginProcess: Focus input field and type characters
    PluginProcess->>DockpluginCompositor: Wayland text_input events
    DockpluginCompositor->>OuterCompositor: Proxy via zwp_text_input
    OuterCompositor->>IMEServer: Forward IME requests
    IMEServer-->>OuterCompositor: Composed text
    OuterCompositor-->>DockpluginCompositor: Composed text result
    DockpluginCompositor-->>PluginProcess: Inject committed text
    PluginProcess-->>User: Chinese text appears in plugin UI
Loading

File-Level Changes

Change Details Files
Persist and override QT_IM_MODULE in the tray plugin loader to force use of the Wayland IM backend.
  • Capture the existing QT_IM_MODULE value into the oldEnvs map alongside other environment variables before modifying the environment for the plugin process.
  • Set QT_IM_MODULE to "wayland" in the plugin loader so the plugin uses the Wayland text_input protocol for input methods.
  • Document via comments that the plugin process connects only to the internal dockplugin compositor and relies on zwp_text_input proxying to reach the real compositor for IME integration.
src/loader/main.cpp

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 - I've left some high level feedback:

  • Since you already capture the previous QT_IM_MODULE in oldEnvs, consider only overriding it when it is unset or non-wayland to avoid surprising behavior for users who explicitly configured a different input method.
  • Double-check that this unconditional QT_IM_MODULE=wayland export only runs in Wayland/plugin contexts and won't affect any X11 or non-Wayland fallback paths, otherwise guard it with an appropriate platform/session check.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Since you already capture the previous `QT_IM_MODULE` in `oldEnvs`, consider only overriding it when it is unset or non-wayland to avoid surprising behavior for users who explicitly configured a different input method.
- Double-check that this unconditional `QT_IM_MODULE=wayland` export only runs in Wayland/plugin contexts and won't affect any X11 or non-Wayland fallback paths, otherwise guard it with an appropriate platform/session check.

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 previously approved these changes Mar 5, 2026
… input

The plugin process connects to the internal dockplugin compositor and
cannot directly access the system fcitx/ibus DBus interfaces. Force the
use of the native Wayland text_input protocol so that IME requests are
properly proxied by the dockplugin compositor (via zwp_text_input) to
the outer real compositor, enabling Chinese input in plugin windows.

feat: force QT_IM_MODULE=wayland for plugin process to enable Chinese input
Pms: BUG-323547
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码的修改主要涉及版权年份的更新以及在 Wayland 环境下对输入法模块(Input Method, IM)行为的调整。以下是对这段 diff 的详细审查意见,涵盖语法逻辑、代码质量、代码性能和代码安全四个方面:

1. 语法逻辑

  • 版权年份更新SPDX-FileCopyrightText: 2023 - 2026。语法正确。将年份范围延长至 2026 年是常见的做法,表示代码预计在该时间段内持续维护。
  • 环境变量操作
    • oldEnvs["QT_IM_MODULE"] = qgetenv("QT_IM_MODULE");:正确保存了原始的输入法环境变量,确保在程序退出或需要时能够恢复(尽管当前代码片段未展示恢复逻辑,但保存是必要的)。
    • qputenv("QT_IM_MODULE", "wayland");:强制将输入法模块设置为 wayland
  • 逻辑一致性:代码逻辑与注释高度一致。注释解释了为什么要强制使用 Wayland 原生文本输入协议(插件进程连接到内部的 dockplugin 合成器,无法直接访问系统 DBus,需要通过合成器代理)。这是一个针对特定架构(Deepin/DDE 的 Dock 插件机制)的合理变通方案。

2. 代码质量

  • 注释质量:新增的注释非常清晰,解释了修改的背景(插件进程隔离)、技术限制(无法直接访问 fcitx/ibus DBus)以及解决方案(使用 zwp_text_input 协议代理)。这极大地提高了代码的可维护性。
  • 变量命名oldEnvs 和环境变量键名(如 QT_IM_MODULE)使用规范,符合 Qt 和 C++ 的常见风格。
  • 代码风格:缩进、空行使用得当,符合 C++ 和 Qt 的编码规范。

3. 代码性能

  • 运行时开销
    • qgetenvqputenv 涉及字符串操作和环境变量表的查询/修改。在 main 函数启动初期执行几次此类操作,对整体应用程序性能的影响可以忽略不计。
    • 此修改将输入法后端从可能存在的 DBus 通信(如 fcitx/ibus)切换为 Wayland 协议通信。从架构上看,通过合成器代理(dockplugin)转发请求,可能会增加一点点通信延迟,但这是为了解决进程隔离和权限问题的必要架构设计,并非代码层面的性能缺陷。

4. 代码安全

  • 环境变量污染/注入:这里使用 qputenv 设置特定的环境变量,是为了控制当前进程及其子进程的行为。由于设置的值是硬编码的字符串常量(如 "wayland"),不存在由用户输入导致的注入风险。
  • 权限与隔离:该修改实际上增强了安全性。通过强制插件进程使用内部的 dockplugin 合成器并禁用其直接访问系统级输入法 DBus 的能力,限制了插件进程的权限,符合最小权限原则。插件只能通过合成器暴露的 Wayland 协议与外界交互,减少了直接攻击系统服务的面。

改进建议

虽然代码本身没有明显错误,但为了进一步提升健壮性,可以考虑以下建议:

  1. 环境变量恢复机制的确认
    代码保存了 oldEnvs,请确保在程序退出或特定场景下(例如,如果这个 loader 会启动其他非插件的子进程),有对应的逻辑将 QT_IM_MODULE 恢复为 oldEnvs["QT_IM_MODULE"]。如果这个 loader 仅用于启动特定插件,且插件生命周期内必须保持 wayland,则当前实现是足够的。

  2. 条件编译或运行时检查(可选)
    虽然注释中提到了 "plugin process",但如果这段代码在非 Wayland 平台(如 X11)运行,强制设置 QT_IM_MODULEwayland 可能会导致输入法失效。
    建议确认 DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::IsXWindowPlatform) 的逻辑是否能完全覆盖此处的执行流。如果这段代码仅在 Wayland 下生效,建议加上明确的判断,例如:

    // 确保仅在 Wayland 平台下强制设置
    if (!DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::IsXWindowPlatform)) {
        qputenv("QT_IM_MODULE", "wayland");
    }

    注:根据 diff 下方出现的 qAddPreRoutine 中的判断,似乎这段代码是在非 XWindow 平台(即 Wayland)逻辑中生效的。如果外层已有控制,则无需重复判断,但需注意执行顺序。

  3. 魔法字符串
    "wayland""dockplugin" 等字符串在代码中多次出现。如果这些是跨模块共享的配置常量,建议定义在统一的头文件中,避免硬编码导致维护困难。例如:

    // 在某个公共头文件中
    const char* const kDockPluginDisplay = "dockplugin";
    const char* const kQtImModuleWayland = "wayland";

总结

这段代码修改逻辑清晰,注释详尽,解决了特定架构下的输入法通信问题,且未引入明显的性能或安全隐患。建议重点确认环境变量恢复策略以及平台适用性检查的完整性。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia, yixinshark

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

@yixinshark
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Mar 5, 2026

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit 47a24f1 into linuxdeepin:master Mar 5, 2026
9 of 11 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