Created
January 5, 2016 03:12
-
-
Save michaelsbradleyjr/e641907e3b1576fe3481 to your computer and use it in GitHub Desktop.
Phoenix configuration
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
// adapted from: | |
// https://gist.github.com/kasper/b7c2a1596a90246c9ccd | |
// partly inspired by the grid hotkeys for Optimal Layout: | |
// http://most-advantageous.com/optimal-layout/ | |
'use strict'; | |
var commandOption = [ 'cmd', 'alt' ], | |
keys = []; | |
/* Window functions */ | |
Window.prototype.reframe = function (position) { | |
this.setFrame(position(this)); | |
} | |
/* Window positions */ | |
Window.windows = { | |
lastPositions: {}, | |
halfFullToggle: {}, | |
halfHalfToggle: {} | |
}; | |
Window.positions = { | |
centered: function (window, whichCentered) { | |
var screen = window.screen(), | |
screenFrame = screen.visibleFrameInRectangle(); | |
Window.windows.lastPositions[ window.hash() ] = whichCentered; | |
var multiplier = undefined; | |
switch (whichCentered) { | |
case 'fourFifthsFullCentered': | |
multiplier = Window.sizes.fourFifthsFull; | |
break; | |
case 'halfFullCentered': | |
multiplier = Window.sizes.halfFull; | |
break; | |
case 'thirdFullCentered': | |
multiplier = Window.sizes.thirdFull; | |
break; | |
case 'twoThirdsFullCentered': | |
multiplier = Window.sizes.twoThirdsFull; | |
break; | |
} | |
return { | |
width: screenFrame.width * multiplier.width, | |
height: screenFrame.height * multiplier.height, | |
x: screenFrame.x | |
+ ((screenFrame.width * 1/2) | |
- (screenFrame.width * multiplier.width * 1/2)), | |
y: screenFrame.y | |
}; | |
}, | |
fourFifthsFullCentered: function (window) { | |
return Window.positions.centered(window, 'fourFifthsFullCentered'); | |
}, | |
full: function (window) { | |
var screen = window.screen(), | |
screenFrame = screen.visibleFrameInRectangle(); | |
Window.windows.lastPositions[ window.hash() ] = 'full'; | |
return { | |
width: screenFrame.width * Window.sizes.full.width, | |
height: screenFrame.height * Window.sizes.full.height, | |
x: screenFrame.x, | |
y: screenFrame.y | |
}; | |
}, | |
halfFullCentered: function (window) { | |
return Window.positions.centered(window, 'halfFullCentered'); | |
}, | |
halfFullToggle: function (window) { | |
var screen = window.screen(), | |
screenFrame = screen.visibleFrameInRectangle(); | |
Window.windows.lastPositions[ window.hash() ] = 'halfFullToggle'; | |
var windowRef = Window.windows.halfFullToggle[ window.hash() ]; | |
if (!windowRef) { | |
windowRef = { | |
currentHalfFullToggle: undefined, | |
nextHalfFullToggle: [ 'left', 'right' ] | |
}; | |
Window.windows.halfFullToggle[ window.hash() ] = windowRef; | |
} | |
var nextHalfFullToggle = windowRef.nextHalfFullToggle.shift(); | |
windowRef.currentHalfFullToggle = nextHalfFullToggle; | |
windowRef.nextHalfFullToggle.push(nextHalfFullToggle); | |
var x = undefined; | |
switch (windowRef.currentHalfFullToggle) { | |
case 'left': | |
x = screenFrame.x; | |
break; | |
case 'right': | |
x = screenFrame.x | |
+ screenFrame.width | |
* Window.sizes.halfFull.width; | |
break; | |
} | |
return { | |
width: screenFrame.width * Window.sizes.halfFull.width, | |
height: screenFrame.height * Window.sizes.halfFull.height, | |
x: x, | |
y: screenFrame.y | |
}; | |
}, | |
halfHalfToggle: function (window) { | |
var screen = window.screen(), | |
screenFrame = screen.visibleFrameInRectangle(); | |
Window.windows.lastPositions[ window.hash() ] = 'halfHalfToggle'; | |
var windowRef = Window.windows.halfHalfToggle[ window.hash() ]; | |
if (!windowRef) { | |
windowRef = { | |
currentHalfHalfToggle: undefined, | |
nextHalfHalfToggle: [ | |
'top-left', | |
'top-right', | |
'bottom-right', | |
'bottom-left' | |
] | |
}; | |
Window.windows.halfHalfToggle[ window.hash() ] = windowRef; | |
} | |
var nextHalfHalfToggle = windowRef.nextHalfHalfToggle.shift(); | |
windowRef.currentHalfHalfToggle = nextHalfHalfToggle; | |
windowRef.nextHalfHalfToggle.push(nextHalfHalfToggle); | |
var x = undefined, | |
y = undefined; | |
switch (windowRef.currentHalfHalfToggle) { | |
case 'top-left': | |
x = screenFrame.x; | |
y = screenFrame.y; | |
break; | |
case 'top-right': | |
x = screenFrame.x | |
+ screenFrame.width | |
* Window.sizes.halfHalf.width; | |
y = screenFrame.y; | |
break; | |
case 'bottom-right': | |
x = screenFrame.x | |
+ screenFrame.width | |
* Window.sizes.halfHalf.width; | |
y = screenFrame.y | |
+ screenFrame.height | |
* Window.sizes.halfHalf.height; | |
break; | |
case 'bottom-left': | |
x = screenFrame.x; | |
y = screenFrame.y | |
+ screenFrame.height | |
* Window.sizes.halfHalf.height; | |
break; | |
} | |
return { | |
width: screenFrame.width * Window.sizes.halfHalf.width, | |
height: screenFrame.height * Window.sizes.halfHalf.height, | |
x: x, | |
y: y | |
}; | |
}, | |
thirdFullCentered: function (window) { | |
return Window.positions.centered(window, 'thirdFullCentered'); | |
}, | |
twoThirdsFullCentered: function (window) { | |
return Window.positions.centered(window, 'twoThirdsFullCentered'); | |
} | |
}; | |
/* Window sizes */ | |
Window.sizes = Object.freeze({ | |
fourFifthsFull: Object.freeze({ | |
width: 4/5, | |
height: 1 | |
}), | |
full: Object.freeze({ | |
width: 1, | |
height: 1 | |
}), | |
halfFull: Object.freeze({ | |
width: 1/2, | |
height: 1 | |
}), | |
halfHalf: Object.freeze({ | |
width: 1/2, | |
height: 1/2 | |
}), | |
thirdFull: Object.freeze({ | |
width: 1/3, | |
height: 1 | |
}), | |
twoThirdsFull: Object.freeze({ | |
width: 2/3, | |
height: 1 | |
}) | |
}); | |
/* Key bindings */ | |
keys.push(Phoenix.bind('1', commandOption, function () { | |
Window.focusedWindow() | |
&& Window.focusedWindow() | |
.reframe(Window.positions.full); | |
})); | |
keys.push(Phoenix.bind('2', commandOption, function () { | |
Window.focusedWindow() | |
&& Window.focusedWindow() | |
.reframe(Window.positions.halfFullToggle); | |
})); | |
keys.push(Phoenix.bind('3', commandOption, function () { | |
Window.focusedWindow() | |
&& Window.focusedWindow() | |
.reframe(Window.positions.thirdFullCentered); | |
})); | |
keys.push(Phoenix.bind('4', commandOption, function () { | |
Window.focusedWindow() | |
&& Window.focusedWindow() | |
.reframe(Window.positions.halfHalfToggle); | |
})); | |
keys.push(Phoenix.bind('5', commandOption, function () { | |
Window.focusedWindow() | |
&& Window.focusedWindow() | |
.reframe(Window.positions.halfFullCentered); | |
})); | |
keys.push(Phoenix.bind('6', commandOption, function () { | |
Window.focusedWindow() | |
&& Window.focusedWindow() | |
.reframe(Window.positions.twoThirdsFullCentered); | |
})); | |
keys.push(Phoenix.bind('7', commandOption, function () { | |
Window.focusedWindow() | |
&& Window.focusedWindow() | |
.reframe(Window.positions.fourFifthsFullCentered); | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment