MenuBar in macOS Catalina

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
HartwigW
In need of some credit
In need of some credit
Posts: 1
Joined: Sat May 02, 2020 3:12 pm

Re: MenuBar in macOS Catalina

Post by HartwigW » Sat May 02, 2020 3:23 pm

Hi,

this is not a bug in wxWidgets, I believe. I had the same problem but I could solve the issue with creating a new Xcode target. Previously, I "upgraded" a command line program to wxWidgets. That worked well till Mojave. After upgrading to Catalina and Xcode this program failed with the same symptoms you have described. I added an Info.plist file but no help.

For whatever reasons the NSMenu callbacks are not called after starting the app (none of them). When bringing the app into the background and back to the foreground all callbacks are served.

Finally, I created in Xcode an App target and associated the same files and libraries (no re-compilation!) to the new target. And everything works now!

BTW: I also checked the repository and could not find any modifications regarding menus.

PS: I am using a 2019 version of wxWidgets.

BeerSmith
Knows some wx things
Knows some wx things
Posts: 27
Joined: Mon Mar 07, 2011 8:39 pm

Re: MenuBar in macOS Catalina

Post by BeerSmith » Sat May 23, 2020 3:02 pm

Can you walk me through the basic steps to create the new target in XCode? I'm interested in trying this solution.
BeerSmith.com

chrism238
Earned a small fee
Earned a small fee
Posts: 20
Joined: Sun Feb 17, 2013 6:45 pm

Re: MenuBar in macOS Catalina

Post by chrism238 » Tue Aug 11, 2020 10:00 pm

chrism238 wrote:
Tue Apr 21, 2020 7:18 pm
We're probably tired of (my) such attempts, but have now recompiled everything :

- Catalina 10.15.4 with Supplemental update,
- Xcode 11.4.1,
- wxWidgets 3.1.3
- my app
- menu sample code .../wxWidgets-3.1.3/samples/menu
Just to report, if anyone is still concerned, that this problem persists with the updated wxWidgets 3.1.4 on macOS 10.15.6

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5154
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: MenuBar in macOS Catalina

Post by ONEEYEMAN » Tue Aug 11, 2020 10:15 pm

Hi,
I presume you did build the Application Bundle" and from the Terminal you are running it as:

Code: Select all

open minimal.app
(as for the minimal sample)?

Thank you.

chrism238
Earned a small fee
Earned a small fee
Posts: 20
Joined: Sun Feb 17, 2013 6:45 pm

Re: MenuBar in macOS Catalina

Post by chrism238 » Wed Aug 12, 2020 2:39 am

ONEEYEMAN wrote:
Tue Aug 11, 2020 10:15 pm
Hi,
I presume you did build the Application Bundle" and from the Terminal you are running it as:

Code: Select all

open minimal.app
(as for the minimal sample)?
Yes, as per previous discussions I (we) are rebuilding 'everything' each time there's a new wxWidgets or macOS releases.

