Skip to content

fix(quake): pin quake window to screen top on Treeland - #585

Closed
JWWTSL wants to merge 1 commit into
linuxdeepin:masterfrom
JWWTSL:fix/344337-quake-window-top-position
Closed

JWWTSL wants to merge 1 commit into
linuxdeepin:masterfrom
JWWTSL:fix/344337-quake-window-top-position

Conversation

@JWWTSL

@JWWTSL JWWTSL commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Wayland toplevels cannot be positioned by the client, so QWidget::move() is a no-op and the quake window gets auto-placed in the middle of the screen instead of the top (BUG-344337).

This change pins the quake window to the top-left of the cursor screen via the Treeland private protocol treeland_dde_shell_unstable_v2:

  • Adds TreelandWindowPositioner which submits set_position_hint(output, 0, 0) before the surface is mapped.
  • The hint only affects the initial placement, so it is re-submitted whenever Qt recreates the wl_surface (on every hide/show cycle).
  • Falls back to no-op behavior when the compositor does not expose the protocol (non-Treeland Wayland) or when the build lacks libwayland-dev/wayland-scanner.
  • X11 behavior is unchanged.

Test plan

  • Release build with the feature enabled.
  • Unit tests (434 tests, 0 failed), including new UT_TreelandWindowPositioner_Test (7 cases).
  • Verified on Treeland: quake window appears at the top on first show and after hide/re-show, with no flicker.

Related

  • PMS: BUG-344337

Summary by Sourcery

Pin the quake window to the top of its cursor-selected screen on Treeland while preserving existing behavior on unsupported platforms.

New Features:

  • Pin the quake window to the top-left of the cursor’s screen on Treeland Wayland sessions using the compositor’s positioning protocol.

Bug Fixes:

  • Prevent the quake window from being automatically placed in the middle of the screen on Treeland.
  • Reapply the placement hint when Wayland recreates the window surface after hide/show cycles.

Enhancements:

  • Provide a no-op fallback for non-Treeland Wayland, X11, and builds without the optional Wayland development dependencies.

Build:

  • Conditionally generate and compile the Treeland shell protocol bindings when the required Wayland and Qt private development components are available.

Tests:

  • Add unit coverage for Treeland window positioning support, screen selection, and event handling.

Wayland toplevels cannot be positioned by the client, so QWidget::move()
is a no-op and the quake window is auto-placed in the middle of the screen.
Use the treeland_dde_shell_unstable_v2 protocol to submit a fixed position
hint before the surface is mapped, and resubmit it whenever Qt recreates
the wl_surface (on every hide/show cycle).

Wayland 顶层窗口无法由客户端指定位置,move() 在 Wayland 下无效,导致雷神
窗口被自动放置到屏幕中间。改用 treeland_dde_shell_unstable_v2 协议在窗口
映射前提交固定位置提示,并在 wl_surface 每次重建(隐藏/再次显示)时重新提交。

Log: 修复雷神窗口在 Treeland 下显示在屏幕中间且闪烁的问题
PMS: BUG-344337
Influence: 仅影响 Treeland 下的雷神窗口显示位置;X11 与其他 Wayland 合成器
行为不变,编译时缺少 libwayland-dev/wayland-scanner 时该特性自动关闭。
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: JWWTSL

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

sourcery-ai Bot commented Oct 27, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR introduces an optional Treeland-specific Wayland positioner that uses the private dde-shell protocol to pin the quake window to the top-left of the cursor’s output, reapplying the initial-placement hint across native-surface recreation while preserving existing behavior on unsupported platforms and X11.

Sequence diagram for Treeland quake window positioning

sequenceDiagram
    participant User
    participant QuakeWindow
    participant TreelandWindowPositioner
    participant WaylandSurface
    participant Treeland

    User->>QuakeWindow: showEvent
    QuakeWindow->>TreelandWindowPositioner: screenForPosition
    QuakeWindow->>TreelandWindowPositioner: setTargetScreen
    QuakeWindow->>TreelandWindowPositioner: applyPosition
    TreelandWindowPositioner->>Treeland: ensureManager
    TreelandWindowPositioner->>WaylandSurface: createShellSurface
    TreelandWindowPositioner->>Treeland: set_role(normal)
    TreelandWindowPositioner->>Treeland: set_position_hint(output, 0, 0)
    Treeland-->>WaylandSurface: map at output top-left
Loading

Sequence diagram for reapplying placement after surface recreation

