1
1
/* xdaliclock - a melting digital clock
2
* Copyright (c) 1991-2007 Jamie Zawinski <jwz@jwz.org>
2
* Copyright (c) 1991-2013 Jamie Zawinski <jwz@jwz.org>
4
4
* Permission to use, copy, modify, distribute, and sell this software and its
5
5
* documentation for any purpose is hereby granted without fee, provided that
31
31
NSUserDefaultsController *controller =
32
32
[NSUserDefaultsController sharedUserDefaultsController];
33
NSUserDefaults *defs = [controller defaults];
34
/* Tell the DaliClockView class to initialize its preferences.
35
This can't just happen in [DaliClockView:initialize], because
36
we have to ensure that DaliClockView is using the same
37
NSUserDefaultsController object that we are using here.
35
/* Tell the DaliClockView class to initialize its default preferences.
39
[DaliClockView initializeDefaults:controller];
37
[DaliClockView registerDefaults:defs];
42
40
/* Now that the DaliClockView class has initialized its preferences,
43
41
set the defaults for those preferences handled by AppController
44
42
rather than by DaliClockView.
46
NSDictionary* defaults = [NSDictionary dictionaryWithObjectsAndKeys:
44
NSDictionary *extras = [NSDictionary dictionaryWithObjectsAndKeys:
47
45
@"NO", @"windowTitlebarIsHidden",
48
46
@"NO", @"dockIconIsHidden",
49
47
@"0", @"windowLevel", // default to "normal window"
52
49
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:100];
53
[dict addEntriesFromDictionary: [controller initialValues]];
54
[dict addEntriesFromDictionary:defaults];
55
[controller setInitialValues:dict];
56
[[controller defaults] registerDefaults:dict];
50
[dict addEntriesFromDictionary:[defs dictionaryRepresentation]];
51
[dict addEntriesFromDictionary:extras];
52
[defs registerDefaults:dict];
54
[DaliClockView setUserDefaultsController: controller];
78
76
int level = real_window_level ([prefs integerForKey:@"windowLevel"]);
78
/* CGDisplayCaptureWithOptions (kCGDirectMainDisplay, kCGCaptureNoFill)
79
is supposed to grab the screen without blanking it, but it blanks anyway.
80
As of 10.7, the new way to do full-screen is
81
[app setPresentationOptions:NSApplicationPresentationFullScreen]
82
but that doesn't seem to do anything. E.g., it doesn't grab the mouse.
83
So let's just not do anything.
87
NSApplication *app = [NSApplication sharedApplication];
80
88
if (was_fullscreen_p) {
82
if (CGDisplayRelease (kCGDirectMainDisplay) != kCGErrorSuccess)
83
NSLog ( @"Couldn't release the display!");
89
if ([app respondsToSelector:@selector(setPresentationOptions:)]) { // 10.7
90
[app setPresentationOptions: NSApplicationPresentationDefault];
92
if (CGDisplayRelease (kCGDirectMainDisplay) != kCGErrorSuccess)
93
NSLog ( @"Couldn't release the display!");
86
97
if (fullscreen_p) {
87
if (CGDisplayCapture (kCGDirectMainDisplay) != kCGErrorSuccess) {
98
if ([app respondsToSelector:@selector(setPresentationOptions:)]) { // 10.7
99
[app setPresentationOptions:(NSApplicationPresentationHideDock|
100
NSApplicationPresentationHideMenuBar|
101
NSApplicationPresentationFullScreen)];
103
if (CGDisplayCaptureWithOptions (kCGDirectMainDisplay, kCGCaptureNoFill)
104
!= kCGErrorSuccess) {
88
105
NSLog(@"Couldn't capture the main display!");
93
112
if (fullscreen_p) {
94
113
level = CGShieldingWindowLevel();
95
114
fullscreen_window_level = level;
117
CGAssociateMouseAndMouseCursorPosition (false); // locks mouse position
120
CGAssociateMouseAndMouseCursorPosition (true); // normal mouse
100
123
NSScreen *screen = [NSScreen mainScreen];
166
189
view = [[DaliClockView alloc] initWithFrame:[window frame]];
191
// Without this, toggling the title bar kills transparency until restart.
192
[window setBackgroundColor:[NSColor clearColor]];
168
194
[window setContentView:view];