Skip to content

fix(output): sync output item DPR on scale change synchronously - #1310

Draft
deepin-wm wants to merge 3 commits into
linuxdeepin:masterfrom
deepin-wm:agent/treeland-developer/88a7d2ae
Draft

fix(output): sync output item DPR on scale change synchronously#1310
deepin-wm wants to merge 3 commits into
linuxdeepin:masterfrom
deepin-wm:agent/treeland-developer/88a7d2ae

Conversation

@deepin-wm

@deepin-wm deepin-wm commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix the greeter/login window appearing at the wrong size (first larger, then smaller) at treeland startup when screen scaling is not 100%.

Root cause

The OutputItem's devicePixelRatio was bound in QML to output?.scale. QML bindings are evaluated lazily. When the output scale is committed (e.g. 150%) at startup, the render window's effectiveDevicePixelRatio was updated synchronously in C++ (via updateSceneDPR on scaleChanged), while the output item's size still reflected the old scale for a frame or more. Since the greeter/lock screen binds its size to the output item, this transient mismatch made the login window render at the wrong size first, then shrink to the correct size. At 100% scaling there is no scale change, so no glitch occurs.

Fix

  • Remove the lazily-evaluated QML devicePixelRatio binding in PrimaryOutput.qml and CopyOutput.qml.
  • Synchronously update the output item devicePixelRatio from C++ in Output::create() and Output::createCopy(), in lockstep with the window DPR change on WOutput::scaleChanged.

Test Plan

  1. Boot treeland with fractional screen scaling (125%/150%): the greeter must appear at the correct size immediately.
  2. Switch screen scale at runtime: no transient wrong-size frame.
  3. Verify copy (mirror) output displays correctly at non-100% scale.

issue-key: WM-306

Summary by Sourcery

Bug Fixes:

  • Synchronize primary and mirrored output item and viewport device pixel ratios with scale changes to prevent transiently incorrect greeter and lock-screen sizing or positioning.

1. Remove the devicePixelRatio QML binding that was evaluated lazily,
   causing a transient mismatch with the window DPR on scale commit.
2. Manage the output item devicePixelRatio from C++ via a direct
   connection to WOutput::scaleChanged, keeping it in sync with the
   render window effectiveDevicePixelRatio.
3. Apply the same pattern to both PrimaryOutput and CopyOutput items.

Log: Fix greeter login window appearing at the wrong size at startup
      when screen scaling is not 100%.

Influence:
1. Verify greeter/lock screen shows at correct size on startup with
   fractional scaling (e.g. 150%, 125%).
2. Verify no visual glitch when switching between different scale
   factors at runtime.
3. Verify copy (mirror) output also renders correctly at non-100%
   scale.

fix(output): 同步输出项缩放比例更新,消除启动时窗口尺寸抖动

1. 移除延迟求值的 devicePixelRatio QML 绑定,该绑定在缩放提交时
   与窗口 DPR 存在短暂不一致。
2. 通过 WOutput::scaleChanged 的 C++ 直连信号同步更新输出项缩放。
3. 同时应用于主屏和复制屏输出项。

Log: 修复屏幕缩放非 100% 时启动 greeter 登录窗口先变大再变小的
     问题。

Influence:
1. 验证启动时 greeter/锁屏界面在分数缩放下尺寸正确。
2. 验证运行时切换缩放比例无界面抖动。
3. 验证复制屏在非 100% 缩放下显示正常。

Fixes: WM-306
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-wm

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

@deepin-wm
deepin-wm marked this pull request as draft August 21, 2026 03:57
@sourcery-ai

sourcery-ai Bot commented Aug 21, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Synchronizes OutputItem devicePixelRatio with WOutput scale in C++ instead of via lazy QML bindings, preventing a transient size mismatch for greeter/login windows when output scale changes, including for mirrored outputs.

Sequence diagram for synchronous devicePixelRatio updates on WOutput scale changes

sequenceDiagram
    participant WOutput
    participant Output
    participant OutputItem

    Note over Output: During Output::create / Output::createCopy
    Output->>OutputItem: setDevicePixelRatio(output->scale())

    Note over WOutput,OutputItem: On runtime scale change
    WOutput-->>Output: scaleChanged
    Output-->>OutputItem: setDevicePixelRatio(output->scale())
Loading

File-Level Changes

Change Details Files
Move OutputItem devicePixelRatio synchronization with output scale from QML bindings to explicit C++ wiring so DPR updates happen synchronously with WOutput::scaleChanged.
  • Removed QML devicePixelRatio binding that derived DPR from output scale in the primary output item definition.
  • Removed QML devicePixelRatio binding that derived DPR from output scale in the copy/mirror output item definition.
  • In primary Output creation, connected WOutput::scaleChanged to OutputItem::setDevicePixelRatio and initialized DPR from the current output scale.
  • In copy/mirror Output creation, connected WOutput::scaleChanged to OutputItem::setDevicePixelRatio and initialized DPR from the current output scale, mirroring the primary path.
src/core/qml/PrimaryOutput.qml
src/core/qml/CopyOutput.qml
src/output/output.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

@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 left some high level feedback:

  • When connecting WOutput::scaleChanged to the lambda, consider using the overload that takes outputItem as the context object (e.g. QObject::connect(output, &WOutput::scaleChanged, outputItem, [outputItem, output] { ... });) so the connection is automatically severed if the OutputItem is destroyed and you avoid potential use-after-free captures.
  • The DPR sync logic in Output::create and Output::createCopy is now duplicated; consider extracting a small helper (e.g. setupDevicePixelRatioSync(output, outputItem)) to keep the behavior consistent and easier to maintain.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- When connecting `WOutput::scaleChanged` to the lambda, consider using the overload that takes `outputItem` as the context object (e.g. `QObject::connect(output, &WOutput::scaleChanged, outputItem, [outputItem, output] { ... });`) so the connection is automatically severed if the `OutputItem` is destroyed and you avoid potential use-after-free captures.
- The DPR sync logic in `Output::create` and `Output::createCopy` is now duplicated; consider extracting a small helper (e.g. `setupDevicePixelRatioSync(output, outputItem)`) to keep the behavior consistent and easier to maintain.

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.

The license-check CI verifies that SPDX copyright headers use a year
range spanning both the file creation and latest modification year.
CopyOutput.qml was created in 2024 and modified in 2026, but its header
only listed "2024", causing the license-check workflow to fail.
Update the copyright year to "2024-2026" to match PrimaryOutput.qml
and pass the check.

Log: 修复CopyOutput.qml版权年份不符合license-check要求的问题
The OutputViewport's devicePixelRatio was still set via a lazy QML binding
(devicePixelRatio: parent.devicePixelRatio), causing a transient size
mismatch at fractional scales. The viewport's implicit size is
output->size() / DPR, so a stale DPR makes it larger than its parent
OutputItem, and with anchors.centerIn the content is offset — the greeter
flashes from bottom-right to center at startup under 1.25 scaling.

Remove the QML binding and sync the viewport DPR from C++ in
Output::create() and Output::createCopy(), same pattern as the
OutputItem DPR fix.

Log: 修复greeter在分数缩放下的位置偏移问题
@deepin-wm
deepin-wm force-pushed the agent/treeland-developer/88a7d2ae branch from 0ba1a5b to 78cd07a Compare August 21, 2026 08:36
@deepin-bot

deepin-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 0.9.0
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1312

@deepin-bot

deepin-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 0.9.1
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #1348

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