Skip to content

fix: correct window flags to prevent KWin animation on screen indicator#3257

Open
tsic404 wants to merge 1 commit into
linuxdeepin:masterfrom
tsic404:master
Open

fix: correct window flags to prevent KWin animation on screen indicator#3257
tsic404 wants to merge 1 commit into
linuxdeepin:masterfrom
tsic404:master

Conversation

@tsic404

@tsic404 tsic404 commented May 27, 2026

Copy link
Copy Markdown
Contributor

The previous window flags included Qt.FramelessWindowHint and Qt.SplashScreen, which caused KWin to apply unnecessary window animations to the screen indicator windows. Changed to use Qt.Tool instead, which is more appropriate for transient helper windows and prevents KWin from adding animations.

Log: Fixed incorrect window type causing unwanted KWin animations

Influence:

  1. Verify screen indicator displays correctly without animation effects
  2. Test screen indicator visibility on multi-monitor setups
  3. Confirm window stays on top as expected
  4. Verify screen indicator closes properly when timer elapses

fix: 修复窗口类型错误导致kwin给屏幕指示器窗口添加动画

之前的窗口标志包含了Qt.FramelessWindowHint和Qt.SplashScreen,导致KWin为 屏幕指示器窗口应用了不必要的动画。改为使用Qt.Tool,这个类型更适合临时辅
助窗口,可以防止KWin添加动画效果。

Log: 修复错误的窗口类型导致KWin动画问题

Influence:

  1. 验证屏幕指示器正常显示且无动画效果
  2. 测试多显示器设置下的屏幕指示器可见性
  3. 确认窗口保持置顶功能正常
  4. 验证屏幕指示器在计时结束后正常关闭

PMS: BUG-360795

@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.

Sorry @tsic404, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

The previous window flags included Qt.FramelessWindowHint and
Qt.SplashScreen, which caused KWin to apply unnecessary window
animations to the screen indicator windows. Changed to use Qt.Tool
instead, which is more appropriate for transient helper windows and
prevents KWin from adding animations.

Log: Fixed incorrect window type causing unwanted KWin animations

Influence:
1. Verify screen indicator displays correctly without animation effects
2. Test screen indicator visibility on multi-monitor setups
3. Confirm window stays on top as expected
4. Verify screen indicator closes properly when timer elapses

fix: 修复窗口类型错误导致kwin给屏幕指示器窗口添加动画

之前的窗口标志包含了Qt.FramelessWindowHint和Qt.SplashScreen,导致KWin为
屏幕指示器窗口应用了不必要的动画。改为使用Qt.Tool,这个类型更适合临时辅
助窗口,可以防止KWin添加动画效果。

Log: 修复错误的窗口类型导致KWin动画问题

Influence:
1. 验证屏幕指示器正常显示且无动画效果
2. 测试多显示器设置下的屏幕指示器可见性
3. 确认窗口保持置顶功能正常
4. 验证屏幕指示器在计时结束后正常关闭

PMS: BUG-360795
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

你好!我是CodeGeeX。我已仔细审查了你提供的Git Diff输入。本次修改主要针对一个QML界面指示器(ScreenIndicator.qml),变更了版权年份以及窗口的标志位。

以下是我从语法逻辑、代码质量、代码性能和代码安全四个维度提出的详细审查意见和改进建议:

1. 语法逻辑

  • 窗口标志位逻辑变更分析
    • 移除的标志Qt.CoverWindowQt.SplashScreenQt.FramelessWindowHint
    • 新增的标志Qt.Tool
    • 潜在逻辑问题:原代码使用了 Qt.FramelessWindowHint 来确保窗口没有系统默认的标题栏和边框。而新代码移除了该标志,仅保留了 Qt.Tool。虽然在某些窗口管理系统(如Wayland或特定桌面环境)中,Qt.Tool 类型的窗口可能默认不绘制边框,但在传统的X11环境中,如果没有 Qt.FramelessWindowHint,窗口极大概率会带有系统边框。对于一个屏幕指示器(通常是需要全屏覆盖或悬浮的色块)来说,出现边框是严重的逻辑错误。
    • 建议:确认目标运行环境的表现。如果该指示器需要保持无边框状态,强烈建议加回 Qt.FramelessWindowHint

2. 代码质量

  • 魔法数字
    • 代码中出现了硬编码的尺寸 width: 10height: 10。这是一个典型的“魔法数字”,其他阅读代码的人无法直观理解为什么是10。
    • 建议:将其提取为具有语义的常量,例如 property int borderWidth: 10
  • 代码重复(DRY原则)
    • 三个内部 Window 的定义高度相似,且 flags 属性被重复修改了三次。如果未来需要再次调整窗口标志,容易遗漏。
    • 建议:可以考虑将内部窗口提取为独立的自定义组件(如 BorderIndicator.qml),或者在根窗口中定义一个属性 property int commonFlags: Qt.WindowStaysOnTopHint | Qt.Tool | Qt.X11BypassWindowManagerHint,然后在内层窗口中使用 flags: root.commonFlags,提高可维护性。

