Skip to content

Commit

Permalink
fix: state change not connect
Browse files Browse the repository at this point in the history
Change-Id: Ied35ea43a0b535f8e12ac053c2edbfc651a85235
  • Loading branch information
Iceyer committed Feb 12, 2018
1 parent 975e36d commit 0049a06
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/widgets/dtitlebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
Expand Down

0 comments on commit 0049a06

Please sign in to comment.