Last active
June 17, 2016 14:36
-
-
Save josser/6c2667628196f7ff2c07ac457611a9fa to your computer and use it in GitHub Desktop.
This file contains hidden or 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
'use strict'; | |
var keys = []; | |
var controlAlt = [ 'ctrl', 'alt' ]; | |
var margin = 0; | |
var increment = 0.1 | |
function log() { | |
Phoenix.log(JSON.stringify(arguments[0], true, 2)); | |
} | |
var Displays = { | |
Internal: 1, | |
External: 0 | |
} | |
Window.prototype.midCenter = function () { | |
var currScreenFrame = this.screen().visibleFrameInRectangle(); | |
var newWindowFrame = { | |
width: currScreenFrame.width * 0.75, | |
height: currScreenFrame.height * 0.75, | |
x: currScreenFrame.x + currScreenFrame.width * 0.125, | |
y: currScreenFrame.y + currScreenFrame.height * 0.125 | |
} | |
this.setFrame(newWindowFrame); | |
} | |
Window.prototype.sideLeft = function () { | |
var currScreenFrame = this.screen().visibleFrameInRectangle(); | |
var newWindowFrame = { | |
width: currScreenFrame.width * 0.5, | |
height: currScreenFrame.height, | |
x: currScreenFrame.x, | |
y: currScreenFrame.y | |
} | |
this.setFrame(newWindowFrame); | |
return this; | |
} | |
Window.prototype.sideRight = function () { | |
var currScreenFrame = this.screen().visibleFrameInRectangle(); | |
var newWindowFrame = { | |
width: currScreenFrame.width * 0.5, | |
height: currScreenFrame.height, | |
x: currScreenFrame.x + currScreenFrame.width * 0.5, | |
y: currScreenFrame.y | |
} | |
this.setFrame(newWindowFrame); | |
return this; | |
} | |
Window.prototype.throwTo = function (screen) { | |
var currScreenFrame = this.screen().visibleFrameInRectangle(); | |
var currWindowFrame = this.frame(); | |
var aspectRatios = { | |
width: currWindowFrame.width / currScreenFrame.width, | |
height: currWindowFrame.height / currScreenFrame.height, | |
x: Math.abs((currScreenFrame.x - currWindowFrame.x) / currScreenFrame.width), | |
y: Math.abs((currScreenFrame.y - currWindowFrame.y) / currScreenFrame.height) | |
} | |
var screens = Screen.screens(); | |
var targetScreenFrame = screens[screen].visibleFrameInRectangle(); | |
var newWindowFrame = { | |
width: targetScreenFrame.width * aspectRatios.width, | |
height: targetScreenFrame.height * aspectRatios.height, | |
x: targetScreenFrame.x + targetScreenFrame.width * aspectRatios.x, | |
y: targetScreenFrame.y + targetScreenFrame.height * aspectRatios.y | |
} | |
this.setFrame(newWindowFrame); | |
return this; | |
} | |
keys.push(Phoenix.bind('up', controlAlt, function () { | |
Window.focusedWindow() && Window.focusedWindow().maximize(); | |
})); | |
// | |
keys.push(Phoenix.bind('down', controlAlt, function () { | |
Window.focusedWindow() && Window.focusedWindow().midCenter(); | |
})); | |
// | |
keys.push(Phoenix.bind('left', controlAlt, function () { | |
Window.focusedWindow() && Window.focusedWindow().sideLeft() | |
})); | |
// | |
keys.push(Phoenix.bind('right', controlAlt, function () { | |
Window.focusedWindow() && Window.focusedWindow().sideRight() | |
})); | |
keys.push(Phoenix.bind('х', controlAlt, function () { | |
Window.focusedWindow() && Window.focusedWindow().throwTo(Displays.Internal); | |
})); | |
keys.push(Phoenix.bind('ъ', controlAlt, function () { | |
Window.focusedWindow() && Window.focusedWindow().throwTo(Displays.External); | |
})); | |
var AppsConfig = { | |
get: function () { | |
return AppsConfig.test[AppsConfig.selector()]; | |
}, | |
selector: function () { | |
return Screen.screens().length; | |
}, | |
test: { | |
1: { | |
'Skype': function (window){ | |
window.throwTo(Displays.External).sideLeft(); | |
}, | |
'Telegram': function (window) { | |
window.throwTo(Displays.External).sideRight(); | |
} | |
}, | |
2: { | |
'Skype': function (window){ | |
window.throwTo(Displays.Internal).sideLeft(); | |
}, | |
'Telegram': function (window) { | |
window.throwTo(Displays.Internal).sideRight(); | |
} | |
} | |
} | |
}; | |
keys.push(Phoenix.bind('delete', ['ctrl', 'alt', 'cmd'], function () { | |
var apps = App.runningApps(); | |
var appsConfig = AppsConfig.get(); | |
_.each(apps, function (app) { | |
appsConfig[app.name()] && appsConfig[app.name()](app.mainWindow()); | |
}) | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment