From 0049a0650ee12fec6f026bdd69b2814ebda30546 Mon Sep 17 00:00:00 2001 From: Iceyer Date: Tue, 13 Feb 2018 03:36:10 +0800 Subject: [PATCH] fix: state change not connect Change-Id: Ied35ea43a0b535f8e12ac053c2edbfc651a85235 --- src/widgets/dtitlebar.cpp | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/widgets/dtitlebar.cpp b/src/widgets/dtitlebar.cpp index e01aabe82..60fe5bf72 100644 --- a/src/widgets/dtitlebar.cpp +++ b/src/widgets/dtitlebar.cpp @@ -96,12 +96,14 @@ class DTitlebarPrivate : public DTK_CORE_NAMESPACE::DObjectPrivate QLabel *separator; #ifndef QT_NO_MENU - QMenu *menu = Q_NULLPTR; - QAction *helpAction = Q_NULLPTR; - QAction *aboutAction = Q_NULLPTR; - QAction *quitAction = Q_NULLPTR; + QMenu *menu = Q_NULLPTR; + QAction *helpAction = Q_NULLPTR; + QAction *aboutAction = Q_NULLPTR; + QAction *quitAction = Q_NULLPTR; #endif + QWindow *targetWindowHandle = Q_NULLPTR; + Qt::WindowFlags disableFlags; bool mousePressed = false; bool embedMode = false; @@ -216,10 +218,6 @@ void DTitlebarPrivate::init() q->connect(optionButton, &DWindowOptionButton::clicked, q, &DTitlebar::optionClicked); q->connect(DWindowManagerHelper::instance(), SIGNAL(windowMotifWMHintsChanged(quint32)), q, SLOT(_q_onTopWindowMotifHintsChanged(quint32))); - - // connect state change if parent has native window - // or connect when parent winid change - handleParentWindowIdChange(); } QWidget *DTitlebarPrivate::targetWindow() @@ -346,13 +344,19 @@ void DTitlebarPrivate::handleParentWindowStateChange() void DTitlebarPrivate::handleParentWindowIdChange() { D_Q(DTitlebar); - if (targetWindow()->windowHandle()) { - q->disconnect(targetWindow()->windowHandle(), &QWindow::windowStateChanged, q, Q_NULLPTR); - q->connect(targetWindow()->windowHandle(), &QWindow::windowStateChanged, + if (!targetWindowHandle) { + targetWindowHandle = targetWindow()->windowHandle(); + targetWindowHandle->disconnect(targetWindow()->windowHandle(), &QWindow::windowStateChanged, + q, Q_NULLPTR); + targetWindowHandle->connect(targetWindow()->windowHandle(), &QWindow::windowStateChanged, q, [ = ](Qt::WindowState) { handleParentWindowStateChange(); }); + } else if (targetWindow()->windowHandle() != targetWindowHandle) { + // Parent change???, show never here + qWarning() << "targetWindowHandle change" << targetWindowHandle << targetWindow()->windowHandle(); } + } void DTitlebarPrivate::_q_toggleWindowState() @@ -634,14 +638,9 @@ bool DTitlebar::eventFilter(QObject *obj, QEvent *event) D_D(DTitlebar); if (obj == d->targetWindow()) { - switch (event->type()) { - // !!! NO state change when fullscreen state change to nostate ? - case QEvent::WinIdChange: { - d->handleParentWindowIdChange(); - break; - } case QEvent::ShowToParent: + d->handleParentWindowIdChange(); d->updateButtonsFunc(); d->updateButtonsState(d->targetWindow()->windowFlags()); break; @@ -878,7 +877,6 @@ void DTitlebar::setVisible(bool visible) if (!d->targetWindow()) { return; } - d->targetWindow()->installEventFilter(this); connect(d->maxButton, SIGNAL(clicked()), this, SLOT(_q_toggleWindowState()));