Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 90 additions & 15 deletions panels/notification/center/package/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 : ""
Copy link

Copilot AI Dec 11, 2025

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

Suggested change
let screen = root.screen ? root.screen.name : ""
let screen = root.screen.name

Copilot uses AI. Check for mistakes.

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
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The screen geometry is recalculated every time updateMargins is called, even when only the dock's frontendRect changes. Since screen geometry changes are rare, consider caching the screen geometry and only recalculating it when the screen actually changes to improve performance.

Copilot uses AI. Check for mistakes.

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
}
//特殊处理:因为会上述计算会导致抖动
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment has a grammatical error. It says "因为会上述计算会导致抖动" which contains "会" twice. It should be "因为上述计算会导致抖动" (remove the first "会").

Suggested change
//特殊处理:因为会上述计算会导致抖动
//特殊处理:因为上述计算会导致抖动

Copilot uses AI. Check for mistakes.
case 2: { // DOCK_BOTTOM
let hideState = dockApplet.hideState
if (hideState === Dock.Hide) {
newBottomMargin = 0
} else {
newBottomMargin = dockApplet.dockSize
}
break
}
}
}

topMarginValue = newTopMargin
rightMarginValue = newRightMargin
bottomMarginValue = newBottomMargin

Copy link

Copilot AI Dec 11, 2025

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.

Suggested change

Copilot uses AI. Check for mistakes.
}

// visible: true
Expand All @@ -39,9 +111,9 @@ Window {
// height: 800
DLayerShellWindow.layer: DLayerShellWindow.LayerOverlay
DLayerShellWindow.anchors: DLayerShellWindow.AnchorRight | DLayerShellWindow.AnchorTop | DLayerShellWindow.AnchorBottom
DLayerShellWindow.topMargin: windowMargin(0)
DLayerShellWindow.rightMargin: windowMargin(1)
DLayerShellWindow.bottomMargin: windowMargin(2)
DLayerShellWindow.topMargin: topMarginValue
DLayerShellWindow.rightMargin: rightMarginValue
DLayerShellWindow.bottomMargin: bottomMarginValue
DLayerShellWindow.exclusionZone: -1
DLayerShellWindow.keyboardInteractivity: DLayerShellWindow.KeyboardInteractivityOnDemand
palette: DTK.palette
Expand Down Expand Up @@ -78,6 +150,9 @@ Window {
function onRequestClosePopup() {
Panel.close()
}
function onFrontendWindowRectChanged(frontendWindowRect) {
root.updateMargins(frontendWindowRect)
}
Comment on lines +153 to +155
Copy link

Copilot AI Dec 11, 2025

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.

Copilot uses AI. Check for mistakes.
}

Item {
Expand Down