-
Notifications
You must be signed in to change notification settings - Fork 56
fix: improve notification center margin calculation #1363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,25 +9,97 @@ import org.deepin.dtk 1.0 | |||||
| import org.deepin.ds 1.0 | ||||||
| import org.deepin.ds.notification | ||||||
| import org.deepin.ds.notificationcenter | ||||||
| import org.deepin.ds.dock 1.0 | ||||||
|
|
||||||
| Window { | ||||||
| id: root | ||||||
|
|
||||||
| function windowMargin(position) { | ||||||
| property int topMarginValue: 0 | ||||||
| property int rightMarginValue: 0 | ||||||
| property int bottomMarginValue: 0 | ||||||
|
|
||||||
| function updateMargins(frontendRect) { | ||||||
| let dockApplet = DS.applet("org.deepin.ds.dock") | ||||||
| if (!dockApplet) | ||||||
| return 0 | ||||||
| if (!dockApplet || !root.screen) { | ||||||
| topMarginValue = 0 | ||||||
| rightMarginValue = 0 | ||||||
| bottomMarginValue = 0 | ||||||
| return | ||||||
| } | ||||||
|
|
||||||
| let dockScreen = dockApplet.screenName | ||||||
| let screen = root.screen.name | ||||||
| let dockHideState = dockApplet.hideState | ||||||
| let dockIsHide = dockHideState === 2 | ||||||
| if (dockScreen !== screen || dockIsHide) | ||||||
| return 0 | ||||||
|
|
||||||
| let dockSize = dockApplet.dockSize | ||||||
| let dockPosition = dockApplet.position | ||||||
| return dockPosition === position ? dockSize : 0 | ||||||
| let screen = root.screen ? root.screen.name : "" | ||||||
|
|
||||||
| if (dockScreen !== screen) { | ||||||
| topMarginValue = 0 | ||||||
| rightMarginValue = 0 | ||||||
| bottomMarginValue = 0 | ||||||
| return | ||||||
| } | ||||||
|
|
||||||
| if (!frontendRect) { | ||||||
| frontendRect = dockApplet.frontendWindowRect | ||||||
| } | ||||||
|
|
||||||
| if (!frontendRect) { | ||||||
| topMarginValue = 0 | ||||||
| rightMarginValue = 0 | ||||||
| bottomMarginValue = 0 | ||||||
| return | ||||||
| } | ||||||
|
|
||||||
| // frontendRect is already in device pixels from dockpanel.cpp | ||||||
| // We need to convert it back to logical pixels | ||||||
| let dpr = root.screen.devicePixelRatio | ||||||
| let dockGeometry = Qt.rect( | ||||||
| frontendRect.x / dpr, | ||||||
| frontendRect.y / dpr, | ||||||
| frontendRect.width / dpr, | ||||||
| frontendRect.height / dpr | ||||||
| ) | ||||||
|
|
||||||
| // Get screen geometry in logical pixels | ||||||
| let screenGeometry = Qt.rect( | ||||||
| root.screen.virtualX, | ||||||
| root.screen.virtualY, | ||||||
| root.screen.width, | ||||||
| root.screen.height | ||||||
| ) | ||||||
|
Comment on lines
+62
to
+67
|
||||||
|
|
||||||
| let newTopMargin = 0 | ||||||
| let newRightMargin = 0 | ||||||
| let newBottomMargin = 0 | ||||||
|
|
||||||
| if (dockGeometry.width > 0 && dockGeometry.height > 0) { | ||||||
| let dockPosition = dockApplet.position | ||||||
| switch (dockPosition) { | ||||||
| case 0: { // DOCK_TOP | ||||||
| let visibleHeight = Math.max(0, dockGeometry.y + dockGeometry.height - screenGeometry.y) | ||||||
| newTopMargin = visibleHeight | ||||||
| break | ||||||
| } | ||||||
| case 1: { // DOCK_RIGHT | ||||||
| let visibleWidth = Math.max(0, screenGeometry.x + screenGeometry.width - dockGeometry.x) | ||||||
| newRightMargin = visibleWidth | ||||||
| break | ||||||
| } | ||||||
| //特殊处理:因为会上述计算会导致抖动 | ||||||
|
||||||
| //特殊处理:因为会上述计算会导致抖动 | |
| //特殊处理:因为上述计算会导致抖动 |
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is trailing whitespace at the end of this line. This should be removed to maintain code cleanliness.
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The updateMargins function is only called when frontendWindowRectChanged signal is emitted, but it's never called during component initialization or when the screen changes. This means the notification center may have incorrect margins when first displayed or when moved to a different screen. Consider calling updateMargins in a Component.onCompleted handler and in the onScreenChanged handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The screen name check on line 31 is redundant. Line 23 already checks if root.screen is falsy and returns early, so by this point root.screen is guaranteed to be non-null. The ternary operator "root.screen ? root.screen.name : ''" can be simplified to just "root.screen.name".