Skip to content

Commit b7d82d1

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 b7d82d1

2 files changed

Lines changed: 36 additions & 10 deletions

File tree

panels/dock/pluginmanagerextension.cpp

Lines changed: 29 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,18 @@ 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+
connect(m_sizeChangeTimer, &QTimer::timeout, this, &PluginPopup::onProcessPendingSizeChanges);
354360
}
355361

356362
QWaylandSurface* PluginPopup::surface() const
@@ -446,15 +452,12 @@ void PluginPopup::plugin_popup_source_size(Resource *resource, int32_t width, in
446452
if (width == 0 || height == 0)
447453
return;
448454

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-
}
455+
m_pendingWidth = width;
456+
m_pendingHeight = height;
457+
m_hasPendingChanged = true;
458+
if (!m_sizeChangeTimer->isActive()) {
459+
m_sizeChangeTimer->start();
460+
}
458461
}
459462

460463
void PluginPopup::plugin_popup_set_cursor(Resource *resource, int32_t cursor_shape)
@@ -463,6 +466,22 @@ void PluginPopup::plugin_popup_set_cursor(Resource *resource, int32_t cursor_sha
463466
Q_EMIT cursorShapeRequested(cursor_shape);
464467
}
465468

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

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)