vcl/osx/salframe.cxx    |   23 +++++++++++++++++------
 vcl/osx/salframeview.mm |   35 +++++++++++++++++++++++++++++------
 vcl/osx/salnsmenu.mm    |   13 ++++++++-----
 3 files changed, 54 insertions(+), 17 deletions(-)

New commits:
commit 2120acaa261aaa1adaafc051582ac7f7dd4de372
Author:     Patrick Luby <[email protected]>
AuthorDate: Wed Dec 18 17:01:24 2024 -0500
Commit:     Patrick Luby <[email protected]>
CommitDate: Thu Dec 19 00:58:58 2024 +0100

    tdf#161623 Fine tune menubar visibility when in LibreOffice full screen mode
    
    Every once in a while, toggling LibreOffice full screen mode in a
    native full screen window causes the menubar to be set to "hide"
    instead of "autohide". So, expand the conditions for enabling
    instead of disabling the menubar's visibility to include from
    when a window is about to enter native full screen mode.
    
    Also, just to be safe, always disable the menu items in the menubar
    for LibreOffice full screen mode windows in case the menubar can't
    be hidden while not in native full screen mode.
    
    Change-Id: I4f1e8fc4a644cc13451690156b56662035321459
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178751
    Tested-by: Jenkins
    Reviewed-by: Patrick Luby <[email protected]>

diff --git a/vcl/osx/salframe.cxx b/vcl/osx/salframe.cxx
index 683a6d1602fa..98ea5a72c718 100644
--- a/vcl/osx/salframe.cxx
+++ b/vcl/osx/salframe.cxx
@@ -918,13 +918,24 @@ void AquaSalFrame::doShowFullScreen( bool bFullScreen, 
sal_Int32 nDisplay )
         }
         // Hide the dock and the menubar if this or one of its child
         // windows are the key window
-        else
+        else if( AquaSalFrame::isAlive( this ) )
         {
-            const NSWindow *pParentWindow = [NSApp keyWindow];
-            while( pParentWindow && pParentWindow != mpNSWindow )
-                pParentWindow = [pParentWindow parentWindow];
-            if( pParentWindow == mpNSWindow )
-                [NSMenu setMenuBarVisible: NO];
+            bool bNativeFullScreen = false;
+            const AquaSalFrame *pParentFrame = this;
+            while( pParentFrame )
+            {
+                bNativeFullScreen |= pParentFrame->mbNativeFullScreen;
+                pParentFrame = AquaSalFrame::isAlive( pParentFrame->mpParent ) 
? pParentFrame->mpParent : nullptr;
+            }
+
+            if( !bNativeFullScreen )
+            {
+                const NSWindow *pParentWindow = [NSApp keyWindow];
+                while( pParentWindow && pParentWindow != mpNSWindow )
+                    pParentWindow = [pParentWindow parentWindow];
+                if( pParentWindow == mpNSWindow )
+                    [NSMenu setMenuBarVisible: NO];
+            }
         }
 
         if( mbNativeFullScreen && !NSIsEmptyRect( 
maNativeFullScreenRestoreRect ) )
diff --git a/vcl/osx/salframeview.mm b/vcl/osx/salframeview.mm
index d8102155e536..ad868d396d59 100644
--- a/vcl/osx/salframeview.mm
+++ b/vcl/osx/salframeview.mm
@@ -255,16 +255,32 @@ static void updateMenuBarVisibility( const AquaSalFrame 
*pFrame )
     // Hide the dock and the menubar if the key window or one of its
     // parent windows are in LibreOffice full screen mode. Otherwise,
     // show the dock and the menubar.
