sofa-framework / sofa

Real-time multi-physics simulation with an emphasis on medical simulation.
https://www.sofa-framework.org
GNU Lesser General Public License v2.1
927 stars 312 forks source link

[MacOS] runSofa menu unresponsive #183

Closed bcarrez closed 7 years ago

bcarrez commented 7 years ago

On Mac, when runSofa is launched, the menu bar is unresponsive to clicks. A workaround is to change the focus to another appllication, then back to runSofa and THEN, the menu is working properly.

Keyboard shortcuts like Cmd+O work properly and are not affected by this bug.

fredroy commented 7 years ago

This problem is because you are launching runSofa from the command line. The "normal" way to solve it would be to launch from a .app application (so-called bundle). In that case, the menubar is directly accessible. I already searched for an other solution, but apparently that is because of MacOS itself: https://github.com/robotology/yarp/issues/457 (I cannot find the bug report on Qt...)

http://www.alecjacobson.com/weblog/?p=3910 This guy is suggesting to call an apple script to do a quick alt-tab.....

jnbrunet commented 7 years ago

Another way to fix this could be by disabling the native menu bar and use the Qt one. That would also have the benefit of having the same menu bar for every version. Here is one way to do it:

diff --git a/applications/sofa/gui/qt/RealGUI.cpp b/applications/sofa/gui/qt/RealGUI.cpp
index b6546a8..efb29c5 100644
--- a/applications/sofa/gui/qt/RealGUI.cpp
+++ b/applications/sofa/gui/qt/RealGUI.cpp
@@ -221,6 +221,7 @@ void RealGUI::InitApplication( RealGUI* _gui)
     QString pathIcon=(sofa::helper::system::DataRepository.getFirstPath() + std::string( "/icons/SOFA.png" )).c_str();

     application->setWindowIcon(QIcon(pathIcon));
+    _gui->menubar->setNativeMenuBar(false);

     // show the gui
     _gui->show(); // adding extra line in the console?

This works perfectly on my mac. The menu bar will be directly on the Sofa's interface like it would with another OS.

screen shot 2017-04-29 at 11 09 38 pm

Edit : I can add this patch as a pull request if you want to go forward with this solution.

jnbrunet commented 7 years ago

I've submitted a small PR for the bug.

@bcarrez Is there any reason why this issue was closed? The bug is still very present on my mac. Did this issue moved somewhere else?