Skip to content

Commit d10769d

Browse files
committed
fix: Fix popup list position display error
When the same signal is sent multiple times simultaneously in C++, QML may only receive the middle signal. The received height is not the latest, causing the display position to be offset. Log: Fix list display issue PMS: BUG-336777 fix: 修复弹出列表位置显示错误 在cpp中同时多次发送同一个信号的情况下,qml可能只收到了中间的那个信号,收到的高度不是最新的,导致显示位置出现了偏移 Log: 修复列表显示的问题
1 parent 0b9cab0 commit d10769d

2 files changed

Lines changed: 38 additions & 10 deletions

File tree

panels/dock/pluginmanagerextension.cpp

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <QInputMethod>
3131
#include <QClipboard>
3232
#include <QMimeData>
33-
33+
#include <QTimer>
3434
#include <QJsonObject>
3535
#include <QJsonParseError>
3636

@@ -345,12 +345,20 @@ PluginPopup::PluginPopup(PluginManager *manager,
345345
, m_popupType(popupType)
346346
, m_height(1)
347347
, m_width(1)
348+
, m_sizeChangeTimer(new QTimer(this))
349+
, m_hasPendingChanged(false)
350+
, m_pendingHeight(1)
351+
, m_pendingWidth(1)
348352
{
349353
Q_UNUSED(x)
350354
Q_UNUSED(y)
351355
init(resource.resource());
352356
setExtensionContainer(surface);
353357
QWaylandCompositorExtension::initialize();
358+
359+
m_sizeChangeTimer->setInterval(50);
360+
m_sizeChangeTimer->setSingleShot(true);
361+
connect(m_sizeChangeTimer, &QTimer::timeout, this, &PluginPopup::onProcessPendingSizeChanges);
354362
}
355363

356364
QWaylandSurface* PluginPopup::surface() const
@@ -446,15 +454,12 @@ void PluginPopup::plugin_popup_source_size(Resource *resource, int32_t width, in
446454
if (width == 0 || height == 0)
447455
return;
448456

449-
if (height != m_height) {
450-
m_height = height;
451-
Q_EMIT heightChanged();
452-
}
453-
454-
if (width != m_width) {
455-
m_width = width;
456-
Q_EMIT widthChanged();
457-
}
457+
m_pendingWidth = width;
458+
m_pendingHeight = height;
459+
m_hasPendingChanged = true;
460+
if (!m_sizeChangeTimer->isActive()) {
461+
m_sizeChangeTimer->start();
462+
}
458463
}
459464

460465
void PluginPopup::plugin_popup_set_cursor(Resource *resource, int32_t cursor_shape)
@@ -463,6 +468,22 @@ void PluginPopup::plugin_popup_set_cursor(Resource *resource, int32_t cursor_sha
463468
Q_EMIT cursorShapeRequested(cursor_shape);
464469
}
465470

471+
void PluginPopup::onProcessPendingSizeChanges()
472+
{
473+
if (!m_hasPendingChanged)
474+
return;
475+
476+
if (m_pendingHeight != m_height) {
477+
m_height = m_pendingHeight;
478+
Q_EMIT heightChanged();
479+
}
480+
if (m_pendingWidth != m_width) {
481+
m_width = m_pendingWidth;
482+
Q_EMIT widthChanged();
483+
}
484+
m_hasPendingChanged = false;
485+
}
486+
466487
PluginManager::PluginManager(QWaylandCompositor *compositor)
467488
: QWaylandCompositorExtensionTemplate(compositor)
468489
{

panels/dock/pluginmanagerextension_p.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ class PluginPopup : public QWaylandShellSurfaceTemplate<PluginPopup>, public QtW
268268
void widthChanged();
269269
void cursorShapeRequested(int cursorShape);
270270

271+
private slots:
272+
void onProcessPendingSizeChanges();
273+
271274
private:
272275
PluginManager* m_manager;
273276
QPointer<QWaylandSurface> m_surface;
@@ -280,6 +283,10 @@ class PluginPopup : public QWaylandShellSurfaceTemplate<PluginPopup>, public QtW
280283
int32_t m_y;
281284
int m_height;
282285
int m_width;
286+
QTimer* m_sizeChangeTimer;
287+
bool m_hasPendingChanged;
288+
int m_pendingHeight;
289+
int m_pendingWidth;
283290
};
284291

285292
Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(PluginManager)

0 commit comments

Comments
 (0)