Created
February 5, 2014 15:58
-
-
Save pirfalt/8826782 to your computer and use it in GitHub Desktop.
Pirfalts Phoenix config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// HELPERS | |
// Sometimes it's easier to work with edges instead of point + size | |
// {x, y, height, width} => {top, bottom, left right} | |
function frameToRect(frame) { | |
return { | |
left: frame.x, | |
right: frame.x + frame.width, | |
top: frame.y, | |
bottom: frame.y + frame.height | |
} | |
} | |
// {top, bottom, left right} => {x, y, height, width} | |
function rectToFrame(rect) { | |
return { | |
x: rect.left, | |
y: rect.top, | |
width: rect.right - rect.left, | |
height: rect.bottom - rect.top | |
} | |
} | |
// Cycle args for the function, if called repeatedly | |
// cycleCalls(fn, [ [args1...], [args2...], ... ]) | |
var lastCall = null | |
function cycleCalls(fn, argsList) { | |
var argIndex = 0, identifier = {} | |
return function () { | |
if (lastCall !== identifier || ++argIndex >= argsList.length) argIndex = 0 | |
lastCall = identifier | |
fn.apply(this, argsList[argIndex]) | |
} | |
} | |
// ACTIONS | |
// toAnything(a,b). Sets the focusWindow size to screensize * a/b | |
function toLeft(fillCols, maxCols) { | |
var win = Window.focusedWindow() | |
var rect = frameToRect(win.frame()) | |
rect.left = 0 | |
rect.right = win.screen().frameWithoutDockOrMenu().width / maxCols * fillCols | |
win.setFrame(rectToFrame(rect), win.screen()) | |
} | |
function toRight(fillCols, maxCols) { | |
var win = Window.focusedWindow() | |
var rect = frameToRect(win.frame()) | |
var screenFrame = win.screen().frameWithoutDockOrMenu() | |
rect.left = screenFrame.width - screenFrame.width / maxCols * fillCols | |
rect.right = screenFrame.width | |
win.setFrame(rectToFrame(rect), win.screen()) | |
} | |
function toTop(fillRows, maxRows) { | |
var win = Window.focusedWindow() | |
var winFrame = win.frame() | |
var screenFrame = win.screen().frameWithoutDockOrMenu() | |
var targetHeight = screenFrame.height / maxRows * fillRows | |
winFrame.y = screenFrame.y | |
winFrame.height = targetHeight | |
win.setFrame(winFrame, win.screen()) | |
} | |
function toBottom(fillRows, maxRows) { | |
var win = Window.focusedWindow() | |
var winFrame = win.frame() | |
var screenFrame = win.screen().frameWithoutDockOrMenu() | |
var targetHeight = screenFrame.height / maxRows * fillRows | |
winFrame.y = screenFrame.y + screenFrame.height - targetHeight | |
winFrame.height = targetHeight | |
win.setFrame(winFrame, win.screen()) | |
} | |
// BINDS | |
var opts = ['ctrl', 'cmd'] | |
api.bind('h', opts, cycleCalls( | |
toLeft, | |
[ | |
[1,2], | |
[1,3], | |
[2,3], | |
[1,1] | |
] | |
)) | |
api.bind('l', opts, cycleCalls( | |
toRight, | |
[ | |
[1,2], | |
[1,3], | |
[2,3], | |
[1,1] | |
] | |
)) | |
api.bind('k', opts, cycleCalls( | |
toTop, | |
[ | |
[1,2], | |
[1,1], | |
[2,3] | |
] | |
)) | |
api.bind('j', opts, cycleCalls( | |
toBottom, | |
[ | |
[1,2], | |
[1,1], | |
[1,3] | |
] | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment