Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Lock" Screen On Mac App

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?

like image 256
The Kraken Avatar asked Dec 27 '22 00:12

The Kraken


2 Answers

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.

like image 126
Ken Thomases Avatar answered Jan 17 '23 08:01

Ken Thomases


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.

Xcode Interface Builder: Menu Item

Or, you can subclass NSApplication and override -sendEvent: to do nothing, thereby ignoring all events (keyboard, mouse, etc.) sent to your application.

like image 32
ma11hew28 Avatar answered Jan 17 '23 08:01

ma11hew28