Skip to content

Commit

Permalink
Added option to select what to blur
Browse files Browse the repository at this point in the history
  • Loading branch information
shinvou committed Jan 13, 2015
1 parent 11e758e commit 620cc2f
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 18 deletions.
79 changes: 64 additions & 15 deletions Tweak.xm
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,27 @@ static BOOL shuffleEnabled = NO;
static BOOL perspectiveZoom = YES;
static BOOL blurEnabled = NO;
static int blurStrenght = 5;
static int blurMode = 0;
static BOOL interwallEnabled = NO;
static int interwallTime = 60;

static void SetWallpaper(UIImage *image)
static void SetWallpaper(UIImage *image, int mode)
{
PLStaticWallpaperImageViewController *wallpaperViewController = [[PLStaticWallpaperImageViewController alloc] initWithUIImage:image];
wallpaperViewController.saveWallpaperData = YES;

PLWallpaperMode wallMode = mode;
uintptr_t address = (uintptr_t)&wallMode;
object_setInstanceVariable(wallpaperViewController, "_wallpaperMode", *(PLWallpaperMode **)address);

[wallpaperViewController _savePhoto];
[wallpaperViewController release];
}

static void PrepareWallpaper(UIImage *image)
{
UIImage *normalImage = image;

if (blurEnabled) {
CIFilter *gaussianBlurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
[gaussianBlurFilter setDefaults];
Expand All @@ -61,21 +77,45 @@ static void SetWallpaper(UIImage *image)
rect.size = image.size;

CGImageRef cgimg = [context createCGImage:outputImage fromRect:rect];
image = [UIImage imageWithCGImage:cgimg];
UIImage *blurredImage = [UIImage imageWithCGImage:cgimg];
CGImageRelease(cgimg);
}

PLStaticWallpaperImageViewController *wallpaperViewController = [[PLStaticWallpaperImageViewController alloc] initWithUIImage:image];
wallpaperViewController.saveWallpaperData = YES;
switch (blurMode) {
case 1:
if (wallpaperMode == 0) {
SetWallpaper(normalImage, 2);
SetWallpaper(blurredImage, 1);
} else if (wallpaperMode == 1) {
SetWallpaper(blurredImage, 1);
} else {
SetWallpaper(normalImage, 2);
}

uintptr_t address = (uintptr_t)&wallpaperMode;
object_setInstanceVariable(wallpaperViewController, "_wallpaperMode", *(PLWallpaperMode **)address);
break;

[wallpaperViewController _savePhoto];
[wallpaperViewController release];
case 2:
if (wallpaperMode == 0) {
SetWallpaper(normalImage, 1);
SetWallpaper(blurredImage, 2);
} else if (wallpaperMode == 2) {
SetWallpaper(blurredImage, 2);
} else {
SetWallpaper(normalImage, 1);
}

break;

default:
SetWallpaper(blurredImage, wallpaperMode);

break;
}
} else {
SetWallpaper(normalImage, wallpaperMode);
}
}

