From f90a26f254c3069cf3e7b614a0cd20a43cc887a3 Mon Sep 17 00:00:00 2001 From: wjyrich Date: Fri, 28 Nov 2025 13:20:24 +0800 Subject: [PATCH] fix: improve notification center margin calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Replaced simple windowMargin function with comprehensive updateMargins function 2. Added proper handling for dock visibility and position 3. Implemented device pixel ratio conversion for accurate geometry calculations 4. Added special handling for bottom dock to prevent flickering 5. Added properties to store margin values instead of recalculating each time 6. Connected to frontendWindowRectChanged signal for dynamic updates Log: Fixed notification center positioning issues when dock is visible Influence: 1. Test notification center display with dock in different positions (top, right, bottom) 2. Verify notification center margins adjust correctly when dock is hidden/shown 3. Test on screens with different device pixel ratios 4. Check that notification center doesn't flicker when dock state changes 5. Verify notification center positioning when dock is on different screens fix: 改进通知中心边距计算 1. 将简单的 windowMargin 函数替换为全面的 updateMargins 函数 2. 添加对任务栏可见性和位置的正确处理 3. 实现设备像素比转换以确保几何计算准确 4. 为底部任务栏添加特殊处理以防止闪烁 5. 添加属性存储边距值而不是每次都重新计算 6. 连接 frontendWindowRectChanged 信号以实现动态更新 Log: 修复任务栏可见时通知中心定位问题 Influence: 1. 测试任务栏在不同位置(顶部、右侧、底部)时通知中心的显示 2. 验证任务栏隐藏/显示时通知中心边距是否正确调整 3. 在不同设备像素比的屏幕上进行测试 4. 检查任务栏状态变化时通知中心不会闪烁 5. 验证任务栏在不同屏幕时通知中心的定位 PMS: BUG-340799 --- panels/notification/center/package/main.qml | 105 +++++++++++++++++--- 1 file changed, 90 insertions(+), 15 deletions(-) diff --git a/panels/notification/center/package/main.qml b/panels/notification/center/package/main.qml index c63f4790c..9a5df5a4d 100644 --- a/panels/notification/center/package/main.qml +++ b/panels/notification/center/package/main.qml @@ -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 + ) + + 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 + } + //特殊处理:因为会上述计算会导致抖动 + 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 + } // visible: true @@ -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 @@ -78,6 +150,9 @@ Window { function onRequestClosePopup() { Panel.close() } + function onFrontendWindowRectChanged(frontendWindowRect) { + root.updateMargins(frontendWindowRect) + } } Item {