3. 代码性能

  • 多窗口实例化开销
    • 为了实现屏幕指示器效果,当前代码实例化了4个 Window 对象(1个根窗口 + 3个子窗口)。在Qt中,每个 Window 对象都会占用独立的GPU资源和图形上下文,频繁创建和销毁多个顶层窗口会带来一定的性能开销。
    • 建议:如果业务场景允许,考虑只使用一个顶层窗口,内部通过 ItemRectangle 配合锚点布局来实现四边指示器效果。单窗口渲染的性能通常优于多窗口叠加。

4. 代码安全

  • X11BypassWindowManagerHint 的滥用风险
    • Qt.X11BypassWindowManagerHint 会使得窗口完全绕过窗口管理器的控制。这会导致窗口无法被正常的快捷键(如Alt+F4关闭)、任务栏或窗口切换器管理。
    • 安全与稳定性风险:如果程序逻辑出现死锁或UI卡死,用户可能无法通过常规系统操作关闭该置顶窗口,导致屏幕被遮挡,甚至需要强制注销或重启。此外,绕过窗口管理器可能导致该窗口在特定安全策略下被拒绝渲染。
    • 建议:评估是否真的必须使用 X11BypassWindowManagerHint。如果只是为了置顶和避免被遮挡,Qt.WindowStaysOnTopHint 配合 Qt.FramelessWindowHint 通常已经足够。仅在需要实现类似锁屏或底层拦截的极端场景下才建议使用该标志。

💡 综合改进建议代码

结合上述分析,我为你提供一份优化后的代码示例(假设仍需保留多窗口结构,并修复了无边框和代码冗余问题):

// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.15

import org.deepin.dcc 1.0

Window {
    id: root

    // 提取公共标志位,便于维护。加回了 FramelessWindowHint 保证无边框
    property int indicatorFlags: Qt.WindowStaysOnTopHint | Qt.Tool | Qt.FramelessWindowHint | Qt.X11BypassWindowManagerHint
    
    // 提取魔法数字,增强可读性
    property int borderIndicatorWidth: 10

    flags: indicatorFlags
    color: "#2ca7f8"
    x: screen.virtualX
    y: screen.virtualY
    width: screen.width
    height: screen.height

    Timer {
        interval: 2000
        running: true
        onTriggered: root.close()
    }

    // 顶部指示器
    Window {
        flags: root.indicatorFlags
        visible: root.visible
        color: root.color
        screen: root.screen
        x: screen.virtualX
        y: screen.virtualY
        width: screen.width
        height: root.borderIndicatorWidth
    }

    // 底部指示器
    Window {
        flags: root.indicatorFlags
        visible: root.visible
        color: root.color
        screen: root.screen
        x: screen.virtualX
        y: screen.virtualY + screen.height - root.borderIndicatorWidth
        width: screen.width
        height: root.borderIndicatorWidth
    }

    // 左侧指示器
    Window {
        flags: root.indicatorFlags
        visible: root.visible
        color: root.color
        screen: root.screen
        x: screen.virtualX
        y: screen.virtualY
        width: root.borderIndicatorWidth
        height: screen.height
    }

    // 右侧指示器
    Window {
        flags: root.indicatorFlags
        visible: root.visible
        color: root.color
        screen: root.screen
        x: screen.virtualX + screen.width - root.borderIndicatorWidth
        y: screen.virtualY
        width: root.borderIndicatorWidth
        height: screen.height
    }
}

主要改动点说明

  1. 恢复了 Qt.FramelessWindowHint,防止在X11下出现窗口边框。
  2. flags 提取为根组件的 indicatorFlags 属性,子窗口直接引用,减少重复代码。
  3. 将硬编码的 10 替换为语义化的 borderIndicatorWidth 属性。
  4. 补充了Diff中未展示但推测存在的第四个边缘窗口(右侧),以保证逻辑完整性。

@caixr23 caixr23 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.

等发布

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: tsic404

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-bot

deepin-bot Bot commented Jun 4, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.90
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3279

@deepin-bot

deepin-bot Bot commented Jun 4, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.91
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3281

@deepin-bot

deepin-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.92
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3292

@deepin-bot

deepin-bot Bot commented Jun 12, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.93
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3293

@deepin-bot

deepin-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.94
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3301

@deepin-bot

deepin-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.95
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3305

@deepin-bot

deepin-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.96
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3314

@deepin-bot

deepin-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.97
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3322

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