static void GetWallpapersFromAlbum()
static void GetWallpaperFromAlbum()
{
if (!assetsLibrary) {
assetsLibrary = [[ALAssetsLibrary alloc] init];
Expand All @@ -90,7 +130,7 @@ static void GetWallpapersFromAlbum()
if (index == currentIndex) {
ALAssetRepresentation *representation = [result defaultRepresentation];
UIImage *image = [UIImage imageWithCGImage:[representation fullScreenImage]];
SetWallpaper(image);
PrepareWallpaper(image);

if (shuffleEnabled) {
currentIndex = arc4random_uniform([group numberOfAssets]);
Expand All @@ -114,7 +154,7 @@ static void GetWallpapersFromAlbum()
if (index == currentIndex) {
ALAssetRepresentation *representation = [result defaultRepresentation];
UIImage *image = [UIImage imageWithCGImage:[representation fullScreenImage]];
SetWallpaper(image);
PrepareWallpaper(image);

if (shuffleEnabled) {
currentIndex = arc4random_uniform([group numberOfAssets]);
Expand Down Expand Up @@ -165,6 +205,10 @@ static void ReloadSettings()
blurStrenght = [[settings objectForKey:@"blur_strenght"] intValue];
}

if ([settings objectForKey:@"wallpaper_blur_options"]) {
blurMode = [[settings objectForKey:@"wallpaper_blur_options"] intValue];
}

if ([settings objectForKey:@"interwall_enabled"]) {
interwallEnabled = [[settings objectForKey:@"interwall_enabled"] boolValue];
}
Expand Down Expand Up @@ -192,6 +236,11 @@ static void ReloadSettings()
}

[settings release];

if (enabled && unlockedAfterBoot) {
currentIndex--;
GetWallpaperFromAlbum();
}
}

%hook SBLockScreenManager
Expand All @@ -201,7 +250,7 @@ static void ReloadSettings()
%orig;

if (enabled && unlockedAfterBoot) {
GetWallpapersFromAlbum();
GetWallpaperFromAlbum();
}
}

Expand Down Expand Up @@ -232,7 +281,7 @@ static void ReloadSettings()
%new - (void)updateWallpaper
{
if (interwallEnabled && unlockedAfterBoot) {
GetWallpapersFromAlbum();
GetWallpaperFromAlbum();
}

[self configureTimer];
Expand All @@ -254,7 +303,7 @@ static void ReloadSettings()
%ctor {
@autoreleasepool {
[[NSDistributedNotificationCenter defaultCenter] addObserverForName:@"WallmartEvent" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
GetWallpapersFromAlbum();
GetWallpaperFromAlbum();
}];

ReloadSettings();
Expand Down
31 changes: 30 additions & 1 deletion WallmartSettings/WallmartSettings.mm
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,23 @@ - (id)specifiers
[blur_strenght setProperty:@(40) forKey:@"max"];
[blur_strenght setProperty:@(NO) forKey:@"showValue"];

_specifiers = [NSArray arrayWithObjects:firstGroup, blur_enabled, secondGroup, blur_strenght, nil];
PSSpecifier *thirdGroup = [PSSpecifier groupSpecifierWithName:@""];
[thirdGroup setProperty:@"These settings respect the default wallpaper mode settings." forKey:@"footerText"];

PSSpecifier *wallpaper_blur_options = [PSSpecifier preferenceSpecifierNamed:@"More options"
target:self
set:@selector(setValue:forSpecifier:)
get:@selector(getValueForSpecifier:)
detail:[PSListItemsController class]
cell:PSLinkListCell
edit:Nil];
[wallpaper_blur_options setIdentifier:@"wallpaper_blur_options"];
[wallpaper_blur_options setProperty:@(YES) forKey:@"enabled"];
[wallpaper_blur_options setValues:@[@(0), @(2), @(1)]
titles:@[@"Blur lockscreen and homescreen", @"Blur lockscreen only", @"Blur homescreen only"]
shortTitles:@[@"Blur lockscreen and homescreen", @"Blur lockscreen only", @"Blur homescreen only"]];

_specifiers = [NSArray arrayWithObjects:firstGroup, blur_enabled, secondGroup, blur_strenght, thirdGroup, wallpaper_blur_options, nil];
}

return _specifiers;
Expand Down Expand Up @@ -99,6 +115,16 @@ - (id)getValueForSpecifier:(PSSpecifier *)specifier
} else {
return @(5);
}
} else if ([specifier.identifier isEqualToString:@"wallpaper_blur_options"]) {
if (settings) {
if ([settings objectForKey:@"wallpaper_blur_options"]) {
return [settings objectForKey:@"wallpaper_blur_options"];
} else {
return @(0);
}
} else {
return @(0);
}
}

return nil;
Expand All @@ -115,6 +141,9 @@ - (void)setValue:(id)value forSpecifier:(PSSpecifier *)specifier
} else if ([specifier.identifier isEqualToString:@"blur_strenght"]) {
[settings setObject:value forKey:@"blur_strenght"];
[settings writeToFile:settingsPath atomically:YES];
} else if ([specifier.identifier isEqualToString:@"wallpaper_blur_options"]) {
[settings setObject:value forKey:@"wallpaper_blur_options"];
[settings writeToFile:settingsPath atomically:YES];
}

CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("com.shinvou.wallmart/reloadSettings"), NULL, NULL, TRUE);
Expand Down
Binary file modified WallmartSettings/obj/WallmartSettings.bundle/WallmartSettings
Binary file not shown.
Binary file modified WallmartSettings/obj/WallmartSettings.mm.7d079acb.o
Binary file not shown.
2 changes: 1 addition & 1 deletion _/DEBIAN/control
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ Architecture: iphoneos-arm
Description: Wallmart
Author: Timm Kandziora
Section: Tweaks
Version: 1.7-1
Version: 1.8-1
Installed-Size: 644
Binary file modified _/Library/MobileSubstrate/DynamicLibraries/Wallmart.dylib
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion control
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: com.shinvou.Wallmart
Name: Wallmart
Depends: mobilesubstrate
Version: 1.7
Version: 1.8
Architecture: iphoneos-arm
Description: Wallmart
Author: Timm Kandziora
Expand Down
Binary file removed deb/com.shinvou.Wallmart_1.7-1_iphoneos-arm.deb
Binary file not shown.
Binary file added deb/com.shinvou.Wallmart_1.8-1_iphoneos-arm.deb
Binary file not shown.
Binary file modified obj/Tweak.xm.51ec5270.o
Binary file not shown.
Binary file modified obj/Wallmart.dylib
Binary file not shown.

0 comments on commit 620cc2f

Please sign in to comment.