Add options for which displays to show screen saver
This commit is contained in:
83
ConfigureSheet.xib
Normal file
83
ConfigureSheet.xib
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13771" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||||
|
<dependencies>
|
||||||
|
<deployment identifier="macosx"/>
|
||||||
|
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13771"/>
|
||||||
|
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||||
|
</dependencies>
|
||||||
|
<objects>
|
||||||
|
<customObject id="-2" userLabel="File's Owner" customClass="EpochFlipClock">
|
||||||
|
<connections>
|
||||||
|
<outlet property="configSheet" destination="QvC-M9-y7g" id="Neh-j4-32j"/>
|
||||||
|
<outlet property="screenDisplayOption" destination="osi-OU-YaU" id="iw1-KE-NYE"/>
|
||||||
|
</connections>
|
||||||
|
</customObject>
|
||||||
|
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||||
|
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||||
|
<window allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="QvC-M9-y7g" userLabel="Panel" customClass="NSPanel">
|
||||||
|
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
|
||||||
|
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
|
||||||
|
<rect key="contentRect" x="196" y="240" width="320" height="102"/>
|
||||||
|
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1418"/>
|
||||||
|
<view key="contentView" wantsLayer="YES" id="EiT-Mj-1SZ">
|
||||||
|
<rect key="frame" x="0.0" y="0.0" width="320" height="102"/>
|
||||||
|
<autoresizingMask key="autoresizingMask"/>
|
||||||
|
<subviews>
|
||||||
|
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="a1k-tn-KC1">
|
||||||
|
<rect key="frame" x="20" y="64" width="60" height="17"/>
|
||||||
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||||
|
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Show on:" id="jOB-rY-MKy">
|
||||||
|
<font key="font" metaFont="system"/>
|
||||||
|
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||||
|
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||||
|
</textFieldCell>
|
||||||
|
</textField>
|
||||||
|
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="osi-OU-YaU">
|
||||||
|
<rect key="frame" x="84" y="58" width="219" height="26"/>
|
||||||
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||||
|
<popUpButtonCell key="cell" type="push" title="Primary Display" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="z3J-9s-f75" id="oq1-VZ-McK">
|
||||||
|
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
|
||||||
|
<font key="font" metaFont="menu"/>
|
||||||
|
<menu key="menu" id="nCe-1g-6sV">
|
||||||
|
<items>
|
||||||
|
<menuItem title="Primary Display" state="on" id="z3J-9s-f75"/>
|
||||||
|
<menuItem title="Last Focussed Display" tag="1" id="5Rz-jw-XVj"/>
|
||||||
|
<menuItem title="All Displays" tag="2" id="uUG-c0-HaR"/>
|
||||||
|
</items>
|
||||||
|
</menu>
|
||||||
|
</popUpButtonCell>
|
||||||
|
</popUpButton>
|
||||||
|
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="1Od-P9-lod">
|
||||||
|
<rect key="frame" x="225" y="13" width="81" height="32"/>
|
||||||
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||||
|
<buttonCell key="cell" type="push" title="OK" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Mho-c8-3n8">
|
||||||
|
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||||
|
<font key="font" metaFont="system"/>
|
||||||
|
<string key="keyEquivalent" base64-UTF8="YES">
|
||||||
|
DQ
|
||||||
|
</string>
|
||||||
|
</buttonCell>
|
||||||
|
<connections>
|
||||||
|
<action selector="okClick:" target="-2" id="eti-FD-ctD"/>
|
||||||
|
</connections>
|
||||||
|
</button>
|
||||||
|
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="OoO-CW-4EW">
|
||||||
|
<rect key="frame" x="144" y="13" width="81" height="32"/>
|
||||||
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||||
|
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="o2L-6m-4TE">
|
||||||
|
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||||
|
<font key="font" metaFont="system"/>
|
||||||
|
<string key="keyEquivalent" base64-UTF8="YES">
|
||||||
|
Gw
|
||||||
|
</string>
|
||||||
|
<connections>
|
||||||
|
<action selector="cancelClick:" target="-2" id="BMF-tx-aGR"/>
|
||||||
|
</connections>
|
||||||
|
</buttonCell>
|
||||||
|
</button>
|
||||||
|
</subviews>
|
||||||
|
</view>
|
||||||
|
<point key="canvasLocation" x="34" y="50"/>
|
||||||
|
</window>
|
||||||
|
</objects>
|
||||||
|
</document>
|
||||||
@@ -11,6 +11,9 @@
|
|||||||
3A40068318B53129005F43A6 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A40068218B53129005F43A6 /* WebKit.framework */; };
|
3A40068318B53129005F43A6 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A40068218B53129005F43A6 /* WebKit.framework */; };
|
||||||
77996CD91C94B825006B0FF7 /* EpochFlipClock.m in Sources */ = {isa = PBXBuildFile; fileRef = 77996CD81C94B825006B0FF7 /* EpochFlipClock.m */; };
|
77996CD91C94B825006B0FF7 /* EpochFlipClock.m in Sources */ = {isa = PBXBuildFile; fileRef = 77996CD81C94B825006B0FF7 /* EpochFlipClock.m */; };
|
||||||
77AD4D2D2041D6A9001100EC /* Webview in Resources */ = {isa = PBXBuildFile; fileRef = 77AD4D2C2041D6A9001100EC /* Webview */; };
|
77AD4D2D2041D6A9001100EC /* Webview in Resources */ = {isa = PBXBuildFile; fileRef = 77AD4D2C2041D6A9001100EC /* Webview */; };
|
||||||
|
77AD4D2F2041DBC6001100EC /* ConfigureSheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = 77AD4D2E2041DBC6001100EC /* ConfigureSheet.xib */; };
|
||||||
|
77AD4D312041E44A001100EC /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77AD4D302041E44A001100EC /* AppKit.framework */; };
|
||||||
|
77AD4D332041F756001100EC /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77AD4D322041F756001100EC /* Cocoa.framework */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
@@ -21,6 +24,9 @@
|
|||||||
77996CD61C94B804006B0FF7 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = SOURCE_ROOT; };
|
77996CD61C94B804006B0FF7 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = SOURCE_ROOT; };
|
||||||
77996CD81C94B825006B0FF7 /* EpochFlipClock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EpochFlipClock.m; sourceTree = SOURCE_ROOT; };
|
77996CD81C94B825006B0FF7 /* EpochFlipClock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EpochFlipClock.m; sourceTree = SOURCE_ROOT; };
|
||||||
77AD4D2C2041D6A9001100EC /* Webview */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Webview; sourceTree = "<group>"; };
|
77AD4D2C2041D6A9001100EC /* Webview */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Webview; sourceTree = "<group>"; };
|
||||||
|
77AD4D2E2041DBC6001100EC /* ConfigureSheet.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ConfigureSheet.xib; sourceTree = "<group>"; };
|
||||||
|
77AD4D302041E44A001100EC /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
|
||||||
|
77AD4D322041F756001100EC /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@@ -28,6 +34,8 @@
|
|||||||
isa = PBXFrameworksBuildPhase;
|
isa = PBXFrameworksBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
77AD4D332041F756001100EC /* Cocoa.framework in Frameworks */,
|
||||||
|
77AD4D312041E44A001100EC /* AppKit.framework in Frameworks */,
|
||||||
3A40068318B53129005F43A6 /* WebKit.framework in Frameworks */,
|
3A40068318B53129005F43A6 /* WebKit.framework in Frameworks */,
|
||||||
3A40066E18B53113005F43A6 /* ScreenSaver.framework in Frameworks */,
|
3A40066E18B53113005F43A6 /* ScreenSaver.framework in Frameworks */,
|
||||||
);
|
);
|
||||||
@@ -56,6 +64,8 @@
|
|||||||
3A40066A18B53112005F43A6 /* Frameworks */ = {
|
3A40066A18B53112005F43A6 /* Frameworks */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
77AD4D322041F756001100EC /* Cocoa.framework */,
|
||||||
|
77AD4D302041E44A001100EC /* AppKit.framework */,
|
||||||
3A40068218B53129005F43A6 /* WebKit.framework */,
|
3A40068218B53129005F43A6 /* WebKit.framework */,
|
||||||
3A40066D18B53113005F43A6 /* ScreenSaver.framework */,
|
3A40066D18B53113005F43A6 /* ScreenSaver.framework */,
|
||||||
);
|
);
|
||||||
@@ -69,6 +79,7 @@
|
|||||||
3A95A94B18EA12D30036779C /* EpochFlipClock.h */,
|
3A95A94B18EA12D30036779C /* EpochFlipClock.h */,
|
||||||
77996CD81C94B825006B0FF7 /* EpochFlipClock.m */,
|
77996CD81C94B825006B0FF7 /* EpochFlipClock.m */,
|
||||||
77996CD61C94B804006B0FF7 /* Info.plist */,
|
77996CD61C94B804006B0FF7 /* Info.plist */,
|
||||||
|
77AD4D2E2041DBC6001100EC /* ConfigureSheet.xib */,
|
||||||
);
|
);
|
||||||
name = Source;
|
name = Source;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -142,6 +153,7 @@
|
|||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
77AD4D2D2041D6A9001100EC /* Webview in Resources */,
|
77AD4D2D2041D6A9001100EC /* Webview in Resources */,
|
||||||
|
77AD4D2F2041DBC6001100EC /* ConfigureSheet.xib in Resources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
#import <ScreenSaver/ScreenSaver.h>
|
#import <ScreenSaver/ScreenSaver.h>
|
||||||
|
|
||||||
@interface EpochFlipClock : ScreenSaverView
|
@interface EpochFlipClock : ScreenSaverView
|
||||||
|
{
|
||||||
|
IBOutlet id configSheet;
|
||||||
|
IBOutlet id screenDisplayOption;
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -3,15 +3,53 @@
|
|||||||
|
|
||||||
@implementation EpochFlipClock
|
@implementation EpochFlipClock
|
||||||
|
|
||||||
|
static NSString * const epochFlipClockModule = @"com.epochflipclock";
|
||||||
|
|
||||||
- (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview {
|
- (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview {
|
||||||
if (!(self = [super initWithFrame:frame isPreview:isPreview])) return nil;
|
if (!(self = [super initWithFrame:frame isPreview:isPreview])) return nil;
|
||||||
|
|
||||||
|
// Preference Defaults
|
||||||
|
ScreenSaverDefaults *defaults;
|
||||||
|
defaults = [ScreenSaverDefaults defaultsForModuleWithName:epochFlipClockModule];
|
||||||
|
|
||||||
|
[defaults registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
|
||||||
|
@"0", @"screenDisplayOption", // Default to show only on primary display
|
||||||
|
nil]];
|
||||||
|
|
||||||
|
// Webview
|
||||||
NSURL* indexHTMLDocumentURL = [NSURL URLWithString:[[[NSURL fileURLWithPath:[[NSBundle bundleForClass:self.class].resourcePath stringByAppendingString:@"/Webview/index.html"] isDirectory:NO] description] stringByAppendingFormat:@"?screensaver=1%@", self.isPreview ? @"&is_preview=1" : @""]];
|
NSURL* indexHTMLDocumentURL = [NSURL URLWithString:[[[NSURL fileURLWithPath:[[NSBundle bundleForClass:self.class].resourcePath stringByAppendingString:@"/Webview/index.html"] isDirectory:NO] description] stringByAppendingFormat:@"?screensaver=1%@", self.isPreview ? @"&is_preview=1" : @""]];
|
||||||
|
|
||||||
WebView* webView = [[WebView alloc] initWithFrame:NSMakeRect(0, 0, frame.size.width, frame.size.height)];
|
WebView* webView = [[WebView alloc] initWithFrame:NSMakeRect(0, 0, frame.size.width, frame.size.height)];
|
||||||
webView.drawsBackground = NO; // Avoids a "white flash" just before the index.html file has loaded
|
webView.drawsBackground = NO; // Avoids a "white flash" just before the index.html file has loaded
|
||||||
[webView.mainFrame loadRequest:[NSURLRequest requestWithURL:indexHTMLDocumentURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0]];
|
[webView.mainFrame loadRequest:[NSURLRequest requestWithURL:indexHTMLDocumentURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0]];
|
||||||
|
|
||||||
|
// Show on screens based on preferences
|
||||||
|
NSArray* screens = [NSScreen screens];
|
||||||
|
NSScreen* primaryScreen = [screens objectAtIndex:0];
|
||||||
|
|
||||||
|
switch ([defaults integerForKey:@"screenDisplayOption"]) {
|
||||||
|
// Primary screen (System Preferences > Displays).
|
||||||
|
// The screen the menubar is shown on under 'arrangement'
|
||||||
|
case 0:
|
||||||
|
if ((primaryScreen.frame.origin.x == frame.origin.x) || isPreview) {
|
||||||
[self addSubview:webView];
|
[self addSubview:webView];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// Last Focussed Screen
|
||||||
|
// This _sometimes_ results in nothing being shown when previewing in system prefs.
|
||||||
|
case 1:
|
||||||
|
if (([NSScreen mainScreen].frame.origin.x == frame.origin.x) || isPreview) {
|
||||||
|
[self addSubview:webView];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// All Screens
|
||||||
|
case 2:
|
||||||
|
[self addSubview:webView];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
[self addSubview:webView];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -19,7 +57,50 @@
|
|||||||
#pragma mark - ScreenSaverView
|
#pragma mark - ScreenSaverView
|
||||||
|
|
||||||
- (void)animateOneFrame { [self stopAnimation]; }
|
- (void)animateOneFrame { [self stopAnimation]; }
|
||||||
- (BOOL)hasConfigureSheet { return NO; }
|
|
||||||
|
#pragma mark - Config
|
||||||
|
// http://cocoadevcentral.com/articles/000088.php
|
||||||
|
|
||||||
|
- (BOOL)hasConfigureSheet { return YES; }
|
||||||
|
|
||||||
|
- (NSWindow *)configureSheet
|
||||||
|
{
|
||||||
|
ScreenSaverDefaults *defaults;
|
||||||
|
defaults = [ScreenSaverDefaults defaultsForModuleWithName:epochFlipClockModule];
|
||||||
|
|
||||||
|
if (!configSheet)
|
||||||
|
{
|
||||||
|
if (![NSBundle loadNibNamed:@"ConfigureSheet" owner:self])
|
||||||
|
{
|
||||||
|
NSLog( @"Failed to load configure sheet." );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[screenDisplayOption selectItemAtIndex:[defaults integerForKey:@"screenDisplayOption"]];
|
||||||
|
|
||||||
|
return configSheet;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (IBAction)cancelClick:(id)sender
|
||||||
|
{
|
||||||
|
[[NSApplication sharedApplication] endSheet:configSheet];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (IBAction) okClick: (id)sender
|
||||||
|
{
|
||||||
|
ScreenSaverDefaults *defaults;
|
||||||
|
defaults = [ScreenSaverDefaults defaultsForModuleWithName:epochFlipClockModule];
|
||||||
|
|
||||||
|
// Update our defaults
|
||||||
|
[defaults setInteger:[screenDisplayOption indexOfSelectedItem]
|
||||||
|
forKey:@"screenDisplayOption"];
|
||||||
|
|
||||||
|
// Save the settings to disk
|
||||||
|
[defaults synchronize];
|
||||||
|
|
||||||
|
// Close the sheet
|
||||||
|
[[NSApplication sharedApplication] endSheet:configSheet];
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - WebFrameLoadDelegate
|
#pragma mark - WebFrameLoadDelegate
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user