From 74f15f8c5e6bf30a990ebf71def1c29581e67c85 Mon Sep 17 00:00:00 2001
From: luoqing <luoqing@kylinsec.com.cn>
Date: Tue, 17 Oct 2023 09:33:24 +0800
Subject: [PATCH] fix(tray):Fixed an issue where the popup was in the wrong
 position when the tray was at the top of the screen
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- 修复托盘在屏幕顶部时，弹窗位置不对的问题

Related #17279
---
 .../src/system-tray/audio-system-tray.cpp     | 32 +++++++++++++------
 .../audio/src/system-tray/audio-system-tray.h |  2 +-
 plugins/network/src/tray/network-tray.cpp     | 16 +++++++---
 3 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/plugins/audio/src/system-tray/audio-system-tray.cpp b/plugins/audio/src/system-tray/audio-system-tray.cpp
index 0c6aca6..cc4015d 100644
--- a/plugins/audio/src/system-tray/audio-system-tray.cpp
+++ b/plugins/audio/src/system-tray/audio-system-tray.cpp
@@ -162,7 +162,19 @@ void AudioSystemTray::setVolumeSettingPos()
     int pageWidth = 300;
     int pageHeight = 66;
 
-    m_volumenPopup->setGeometry(xTray - pageWidth / 2, yTray - pageHeight - offset, pageWidth, pageHeight);
+    int showPosY; 
+    // 托盘程序在顶端
+    if(m_yTray == 0)
+    {
+        showPosY  = m_heightTray - offset;
+    }
+    else
+    {
+        //托盘程序在底部
+        showPosY = m_yTray - pageHeight - offset;
+    }
+
+    m_volumenPopup->setGeometry(m_xTray - pageWidth / 2, showPosY, pageWidth, pageHeight);
 }
 
 void AudioSystemTray::handleMixedSettingClicked()
@@ -180,7 +192,7 @@ void AudioSystemTray::setMixedSettingPos()
     int width = m_mixedPopup->sizeHint().width();
 
     m_mixedPopup->setFixedHeight(height + offset * 2);
-    m_mixedPopup->move(xTray - width / 2, yTray - height - offset);
+    m_mixedPopup->move(m_xTray - width / 2, m_yTray - height - offset);
 }
 
 void AudioSystemTray::handleAdjustedMixedSettingPageSize()
@@ -228,15 +240,15 @@ void AudioSystemTray::getTrayGeometry()
             }
         }
     }
-    heightTray = static_cast<int>(height);
-    widthTray = static_cast<int>(width);
-    xTray = static_cast<int>(x);
-    yTray = static_cast<int>(y);
+    m_heightTray = static_cast<int>(height);
+    m_widthTray = static_cast<int>(width);
+    m_xTray = static_cast<int>(x);
+    m_yTray = static_cast<int>(y);
     KLOG_DEBUG() << "getTrayGeometry ";
-    KLOG_DEBUG() << "heightTray" << heightTray;
-    KLOG_DEBUG() << "widthTray" << widthTray;
-    KLOG_DEBUG() << "xTray" << xTray;
-    KLOG_DEBUG() << "yTray" << yTray;
+    KLOG_DEBUG() << "heightTray" << m_heightTray;
+    KLOG_DEBUG() << "widthTray" << m_widthTray;
+    KLOG_DEBUG() << "xTray" << m_xTray;
+    KLOG_DEBUG() << "yTray" << m_yTray;
 }
 
 // XXX:频繁调用函数,需要优化
diff --git a/plugins/audio/src/system-tray/audio-system-tray.h b/plugins/audio/src/system-tray/audio-system-tray.h
index a61284e..fd5f150 100644
--- a/plugins/audio/src/system-tray/audio-system-tray.h
+++ b/plugins/audio/src/system-tray/audio-system-tray.h
@@ -70,7 +70,7 @@ private:
     AudioInterface* m_audioInterface;
 
     QString m_colorTheme;
-    int xTray, yTray, heightTray, widthTray;
+    int m_xTray, m_yTray, m_heightTray, m_widthTray;
 
     QDBusServiceWatcher *m_dbusServiceWatcher;
 };
diff --git a/plugins/network/src/tray/network-tray.cpp b/plugins/network/src/tray/network-tray.cpp
index dd5ff12..c43d8ff 100644
--- a/plugins/network/src/tray/network-tray.cpp
+++ b/plugins/network/src/tray/network-tray.cpp
@@ -305,16 +305,24 @@ void NetworkTray::showOrHideTrayPage()
 
 void NetworkTray::setTrayPagePos()
 {
-    // KLOG_DEBUG() << "this->sizeHint():" << this->sizeHint();
-    // KLOG_DEBUG() << "this->size():" << this->size();
-
     int pageHeight = this->size().height();
     int pageWidth = this->size().width();
 
     getTrayGeometry();
     // 抵消KiranRoundedTrayPopup的margin
     int offset = 8;
-    this->move(m_xTray - pageWidth / 2, m_yTray - pageHeight + offset);
+    int showPosY; 
+    // 托盘程序在顶端
+    if(m_yTray == 0)
+    {
+        showPosY  = m_heightTray - offset;
+    }
+    else
+    {
+        //托盘程序在底部
+        showPosY = m_yTray - pageHeight + offset;
+    }
+    this->move(m_xTray - pageWidth / 2, showPosY);
 }
 
 void NetworkTray::getTrayGeometry()
-- 
2.33.0

