Skip to content

Commit

Permalink
- The window flipping class I found didn't work correctly if the wind…
Browse files Browse the repository at this point in the history
…ow was close to the side of the screen. Fixed it.
  • Loading branch information
Sappharad authored and Sappharad committed Dec 29, 2015
1 parent 55bc905 commit eded13a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions mbFlipWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ - (CALayer *) layerFromView :(NSView*)view;
- (CAAnimation *) animationWithDuration:(CGFloat)time flip:(BOOL)bFlip right:(BOOL)rightFlip;
@end

@interface OutsideWindow : NSWindow
@end

@implementation OutsideWindow
-(NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen{
//Allow the flipping animation window to go wherever it flipping wants to.
//If the user flips a window close to the side of the screen, we don't want the animation
//to jump somewhere else because the animation window got pushed back into screen bounds.
return frameRect;
}
@end

@implementation mbFlipWindow

@synthesize flipRight;
Expand All @@ -29,9 +41,9 @@ - (id)init
}

// this method create the window for animation with the image the window
- (NSWindow *) windowForAnimation:(NSRect)aFrame {
- (NSWindow*) windowForAnimation:(NSRect)aFrame {

NSWindow *wnd = [[NSWindow alloc] initWithContentRect:aFrame
OutsideWindow* wnd = [[OutsideWindow alloc] initWithContentRect:aFrame
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO];
Expand Down Expand Up @@ -137,8 +149,8 @@ - (void) flip:(NSWindow *)activeWindow to:(NSWindow *)targetWindow {
NSView *targetView = [targetWindow.contentView superview];

// create window for animation
CGFloat maxWidth = MAX(NSWidth(activeWindow.frame), NSWidth(targetWindow.frame)) + 500;
CGFloat maxHeight = MAX(NSHeight(activeWindow.frame), NSHeight(targetWindow.frame)) + 500;
CGFloat maxWidth = MAX(NSWidth(activeWindow.frame), NSWidth(targetWindow.frame)) + 250;
CGFloat maxHeight = MAX(NSHeight(activeWindow.frame), NSHeight(targetWindow.frame)) + 250;

CGRect animationFrame = CGRectMake(NSMidX(activeWindow.frame) - (maxWidth / 2),
NSMidY(activeWindow.frame) - (maxHeight / 2),
Expand Down

0 comments on commit eded13a

Please sign in to comment.