Skip to content

Commit

Permalink
Merge pull request alinebee#79 from alunbestor/64bit/remove-cgs-apis
Browse files Browse the repository at this point in the history
Remove undocumented CoreGraphics API usage
  • Loading branch information
alinebee authored Apr 29, 2018
2 parents b8204e9 + c5cc88f commit 25671ad
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 528 deletions.
7 changes: 3 additions & 4 deletions Boxer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,6 @@
9FDCA78E118F2B7900E2FD74 /* BXCoalface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BXCoalface.h; sourceTree = "<group>"; };
9FDCA78F118F2B7900E2FD74 /* BXCoalface.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BXCoalface.mm; sourceTree = "<group>"; };
9FDCDEFC11B5B83B0032DA4E /* dsa_pub.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = dsa_pub.pem; sourceTree = "<group>"; };
9FDD4CB411E619D50035BA9E /* CGSPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CGSPrivate.h; sourceTree = "<group>"; };
9FDE341D1351DE26000DCE44 /* BXBlueprintBackgroundView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BXBlueprintBackgroundView.h; sourceTree = "<group>"; };
9FDE341E1351DE26000DCE44 /* BXBlueprintBackgroundView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BXBlueprintBackgroundView.m; sourceTree = "<group>"; };
9FDE34321351DFD4000DCE44 /* BXImportTipsPanelController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BXImportTipsPanelController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3512,7 +3511,6 @@
isa = PBXGroup;
children = (
9F991BDE1800395900E2C0FE /* Scripting Bridge */,
9FDD4CB411E619D50035BA9E /* CGSPrivate.h */,
9FADFE9511EC932800990E91 /* NSData+HexStrings.h */,
9FADFE9611EC932800990E91 /* NSData+HexStrings.m */,
9F7A8F230F8E705100D1AAD5 /* ADBToolkit */,
Expand Down Expand Up @@ -5105,7 +5103,7 @@
ENABLE_TESTABILITY = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = USE_PRIVATE_APIS;
GCC_PREPROCESSOR_DEFINITIONS = "";
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
Expand Down Expand Up @@ -5178,6 +5176,7 @@
"$(inherited)",
"\"$(SRCROOT)/Frameworks\"",
);
GCC_PREPROCESSOR_DEFINITIONS = "";
GCC_WARN_64_TO_32_BIT_CONVERSION = NO;
GCC_WARN_CHECK_SWITCH_STATEMENTS = NO;
HEADER_SEARCH_PATHS = (
Expand Down Expand Up @@ -5224,7 +5223,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_NO_COMMON_BLOCKS = YES;
GCC_PREPROCESSOR_DEFINITIONS = USE_PRIVATE_APIS;
GCC_PREPROCESSOR_DEFINITIONS = "";
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
Expand Down
7 changes: 0 additions & 7 deletions Boxer/BXWelcomeWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,7 @@ - (void) windowDidResignKey: (NSNotification *)notification

- (void) showWindowWithTransition: (id)sender
{
#ifdef USE_PRIVATE_APIS
[self.window revealWithTransition: CGSFlip
direction: CGSDown
duration: 0.4
blockingMode: NSAnimationNonblocking];
#else
[self.window fadeInWithDuration: 0.4];
#endif

[self showWindow: sender];
}
Expand Down
1 change: 0 additions & 1 deletion Boxer/Inspector Panel/BXInspectorController.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ - (void) showWindow: (id)sender
[self loadWindow];

[self.window fadeInWithDuration: 0.2];
//[[self window] applyGaussianBlurWithRadius: BXInspectorPanelBlurRadius];

_isTemporarilyHidden = NO;
}
Expand Down
49 changes: 0 additions & 49 deletions Other Sources/ADBToolkit/NSWindow+ADBWindowEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,52 +37,3 @@
- (void) fadeOutWithDuration: (NSTimeInterval)duration;

@end


//The following methods use private Core Graphics APIs that will likely fall foul
//of App Store private-API restrictions.
#ifdef USE_PRIVATE_APIS

#import "CGSPrivate.h"

NS_ASSUME_NONNULL_BEGIN

@interface NSWindow (ADBPrivateAPIWindowEffects)

/// Applies a gaussian blur filter behind the window background.
/// Only useful for HUD-style translucent windows.
- (void) applyGaussianBlurWithRadius: (CGFloat)radius;

/// Hide the window by using the specified transition.
- (void) hideWithTransition: (CGSTransitionType)type
direction: (CGSTransitionOption)direction
duration: (NSTimeInterval)duration
blockingMode: (NSAnimationBlockingMode)blockingMode;

/// Reveal the window by using the specified transition.
- (void) revealWithTransition: (CGSTransitionType)type
direction: (CGSTransitionOption)direction
duration: (NSTimeInterval)duration
blockingMode: (NSAnimationBlockingMode)blockingMode;

#pragma mark -
#pragma mark Low-level methods

/// Adds a filter with the specified name and options to the window. The backgroundOnly flag
/// determines whether the filter applies directly to the window's contents, or to what lies
/// behind the window.
- (void) addCGSFilterWithName: (NSString *)filterName
withOptions: (NSDictionary *)filterOptions
backgroundOnly: (BOOL)backgroundOnly;

/// Applies the specified Core Graphics transition to the window.
- (void) applyCGSTransition: (CGSTransitionType)type
direction: (CGSTransitionOption)direction
duration: (NSTimeInterval)duration
blockingMode: (NSAnimationBlockingMode)blockingMode;

@end

NS_ASSUME_NONNULL_END

#endif
185 changes: 0 additions & 185 deletions Other Sources/ADBToolkit/NSWindow+ADBWindowEffects.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,188 +78,3 @@ - (void) _orderOutAfterFade
}