-    else if( AquaSalFrame::isAlive( pFrame ) && [pFrame->getNSWindow() 
isKeyWindow] )
+    else if( AquaSalFrame::isAlive( pFrame ) )
     {
+        bool bInternalFullScreen = false;
+        bool bNativeFullScreen = false;
         const AquaSalFrame *pParentFrame = pFrame;
-        while( pParentFrame && !pParentFrame->mbInternalFullScreen )
-            pParentFrame = AquaSalFrame::isAlive( pFrame->mpParent ) ? 
pParentFrame->mpParent : nullptr;
+        while( pParentFrame )
+        {
+            bInternalFullScreen |= pParentFrame->mbInternalFullScreen;
+            bNativeFullScreen |= pParentFrame->mbNativeFullScreen;
+            pParentFrame = AquaSalFrame::isAlive( pParentFrame->mpParent ) ? 
pParentFrame->mpParent : nullptr;
+        }
 
-        if( pParentFrame && pParentFrame->mbInternalFullScreen )
-            [NSMenu setMenuBarVisible: NO];
+        if( bInternalFullScreen && !bNativeFullScreen )
+        {
+            const NSWindow *pParentWindow = [NSApp keyWindow];
+            while( pParentWindow && pParentWindow != pFrame->getNSWindow() )
+                pParentWindow = [pParentWindow parentWindow];
+            if( pParentWindow == pFrame->getNSWindow() )
+                [NSMenu setMenuBarVisible: NO];
+            else
+                [NSMenu setMenuBarVisible: YES];
+        }
         else
+        {
             [NSMenu setMenuBarVisible: YES];
+        }
     }
 }
 
@@ -437,12 +453,19 @@ static void updateMenuBarVisibility( const AquaSalFrame 
*pFrame )
         mpFrame->SendPaintEvent(); // repaint controls as inactive
     }
 
+    // Show the menubar if application is in native full screen mode
+    // since hiding the menubar in that mode will cause the window's
+    // titlebar to fail to display or fail to hide when expected.
+    if( [NSApp presentationOptions] & NSApplicationPresentationFullScreen )
+    {
+        [NSMenu setMenuBarVisible: YES];
+    }
     // Show the dock and the menubar if there is no native modal dialog
     // and if the key window is nil or is not a SalFrameWindow instance.
     // If a SalFrameWindow is the key window, it should have already set
     // the menubar visibility to match its LibreOffice full screen mode
     // state.
-    if ( ![NSApp modalWindow] )
+    else if ( ![NSApp modalWindow] )
     {
         NSWindow *pKeyWindow = [NSApp keyWindow];
         if( !pKeyWindow || ![pKeyWindow isKindOfClass: [SalFrameWindow class]] 
)
diff --git a/vcl/osx/salnsmenu.mm b/vcl/osx/salnsmenu.mm
index 74a8dd757430..e426d682acd2 100644
--- a/vcl/osx/salnsmenu.mm
+++ b/vcl/osx/salnsmenu.mm
@@ -287,12 +287,15 @@
     // Related: tdf#161623 the menubar is always visible when in native
     // full screen mode so disable all menu items when also in LibreOffice
     // full screen mode to mimic the effect of a hidden menubar.
-    if ([NSApp presentationOptions] & NSApplicationPresentationFullScreen)
+    SolarMutexGuard aGuard;
+    const AquaSalFrame* pFrame = mpMenuItem->mpParentMenu ? 
mpMenuItem->mpParentMenu->getFrame() : nullptr;
+    if (pFrame && AquaSalFrame::isAlive( pFrame ) && 
pFrame->mbInternalFullScreen)
     {
-        SolarMutexGuard aGuard;
-
-        const AquaSalFrame* pFrame = mpMenuItem->mpParentMenu ? 
mpMenuItem->mpParentMenu->getFrame() : nullptr;
-        if( pFrame && AquaSalFrame::isAlive( pFrame ) && 
pFrame->mbInternalFullScreen )
+        NSMenu *pMainMenu = [NSApp mainMenu];
+        NSMenu *pParentMenu = [pMenuItem menu];
+        while (pParentMenu && pParentMenu != pMainMenu)
+            pParentMenu = [pParentMenu supermenu];
+        if (pParentMenu && pParentMenu == pMainMenu)
             return NO;
     }
 

Reply via email to