-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathFullScreenWindow.m
66 lines (47 loc) · 1.81 KB
/
FullScreenWindow.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// FullScreenWindow.m
// ECBrowser
//
// Created by Florian Bogner on 1/26/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "FullScreenWindow.h"
@implementation FullScreenWindow
//This Method access as wrapper to allow us to create a window larger than the screen => to hide the window border
- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
{
return frameRect;
}
//Init full screen
- (void)awakeFromNib {
//Enable detection for NSApplicationPresentationOptions
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setKioskMode) name:@"NSWindowDidUpdateNotification" object:nil];
//Make bg black
[self setBackgroundColor:[NSColor blackColor]];
//Get fullscreen
NSRect screensize=[[NSScreen mainScreen] frame]; //get screen size
screensize.size.height+=23; //add menu bar height
[self setFrame:screensize display:YES animate:YES]; //make fullscreen
//disable resize, move,...
[self setStyleMask:NSBorderlessWindowMask];
//center the cursor
NSPoint center;
center.x=floor([[NSScreen mainScreen] frame].size.width/2);
center.y=floor([[NSScreen mainScreen] frame].size.height/2);
CGWarpMouseCursorPosition(NSPointToCGPoint(center));
}
- (BOOL) canBecomeKeyWindow { //be the key window even if you are borderless
return YES;
}
-(void)dealloc { //Cleaning up
[[NSNotificationCenter defaultCenter] removeObserver:self]; //stop listening
[NSCursor unhide];
[super dealloc];
}
-(void)setKioskMode { //hide menu bar, dock, . . .
NSApplicationPresentationOptions options = NSApplicationPresentationHideDock + NSApplicationPresentationHideMenuBar;// + NSApplicationPresentationDisableProcessSwitching; //+ NSApplicationPresentationDisableForceQuit;
[NSApp setPresentationOptions:options];
//hide the cursor
[NSCursor hide];
}
@end