sequenceDiagram
    participant QuakeWindow
    participant TreelandWindowPositioner
    participant WaylandSurface
    participant Treeland

    QuakeWindow->>WaylandSurface: hide/show recreates surface
    WaylandSurface-->>TreelandWindowPositioner: surfaceCreated
    TreelandWindowPositioner->>Treeland: createShellSurface
    TreelandWindowPositioner->>Treeland: set_position_hint(output, 0, 0)
    Treeland-->>WaylandSurface: map at output top-left
Loading

File-Level Changes

Change Details Files
Adds optional Treeland protocol integration to request initial top-left placement for the quake window on its cursor-selected output.
  • Adds the Treeland dde-shell v2 protocol definition and generates Wayland client bindings when dependencies and Qt private headers are available.
  • Discovers the compositor protocol through a dedicated Wayland event queue, binds the manager, creates a shell surface for the Qt Wayland surface, selects the normal role, and submits a zero-coordinate output-relative position hint.
  • Recreates the shell-surface association and reapplies the hint when Qt recreates the native surface, covering hide/show cycles.
  • Keeps non-Wayland, non-Treeland, X11, and builds without Wayland development tooling on no-op paths.
3rdparty/treeland-protocols/treeland-dde-shell-unstable-v2.xml
CMakeLists.txt
debian/control
src/main/treelandwindowpositioner.cpp
src/main/treelandwindowpositioner.h
Integrates position handling into quake-window show lifecycle and resolves the target output from the cursor location.
  • Creates a positioner for each quake window.
  • Before each show mapping, selects the screen under the cursor and requests compositor placement at its top-left.
  • Retains the existing window behavior when the positioner is unsupported or unavailable.
src/main/mainwindow.cpp
src/main/mainwindow.h
Adds unit-test coverage for the positioner’s fallback and screen-resolution behavior.
  • Registers the new test suite and compiles the positioner into the test target.
  • Tests unsupported-platform no-op behavior, cursor-screen lookup, widget-screen fallback, null-window handling, and event-filter delegation.
tests/CMakeLists.txt
tests/src/common/ut_defines.h
tests/src/main/ut_treelandwindowpositioner_test.cpp
tests/src/main/ut_treelandwindowpositioner_test.h

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 ✨

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 95 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本 PR 为 deepin-terminal 的雷神窗口(QuakeWindow)在 Wayland/Treeland 环境下新增了通过 treeland_dde_shell_unstable_v2 协议固定窗口位置的能力。代码结构清晰,条件编译处理规范, 资源管理(Wayland proxy 生命周期)处理得当,含完整单元测试。仅存在少量轻微问题 (error path 资源泄漏、测试文件版权年份),不影响功能正确性与安全性。无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['在 ensureManager() 中,若 wl_display_get_registry 失败,应先释放已创建的 m_eventQueue 再返回,或调整 m_managerQueried 的赋值时机使其仅在全部成功后置 true']


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['更新测试文件版权头中的年份为 2025']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: []


💡 改进建议代码示例

// 修复 ensureManager() 中的 error path 资源泄漏
void TreelandWindowPositioner::ensureManager()
{
    if (m_managerQueried)
        return;

    auto *platformNative = QGuiApplication::platformNativeInterface();
    if (!platformNative)
        return;

    m_display = static_cast<wl_display *>(
        platformNative->nativeResourceForWindow("display", windowOf(m_window)));
    if (!m_display)
        return;

    m_eventQueue = wl_display_create_queue(m_display);
    if (!m_eventQueue)
        return;

    m_registry = wl_display_get_registry(m_display);
    if (!m_registry) {
        // 释放已创建的 event queue,避免泄漏
        wl_event_queue_destroy(m_eventQueue);
        m_eventQueue = nullptr;
        return;
    }

    m_managerQueried = true;

    wl_proxy_set_queue(reinterpret_cast<wl_proxy *>(m_registry), m_eventQueue);

    static const wl_registry_listener listener = {
        &TreelandWindowPositioner::onRegistryGlobal,
        nullptr,
    };
    wl_registry_add_listener(m_registry, &listener, this);
    wl_display_roundtrip_queue(m_display, m_eventQueue);
}

本报告由 AI 代码审查工具自动生成

@deepin-bot

deepin-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.5.41
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #588

@deepin-bot

deepin-bot Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.5.42
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #594

@lzwind lzwind closed this Nov 23, 2026
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