No, not running the application with 'open' from the command line, but with ./myapp [command-line-arguments]
(with myapp being a symbolic link to myapp.app/Contents/MacOS/myapp

This method has worked for many years, until this topic was first posted in this forum.
The suspicion is that macOS is not passing some initialization event to wxWidgets (since Catalina).

Thanks.

chrism238
Earned a small fee
Earned a small fee
Posts: 20
Joined: Sun Feb 17, 2013 6:45 pm

Re: MenuBar in macOS Catalina

Post by chrism238 » Wed Aug 12, 2020 7:29 am

chrism238 wrote:
Wed Aug 12, 2020 2:39 am
No, not running the application with 'open' from the command line, but with ./myapp [command-line-arguments]
(with myapp being a symbolic link to myapp.app/Contents/MacOS/myapp
Sorry, forgot to add - even if one invokes the program with:

open myapp.app --args -x

macOS redirects stdout and stderr (somewhere?) making it not behave like a traditional Unix program.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5154
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: MenuBar in macOS Catalina

Post by ONEEYEMAN » Wed Aug 12, 2020 7:54 am

Hi,
Could you try building the minimal sample and run it with:

Code: Select all

open minimal.app
and then check if the menu works correctly?

Please remember that Apple make it a hard requirement with Catalina to build the Application Bundle (I believe you could work without it in the past). That is according to Stefan. And so one should operate with the Bundle directly.

If "minimal" sample will work - it will be confirmed.

Also, are you doing a GUI or a console application?

Thank you.

Also, about your comment - OSX is NOT UNIX/Linux. Those are 2 completely different OSes.

So of course they are behaving differently.

But I don;t know where/how/what OSX doing when you passing an arguments to a program. But that should be for later. Right now we are trying to fix the menu under Catalina.

chrism238
Earned a small fee
Earned a small fee
Posts: 20
Joined: Sun Feb 17, 2013 6:45 pm

Re: MenuBar in macOS Catalina

Post by chrism238 » Sat Aug 15, 2020 3:44 am

ONEEYEMAN wrote:
Wed Aug 12, 2020 7:54 am
Hi,
Could you try building the minimal sample and run it with:

Code: Select all

open minimal.app
and then check if the menu works correctly?
Thanks for your reply but, politely, this is covering old ground already discussed in this thread.
Yes, (re)building and running:

Code: Select all

open minimal.app
does run exactly as expected (big thanks to the wxWidgets team!).
Running:

Code: Select all

./minimal
from the command line does not run as it used to (before Catalina).
I'm not suggesting that something has broken in wxWdgets, just that the interaction between macOS and wxWidgets (and Tcl/Tk) has recently changed.
Please remember that Apple make it a hard requirement with Catalina to build the Application Bundle (I believe you could work without it in the past). That is according to Stefan. And so one should operate with the Bundle directly.
My application is built as a macOS bundle, exactly as is 'minimal'.
But building something as a bundle (all with the correct directory structure) is not the problem being discussed - somewhere along the way it appears Apple stopped sending a menu initialisation event to programs freshly invoked from the command line. It used to do this, and has recently (with Catalina) stopped. But that event sequence is now only sent when the wxWidgets application is brought back to the foreground. This also affects Tcl/Tk programs that should be able to be executed just from the command-line.
Also, are you doing a GUI or a console application?
My application being discussed is a simulator, with provides awxWidgets interface if invoked with its (-W) command-line switch, or as just a text-based application otherwise. This combination works perfectly on Linux, and has on macOS before Catalina.

I'm not pointing fingers at anyone (well, maybe Apple), but do keep 'probing' to see if anyone on this forum is investigating, or has solved, this problem. Thanks for reading.

Also, about your comment - OSX is NOT UNIX/Linux. Those are 2 completely different OSes.
Please let's not get into semantics - macOS is as much a version of UNIX as Linux is (and there's no such thing as UNIX/Linux).
I undertake nearly all of my software development and work on macOS while using it as a traditional Unix-like, command-line dominated box.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5154
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: MenuBar in macOS Catalina

Post by ONEEYEMAN » Sat Aug 15, 2020 4:12 am

Hi,
I completely agree with you.
As I said - running application outside the Bundle stops working with Catalina. And since wxWidgets tries to stay platform complaint as much as possible I believe you should bring it up with Apple, just as much as authors of Tcl/Tk.

Also, please correct me if I'm wrong, but I believe that when on OSX you invoke your program as just

Code: Select all

./minimal
it was started as background application and you had to bring it to top, as some functionality was not working. Unfortunately I don't remember exactly what but you can google this forum and check.

So, its not just with OSX and wxWidgets - its with every single GUI application on Catalina. Devs will have to build the Bundle and invoke it with "open".

Also Apple is known to break "backward compatibility" and not responding to the complaints about it.
You can try to bring it up though.

Now what's wrong with asking people to change their script to invoke:

Code: Select all

open minimal.app -W
(sorry, I don't know exact syntax here).

And finally, yes lets not go into semantics. ;-)

Thank you.

BeerSmith
Knows some wx things
Knows some wx things
Posts: 27
Joined: Mon Mar 07, 2011 8:39 pm

Re: MenuBar in macOS Catalina and Big Sur

Post by BeerSmith » Mon Apr 12, 2021 10:53 pm

I know this is an old post but the problem persists. Surely there is some way to build an OSX app that has the menu bar show up?

I did try the suggestion above of adding a new target in XCode but have not been able to associate everything with the new target properly so it will build. The older target builds just fine in XCode but then the menu does not show up.

Recompiled wx with the latest version, running latest XCode. Everything compiles just fine and the program runs just fine but the menu bar is empty.

Not sure if I should create an entirely new XCode project or if there is some easier way to actually make this work. A bit tougher since Apple has no easy way to create an app bundle in XCode that is C++ based anymore.
BeerSmith.com

BeerSmith
Knows some wx things
Knows some wx things
Posts: 27
Joined: Mon Mar 07, 2011 8:39 pm

Re: MenuBar in macOS Catalina

Post by BeerSmith » Mon Apr 12, 2021 11:33 pm

Quick update - created a new target in the same project (per one suggestion in thread above) and got it to compile - still no menu bar.
BeerSmith.com

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5154
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: MenuBar in macOS Catalina

Post by ONEEYEMAN » Mon Apr 12, 2021 11:37 pm

Hi,
Are you running application bundle?
Can you compile and run the "minimal" sample provided by wxWidgets?
How did you compile the library? How do you create Xcode project?

Thank you.

BeerSmith
Knows some wx things
Knows some wx things
Posts: 27
Joined: Mon Mar 07, 2011 8:39 pm

Re: MenuBar in macOS Catalina

Post by BeerSmith » Tue Apr 13, 2021 5:10 pm

OK,
After trying several different things I found a solution today:
Needed to add OSX specific code to call wxMenuBar::MacSetCommonMenuBar(bar) to the frame initialization.

Older versions worked just fine when I set the menu bar as part of the wxFrame creation, but apparently under the last three builds of wxWidgets you now need to explicitly set the common menu bar using this special call when using wxFrame as a basis for the app.
BeerSmith.com

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5154
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: MenuBar in macOS Catalina

Post by ONEEYEMAN » Tue Apr 13, 2021 5:12 pm

Hi,
Is "minimal" sample works for you?

Thank you.

chrism238
Earned a small fee
Earned a small fee
Posts: 20
Joined: Sun Feb 17, 2013 6:45 pm

Re: MenuBar in macOS Catalina

Post by chrism238 » Mon Apr 19, 2021 6:34 am

chrism238 wrote:
Tue Aug 11, 2020 10:00 pm
chrism238 wrote:
Tue Apr 21, 2020 7:18 pm
We're probably tired of (my) such attempts, but have now recompiled everything :

- Catalina 10.15.4 with Supplemental update,
- Xcode 11.4.1,
- wxWidgets 3.1.3
- my app
- menu sample code .../wxWidgets-3.1.3/samples/menu
Just to report, if anyone is still concerned, that this problem persists with the updated wxWidgets 3.1.4 on macOS 10.15.6
Hello All,

Further to this, I can happily report that the problem with the MenuBar on OSX has been fixed!
My environment: wxWidgets-3.1.5, macOS 10.15.7, clang 11.0.3

Thanks very much to anyone here reading this who helped in fixing the problem.

Chris.

Post Reply