@end



#ifdef USE_PRIVATE_APIS

@interface NSWindow (ADBPrivateAPIWindowEffectsReallyPrivate)
//Cleans up after a transition by releasing the specified handle.
- (void) _releaseTransitionHandle: (NSNumber *)handleNum;

//Used internally by applyCGSTransition:direction:duration: and related methods.
//Callback is called with callbackObj as the parameter immediately before the
//transition is invoked: this allows the callback to update the window state
//(or show/hide the window) for the end of the transition.
- (void) _applyCGSTransition: (CGSTransitionType)type
direction: (CGSTransitionOption)direction
duration: (NSTimeInterval)duration
withCallback: (SEL)callback
callbackObject: (id)callbackObj
blockingMode: (NSAnimationBlockingMode)blockingMode;

//Takes the float value of the specified number and sets the window's alpha to it.
//Used for showing/hiding windows during a transition.
- (void) _setAlphaForTransition: (NSNumber *)alphaValue;
@end

@implementation NSWindow (ADBPrivateAPIWindowEffects)

#pragma mark -
#pragma mark High-level methods you might actually want to call

- (void) applyGaussianBlurWithRadius: (CGFloat)radius
{
[self addCGSFilterWithName: @"CIGaussianBlur"
withOptions: @{@"inputRadius": @(radius)}
backgroundOnly: YES];
}

- (void) revealWithTransition: (CGSTransitionType)type
direction: (CGSTransitionOption)direction
duration: (NSTimeInterval)duration
blockingMode: (NSAnimationBlockingMode)blockingMode
{
CGFloat oldAlpha = self.alphaValue;
self.alphaValue = 0.0f;
[self orderFront: self];

[self _applyCGSTransition: type
direction: direction
duration: duration
withCallback: @selector(_setAlphaForTransition:)
callbackObject: @(oldAlpha)
blockingMode: blockingMode];
}

- (void) hideWithTransition: (CGSTransitionType)type
direction: (CGSTransitionOption)direction
duration: (NSTimeInterval)duration
blockingMode: (NSAnimationBlockingMode)blockingMode
{
CGFloat oldAlpha = self.alphaValue;
[self _applyCGSTransition: type
direction: direction
duration: duration
withCallback: @selector(_setAlphaForTransition:)
callbackObject: @(0.0f)
blockingMode: blockingMode];

[self willChangeValueForKey: @"visible"];
[self orderOut: self];
[self didChangeValueForKey: @"visible"];

self.alphaValue = oldAlpha;
}

- (void) _setAlphaForTransition: (NSNumber *)alphaValue
{
self.alphaValue = alphaValue.floatValue;
}

#pragma mark -
#pragma mark Low-level effects

- (void) addCGSFilterWithName: (NSString *)filterName
withOptions: (NSDictionary *)filterOptions
backgroundOnly: (BOOL)backgroundOnly
{
CGSConnection conn = _CGSDefaultConnection();

if (conn)
{
CGSWindowFilterRef filter = NULL;

//Create a CoreImage gaussian blur filter.
CGSNewCIFilterByName(conn, (__bridge CFStringRef)filterName, &filter);

if (filter)
{
CGSWindowID windowNumber = (CGSWindowID)self.windowNumber;
int compositingType = (int)backgroundOnly;

CGSSetCIFilterValuesFromDictionary(conn, filter, (__bridge CFDictionaryRef)filterOptions);

CGSAddWindowFilter(conn, windowNumber, filter, compositingType);

//Clean up after ourselves.
CGSReleaseCIFilter(conn, filter);
}
}
}

- (void) applyCGSTransition: (CGSTransitionType)type
direction: (CGSTransitionOption)direction
duration: (NSTimeInterval)duration
blockingMode: (NSAnimationBlockingMode)blockingMode
{
[self _applyCGSTransition: type
direction: direction
duration: duration
withCallback: @selector(display)
callbackObject: nil
blockingMode: blockingMode];
}

- (void) _applyCGSTransition: (CGSTransitionType)type
direction: (CGSTransitionOption)direction
duration: (NSTimeInterval)duration
withCallback: (SEL)callback
callbackObject: (id)callbackObj
blockingMode: (NSAnimationBlockingMode)blockingMode
{
//If the application isn't active, then avoid applying the effect: it will look distractingly wrong anyway
if (![NSApp isActive] || [NSApp isHidden])
{
[self performSelector: callback withObject: callbackObj];
return;
}

CGSConnection conn = _CGSDefaultConnection();

if (conn)
{
CGSTransitionSpec spec;
spec.unknown1 = 0;
spec.type = type;
spec.option = direction | CGSTransparentBackgroundMask;
spec.wid = (CGSWindow)self.windowNumber;
spec.backColour = NULL;

int handle = 0;

CGSNewTransition(conn, &spec, &handle);

//Do any redrawing, now that Core Graphics has captured the previous window state.
//The transition will switch from the previous window state to this new one.
[self performSelector: callback withObject: callbackObj];

if (handle)
{
CGSInvokeTransition(conn, handle, (float)duration);

if (blockingMode == NSAnimationBlocking)
{
[NSThread sleepForTimeInterval: duration];
CGSReleaseTransition(conn, handle);
}
else
{
//To avoid blocking the thread, call the cleanup function with a delay.
[self performSelector: @selector(_releaseTransitionHandle:)
withObject: @(handle)
afterDelay: duration];
}

}
}
}

- (void) _releaseTransitionHandle: (NSNumber *)handleNum
{
CGSConnection conn = _CGSDefaultConnection();
CGSReleaseTransition(conn, [handleNum intValue]);
}

@end
#endif
Loading

0 comments on commit 25671ad

Please sign in to comment.