Forum > LCL

[Solved] How can I call NSWindow.togglefullscreen?

(1/2) > >>

Clover:
I'm porting my carbon app to cocoa 64-bit.

I notice that MacOS adds "Enter Full Screen" automatically to my View main menu item and enables the special green traffic light button, for toggling in and out of fullscreen mode. These two methods work great. But it would be nice to also start in full screen mode if that's how the user left the app.

Unfortunately setting full screen in code by setting WindowState := wsFullScreen causes big problems: popup menus no longer appear, the main menu no longer unhides itself, it's impossible to return to wsNormal mode and the app has to be force quit.

I was wondering if instead I could invoke the "Enter Full Screen" item that MacOS adds to my View menu.

I see that https://developer.apple.com/library/content/documentation/General/Conceptual/MOSXAppProgrammingGuide/FullScreenApp/FullScreenApp.html shows that the NSWindow API contains a simple togglefullscreen function. How would I call that from my Lazarus code?

Phil:

--- Quote from: Clover on February 22, 2018, 04:19:30 pm ---Unfortunately setting full screen in code by setting WindowState := wsFullScreen causes big problems: popup menus no longer appear, the main menu no longer unhides itself, it's impossible to return to wsNormal mode and the app has to be force quit.

--- End quote ---

Are you using trunk code? If not, test with it - appears to have support for this. If still a problem, file a bug report for the Cocoa widgetset with a small reproducible example (project source files).

Clover:
Yes indeed, I'm using trunk code after following your excellent directions at https://macpgmr.github.io/MacXPlatform/UsingCocoaFromTrunk.html

I am filing bug reports as I go and I've just filed one for this.

Clover:
Since it could be a while for this to be fixed in trunk, and a MacOS will be released in a couple of weeks that will start warning about 32-bit apps, can anyone assist with my question, which was: How can I call the NSWindow.togglefullscreen (or invoke the "Enter Full Screen" menu item added by MacOS) from my Lazarus code? Thanks!

Phil:

--- Quote from: Clover on February 23, 2018, 06:44:22 pm ---Since it could be a while for this to be fixed in trunk, and a MacOS will be released in a couple of weeks that will start warning about 32-bit apps, can anyone assist with my question, which was: How can I call the NSWindow.togglefullscreen (or invoke the "Enter Full Screen" menu item added by MacOS) from my Lazarus code? Thanks!

--- End quote ---

If you look at TCocoaWidgetSet.ShowWindow in cocoawinapi.inc, you can see how it currently does it. And the code that leaves fullscreen mode is commented out, apparently because it crashes.

Using exit/enterFullScreenMode methods like Cocoa widgetset does is the old way of doing it. The new way, which you link to, using toggleFullScreen, is presumably what the Cocoa-added View menu item uses. But toggleFullScreen was added in 10.7, but FPC CocoaAll is based on parsing of 10.6, I believe, hence it has no toggleFullScreen. You would need to add this to NSWindow, perhaps via a category, then call it similar to the way TCocoaWidgetSet.ShowWindow calls NSWindow methods.

You could also try sending the shortcut key, per these approaches:

https://stackoverflow.com/questions/4705748/send-a-keyboard-shortcut-to-a-mac-os-x-window

I hope you're not using the Cocoa widgetset for production code. I don't consider it suitable for that.

Navigation

[0] Message Index

[#] Next page

Go to full version