diff --git a/ShiftIt/DefaultShiftItActions.h b/ShiftIt/DefaultShiftItActions.h index 0433c551..4229e413 100644 --- a/ShiftIt/DefaultShiftItActions.h +++ b/ShiftIt/DefaultShiftItActions.h @@ -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; diff --git a/ShiftIt/DefaultShiftItActions.m b/ShiftIt/DefaultShiftItActions.m index 5fe711e4..81b6a518 100644 --- a/ShiftIt/DefaultShiftItActions.m +++ b/ShiftIt/DefaultShiftItActions.m @@ -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); }; @@ -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); }; @@ -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); }; @@ -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); };