In Mac OS X, what API do I need to call in order to place a window over not only the entire screen, but the menu bar and dock as well? Also, is it possible to effectively "lock" the screen into this position, disabling Mission Control, launchpad, etc.?
I have tried the following code within the App Delegate's implementation file:
- (void)awakeFromNib {
@try {
NSApplicationPresentationOptions options = NSApplicationPresentationDisableForceQuit + NSApplicationPresentationDisableHideApplication + NSApplicationPresentationDisableProcessSwitching + NSApplicationPresentationHideDock + NSApplicationPresentationHideMenuBar + NSApplicationPresentationFullScreen;
[NSApp setPresentationOptions:options];
NSLog(@"Set presentation options");
}
@catch (NSException *exception) {
NSLog(@"Error. Invalid options");
}
}
NSLog reads "Set presentation options", but nothing else happens. Any tips?
This would basically involve the same sorts of thing as "kiosk mode". See Apple's Kiosk Mode Programming Topic.
You basically use -[NSApplication setPresentationOptions:]
or -[NSView enterFullScreenMode:withOptions:]
with an option dictionary containing the key NSFullScreenModeApplicationPresentationOptions
whose value is an NSNumber
containing the same sort of presentation option values as the NSApplication
method takes.
In Xcode, create a new Cocoa Application, and paste the code below in AppDelegate.m
.
- (void)awakeFromNib
{
// Lock app in full screen mode for 10 seconds.
NSApplicationPresentationOptions presentationOptions = (NSApplicationPresentationHideDock |
NSApplicationPresentationHideMenuBar |
NSApplicationPresentationDisableAppleMenu |
NSApplicationPresentationDisableProcessSwitching |
NSApplicationPresentationDisableForceQuit |
NSApplicationPresentationDisableSessionTermination |
NSApplicationPresentationDisableHideApplication);
NSDictionary *fullScreenOptions = @{NSFullScreenModeApplicationPresentationOptions: @(presentationOptions)};
[_window.contentView enterFullScreenMode:[NSScreen mainScreen] withOptions:fullScreenOptions];
[_window.contentView performSelector:@selector(exitFullScreenModeWithOptions:) withObject:nil afterDelay:10.0];
}
You will still be able to quit the app with ⌘Q
. To prevent that, you can delete the Key Equivalent of the Quit Menu Item.
Or, you can subclass NSApplication
and override -sendEvent:
to do nothing, thereby ignoring all events (keyboard, mouse, etc.) sent to your application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With