Skip to content

Instantly share code, notes, and snippets.

@jamesez
Created April 14, 2015 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesez/a56e5b3fb4e363b41e0f to your computer and use it in GitHub Desktop.
Save jamesez/a56e5b3fb4e363b41e0f to your computer and use it in GitHub Desktop.
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
self.windows = [NSMutableArray new];
#ifndef DEBUG
for (NSScreen *screen in [NSScreen screens]) {
NSWindow *blockingWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, [screen frame].size.width, [screen frame].size.height)
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:YES
screen:screen];
blockingWindow.alphaValue = 0.75;
blockingWindow.backgroundColor = [NSColor blackColor];
blockingWindow.level = kCGPopUpMenuWindowLevel + 100;
[blockingWindow makeKeyAndOrderFront:self];
[self.windows addObject:blockingWindow];
}
// Capture displays (really black it out)
if (CGCaptureAllDisplays() != kCGErrorSuccess) {
NSLog(@"Couldn't capture displays!");
// Note: you'll probably want to display a proper error dialog here
}
#endif
// Create the usage agreement window
NSRect rect = [agreementView bounds];
unsigned int stylemask = NSBorderlessWindowMask;
agreementWindow = [[UsageAgreementWindow alloc] initWithContentRect:rect
styleMask:stylemask
backing:NSBackingStoreBuffered
defer:NO ];
[agreementWindow setLevel:CGShieldingWindowLevel()];
[agreementWindow setHasShadow:YES];
[agreementWindow center];
[agreementWindow makeKeyAndOrderFront:nil];
[NSApp activateIgnoringOtherApps:YES];
}
- (void)applicationWillTerminate:(NSNotification *)notification
{
CGReleaseAllDisplays();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment