From 1ba62acfcc81b597b7b57a96863edc7a8f357964 Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 7 Jan 2015 09:19:04 +0000 Subject: [PATCH] Fix native menubar in Mac builds with Qt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - where we don’t use the launcher, we must pass tell OSG we want to pose as standalone when setting the window traits. --- src/Main/main.cxx | 5 +++++ src/Viewer/WindowBuilder.cxx | 16 +++++++++++++++- src/Viewer/WindowBuilder.hxx | 3 +++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 581bc7aa3..b578e464a 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -67,6 +67,7 @@ extern bool global_crashRptEnabled; #include #include #include +#include #include "fg_commands.hxx" #include "fg_io.hxx" @@ -464,6 +465,10 @@ int fgMainInit( int argc, char **argv ) showLauncher |= (::getenv("FG_LAUNCHER") != 0); if (showLauncher) { + // avoid double Apple menu and other weirdness if both Qt and OSG + // try to initialise various Cocoa structures. + flightgear::WindowBuilder::setPoseAsStandaloneApp(false); + if (!QtLauncher::runLauncherDialog()) { return EXIT_SUCCESS; } diff --git a/src/Viewer/WindowBuilder.cxx b/src/Viewer/WindowBuilder.cxx index 901b72e14..06d94e118 100644 --- a/src/Viewer/WindowBuilder.cxx +++ b/src/Viewer/WindowBuilder.cxx @@ -45,6 +45,10 @@ ref_ptr WindowBuilder::windowBuilder; const string WindowBuilder::defaultWindowName("FlightGear"); +// default to true (historical behaviour), we will clear the flag if +// we run another GUI. +bool WindowBuilder::poseAsStandaloneApp = true; + void WindowBuilder::initWindowBuilder(bool stencil) { windowBuilder = new WindowBuilder(stencil); @@ -250,9 +254,13 @@ GraphicsWindow* WindowBuilder::getDefaultWindow() traits->windowName = "FlightGear"; #if defined(HAVE_QT) && defined(SG_MAC) + int flags = osgViewer::GraphicsWindowCocoa::WindowData::CheckForEvents; + // avoid both QApplication and OSG::CocoaViewer doing single-application // init (Apple menu, making front process, etc) - int flags = osgViewer::GraphicsWindowCocoa::WindowData::CheckForEvents; + if (poseAsStandaloneApp) { + flags |= osgViewer::GraphicsWindowCocoa::WindowData::PoseAsStandaloneApp; + } traits->inheritedWindowData = new osgViewer::GraphicsWindowCocoa::WindowData(flags); #endif @@ -266,4 +274,10 @@ GraphicsWindow* WindowBuilder::getDefaultWindow() return 0; } } + +void WindowBuilder::setPoseAsStandaloneApp(bool b) +{ + poseAsStandaloneApp = b; } + +} // of namespace flightgear diff --git a/src/Viewer/WindowBuilder.hxx b/src/Viewer/WindowBuilder.hxx index 92e158bb8..8836d6956 100644 --- a/src/Viewer/WindowBuilder.hxx +++ b/src/Viewer/WindowBuilder.hxx @@ -57,6 +57,8 @@ public: /** Get the name used to look up the default window. */ const std::string& getDefaultWindowName() { return defaultWindowName; } + + static void setPoseAsStandaloneApp(bool b); protected: WindowBuilder(bool stencil); static osg::GraphicsContext::Traits* makeDefaultTraits(bool stencil); @@ -64,6 +66,7 @@ protected: int defaultCounter; static osg::ref_ptr windowBuilder; static const std::string defaultWindowName; + static bool poseAsStandaloneApp; }; /** Silly function for making the default window and camera