Fix maximize/restore button state in TitleWidget.
This commit is contained in:
parent
0adf0383d8
commit
f6a1a44efe
2 changed files with 26 additions and 18 deletions
|
|
@ -122,29 +122,36 @@ void TitleControls::init(Fn<void(bool maximized)> maximize) {
|
|||
updateControlsPosition();
|
||||
}, _close->lifetime());
|
||||
|
||||
const auto winIdEventFilter = std::make_shared<QObject*>(nullptr);
|
||||
*winIdEventFilter = base::install_event_filter(
|
||||
window(),
|
||||
[=](not_null<QEvent*> e) {
|
||||
if (!*winIdEventFilter || e->type() != QEvent::WinIdChange) {
|
||||
return base::EventFilterResult::Continue;
|
||||
}
|
||||
|
||||
QObject::connect(
|
||||
window()->windowHandle(),
|
||||
&QWindow::windowStateChanged,
|
||||
[=](Qt::WindowState state) {
|
||||
handleWindowStateChanged(state);
|
||||
});
|
||||
|
||||
base::take(*winIdEventFilter)->deleteLater();
|
||||
return base::EventFilterResult::Continue;
|
||||
});
|
||||
subscribeToStateChanges();
|
||||
|
||||
_activeState = parent()->isActiveWindow();
|
||||
updateButtonsState();
|
||||
}
|
||||
|
||||
void TitleControls::subscribeToStateChanges() {
|
||||
const auto subscribe = [=] {
|
||||
QObject::connect(
|
||||
window()->windowHandle(),
|
||||
&QWindow::windowStateChanged,
|
||||
[=](Qt::WindowState state) { handleWindowStateChanged(state); });
|
||||
};
|
||||
if (window()->windowHandle()) {
|
||||
subscribe();
|
||||
} else {
|
||||
const auto winIdEventFilter = std::make_shared<QObject*>(nullptr);
|
||||
*winIdEventFilter = base::install_event_filter(
|
||||
window(),
|
||||
[=](not_null<QEvent*> e) {
|
||||
if (!*winIdEventFilter || e->type() != QEvent::WinIdChange) {
|
||||
return base::EventFilterResult::Continue;
|
||||
}
|
||||
subscribe();
|
||||
base::take(*winIdEventFilter)->deleteLater();
|
||||
return base::EventFilterResult::Continue;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void TitleControls::setResizeEnabled(bool enabled) {
|
||||
_resizeEnabled = enabled;
|
||||
updateControlsPosition();
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ private:
|
|||
[[nodiscard]] Ui::IconButton *controlWidget(Control control) const;
|
||||
|
||||
void init(Fn<void(bool maximized)> maximize);
|
||||
void subscribeToStateChanges();
|
||||
void updateButtonsState();
|
||||
void updateControlsPosition();
|
||||
void updateControlsPositionBySide(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue