Skip to content

Instantly share code, notes, and snippets.

@kaushikgopal
Last active October 7, 2018 02:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaushikgopal/b45de9d70d2b62dbbe85254caa7f0d26 to your computer and use it in GitHub Desktop.
Save kaushikgopal/b45de9d70d2b62dbbe85254caa7f0d26 to your computer and use it in GitHub Desktop.
Kaushik Gopal's window management tool of choice - phoenix.js
// download Phoenix from here https://github.com/kasper/phoenix
"use strict";
Phoenix.set({
openAtLogin: true
});
// -------------------------------------------
// Utility methods
// -------------------------------------------
function debug(o) {
Phoenix.notify(JSON.stringify(o));
}
/**
* TODO - Reuse the same Modal object to avoid artifacts when repeating actions and building lots of modals.
* @param message
* @param onScreen
* @returns {Modal}
*/
var alertModal = function (message, onScreen) {
var alertModal = new Modal();
alertModal.duration = 0.5;
alertModal.text = message;
alertModal.appearance = 'dark';
var screenFrame = (onScreen || Screen.main()).frame();
var alertFrame = alertModal.frame();
alertModal.origin = {
x: (screenFrame.x + (screenFrame.width * 0.5)) - (alertFrame.width * 0.5),
y: (screenFrame.y + (screenFrame.height * 0.5)) - (alertFrame.height * 0.5)
};
alertModal.show();
return alertModal;
};
// -------------------------------------------
// HELPFUL VARIABLES
// -------------------------------------------
var screen = Screen.main().flippedVisibleFrame();
// -------------------------------------------
// KEY BINDINGS
// -------------------------------------------
var mash = 'cmd-ctrl-shift'.split('-');
Key.on('t', mash, function () {
var activeWindows = App.focused().windows();
var frontWindow = activeWindows[0];
var prevX = (screen.width - 0.8 * screen.width) / 2;
var prevY = (screen.height - 0.8 * screen.height);
var newFrame;
var flip = -60;
_.map(activeWindows, function (window) {
newFrame = {
x: prevX,
y: prevY,
width: 0.8 * screen.width,
height: 0.8 * screen.height
};
window.setFrame(newFrame);
prevX = prevX + flip;
prevY = prevY + (Math.abs(flip) * -1);
if (prevX < 0 || prevY < 0) {
flip = flip * -1;
prevX = (screen.width - 0.8 * screen.width) / 2;
prevY = (screen.height - 0.8 * screen.height);
}
});
});
// full screen
Key.on('f', mash, function () {
Window.focused().maximise();
});
// center
Key.on('c', mash, function () {
var frontWindowWidth = 0.7 * screen.width;
var frontWindowHeight = 0.9 * screen.height;
Window.focused().setFrame({
x: (screen.width - frontWindowWidth) / 2,
y: (screen.height - frontWindowHeight) / 2,
width: frontWindowWidth,
height: frontWindowHeight,
});
});
Phoenix.notify("Configuration loaded.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment