Skip to content

Commit fb42cf1

Browse files
committed
Plugins::WebBrowser: fix CAddressCompleter show in wayland
1 parent 3e31aac commit fb42cf1

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎Plugins/WebBrowser/AddressCompleter.cpp‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ CAddressCompleter::CAddressCompleter(CHistoryDatabase *db, QWidget *parent)
6161
, m_maxVisibleItems(8)
6262
, m_isCompleterVisible(false)
6363
, m_pDatabase(db)
64+
, m_bIsWayland(false)
6465
{
6566
m_szEnter = tr("Enter '@' show commands") + "; "
6667
+ tr("Enter a website URL or search content ......");
@@ -77,6 +78,13 @@ CAddressCompleter::CAddressCompleter(CHistoryDatabase *db, QWidget *parent)
7778
m_szLineEditToolTipShow = m_szEnter + "\n\n" + m_szListWidgetToolTip;
7879
setToolTip(m_szListWidgetToolTip);
7980

81+
#if defined(Q_OS_LINUX)
82+
if(-1 == QGuiApplication::platformName().indexOf(QRegularExpression("wayland.*")))
83+
m_bIsWayland = false;
84+
else
85+
m_bIsWayland = true;
86+
#endif
87+
8088
setupUI();
8189

8290
// 设置搜索延迟定时器(300ms防抖动)
@@ -103,7 +111,12 @@ CAddressCompleter::~CAddressCompleter()
103111

104112
void CAddressCompleter::setupUI()
105113
{
106-
setWindowFlags(Qt::Tool /*Qt::ToolTip*/ | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint);
114+
Qt::WindowFlags flags;
115+
flags = Qt::FramelessWindowHint | Qt::CustomizeWindowHint;
116+
if(!m_bIsWayland) {
117+
flags |= Qt::Tool;
118+
}
119+
setWindowFlags(flags);
107120
setAttribute(Qt::WA_TranslucentBackground);
108121

109122
QVBoxLayout *mainLayout = new QVBoxLayout(this);
@@ -508,11 +521,15 @@ void CAddressCompleter::showCompleter()
508521
m_pShowAnimation->setEndValue(endRect);
509522
m_pShowAnimation->setEasingCurve(QEasingCurve::OutCubic);
510523
connect(m_pShowAnimation, &QPropertyAnimation::finished,
511-
this, &CAddressCompleter::show);
524+
this, [this]() {
525+
show();
526+
raise();
527+
});
512528
m_pShowAnimation->start();
513529
} else {
514530
setGeometry(endRect);
515531
show();
532+
raise();
516533
}
517534
}
518535

@@ -576,6 +593,15 @@ void CAddressCompleter::updateCompleterPosition()
576593
}
577594
}
578595

596+
if(m_bIsWayland) {
597+
QWidget* pWin = qobject_cast<QWidget*>(parent());
598+
if(pWin) {
599+
globalPos = pWin->mapFromGlobal(globalPos);
600+
} else {
601+
qCritical(log) << "Current platform plugin is wayland. the parent must be setted.";
602+
}
603+
}
604+
579605
// 设置位置和大小
580606
setGeometry(globalPos.x(), globalPos.y(), width, 0);
581607
}

‎Plugins/WebBrowser/AddressCompleter.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CAddressCompleter : public QWidget
4141
{
4242
Q_OBJECT
4343
public:
44-
explicit CAddressCompleter(CHistoryDatabase* db, QWidget *parent = nullptr);
44+
explicit CAddressCompleter(CHistoryDatabase* db, QWidget *parent);
4545
~CAddressCompleter();
4646

4747
void attachToLineEdit(QLineEdit *lineEdit);
@@ -96,4 +96,5 @@ private Q_SLOTS:
9696
bool m_isCompleterVisible;
9797

9898
CHistoryDatabase* m_pDatabase;
99+
bool m_bIsWayland;
99100
};

0 commit comments

Comments
 (0)