fix: resolve tray submenu display position issue at screen top-left#1567
fix: resolve tray submenu display position issue at screen top-left#156718202781743 merged 1 commit intolinuxdeepin:masterfrom
Conversation
1. Fix incorrect property usage in submenu geometry calculation - use `requestedWidth`/`requestedHeight` instead of `width`/`height` 2. Ensure submenu dimensions are properly set from requested values before geometry adjustment 3. Use `setWindowGeometry()` to properly position and size the submenu window with calculated coordinates Log: Fixed tray tray submenu appearing at screen top-left corner Influence: 1. Test submenu display position with various application tray icons 2. Verify submenu positioning when screen resolution changes 3. Test submenu behavior with different popup sizes 4. Confirm submenu stays within visible screen boundaries 5. Verify multiple submenu cascade functionality fix: 修复托盘子菜单显示在屏幕左上角的问题 1. 修复子菜单几何计算中使用错误的属性 - 改用`requestedWidth`/ `requestedHeight`替代`width`/`height` 2. 确保在几何调整前使用请求尺寸正确设置子菜单尺寸 3. 使用`setWindowGeometry()`通过计算坐标正确定位和设置子菜单窗口尺寸 Log: 修复托盘子菜单显示在屏幕左上角的问题 Influence: 1. 测试不同应用托盘图标点击后的子菜单位置 2. 验证屏幕分辨率变化时子菜单位置是否正确 3. 测试不同大小弹出菜单的显示行为 4. 确认子菜单始终显示在屏幕可视区域内 5. 验证多层子菜单的级联显示功能
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts tray submenu geometry calculation to use requested dimensions and applies positioning via setWindowGeometry to prevent the submenu from appearing at the screen’s top-left corner, while updating the file copyright header years. Sequence diagram for updated tray submenu geometry and positioningsequenceDiagram
actor User
participant TrayIcon
participant SurfaceSubPopup
participant menuWindow
participant Screen
User ->> TrayIcon: click
TrayIcon ->> SurfaceSubPopup: openSubmenu
SurfaceSubPopup ->> menuWindow: updateGeometryer()
alt requested size too small
SurfaceSubPopup ->> menuWindow: read requestedWidth, requestedHeight
SurfaceSubPopup ->> menuWindow: set width = requestedWidth
SurfaceSubPopup ->> menuWindow: set height = requestedHeight
SurfaceSubPopup -->> menuWindow: return
else normal geometry calculation
SurfaceSubPopup ->> menuWindow: read requestedWidth, requestedHeight
SurfaceSubPopup ->> Screen: read virtualX, virtualY, width, height
SurfaceSubPopup ->> SurfaceSubPopup: compute bounding rect with margins
SurfaceSubPopup ->> SurfaceSubPopup: compute pos from xOffset, yOffset
SurfaceSubPopup ->> SurfaceSubPopup: newX = selectValue(pos.x, bounding.left, bounding.right - requestedWidth)
SurfaceSubPopup ->> SurfaceSubPopup: newY = selectValue(pos.y, bounding.top, bounding.bottom - requestedHeight)
SurfaceSubPopup ->> menuWindow: setWindowGeometry(newX, newY, requestedWidth, requestedHeight)
end
menuWindow -->> User: submenu displayed near tray icon within screen bounds
Flow diagram for updated submenu geometry calculationflowchart TD
A[updateGeometryer called] --> B{requestedWidth <= 10 or requestedHeight <= 10}
B -->|yes| C[Set menuWindow.width = requestedWidth]
C --> D[Set menuWindow.height = requestedHeight]
D --> E[Return]
B -->|no| F[Read screen virtualX, virtualY, width, height]
F --> G[Compute bounding rect with margins]
G --> H[Compute pos from xOffset and yOffset]
H --> I[Compute newX using selectValue with requestedWidth]
I --> J[Compute newY using selectValue with requestedHeight]
J --> K["Call menuWindow.setWindowGeometry(newX, newY, requestedWidth, requestedHeight)"]
K --> L[Submenu window positioned within screen bounds]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review这段代码的修改主要涉及窗口几何计算和尺寸更新逻辑。以下是对该diff的详细审查和改进建议: 1. 语法逻辑审查修改分析:
潜在问题:
2. 代码质量改进建议
if (menuWindow.requestedWidth <= 10 || menuWindow.requestedHeight <= 10) {
if (menuWindow.requestedWidth > 0 && menuWindow.requestedHeight > 0) {
menuWindow.width = menuWindow.requestedWidth
menuWindow.height = menuWindow.requestedHeight
}
return
}
function calculateBounds() {
let margins = 10
return Qt.rect(
menuWindow.screen.virtualX + margins,
menuWindow.screen.virtualY + margins,
menuWindow.screen.width - margins * 2,
menuWindow.screen.height - margins * 2
)
}
readonly property int minimumWindowSize: 10
readonly property int screenMargins: 103. 代码性能优化建议
let requestedWidth = menuWindow.requestedWidth
let requestedHeight = menuWindow.requestedHeight
let screen = menuWindow.screen
let bounding = Qt.rect(
screen.virtualX + screenMargins,
screen.virtualY + screenMargins,
screen.width - screenMargins * 2,
screen.height - screenMargins * 2
)4. 代码安全改进建议
if (!menuWindow || !menuWindow.screen) {
console.warn("Invalid menuWindow or screen reference")
return
}
let safeWidth = Math.max(minimumWindowSize, requestedWidth)
let safeHeight = Math.max(minimumWindowSize, requestedHeight)
try {
menuWindow.setWindowGeometry(newX, newY, safeWidth, safeHeight)
} catch (e) {
console.error("Failed to set window geometry:", e)
}综合改进后的代码示例:updateGeometryer : function () {
// 参数验证
if (!menuWindow || !menuWindow.screen) {
console.warn("Invalid menuWindow or screen reference")
return
}
// 缓存请求尺寸
let requestedWidth = menuWindow.requestedWidth
let requestedHeight = menuWindow.requestedHeight
// 最小尺寸检查
if (requestedWidth <= minimumWindowSize || requestedHeight <= minimumWindowSize) {
if (requestedWidth > 0 && requestedHeight > 0) {
menuWindow.width = requestedWidth
menuWindow.height = requestedHeight
}
return
}
// 计算安全边界
let screen = menuWindow.screen
let bounding = Qt.rect(
screen.virtualX + screenMargins,
screen.virtualY + screenMargins,
screen.width - screenMargins * 2,
screen.height - screenMargins * 2
)
// 计算新位置
let pos = Qt.point(xOffset, yOffset)
let newX = selectValue(pos.x, bounding.left, bounding.right - requestedWidth)
let newY = selectValue(pos.y, bounding.top, bounding.bottom - requestedHeight)
// 安全设置窗口几何
try {
menuWindow.setWindowGeometry(newX, newY, requestedWidth, requestedHeight)
} catch (e) {
console.error("Failed to set window geometry:", e)
}
}总结原修改方向是正确的,但可以进一步改进:
这些改进将使代码更安全、更易维护,同时保持原有功能不变。 |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
updateGeometryer, the early-return branch for smallrequestedWidth/requestedHeightnow setsmenuWindow.width/heightbut skipssetWindowGeometry(), which means position is never updated in that case; consider routing all paths through a single geometry-setting call to avoid inconsistent behavior for small menus. - You now consistently use
requestedWidth/requestedHeightfor bounds clamping but still rely onscreen.width/height; if the requested size exceeds the available bounding rect,selectValuecan return values that place part of the menu off-screen, so you may want to explicitly clamprequestedWidth/requestedHeightagainst the bounding rect before callingsetWindowGeometry().
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `updateGeometryer`, the early-return branch for small `requestedWidth`/`requestedHeight` now sets `menuWindow.width/height` but skips `setWindowGeometry()`, which means position is never updated in that case; consider routing all paths through a single geometry-setting call to avoid inconsistent behavior for small menus.
- You now consistently use `requestedWidth`/`requestedHeight` for bounds clamping but still rely on `screen.width/height`; if the requested size exceeds the available bounding rect, `selectValue` can return values that place part of the menu off-screen, so you may want to explicitly clamp `requestedWidth`/`requestedHeight` against the bounding rect before calling `setWindowGeometry()`.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, yixinshark The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
requestedWidth/requestedHeightinstead ofwidth/heightbefore geometry adjustment
setWindowGeometry()to properly position and size the submenuwindow with calculated coordinates
Log: Fixed tray tray submenu appearing at screen top-left corner
Influence:
fix: 修复托盘子菜单显示在屏幕左上角的问题
requestedWidth/requestedHeight替代width/heightsetWindowGeometry()通过计算坐标正确定位和设置子菜单窗口尺寸Log: 修复托盘子菜单显示在屏幕左上角的问题
Influence:
Summary by Sourcery
Bug Fixes: