Skip to content

Commit 1e489a7

Browse files
committed
perf: optimize dock network plugin panel height resizing frequency
Introduced a QTimer to debounce the updateSize calls within the DockContentWidget. This heavily reduces the number of layout and geometry calculation events fired to the compositor (max 1 per 150ms) when rapidly scanning and appending Wi-Fi hotspots, thereby fixing visual flickering issues in Wayland without leaving dead space. 性能:优化任务栏网络插件面板高度调整频率 在 DockContentWidget 内部引入了 QTimer 对 updateSize 调用进行节流 (防抖)处理。扫描并连续追加 Wi-Fi 热点时,大幅减少发往合成器的 布局与几何计算事件(受限于最多 150ms 一次),从而修复了 Wayland 下 因窗口频繁变尺寸而引发的闪烁问题,同时也完整保留了正常的自适应包 裹尺寸机制。 Log: optimize dock network plugin panel height resizing frequency
1 parent c3c7c47 commit 1e489a7

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

dock-network-plugin/dockcontentwidget.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <QTreeView>
1919
#include <QVBoxLayout>
2020
#include <QWidget>
21+
#include <QTimer>
2122

2223
namespace dde {
2324
namespace network {
@@ -31,7 +32,12 @@ class DockContentWidget : public QWidget
3132
, m_mainLayout(new QVBoxLayout(this))
3233
, m_netView(netView)
3334
, m_minHeight(-1)
35+
, m_updateTimer(new QTimer(this))
3436
{
37+
m_updateTimer->setSingleShot(true);
38+
m_updateTimer->setInterval(150);
39+
connect(m_updateTimer, &QTimer::timeout, this, &DockContentWidget::doUpdateSize);
40+
3541
m_netView->installEventFilter(this);
3642
m_netView->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
3743
connect(m_netView, &NetView::updateSize, this, &DockContentWidget::updateSize);
@@ -72,6 +78,14 @@ class DockContentWidget : public QWidget
7278

7379
public Q_SLOTS:
7480
void updateSize() {
81+
if (!isVisible()) {
82+
doUpdateSize();
83+
} else {
84+
m_updateTimer->start();
85+
}
86+
}
87+
88+
void doUpdateSize() {
7589
auto h = Dock::DOCK_POPUP_WIDGET_MAX_HEIGHT - 20 - m_mainLayout->contentsMargins().top() - (m_netCheckBtn->isVisible() ? (m_netSetBtn->height() + m_netCheckBtn->height() + 10) : m_netSetBtn->height());
7690
m_netView->setMaxHeight(h);
7791
if (m_netView->height() > h)
@@ -94,10 +108,10 @@ public Q_SLOTS:
94108

95109
void showEvent(QShowEvent *event) override
96110
{
97-
updateSize();
111+
doUpdateSize();
98112
QWidget::showEvent(event);
99113
QMetaObject::invokeMethod(this, [this]() {
100-
updateSize();
114+
doUpdateSize();
101115
resize(size());
102116
}, Qt::QueuedConnection);
103117
}
@@ -116,6 +130,7 @@ public Q_SLOTS:
116130
int m_minHeight;
117131
JumpSettingButton *m_netSetBtn;
118132
JumpSettingButton *m_netCheckBtn;
133+
QTimer *m_updateTimer;
119134
};
120135

121136
} // namespace network

0 commit comments

Comments
 (0)