Improve macOS custom window title.

This commit is contained in:
John Preston 2020-12-17 15:54:04 +04:00
parent 3bd98ac564
commit 5e3897fcff
2 changed files with 11 additions and 11 deletions

View file

@ -33,11 +33,12 @@ private:
void setupBodyTitleAreaEvents() override; void setupBodyTitleAreaEvents() override;
void init(); void init();
void toggleCustomTitle(bool visible); void updateCustomTitleVisibility(bool force = false);
const std::unique_ptr<Private> _private; const std::unique_ptr<Private> _private;
const not_null<TitleWidget*> _title; const not_null<TitleWidget*> _title;
const not_null<RpWidget*> _body; const not_null<RpWidget*> _body;
bool _titleVisible = true;
#ifdef OS_OSX #ifdef OS_OSX
struct WindowDrag { struct WindowDrag {

View file

@ -207,7 +207,8 @@ void WindowHelper::Private::close() {
Fn<void(bool)> WindowHelper::Private::toggleCustomTitleCallback() { Fn<void(bool)> WindowHelper::Private::toggleCustomTitleCallback() {
return crl::guard(_owner->window(), [=](bool visible) { return crl::guard(_owner->window(), [=](bool visible) {
_owner->toggleCustomTitle(visible); _owner->_titleVisible = visible;
_owner->updateCustomTitleVisibility(true);
}); });
} }
@ -286,7 +287,7 @@ WindowHelper::WindowHelper(not_null<RpWidget*> window)
: nullptr) : nullptr)
, _body(Ui::CreateChild<RpWidget>(window.get())) { , _body(Ui::CreateChild<RpWidget>(window.get())) {
if (_title->shouldBeHidden()) { if (_title->shouldBeHidden()) {
toggleCustomTitle(false); updateCustomTitleVisibility();
} }
init(); init();
} }
@ -303,27 +304,25 @@ void WindowHelper::setTitle(const QString &title) {
_title->setText(title); _title->setText(title);
} }
window()->setWindowTitle( window()->setWindowTitle(
(!_title || _title->isHidden()) ? title : QString()); (!_title || !_titleVisible) ? title : QString());
} }
void WindowHelper::setTitleStyle(const style::WindowTitle &st) { void WindowHelper::setTitleStyle(const style::WindowTitle &st) {
if (_title) { if (_title) {
_title->setStyle(st); _title->setStyle(st);
if (_title->shouldBeHidden()) { if (_title->shouldBeHidden()) {
toggleCustomTitle(false); updateCustomTitleVisibility();
} }
} }
} }
void WindowHelper::toggleCustomTitle(bool visible) { void WindowHelper::updateCustomTitleVisibility(bool force) {
if (_title->shouldBeHidden()) { auto visible = !_title->shouldBeHidden() && _titleVisible;
visible = false; if (!_title || (!force && _title->isHidden() != visible)) {
}
if (!_title || _title->isHidden() != visible) {
return; return;
} }
_title->setVisible(visible); _title->setVisible(visible);
window()->setWindowTitle(visible ? QString() : _title->text()); window()->setWindowTitle(_titleVisible ? QString() : _title->text());
} }
void WindowHelper::setMinimumSize(QSize size) { void WindowHelper::setMinimumSize(QSize size) {