Browse Source

now with shortcuts to focus certain apps

master
Josh Fabean 8 years ago
parent
commit
6533ae8322
1 changed files with 162 additions and 127 deletions
  1. +162
    -127
      .phoenix.js

+ 162
- 127
.phoenix.js View File

@ -1,8 +1,9 @@
'use strict';
var keys = [];
var controlShift = [ 'ctrl', 'shift' ];
var controlAltShift = [ 'ctrl', 'alt', 'shift' ];
var controlShift = ['ctrl', 'shift'];
var controlAltShift = ['ctrl', 'alt', 'shift'];
var controlCommandShift = ['ctrl', 'cmd', 'shift'];
var margin = 0;
var increment = 0.05;
@ -10,268 +11,302 @@ var increment = 0.05;
var Position = {
central: function (frame, window) {
central: function(frame, window) {
return {
return {
x: frame.x + ((frame.width - window.width) / 2),
y: frame.y + ((frame.height - window.height) / 2)
x: frame.x + ((frame.width - window.width) / 2),
y: frame.y + ((frame.height - window.height) / 2)
};
},
};
},
top: function (frame, window) {
top: function(frame, window) {
return {
return {
x: window.x,
y: frame.y
x: window.x,
y: frame.y
};
},
};
},
bottom: function (frame, window) {
bottom: function(frame, window) {
return {
return {
x: window.x,
y: (frame.y + frame.height) - window.height
x: window.x,
y: (frame.y + frame.height) - window.height
};
},
};
},
left: function (frame, window) {
left: function(frame, window) {
return {
return {
x: frame.x,
y: window.y
x: frame.x,
y: window.y
};
},
};
},
right: function (frame, window) {
right: function(frame, window) {
return {
return {
x: (frame.x + frame.width) - window.width,
y: window.y
x: (frame.x + frame.width) - window.width,
y: window.y
};
},
};
},
topLeft: function (frame, window, margin) {
topLeft: function(frame, window, margin) {
return {
return {
x: Position.left(frame, window).x + margin,
y: Position.top(frame, window).y + margin
x: Position.left(frame, window).x + margin,
y: Position.top(frame, window).y + margin
};
},
};
},
topRight: function (frame, window, margin) {
topRight: function(frame, window, margin) {
return {
return {
x: Position.right(frame, window).x - margin,
y: Position.top(frame, window).y + margin
x: Position.right(frame, window).x - margin,
y: Position.top(frame, window).y + margin
};
},
};
},
bottomLeft: function (frame, window, margin) {
bottomLeft: function(frame, window, margin) {
return {
return {
x: Position.left(frame, window).x + margin,
y: Position.bottom(frame, window).y - margin
x: Position.left(frame, window).x + margin,
y: Position.bottom(frame, window).y - margin
};
},
};
},
bottomRight: function (frame, window, margin) {
bottomRight: function(frame, window, margin) {
return {
return {
x: Position.right(frame, window).x - margin,
y: Position.bottom(frame, window).y - margin
x: Position.right(frame, window).x - margin,
y: Position.bottom(frame, window).y - margin
};
}
};
}
};
/* Grid */
var Frame = {
width: 1,
height: 1,
width: 1,
height: 1,
half: {
half: {
width: 0.5,
height: 0.5
width: 0.5,
height: 0.5
}
}
};
/* Window Functions */
Window.prototype.to = function (position) {
Window.prototype.to = function(position) {
this.setTopLeft(position(this.screen().visibleFrameInRectangle(), this.frame(), margin));
this.setTopLeft(position(this.screen().visibleFrameInRectangle(), this.frame(), margin));
}
Window.prototype.grid = function (x, y, reverse) {
Window.prototype.grid = function(x, y, reverse) {
var frame = this.screen().visibleFrameInRectangle();
var frame = this.screen().visibleFrameInRectangle();
var newWindowFrame = _(this.frame()).extend({
var newWindowFrame = _(this.frame()).extend({
width: (frame.width * x) - (2 * margin),
height: (frame.height * y) - (2 * margin)
width: (frame.width * x) - (2 * margin),
height: (frame.height * y) - (2 * margin)
});
});
var position = reverse ? Position.topRight(frame, newWindowFrame, margin) :
Position.topLeft(frame, newWindowFrame, margin);
var position = reverse ? Position.topRight(frame, newWindowFrame, margin) :
Position.topLeft(frame, newWindowFrame, margin);
this.setFrame(_(newWindowFrame).extend(position));
this.setFrame(_(newWindowFrame).extend(position));
}
Window.prototype.reverseGrid = function (x, y) {
Window.prototype.reverseGrid = function(x, y) {
this.grid(x, y, true);
this.grid(x, y, true);
}
Window.prototype.resize = function (multiplier) {
Window.prototype.resize = function(multiplier) {
var frame = this.screen().visibleFrameInRectangle();
var newSize = this.size();
var frame = this.screen().visibleFrameInRectangle();
var newSize = this.size();
if (multiplier.x) {
newSize.width += frame.width * multiplier.x;
}
if (multiplier.x) {
newSize.width += frame.width * multiplier.x;
}
if (multiplier.y) {
newSize.height += frame.height * multiplier.y;
}
if (multiplier.y) {
newSize.height += frame.height * multiplier.y;
}
this.setSize(newSize);
this.setSize(newSize);
}
Window.prototype.increaseWidth = function () {
Window.prototype.increaseWidth = function() {
this.resize({ x: increment });
this.resize({
x: increment
});
}
Window.prototype.decreaseWidth = function () {
Window.prototype.decreaseWidth = function() {
this.resize({ x: -increment });
this.resize({
x: -increment
});
}
Window.prototype.increaseHeight = function () {
Window.prototype.increaseHeight = function() {
this.resize({ y: increment });
this.resize({
y: increment
});
}
Window.prototype.decreaseHeight = function () {
Window.prototype.decreaseHeight = function() {
this.resize({ y: -increment });
this.resize({
y: -increment
});
}
/* Position Bindings */
keys.push(Phoenix.bind('q', controlShift, function () {
keys.push(Phoenix.bind('q', controlShift, function() {
Window.focusedWindow() && Window.focusedWindow().to(Position.topLeft);
Window.focusedWindow() && Window.focusedWindow().to(Position.topLeft);
}));
keys.push(Phoenix.bind('w', controlShift, function () {
keys.push(Phoenix.bind('w', controlShift, function() {
Window.focusedWindow() && Window.focusedWindow().to(Position.topRight);
Window.focusedWindow() && Window.focusedWindow().to(Position.topRight);
}));
keys.push(Phoenix.bind('a', controlShift, function () {
keys.push(Phoenix.bind('a', controlShift, function() {
Window.focusedWindow() && Window.focusedWindow().to(Position.bottomLeft);
Window.focusedWindow() && Window.focusedWindow().to(Position.bottomLeft);
}));
keys.push(Phoenix.bind('s', controlShift, function () {
keys.push(Phoenix.bind('s', controlShift, function() {
Window.focusedWindow() && Window.focusedWindow().to(Position.bottomRight);
Window.focusedWindow() && Window.focusedWindow().to(Position.bottomRight);
}));
keys.push(Phoenix.bind('z', controlShift, function () {
keys.push(Phoenix.bind('z', controlShift, function() {
Window.focusedWindow() && Window.focusedWindow().to(Position.central);
Window.focusedWindow() && Window.focusedWindow().to(Position.central);
}));
/* Grid Bindings */
keys.push(Phoenix.bind('p', controlShift, function () {
keys.push(Phoenix.bind('p', controlShift, function() {
Window.focusedWindow() && Window.focusedWindow().grid(Frame.half.width, Frame.half.height);
Window.focusedWindow() && Window.focusedWindow().grid(Frame.half.width, Frame.half.height);
}));
keys.push(Phoenix.bind('o', controlShift, function () {
keys.push(Phoenix.bind('o', controlShift, function() {
Window.focusedWindow() && Window.focusedWindow().grid(Frame.width, Frame.half.height);
Window.focusedWindow() && Window.focusedWindow().grid(Frame.width, Frame.half.height);
}));
keys.push(Phoenix.bind('k', controlShift, function () {
keys.push(Phoenix.bind('k', controlShift, function() {
Window.focusedWindow() && Window.focusedWindow().grid(Frame.half.width, Frame.height);
Window.focusedWindow() && Window.focusedWindow().grid(Frame.half.width, Frame.height);
}));
keys.push(Phoenix.bind('l', controlShift, function () {
keys.push(Phoenix.bind('l', controlShift, function() {
Window.focusedWindow() && Window.focusedWindow().grid(Frame.width, Frame.height);
Window.focusedWindow() && Window.focusedWindow().grid(Frame.width, Frame.height);
}));
/* Reverse Grid Bindings */
keys.push(Phoenix.bind('å', controlAltShift, function () {
keys.push(Phoenix.bind('å', controlAltShift, function() {
Window.focusedWindow() && Window.focusedWindow().reverseGrid(Frame.half.width, Frame.half.height);
Window.focusedWindow() && Window.focusedWindow().reverseGrid(Frame.half.width, Frame.half.height);
}));
keys.push(Phoenix.bind('p', controlAltShift, function () {
keys.push(Phoenix.bind('p', controlAltShift, function() {
Window.focusedWindow() && Window.focusedWindow().reverseGrid(Frame.width, Frame.half.height);
Window.focusedWindow() && Window.focusedWindow().reverseGrid(Frame.width, Frame.half.height);
}));
keys.push(Phoenix.bind('ä', controlAltShift, function () {
keys.push(Phoenix.bind('ä', controlAltShift, function() {
Window.focusedWindow() && Window.focusedWindow().reverseGrid(Frame.half.width, Frame.height);
Window.focusedWindow() && Window.focusedWindow().reverseGrid(Frame.half.width, Frame.height);
}));
keys.push(Phoenix.bind('ö', controlAltShift, function () {
keys.push(Phoenix.bind('ö', controlAltShift, function() {
Window.focusedWindow() && Window.focusedWindow().reverseGrid(Frame.width, Frame.height);
Window.focusedWindow() && Window.focusedWindow().reverseGrid(Frame.width, Frame.height);
}));
/* Resize Bindings */
keys.push(Phoenix.bind(',', controlShift, function () {
keys.push(Phoenix.bind(',', controlShift, function() {
Window.focusedWindow() && Window.focusedWindow().increaseWidth();
Window.focusedWindow() && Window.focusedWindow().increaseWidth();
}));
keys.push(Phoenix.bind('.', controlShift, function () {
keys.push(Phoenix.bind('.', controlShift, function() {
Window.focusedWindow() && Window.focusedWindow().increaseHeight();
Window.focusedWindow() && Window.focusedWindow().increaseHeight();
}));
keys.push(Phoenix.bind(',', controlAltShift, function () {
keys.push(Phoenix.bind(',', controlAltShift, function() {
Window.focusedWindow() && Window.focusedWindow().decreaseWidth();
Window.focusedWindow() && Window.focusedWindow().decreaseWidth();
}));
keys.push(Phoenix.bind('.', controlAltShift, function () {
keys.push(Phoenix.bind('.', controlAltShift, function() {
Window.focusedWindow() && Window.focusedWindow().decreaseHeight();
Window.focusedWindow() && Window.focusedWindow().decreaseHeight();
}));
function focusApp(name) {
Phoenix.log('About to focus ' + name);
App.runningApps().forEach(function(app) {
if (app.name() === name) {
Phoenix.log('Found and focusing ' + name);
Phoenix.log(app.focus());
Phoenix.log('Done focusing ' + name);
}
});
}
keys.push(Phoenix.bind('g', controlCommandShift, function () {
focusApp('Google Chrome');
}));
keys.push(Phoenix.bind('a', controlCommandShift, function () {
focusApp('Atom');
}));
keys.push(Phoenix.bind('s', controlCommandShift, function () {
focusApp('Slack');
}));
keys.push(Phoenix.bind('t', controlCommandShift, function () {
focusApp('iTerm');
}));
keys.push(Phoenix.bind('m', controlCommandShift, function () {
focusApp('Messages');
}));

Loading…
Cancel
Save