Skip to content

Commit a1edb93

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 7b4cd8b commit a1edb93

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);
@@ -71,6 +77,14 @@ class DockContentWidget : public QWidget
7177

7278
public Q_SLOTS:
7379
void updateSize() {
80+
if (!isVisible()) {
81+
doUpdateSize();
82+
} else {
83+
m_updateTimer->start();
84+
}
85+
}
86+
87+
void doUpdateSize() {
7488
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());
7589
m_netView->setMaxHeight(h);
7690
if (m_netView->height() > h)
@@ -93,10 +107,10 @@ public Q_SLOTS:
93107

94108
void showEvent(QShowEvent *event) override
95109
{
96-
updateSize();
110+
doUpdateSize();
97111
QWidget::showEvent(event);
98112
QMetaObject::invokeMethod(this, [this]() {
99-
updateSize();
113+
doUpdateSize();
100114
resize(size());
101115
}, Qt::QueuedConnection);
102116
}
@@ -115,6 +129,7 @@ public Q_SLOTS:
115129
int m_minHeight;
116130
JumpSettingButton *m_netSetBtn;
117131
JumpSettingButton *m_netCheckBtn;
132+
QTimer *m_updateTimer;
118133
};
119134

120135
} // namespace network

0 commit comments

Comments
 (0)