Skip to content

fix: ensure minimum OSD window size to prevent zero-size protocol error#1593

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
mhduiy:osd
May 9, 2026
Merged

fix: ensure minimum OSD window size to prevent zero-size protocol error#1593
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
mhduiy:osd

Conversation

@mhduiy
Copy link
Copy Markdown
Contributor

@mhduiy mhduiy commented May 9, 2026

Use Math.max to enforce a minimum size of 60px for OSD window width and height when osdView is null or has zero dimensions, preventing Wayland protocol errors caused by zero-size windows.

Log: Fixed OSD window width=0 protocol error by enforcing minimum size

Influence:

  1. Test OSD notifications display correctly with various content sizes
  2. Verify no Wayland protocol error when osdView dimensions are zero
  3. Test OSD window positioning and display under different screen configurations

fix: 确保 OSD 窗口最小尺寸以防止零尺寸协议错误

使用 Math.max 为 OSD 窗口的宽度和高度设置 60px 的最小尺寸限制,当
osdView 为空或尺寸为零时防止因零尺寸窗口导致的 Wayland 协议错误。

Log: 修复 OSD 窗口 width=0 协议错误,强制设置最小尺寸

Influence:

  1. 测试不同内容大小下 OSD 通知的正常显示
  2. 验证 osdView 尺寸为零时不会出现 Wayland 协议错误
  3. 测试不同屏幕配置下 OSD 窗口的定位和显示

PMS: BUG-344893

Copy link
Copy Markdown

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

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

Please try again later or upgrade to continue using Sourcery

Comment thread panels/notification/osd/package/main.qml Outdated
BLumia
BLumia previously approved these changes May 9, 2026
Use Math.max to enforce a minimum size of 60px for OSD window width
and height when osdView is null or has zero dimensions, preventing
Wayland protocol errors caused by zero-size windows.

Log: Fixed OSD window width=0 protocol error by enforcing minimum size

Influence:
1. Test OSD notifications display correctly with various content sizes
2. Verify no Wayland protocol error when osdView dimensions are zero
3. Test OSD window positioning and display under different screen configurations

fix: 确保 OSD 窗口最小尺寸以防止零尺寸协议错误

使用 Math.max 为 OSD 窗口的宽度和高度设置 60px 的最小尺寸限制,当
osdView 为空或尺寸为零时防止因零尺寸窗口导致的 Wayland 协议错误。

Log: 修复 OSD 窗口 width=0 协议错误,强制设置最小尺寸

Influence:
1. 测试不同内容大小下 OSD 通知的正常显示
2. 验证 osdView 尺寸为零时不会出现 Wayland 协议错误
3. 测试不同屏幕配置下 OSD 窗口的定位和显示

PMS: BUG-344893
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段代码修改主要涉及版权年份更新和窗口尺寸计算逻辑的优化。以下是详细的审查意见和改进建议:

1. 语法逻辑审查

修改点:

// 原代码
width: osdView ? osdView.width : 100
height: osdView ? osdView.height : 100

// 新代码
width: Math.max(osdView?.width ?? 0, 60)
height: Math.max(osdView?.height ?? 0, 60)

分析:

  • 新代码使用了可选链操作符 ?. 和空值合并操作符 ??,这是 QML 5.15+ 支持的语法
  • 逻辑上更严谨:当 osdView 为 null/undefined 时,?.width 会返回 undefined,然后 ?? 0 会提供默认值 0
  • Math.max() 确保窗口不会小于 60x60 像素

潜在问题:

  • 如果项目需要兼容 QML 5.15 以下版本,这段代码会报错
  • 原代码的 100 像素默认值被改为 60,需要确认这是否符合设计要求

2. 代码质量审查

优点:

  1. 更简洁的表达方式,减少了条件判断
  2. 使用现代 JavaScript/QML 语法,代码可读性更好
  3. 明确了最小尺寸限制(60x60)

建议改进:

  1. 考虑将最小尺寸值(60)提取为常量,便于统一维护:
readonly property int minWindowSize: 60

width: Math.max(osdView?.width ?? 0, minWindowSize)
height: Math.max(osdView?.height ?? 0, minWindowSize)
  1. 如果 osdView 可能为 null 的情况很少,可以考虑在组件初始化时就确保它不为 null,从而简化逻辑

3. 代码性能审查

性能影响:

  • 可选链操作符 ?. 的性能略优于三元运算符 ? :,但差异极小
  • Math.max() 是原生函数,性能良好
  • 这些属性绑定会在 osdView 或其尺寸变化时重新计算,这是 QML 的正常行为

优化建议:
如果 osdView 的尺寸频繁变化,可以考虑使用 Binding 元素延迟绑定:

Binding {
    target: root
    property: "width"
    value: Math.max(osdView?.width ?? 0, minWindowSize)
    when: osdView !== null
}

4. 代码安全审查

安全考虑:

  1. 空值安全:新代码更好地处理了 osdView 为 null 的情况
  2. 边界保护Math.max() 确保窗口不会变得太小,避免 UI 异常
  3. 类型安全?? 操作符确保最终值是数字类型

潜在风险:

  1. 如果 osdView.width 返回非数字值(如字符串"100"),Math.max() 可能会产生意外结果
  2. 建议添加类型检查:
width: Math.max(Number(osdView?.width ?? 0) || 0, minWindowSize)
height: Math.max(Number(osdView?.height ?? 0) || 0, minWindowSize)

综合改进建议代码

Window {
    id: root
    readonly property int minWindowSize: 60
    
    width: Math.max(Number(osdView?.width ?? 0) || 0, minWindowSize)
    height: Math.max(Number(osdView?.height ?? 0) || 0, minWindowSize)
    
    // ... 其他代码
}

总结

这次修改总体上是积极的改进,使用了更现代的语法并增强了代码的健壮性。主要需要注意:

  1. 确认项目使用的 QML 版本支持新语法
  2. 考虑将魔法数字(60)提取为常量
  3. 添加类型检查可以进一步提高安全性
  4. 确认最小尺寸(60)是否符合设计规范

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia, 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
Copy link
Copy Markdown
Contributor Author

mhduiy commented May 9, 2026

/forcemerge

@deepin-bot
Copy link
Copy Markdown

deepin-bot Bot commented May 9, 2026

This pr force merged! (status: blocked)

@deepin-bot deepin-bot Bot merged commit 66d5690 into linuxdeepin:master May 9, 2026
9 of 12 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