Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code for incremental sizing #32

Closed
wants to merge 8 commits into from
2 changes: 2 additions & 0 deletions ShiftIt/DefaultShiftItActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ NSRect ShiftIt_BottomLeft(NSSize screenSize, NSRect windowRect);
NSRect ShiftIt_BottomRight(NSSize screenSize, NSRect windowRect);
NSRect ShiftIt_FullScreen(NSSize screenSize, NSRect windowRect);
NSRect ShiftIt_Center(NSSize screenSize, NSRect windowRect);
NSRect ShiftIt_Increase(NSSize screenSize, NSRect windowRect);
NSRect ShiftIt_Reduce(NSSize screenSize, NSRect windowRect);
133 changes: 132 additions & 1 deletion ShiftIt/DefaultShiftItActions.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

#import "DefaultShiftItActions.h"
#import "FMTDefines.h"
#import "WindowSizer.h"

extern short GetMBarHeight(void);

NSRect ShiftIt_Left(NSSize screenSize, NSRect windowRect) {
NSRect r;
Expand All @@ -40,7 +43,7 @@ NSRect ShiftIt_Right(NSSize screenSize, NSRect windowRect) {

r.size.width = screenSize.width / 2;
r.size.height = screenSize.height;

return r;
}

Expand Down Expand Up @@ -138,3 +141,131 @@ NSRect ShiftIt_Center(NSSize screenSize, NSRect windowRect) {

return r;
}

//wider
NSRect ShiftIt_Increase(NSSize screenSize, NSRect windowRect) {
NSRect r;
float menuBarHeight = GetMBarHeight();

NSString *lastActionExecuted = [[WindowSizer sharedWindowSize] lastActionExecuted];
if (lastActionExecuted == @"left" || lastActionExecuted == @"right") {
//wider
int whichSide;
(windowRect.origin.x == 0) ? (whichSide = 0) : (whichSide = 1);

switch (whichSide) {
case 0: // window origin is in left region
r.size.width = windowRect.size.width + (screenSize.width/12);
r.size.height = windowRect.size.height;

r.origin.x = windowRect.origin.x;
r.origin.y = windowRect.origin.y - menuBarHeight;

break;
case 1: // window origin is in right region
r.size.width = windowRect.size.width + (screenSize.width/12);
r.size.height = windowRect.size.height;

r.origin.x = screenSize.width - r.size.width;
r.origin.y = windowRect.origin.y - menuBarHeight;

break;
default:
break;
}
} else if (lastActionExecuted == @"top" || lastActionExecuted == @"bottom") {
//taller
// detect which side of the screen the window is touching the side of the display
int topOrBottom;
(windowRect.origin.y - menuBarHeight == 0) ? (topOrBottom = 0) : (topOrBottom = 1);

switch (topOrBottom) {
case 0: // window origin is in upper region
r.size.width = windowRect.size.width;
r.size.height = windowRect.size.height + (screenSize.height/12);

r.origin.x = windowRect.origin.x;
r.origin.y = windowRect.origin.y - menuBarHeight;

break;
case 1: // window origin is in lower region
r.size.width = windowRect.size.width;
r.size.height = windowRect.size.height + (screenSize.height/12);

r.origin.x = 0;
r.origin.y = screenSize.height - r.size.height;

break;
default:
break;
}

} else
return windowRect;

return r;
}

//taller
NSRect ShiftIt_Reduce(NSSize screenSize, NSRect windowRect) {
NSRect r;
float menuBarHeight = GetMBarHeight();

NSString *lastActionExecuted = [[WindowSizer sharedWindowSize] lastActionExecuted];
if (lastActionExecuted == @"left" || lastActionExecuted == @"right") {
//thinner
int whichSide;
(windowRect.origin.x == 0) ? (whichSide = 0) : (whichSide = 1);

switch (whichSide) {
case 0: // window origin is in left region
r.size.width = windowRect.size.width - (screenSize.width/12);
r.size.height = windowRect.size.height;

r.origin.x = windowRect.origin.x;
r.origin.y = windowRect.origin.y - menuBarHeight;

break;
case 1: // window origin is in right region
r.size.width = windowRect.size.width - (screenSize.width/12);
r.size.height = windowRect.size.height;

r.origin.x = screenSize.width - r.size.width;
r.origin.y = windowRect.origin.y - menuBarHeight;

break;
default:
break;
}
} else if (lastActionExecuted == @"top" || lastActionExecuted == @"bottom") {
//shorter
// detect which side of the screen the window is touching the side of the display
int topOrBottom;
(windowRect.origin.y - menuBarHeight == 0) ? (topOrBottom = 0) : (topOrBottom = 1);

switch (topOrBottom) {
case 0: // window origin is in upper region
r.size.width = windowRect.size.width;
r.size.height = windowRect.size.height - (screenSize.height/12);

r.origin.x = windowRect.origin.x;
r.origin.y = windowRect.origin.y - menuBarHeight;

break;
case 1: // window origin is in lower region
r.size.width = windowRect.size.width;
r.size.height = windowRect.size.height - (screenSize.height/12);

r.origin.x = 0;
r.origin.y = screenSize.height - r.size.height;

break;
default:
break;
}

} else
return windowRect;

return r;
}
Loading