From e4b23cad1b284bc036e9a11966f13a232ccb1a5d Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 18 Oct 2019 20:56:17 +0400 Subject: [PATCH] Fix custom title on macOS. --- ui/platform/mac/ui_window_mac.mm | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/ui/platform/mac/ui_window_mac.mm b/ui/platform/mac/ui_window_mac.mm index 95c8ee4..df9039f 100644 --- a/ui/platform/mac/ui_window_mac.mm +++ b/ui/platform/mac/ui_window_mac.mm @@ -17,19 +17,22 @@ @interface WindowObserver : NSObject { } -- (id) init:(Fn)toggleCustomTitleVisibility; +- (id) initWithToggle:(Fn)toggleCustomTitleVisibility enforce:(Fn)enforceCorrectStyle; - (void) windowWillEnterFullScreen:(NSNotification *)aNotification; - (void) windowWillExitFullScreen:(NSNotification *)aNotification; +- (void) windowDidExitFullScreen:(NSNotification *)aNotification; @end // @interface WindowObserver @implementation WindowObserver { Fn _toggleCustomTitleVisibility; + Fn _enforceCorrectStyle; } -- (id) init:(Fn)toggleCustomTitleVisibility { +- (id) initWithToggle:(Fn)toggleCustomTitleVisibility enforce:(Fn)enforceCorrectStyle { if (self = [super init]) { _toggleCustomTitleVisibility = toggleCustomTitleVisibility; + _enforceCorrectStyle = enforceCorrectStyle; } return self; } @@ -39,9 +42,14 @@ } - (void) windowWillExitFullScreen:(NSNotification *)aNotification { + _enforceCorrectStyle(); _toggleCustomTitleVisibility(true); } +- (void) windowDidExitFullScreen:(NSNotification *)aNotification { + _enforceCorrectStyle(); +} + @end // @implementation MainWindowObserver namespace Ui { @@ -85,6 +93,7 @@ private: void initCustomTitle(); [[nodiscard]] Fn toggleCustomTitleCallback(); + [[nodiscard]] Fn enforceStyleCallback(); const not_null _owner; const WindowObserver *_observer = nullptr; @@ -100,7 +109,7 @@ private: WindowHelper::Private::Private(not_null owner) : _owner(owner) -, _observer([[WindowObserver alloc] init:toggleCustomTitleCallback()]) { +, _observer([[WindowObserver alloc] initWithToggle:toggleCustomTitleCallback() enforce:enforceStyleCallback()]) { init(); } @@ -114,6 +123,14 @@ Fn WindowHelper::Private::toggleCustomTitleCallback() { }; } +Fn WindowHelper::Private::enforceStyleCallback() { + return [=] { + if (_nativeWindow && _customTitleHeight > 0) { + [_nativeWindow setStyleMask:[_nativeWindow styleMask] | NSFullSizeContentViewWindowMask]; + } + }; +} + void WindowHelper::Private::initOpenGL() { auto forceOpenGL = std::make_unique(_owner->_window); } @@ -132,10 +149,12 @@ void WindowHelper::Private::initCustomTitle() { || ![_nativeWindow respondsToSelector:@selector(setTitlebarAppearsTransparent:)]) { return; } + [_nativeWindow setTitlebarAppearsTransparent:YES]; [[NSNotificationCenter defaultCenter] addObserver:_observer selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:_nativeWindow]; [[NSNotificationCenter defaultCenter] addObserver:_observer selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:_nativeWindow]; + [[NSNotificationCenter defaultCenter] addObserver:_observer selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:_nativeWindow]; // Qt has bug with layer-backed widgets containing QOpenGLWidgets. // See https://bugreports.qt.io/browse/QTBUG-64494