diff --git a/CKBlurView.h b/CKBlurView.h new file mode 100755 index 0000000..b9eb0dc --- /dev/null +++ b/CKBlurView.h @@ -0,0 +1,39 @@ +// +// CKBlurView.h +// CKBlurView +// +// Created by Conrad Kramer on 10/25/13. +// Copyright (c) 2013 Kramer Software Productions, LLC. All rights reserved. +// + +#import +#import +#import + +extern NSString * const CKBlurViewQualityDefault; + +extern NSString * const CKBlurViewQualityLow; + +NS_CLASS_AVAILABLE_IOS(7_0) @interface CKBlurView : UIView + +/** + Quality of the blur. The lower the quality, the more performant the blur. Must be one of `CKBlurViewQualityDefault` or `CKBlurViewQualityLow`. Defaults to `CKBlurViewQualityDefault`. + */ +@property (nonatomic, retain) NSString *blurQuality; + +/** + Radius of the Gaussian blur. Defaults to 5.0. + */ +@property (nonatomic, readwrite) CGFloat blurRadius; + +/** + Bounds to be blurred, in the receiver's coordinate system. Defaults to CGRectNull. + */ +@property (nonatomic, readwrite) CGRect blurCroppingRect; + +/** + Boolean indicating whether the edge of the view should be softened. Defaults to YES. + */ +@property (nonatomic, readwrite) BOOL blurEdges; + +@end \ No newline at end of file diff --git a/CKBlurView.m b/CKBlurView.m new file mode 100755 index 0000000..c8d1a8f --- /dev/null +++ b/CKBlurView.m @@ -0,0 +1,94 @@ +// +// CKBlurView.m +// CKBlurView +// +// Created by Conrad Kramer on 10/25/13. +// Copyright (c) 2013 Kramer Software Productions, LLC. All rights reserved. +// + +#import "CKBlurView.h" + +@interface CABackdropLayer : CALayer + +@end + +@interface CAFilter : NSObject + ++ (instancetype)filterWithName:(NSString *)name; + +@end + +@interface CKBlurView () + +@property (retain, nonatomic) CAFilter *blurFilter; + +@end + +extern NSString * const kCAFilterGaussianBlur; + +NSString * const CKBlurViewQualityDefault = @"default"; + +NSString * const CKBlurViewQualityLow = @"low"; + +static NSString * const CKBlurViewQualityKey = @"inputQuality"; + +static NSString * const CKBlurViewRadiusKey = @"inputRadius"; + +static NSString * const CKBlurViewBoundsKey = @"inputBounds"; + +static NSString * const CKBlurViewHardEdgesKey = @"inputHardEdges"; + + +@implementation CKBlurView + ++ (Class)layerClass { + return [CABackdropLayer class]; +} + +- (instancetype)initWithFrame:(CGRect)frame { + self = [super initWithFrame:frame]; + if (self) { + CAFilter *filter = [CAFilter filterWithName:kCAFilterGaussianBlur]; + self.layer.filters = @[ filter ]; + self.blurFilter = filter; + + self.blurQuality = CKBlurViewQualityDefault; + self.blurRadius = 5.0f; + } + return self; +} + +- (void)setQuality:(NSString *)quality { + [self.blurFilter setValue:quality forKey:CKBlurViewQualityKey]; +} + +- (NSString *)quality { + return [self.blurFilter valueForKey:CKBlurViewQualityKey]; +} + +- (void)setBlurRadius:(CGFloat)radius { + [self.blurFilter setValue:@(radius) forKey:CKBlurViewRadiusKey]; +} + +- (CGFloat)blurRadius { + return [[self.blurFilter valueForKey:CKBlurViewRadiusKey] floatValue]; +} + +- (void)setBlurCroppingRect:(CGRect)croppingRect { + [self.blurFilter setValue:[NSValue valueWithCGRect:croppingRect] forKey:CKBlurViewBoundsKey]; +} + +- (CGRect)blurCroppingRect { + NSValue *value = [self.blurFilter valueForKey:CKBlurViewBoundsKey]; + return value ? [value CGRectValue] : CGRectNull; +} + +- (void)setBlurEdges:(BOOL)blurEdges { + [self.blurFilter setValue:@(!blurEdges) forKey:CKBlurViewHardEdgesKey]; +} + +- (BOOL)blurEdges { + return ![[self.blurFilter valueForKey:CKBlurViewHardEdgesKey] boolValue]; +} + +@end diff --git a/Makefile b/Makefile index 3c9afbb..86d1e48 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,8 @@ ARCHS = armv7 armv7s arm64 include theos/makefiles/common.mk TWEAK_NAME = SwitcherBlur -SwitcherBlur_OBJC_FILES = SwitcherBlur.xm -SwitcherBlur_FRAMEWORKS = UIKit QuartzCore +SwitcherBlur_OBJC_FILES = SwitcherBlur.xm CKBlurView.m +SwitcherBlur_FRAMEWORKS = UIKit QuartzCore CoreGraphics include $(THEOS_MAKE_PATH)/tweak.mk SUBPROJECTS += switcherblurprefs diff --git a/README.md b/README.md index 4a1b297..1111262 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ SwitcherBlur ======================= -Configurable iOS 7 snapshots blurs. +Configurable iOS 7 snapshots blurs. Uses [CKBlurView](https://github.com/conradev/CKBlurView) by conradev for the wallpaper blurring. ![Gaussian Blur your app snapshots](https://f.cloud.github.com/assets/951011/2054415/231a633a-8ab5-11e3-99d8-0d8b75842f47.PNG) diff --git a/SwitcherBlur.xm b/SwitcherBlur.xm index 8a17607..8cb235f 100644 --- a/SwitcherBlur.xm +++ b/SwitcherBlur.xm @@ -1,18 +1,26 @@ #import #import #import +#import "CKBlurView.h" -/******************** Forward-Declarations *********************/ +/**************************** Forward-Declarations ****************************/ @interface CAFilter : NSObject +(instancetype)filterWithName:(NSString *)name; @end +@interface SpringBoard : UIApplication +-(void)_relaunchSpringBoardNow; +@end + @interface SBApplication -(id)bundleIdentifier; -(BOOL)isRunning; @end +@interface SBAppSliderWindow : UIWindow +@end + @interface SBAppSliderSnapshotView { UIImageView *_snapshotImage; } @@ -22,10 +30,10 @@ @end -/*********************** Global Functions **********************/ +/**************************** Settings Assignments ***************************/ static NSMutableArray *switcherblur_DisabledApps; // @"All" means all are disabled, nil means everything's enabled -static NSInteger switcherblur_blurIfInactive; +static NSInteger switcherblur_blurIfInactive, switcherblur_blurWallpaper; static void switcherBlur_reloadSettings(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){ NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Preferences/com.insanj.switcherblur.plist"]]; @@ -33,7 +41,8 @@ static void switcherBlur_reloadSettings(CFNotificationCenterRef center, void *ob if([settings objectForKey:@"enabled"] && ![[settings objectForKey:@"enabled"] boolValue]){ switcherblur_DisabledApps = @[@"All"].mutableCopy; - switcherblur_blurIfInactive = NO; + switcherblur_blurIfInactive = 1; + switcherblur_blurWallpaper = 1; } else{ @@ -46,10 +55,38 @@ static void switcherBlur_reloadSettings(CFNotificationCenterRef center, void *ob switcherblur_DisabledApps = nil; switcherblur_blurIfInactive = ([settings objectForKey:@"running"] && [[settings objectForKey:@"running"] boolValue]) + 1; + + int previousWallpaper = switcherblur_blurWallpaper; + switcherblur_blurWallpaper = ([settings objectForKey:@"wallpaper"] && [[settings objectForKey:@"wallpaper"] boolValue]) + 1; + if(previousWallpaper != switcherblur_blurWallpaper) + [(SpringBoard *)[%c(SpringBoard) sharedApplication] _relaunchSpringBoardNow]; } } -/**************************** Hooks ****************************/ +/**************************** Background Blur ****************************/ + +%hook SBAppSliderWindow + +-(id)initWithFrame:(CGRect)frame{ + if(switcherblur_blurWallpaper == 0){ + NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Preferences/com.insanj.switcherblur.plist"]]; + switcherblur_blurWallpaper = ([settings objectForKey:@"wallpaper"] && [[settings objectForKey:@"wallpaper"] boolValue]) + 1; + } + + SBAppSliderWindow *window = %orig(); + + if(switcherblur_blurWallpaper == 2){ + NSLog(@"[SwitcherBlur] Blurrig app switcher background : %@", self); + CKBlurView *blurView = [[CKBlurView alloc] initWithFrame:frame]; + [window addSubview:blurView]; + } + + return window; +} + +%end + +/**************************** Snapshot Blur ****************************/ %hook SBAppSliderSnapshotView diff --git a/control b/control index eb8566d..3ece0ba 100644 --- a/control +++ b/control @@ -2,9 +2,9 @@ Package: com.insanj.switcherblur Name: SwitcherBlur Pre-Depends: firmware (>= 7.0) Depends: mobilesubstrate, applist -Version: 1.1.1 +Version: 1.2 Architecture: iphoneos-arm -Description: Blur iOS 7 switcher snapshots. +Description: Blur the iOS 7 switcher. Maintainer: Julian Weiss Author: Julian (insanj) Weiss Section: Tweaks diff --git a/switcherblurprefs/Resources/SwitcherBlurPrefs.plist b/switcherblurprefs/Resources/SwitcherBlurPrefs.plist index b5a7611..72c53d1 100644 --- a/switcherblurprefs/Resources/SwitcherBlurPrefs.plist +++ b/switcherblurprefs/Resources/SwitcherBlurPrefs.plist @@ -62,18 +62,23 @@ label Inactive Blur + + cell PSGroupCell + footerText Blurs your wallpaper behind the switcher. Will respring when toggling. + - cell PSGroupCell - label Contact - footerText Source available online. Special thanks to Elijah Frederickson for code contributions. + PostNotification com.insanj.switcherblur/reloadSettings + cell PSSwitchCell + default + defaults com.insanj.switcherblur + key wallpaper + label Wallpaper Blur - cell PSButtonCell - label Support & Feedback - icon mail.png - action mail + cell PSGroupCell + footerText Source available online. Special thanks to Elijah Frederickson for code contributions. diff --git a/switcherblurprefs/Resources/mail@2x.png b/switcherblurprefs/Resources/mail@2x.png deleted file mode 100644 index b2c60f0..0000000 Binary files a/switcherblurprefs/Resources/mail@2x.png and /dev/null differ diff --git a/switcherblurprefs/SwitcherBlurPrefs.xm b/switcherblurprefs/SwitcherBlurPrefs.xm index 3aef877..7f09e30 100644 --- a/switcherblurprefs/SwitcherBlurPrefs.xm +++ b/switcherblurprefs/SwitcherBlurPrefs.xm @@ -63,23 +63,6 @@ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://mobile.twitter.com/insanj"]]; } --(void)mail{ - NSURL *helpurl = [NSURL URLWithString:@"mailto:insanjmail%40gmail.com?subject=SwitcherBlur%20(1.1.1)%20Support"]; - if([MFMailComposeViewController canSendMail]){ - MFMailComposeViewController *composeViewController = [[MFMailComposeViewController alloc] initWithNibName:nil bundle:nil]; - [composeViewController setMailComposeDelegate:self]; - [composeViewController setToRecipients:@[@"insanjmail@gmail.com"]]; - [composeViewController setSubject:@"SwitcherBlur (1.1.1) Support"]; - [self presentViewController:composeViewController animated:YES completion:nil]; - }//end if - - else if ([[UIApplication sharedApplication] canOpenURL:helpurl]) - [[UIApplication sharedApplication] openURL:helpurl]; - - else - [[[UIAlertView alloc] initWithTitle:@"Contact Developer" message:@"Shoot an email to insanjmail@gmail.com, or talk to me on twitter (@insanj) if you have any problems, requests, or ideas!" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Dismiss", nil] show]; -} - -(void)shareTapped:(UIBarButtonItem *)sender{ NSString *text = @"An iOS 7 switcher with style, utility, and a bit of blur. Get SwitcherBlur from @insanj today!"; NSURL *url = [NSURL URLWithString:@"https://github.com/insanj/SwitcherBlur/"];