Skip to content

Commit

Permalink
Shifting left and right toggles through 1/3, 1/2, 2/3 widths.
Browse files Browse the repository at this point in the history
Shifting top and bottom toggles through full, 1/3 widths.
  • Loading branch information
Onsi Fakhouri committed Feb 25, 2011
1 parent 0f6a313 commit 99948f0
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 52 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ ShiftIt/build
release-notes-*
ShiftIt-*.zip
ShiftIt/ShiftIt.xcodeproj/*.pbxuser
ShiftIt/ShiftIt.xcodeproj/*.perspectivev3
ShiftIt/ShiftIt.xcodeproj/*.perspectivev3
*.mode1v3
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ It is a fork from the original [ShiftIt][1] by [Aravindkumar Rajendiran][2] whic

License: [GNU General Public License v3][5]

About this Fork
---------------

This fork adds a nifty little feature: shifting windows to the left or right now toggles through 3 different window widths: 1/2 screen width, 1/3 screen width and 2/3 screen width. Also, shifting windows to the top/bottom toggles through 2 widths: full width and 1/3 width. I've found that this allows for far better screen width utilization on widescreen machines and enables rapidly tiling windows into thirds.

Requirements
------------

Expand Down
22 changes: 12 additions & 10 deletions ShiftIt/DefaultShiftItActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@

#import <Foundation/Foundation.h>

NSRect ShiftIt_Left(NSSize screenSize, NSRect windowRect);
NSRect ShiftIt_Right(NSSize screenSize, NSRect windowRect);
NSRect ShiftIt_Top(NSSize screenSize, NSRect windowRect);
NSRect ShiftIt_Bottom(NSSize screenSize, NSRect windowRect);
NSRect ShiftIt_TopLeft(NSSize screenSize, NSRect windowRect);
NSRect ShiftIt_TopRight(NSSize screenSize, NSRect windowRect);
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);
BOOL CloseTo(float a, float b);

NSRect ShiftIt_Left(NSRect screenRect, NSRect windowRect);
NSRect ShiftIt_Right(NSRect screenRect, NSRect windowRect);
NSRect ShiftIt_Top(NSRect screenRect, NSRect windowRect);
NSRect ShiftIt_Bottom(NSRect screenRect, NSRect windowRect);
NSRect ShiftIt_TopLeft(NSRect screenRect, NSRect windowRect);
NSRect ShiftIt_TopRight(NSRect screenRect, NSRect windowRect);
NSRect ShiftIt_BottomLeft(NSRect screenRect, NSRect windowRect);
NSRect ShiftIt_BottomRight(NSRect screenRect, NSRect windowRect);
NSRect ShiftIt_FullScreen(NSRect screenRect, NSRect windowRect);
NSRect ShiftIt_Center(NSRect screenRect, NSRect windowRect);
198 changes: 159 additions & 39 deletions ShiftIt/DefaultShiftItActions.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,121 +20,241 @@
#import "DefaultShiftItActions.h"
#import "FMTDefines.h"

NSRect ShiftIt_Left(NSSize screenSize, NSRect windowRect) {
BOOL CloseTo(float a, float b) {
return fabs(a - b) < 20;
}

NSRect ShiftIt_Left(NSRect screenRect, NSRect windowRect) {
NSRect r;

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

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

float w = windowRect.size.width;
float h = windowRect.size.height;
float x = windowRect.origin.x;
float sw = screenRect.size.width;

if (windowRect.origin.y == screenRect.origin.y && CloseTo(x, 0) && CloseTo(h, r.size.height)) {
if (CloseTo(w, sw / 2)) {
r.size.width = floor(sw / 3.0);
} else if (CloseTo(w, floor(sw / 3.0))) {
r.size.width = floor(sw * 2.0 / 3.0);
}
}

return r;
}

NSRect ShiftIt_Right(NSSize screenSize, NSRect windowRect) {
NSRect ShiftIt_Right(NSRect screenRect, NSRect windowRect) {
NSRect r;

r.origin.x = screenSize.width/2;
r.origin.y = 0;

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

float w = windowRect.size.width;
float h = windowRect.size.height;
float x = windowRect.origin.x;
float sw = screenRect.size.width;

if (CloseTo(windowRect.origin.y, screenRect.origin.y) && CloseTo(x, sw - w) && CloseTo(h, r.size.height)) {
if (CloseTo(w, sw / 2)) {
r.size.width = floor(sw / 3.0);
} else if (CloseTo(w, floor(sw / 3.0))) {
r.size.width = floor(sw * 2.0 / 3.0);
}
}

r.origin.x = screenRect.size.width - r.size.width;

return r;
}

NSRect ShiftIt_Top(NSSize screenSize, NSRect windowRect) {
NSRect ShiftIt_Top(NSRect screenRect, NSRect windowRect) {
NSRect r;

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

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

float w = windowRect.size.width;
float h = windowRect.size.height;
float x = windowRect.origin.x;
float sw = screenRect.size.width;

if (CloseTo(windowRect.origin.y, screenRect.origin.y) && CloseTo(x, floor((sw - w) / 2)) && CloseTo(h, r.size.height)) {
if (CloseTo(w, screenRect.size.width)) {
r.size.width = floor(screenRect.size.width / 3.0);
}
}

r.origin.x = floor((screenRect.size.width - r.size.width) / 2);

return r;
}

NSRect ShiftIt_Bottom(NSSize screenSize, NSRect windowRect) {
NSRect ShiftIt_Bottom(NSRect screenRect, NSRect windowRect) {
NSRect r;

r.origin.x = 0;
r.origin.y = screenSize.height / 2;
r.origin.y = screenRect.size.height / 2;

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

float w = windowRect.size.width;
float h = windowRect.size.height;
float x = windowRect.origin.x;
float sw = screenRect.size.width;

if (CloseTo(windowRect.origin.y, screenRect.origin.y + screenRect.size.height / 2) && CloseTo(x, floor((sw - w) / 2)) && CloseTo(h, r.size.height)) {
if (CloseTo(w,screenRect.size.width)) {
r.size.width = floor(screenRect.size.width / 3.0);
}
}

r.size.width = screenSize.width;
r.size.height = screenSize.height / 2;
r.origin.x = floor((screenRect.size.width - r.size.width) / 2);

return r;
}

NSRect ShiftIt_TopLeft(NSSize screenSize, NSRect windowRect) {
NSRect ShiftIt_TopLeft(NSRect screenRect, NSRect windowRect) {
NSRect r;

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

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

float w = windowRect.size.width;
float h = windowRect.size.height;
float x = windowRect.origin.x;
float sw = screenRect.size.width;

if (CloseTo(windowRect.origin.y, screenRect.origin.y) && CloseTo(x, 0) && CloseTo(h, r.size.height)) {
if (CloseTo(w, sw/2)) {
r.size.width = floor(sw / 3.0);
} else if (CloseTo(w, floor(sw / 3.0))) {
r.size.width = floor(sw * 2.0 / 3.0);
}
}


return r;
}

NSRect ShiftIt_TopRight(NSSize screenSize, NSRect windowRect) {
NSRect ShiftIt_TopRight(NSRect screenRect, NSRect windowRect) {
NSRect r;

r.origin.x = screenSize.width / 2;
r.origin.y = 0;

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

float w = windowRect.size.width;
float h = windowRect.size.height;
float x = windowRect.origin.x;
float sw = screenRect.size.width;

if (CloseTo(windowRect.origin.y, screenRect.origin.y) && CloseTo(x, sw - w) && CloseTo(h, r.size.height)) {
if (CloseTo(w, sw / 2)) {
r.size.width = floor(sw / 3.0);
} else if (CloseTo(w, floor(sw / 3.0))) {
r.size.width = floor(sw * 2.0 / 3.0);
}
}

r.origin.x = screenRect.size.width - r.size.width;

return r;
}

NSRect ShiftIt_BottomLeft(NSSize screenSize, NSRect windowRect) {
NSRect ShiftIt_BottomLeft(NSRect screenRect, NSRect windowRect) {
NSRect r;

r.origin.x = 0;
r.origin.y = screenSize.height / 2;
r.origin.y = screenRect.size.height / 2;

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

r.size.width = screenSize.width / 2;
r.size.height = screenSize.height / 2;
float w = windowRect.size.width;
float h = windowRect.size.height;
float x = windowRect.origin.x;
float sw = screenRect.size.width;

if (CloseTo(windowRect.origin.y, screenRect.origin.y + screenRect.size.height / 2) && CloseTo(x, 0) && CloseTo(h, r.size.height)) {
if (CloseTo(w, sw / 2)) {
r.size.width = floor(sw / 3.0);
} else if (CloseTo(w, floor(sw / 3.0))) {
r.size.width = floor(sw * 2.0 / 3.0);
}
}

return r;
}

NSRect ShiftIt_BottomRight(NSSize screenSize, NSRect windowRect) {
NSRect ShiftIt_BottomRight(NSRect screenRect, NSRect windowRect) {
NSRect r;

r.origin.x = screenSize.width / 2;
r.origin.y = screenSize.height / 2;
r.origin.y = screenRect.size.height / 2;

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

float w = windowRect.size.width;
float h = windowRect.size.height;
float x = windowRect.origin.x;
float sw = screenRect.size.width;

if (CloseTo(windowRect.origin.y, screenRect.origin.y + screenRect.size.height / 2) && CloseTo(x, sw - w) && CloseTo(h, r.size.height)) {
if (CloseTo(w, sw / 2)) {
r.size.width = floor(sw / 3.0);
} else if (CloseTo(w, floor(sw / 3.0))) {
r.size.width = floor(sw * 2.0 / 3.0);
}
}

r.size.width = screenSize.width / 2;
r.size.height = screenSize.height / 2;
r.origin.x = screenRect.size.width - r.size.width;

return r;
}

NSRect ShiftIt_FullScreen(NSSize screenSize, NSRect windowRect) {
NSRect ShiftIt_FullScreen(NSRect screenRect, NSRect windowRect) {
NSRect r;

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

r.size.width = screenSize.width;
r.size.height = screenSize.height;
r.size.width = screenRect.size.width;
r.size.height = screenRect.size.height;

return r;
}

NSRect ShiftIt_Center(NSSize screenSize, NSRect windowRect) {
NSRect ShiftIt_Center(NSRect screenRect, NSRect windowRect) {
NSRect r;

r.origin.x = (screenSize.width / 2)-(windowRect.size.width / 2);
r.origin.y = (screenSize.height / 2)-(windowRect.size.height / 2);
float w = floor(screenRect.size.width * 0.85);
float h = floor(screenRect.size.height * 0.85);

if (CloseTo(w, windowRect.size.width) && CloseTo(h, windowRect.size.height)) {
w = floor(screenRect.size.width * 0.6);
h = floor(screenRect.size.height * 0.6);
}


r.origin.x = (screenRect.size.width / 2) - (w / 2);
r.origin.y = (screenRect.size.height / 2) - (h / 2);

r.size = windowRect.size;
r.size.width = w;
r.size.height = h;

return r;
}
1 change: 1 addition & 0 deletions ShiftIt/ShiftIt.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@
isa = PBXProject;
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "ShiftIt" */;
compatibilityVersion = "Xcode 3.1";
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
English,
Expand Down
2 changes: 1 addition & 1 deletion ShiftIt/ShiftItAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* and has a size screenSize. The windowRect is the whole window
* including any sort window decorators.
*/
typedef NSRect (*ShiftItFunctionRef)(NSSize screenSize, NSRect windowRect);
typedef NSRect (*ShiftItFunctionRef)(NSRect screenSize, NSRect windowRect);

@interface ShiftItAction : NSObject {
@private
Expand Down
2 changes: 1 addition & 1 deletion ShiftIt/WindowSizer.m
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ - (void) shiftFocusedWindowUsing:(ShiftItAction *)action error:(NSError **)error

// execute shift it action to reposition the application window
ShiftItFunctionRef actionFunction = [action action];
NSRect shiftedRect = actionFunction(visibleScreenRect.size, windowRect);
NSRect shiftedRect = actionFunction(visibleScreenRect, windowRect);
FMTDevLog(@"shifted window rect: %@", RECT_STR(shiftedRect));

// readjust adjust the visibility
Expand Down

0 comments on commit 99948f0

Please sign in to comment.