Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ShiftIt/DefaultShiftItActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#import "WindowGeometryShiftItAction.h"
#import "ShiftIt.h"

BOOL CloseTo(double a, double b);
const extern SimpleWindowGeometryChangeBlock shiftItLeft;
const extern SimpleWindowGeometryChangeBlock shiftItRight;
const extern SimpleWindowGeometryChangeBlock shiftItTop;
Expand Down
50 changes: 48 additions & 2 deletions ShiftIt/DefaultShiftItActions.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,28 @@
// TODO: extract this to be out of here
#import "ShiftItApp.h"

BOOL CloseTo(double a, double b) {
return fabs(a - b) < 20;
}

const SimpleWindowGeometryChangeBlock shiftItLeft = ^AnchoredRect(NSRect windowRect, NSSize screenSize) {
NSRect r = NSMakeRect(0, 0, 0, 0);

r.origin.x = 0;
r.origin.y = 0;

r.size.width = screenSize.width / 2;
double w = windowRect.size.width;
double sw = screenSize.width;

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

if (CloseTo(w, sw / 2.0)) {
r.size.width = floor(sw * 1.0 / 3.0);
} else if (CloseTo(w, sw / 3.0)) {
r.size.width = floor(sw * 2.0 / 3.0);
}

return MakeAnchoredRect(r, kLeftDirection);
};

Expand All @@ -39,9 +52,20 @@
r.origin.x = screenSize.width / 2;
r.origin.y = 0;

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

double w = windowRect.size.width;
double sw = screenSize.width;

if (CloseTo(w, sw / 2.0)) {
r.size.width = floor(sw * 1.0 / 3.0);
r.origin.x = sw - (sw * 1.0 / 3.0);
} else if (CloseTo(w, sw / 3.0)) {
r.size.width = floor(sw * 2.0 / 3.0);
r.origin.x = sw - (sw * 2.0 / 3.0);
}

return MakeAnchoredRect(r, kRightDirection);
};

Expand All @@ -54,6 +78,17 @@
r.size.width = screenSize.width;
r.size.height = screenSize.height / 2;

double windowHeight = windowRect.size.height;
double screenHeight = screenSize.height;

if (CloseTo(windowHeight, screenHeight / 2.0)) {
r.size.height = floor(screenHeight * 1.0 / 3.0);
r.origin.y = screenHeight * 1.0 / 3.0;
} else if (CloseTo(windowHeight, screenHeight / 3.0)) {
r.size.height = floor(screenHeight * 2.0 / 3.0);
r.origin.y = screenHeight * 2.0 / 3.0;
}

return MakeAnchoredRect(r, kTopDirection);
};

Expand All @@ -66,6 +101,17 @@
r.size.width = screenSize.width;
r.size.height = screenSize.height / 2;

double windowHeight = windowRect.size.height;
double screenHeight = screenSize.height;

if (CloseTo(windowHeight, screenHeight / 2.0)) {
r.size.height = floor(screenHeight * 1.0 / 3.0);
r.origin.y = screenHeight - (screenHeight * 1.0 / 3.0);
} else if (CloseTo(windowHeight, screenHeight / 3.0)) {
r.size.height = floor(screenHeight * 2.0 / 3.0);
r.origin.y = screenHeight - (screenHeight * 2.0 / 3.0);
}

return MakeAnchoredRect(r, kBottomDirection);
};

Expand Down