Skip to content

Instantly share code, notes, and snippets.

@josser
Created December 15, 2016 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josser/c934124a703971e92f0c9087c08e029b to your computer and use it in GitHub Desktop.
Save josser/c934124a703971e92f0c9087c08e029b to your computer and use it in GitHub Desktop.
'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.all();
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(Key.on('up', controlAlt, function () {
Window.focused() && Window.focused().maximize();
}));
//
keys.push(Key.on('down', controlAlt, function () {
Window.focused() && Window.focused().midCenter();
}));
//
keys.push(Key.on('left', controlAlt, function () {
Window.focused() && Window.focused().sideLeft()
}));
//
keys.push(Key.on('right', controlAlt, function () {
Window.focused() && Window.focused().sideRight()
}));
keys.push(Key.on('[', controlAlt, function () {
Window.focused() && Window.focused().throwTo(Displays.Internal);
}));
keys.push(Key.on(']', controlAlt, function () {
Window.focused() && Window.focused().throwTo(Displays.External);
}));
var AppsConfig = {
get: function () {
return AppsConfig.test[AppsConfig.selector()];
},
selector: function () {
return Screen.all().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(Key.on('delete', ['ctrl', 'alt', 'cmd'], function () {
var apps = App.all();
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