瀏覽代碼

Allow macOS menubar to be shown in desktop mode.

Previously we patched this into Qt, but that made it
so that we couldn't configure the presentation options.

So instead I rolled back the Qt patch and added calls to
setPresentationOptions in the fullscreen callbacks.

Fixes #515
Tobias Hieta 8 年之前
父節點
當前提交
36b5716bae
共有 5 個文件被更改,包括 48 次插入12 次删除
  1. 2 2
      src/display/osx/DisplayManagerOSX.cpp
  2. 19 2
      src/ui/KonvergoWindow.cpp
  3. 2 0
      src/ui/KonvergoWindow.h
  4. 4 1
      src/utils/osx/OSXUtils.h
  5. 21 7
      src/utils/osx/OSXUtils.mm

+ 2 - 2
src/display/osx/DisplayManagerOSX.cpp

@@ -107,8 +107,8 @@ bool DisplayManagerOSX::setDisplayMode(int display, int mode)
 
   // HACK : on OSX, switching display mode can leave dock in a state where mouse cursor
   // will not hide on top of hidden dock, so we reset it state to fix this
-  OSXUtils::SetMenuBarVisible(true);
-  OSXUtils::SetMenuBarVisible(false);
+  OSXUtils::SetPresentationOptions(OSXUtils::GetPresentationOptionsForFullscreen(false));
+  OSXUtils::SetPresentationOptions(OSXUtils::GetPresentationOptionsForFullscreen(true));
 
   return true;
 }

+ 19 - 2
src/ui/KonvergoWindow.cpp

@@ -27,7 +27,8 @@ KonvergoWindow::KonvergoWindow(QWindow* parent) :
   m_debugLayer(false),
   m_lastScale(1.0),
   m_ignoreFullscreenSettingsChange(0),
-  m_showedUpdateDialog(false)
+  m_showedUpdateDialog(false),
+  m_osxPresentationOptions(0)
 {
   // NSWindowCollectionBehaviorFullScreenPrimary is only set on OSX if Qt::WindowFullscreenButtonHint is set on the window.
   setFlags(flags() | Qt::WindowFullscreenButtonHint);
@@ -77,6 +78,10 @@ KonvergoWindow::KonvergoWindow(QWindow* parent) :
   connect(&UpdaterComponent::Get(), &UpdaterComponent::downloadComplete,
           this, &KonvergoWindow::showUpdateDialog);
 
+#ifdef Q_OS_MAC
+  m_osxPresentationOptions = OSXUtils::GetPresentationOptions();
+#endif
+
 #ifdef KONVERGO_OPENELEC
   setVisibility(QWindow::FullScreen);
 #else
@@ -310,6 +315,8 @@ void KonvergoWindow::updateMainSectionSettings(const QVariantMap& values)
     emit webDesktopModeChanged();
     emit webUrlChanged();
     SystemComponent::Get().setCursorVisibility(true);
+
+    updateWindowState();
   }
 
   if (values.contains("startupurl"))
@@ -329,6 +336,12 @@ void KonvergoWindow::updateWindowState(bool saveGeo)
       saveGeometry();
 
     setVisibility(QWindow::FullScreen);
+
+#ifdef Q_OS_MAC
+    QTimer::singleShot(0, [&] {
+      OSXUtils::SetPresentationOptions(m_osxPresentationOptions | OSXUtils::GetPresentationOptionsForFullscreen(!m_webDesktopMode));
+    });
+#endif
   }
   else
   {
@@ -344,6 +357,10 @@ void KonvergoWindow::updateWindowState(bool saveGeo)
       setFlags(flags() | forceOnTopFlags);
     else
       setFlags(flags() &~ forceOnTopFlags);
+
+#ifdef Q_OS_MAC
+    QTimer::singleShot(0, [&]{ OSXUtils::SetPresentationOptions(m_osxPresentationOptions); });
+#endif
   }
 }
 
@@ -366,7 +383,6 @@ void KonvergoWindow::onVisibilityChanged(QWindow::Visibility visibility)
   if (visibility == QWindow::Windowed)
     loadGeometry();
 
-
   if (visibility == QWindow::FullScreen || visibility == QWindow::Windowed) {
     m_ignoreFullscreenSettingsChange++;
     ScopedDecrementer decrement(&m_ignoreFullscreenSettingsChange);
@@ -521,6 +537,7 @@ QScreen* KonvergoWindow::loadLastScreen()
   return nullptr;
 }
 
+/////////////////////////////////////////////////////////////////////////////////////////
 QString KonvergoWindow::webUrl()
 {
   auto url = SettingsComponent::Get().getWebClientUrl();

+ 2 - 0
src/ui/KonvergoWindow.h

@@ -134,6 +134,8 @@ private:
   int m_ignoreFullscreenSettingsChange;
   bool m_webDesktopMode;
   bool m_showedUpdateDialog;
+
+  unsigned long m_osxPresentationOptions;
 };
 
 #endif // KONVERGOWINDOW_H

+ 4 - 1
src/utils/osx/OSXUtils.h

@@ -6,9 +6,12 @@
 
 namespace OSXUtils
 {
-  void SetMenuBarVisible(bool visible);
   QString ComputerName();
   OSStatus SendAppleEventToSystemProcess(AEEventID eventToSendID);
+
+  void SetPresentationOptions(unsigned long flags);
+  unsigned long GetPresentationOptions();
+  unsigned long GetPresentationOptionsForFullscreen(bool hideMenuAndDock);
 };
 
 #endif /* OSXUTILS_H */

+ 21 - 7
src/utils/osx/OSXUtils.mm

@@ -2,19 +2,33 @@
 #import <Cocoa/Cocoa.h>
 
 /////////////////////////////////////////////////////////////////////////////////////////
-void OSXUtils::SetMenuBarVisible(bool visible)
+unsigned long OSXUtils::GetPresentationOptionsForFullscreen(bool hideMenuAndDock)
 {
-  if(visible)
+  unsigned long flags = 0;
+  if (hideMenuAndDock)
   {
-    [[NSApplication sharedApplication]
-      setPresentationOptions:   NSApplicationPresentationDefault];
+    flags = flags & ~(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar);
+    flags |= NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar;
   }
   else
   {
-    [[NSApplication sharedApplication]
-      setPresentationOptions:   NSApplicationPresentationHideMenuBar |
-                                NSApplicationPresentationHideDock];
+    flags = flags & ~(NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar);
+    flags |= NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar;
   }
+
+  return flags;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+void OSXUtils::SetPresentationOptions(unsigned long flags)
+{
+  [[NSApplication sharedApplication] setPresentationOptions:flags];
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+unsigned long OSXUtils::GetPresentationOptions()
+{
+  return [[NSApplication sharedApplication] presentationOptions];
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////