Last active
May 24, 2018 03:20
-
-
Save ashikahmad/94bfcde8cc5a5ff45007661943646b7e to your computer and use it in GitHub Desktop.
My Phoenix dot file (configuration)
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
/* | |
Created by Ashik uddin Ahmad | |
Copyright © 2017 Ashik uddin Ahmad. All rights reserved. | |
*/ | |
//------------------------------------------------------ | |
// Overview | |
//------------------------------------------------------ | |
/* | |
Key symbols | |
------------------------------------------- | |
⇧ Shift ⌃ Control | |
⌥ Option ⌘ Command | |
← Left Arrow → Right Arrow | |
↑ Up Arrow ↓ Down Arrow | |
␣ Space | |
Shortcuts: [✔] Added [︎✘] Not Added Yet | |
----------------------------------------------------- | |
## Global | |
[✔] ⌃ ⌥ P ~~~~~> ⨂ Enable / Disable all other shortcuts | |
## Column Splits | |
[✔] ⌃ ⌥ ← ~~~~~> ◧ Left Half | |
[✔] ⌃ ⌥ → ~~~~~> ◨ Right Half | |
## Row Splits | |
︎[✔] ⌃ ⌥ ↑ ~~~~~> ⬒ Top Half | |
︎[✔] ⌃ ⌥ ↓ ~~~~~> ⬓ Bottom Half | |
## Fullscreen Toggle | |
[✔] ⌃ ⌥ ␣ ~~~~~> ⧈ Toggle Full screen ↔︎ Centered | |
## Quarter splits | |
︎[✔] ⌃ ⌥ U ~~~~~> ◰ Top Left Quarter | |
︎[✔] ⌃ ⌥ I ~~~~~> ◳ Top Right Quarter | |
︎[✔] ⌃ ⌥ J ~~~~~> ◱ Bottom Left Quarter | |
︎[✔] ⌃ ⌥ K ~~~~~> ◲ Bottom Right Quarter | |
## Third splits | |
[✔] ⌃ ⌥ ⇧ ← ~~~> ⧯⧮⧮ Left Third | |
[✔] ⌃ ⌥ ⇧ ↓ ~~~> ⧮⧯⧮ Center Third | |
[✔] ⌃ ⌥ ⇧ → ~~~> ⧮⧮⧯ Right Third | |
## Space shifts | |
[✔] ⌃ ⌥ ⌘ ← ~~> ⇠◻︎ To Previous Space | |
[✔] ⌃ ⌥ ⌘ → ~~> ◻︎⇢ To Next Space | |
## Auto-split Recent Windows | |
┌─┬─┐ ┌─┬─┬─┐ ┌─┬─┐ | |
│ │ │ │ │ │ │ ├─┼─┤ | |
└─┴─┘ └─┴─┴─┘ └─┴─┘ | |
[︎✘] ⌥ 1 ~~~~~~~> Fullscreen current one | |
[︎✘] ⌥ 2 ~~~~~~~> Column split first two equally | |
[︎✘] ⌥ 3 ~~~~~~~> Column split first three equally | |
[︎✘] ⌥ 4 ~~~~~~~> Split first four as quarters | |
*/ | |
//------------------------------------------------------ | |
// Configurations | |
//------------------------------------------------------ | |
Phoenix.set({ | |
daemon: false, // true => run in background, false => run in menubar | |
openAtLogin: true | |
}); | |
var MOD = { | |
alt: ['alt'], | |
ctrl_alt: ['ctrl', 'alt'], | |
ctrl_alt_shift: ['ctrl', 'alt', 'shift'], | |
ctrl_alt_cmd: ['ctrl', 'alt', 'cmd'] | |
} | |
var pMan = { | |
// This config is only applied on loading, not dynamically changed | |
config: { | |
colSplits: true, // ◧ ◨ | |
rowSplits: false, // ⬒ ⬓ | |
quarterSplits: false, // ◰ ◳ ◱ ◲ | |
thirdSplits: true, // ⧯⧮⧮ ⧮⧯⧮ ⧮⧮⧯ | |
fullscreenToggle: true, // ⧈ | |
spaceShifts: true, // ⇠◻︎ ◻︎⇢ | |
autoSplits: true | |
}, | |
// Samll centered window toggled from fulscreen (relative ratio to screen) | |
smallFrame: {x: 0.15, y: 0.15, width: 0.7, height: 0.7}, | |
fullFrame: {x: 0, y: 0, width: 1, height: 1}, | |
bottomOffset: 35.0, | |
// All shortcut mapping. Will not be bound if disabled in config. | |
shortcuts: { | |
mainToggle: { mod: MOD.ctrl_alt, key: 'p' }, | |
leftHalf: { mod: MOD.ctrl_alt, key: 'left' }, | |
rightHalf: { mod: MOD.ctrl_alt, key: 'right' }, | |
topHalf: { mod: MOD.ctrl_alt, key: 'up' }, | |
bottomHalf: { mod: MOD.ctrl_alt, key: 'down' }, | |
topLeft: { mod: MOD.ctrl_alt, key: 'u' }, | |
topRight: { mod: MOD.ctrl_alt, key: 'i' }, | |
bottomLeft: { mod: MOD.ctrl_alt, key: 'j' }, | |
bottomRight: { mod: MOD.ctrl_alt, key: 'k' }, | |
leftThird: { mod: MOD.ctrl_alt_shift, key: 'left' }, | |
centerThird: { mod: MOD.ctrl_alt_shift, key: 'down' }, | |
rightThird: { mod: MOD.ctrl_alt_shift, key: 'right' }, | |
toggleFull: { mod: MOD.ctrl_alt, key: 'space' }, | |
prevSpace: { mod: MOD.ctrl_alt_cmd, key: 'left' }, | |
nextSpace: { mod: MOD.ctrl_alt_cmd, key: 'right' }, | |
autoHalves: { mod: MOD.alt, key: '2' }, | |
autoThirds: { mod: MOD.alt, key: '3' }, | |
autoQuarters: { mod: MOD.alt, key: '4' }, | |
}, | |
// Variables below SHOULD NOT BE CHANGED! | |
keys: [], // To keep reference of all key binds to enable/disable. | |
enabled: true // To keep track if keys are enabled. | |
}; | |
//------------------------------------------------------ | |
// Helper Methods | |
//------------------------------------------------------ | |
// Binds shortcut s to task. This shortcut is toggle-able by main toggle. | |
pMan.bindShortcut = function(s, task) { | |
this.keys.push(new Key(s.key, s.mod, task)); | |
} | |
function setWindowFrame(frame) { | |
var screen = Screen.main().flippedVisibleFrame(); | |
var window = Window.focused(); | |
if(window) { | |
window.setFrame({ | |
x: frame.x * screen.width, | |
y: frame.y * screen.height, | |
width: frame.width * screen.width, | |
height: frame.height * (screen.height-pMan.bottomOffset) | |
}); | |
} | |
} | |
function showModal(text, icon) { | |
var screen = Screen.main().flippedVisibleFrame(); | |
var modal = new Modal(); | |
modal.duration = 2; | |
modal.text = text; | |
modal.icon = icon || App.get('Phoenix').icon(); | |
// if(typeof icon === 'undefined') modal.icon = App.get('Phoenix').icon(); | |
// else modal.icon = icon; | |
var mrect = modal.frame(); | |
modal.origin = { | |
x: screen.x + screen.width/2 - mrect.width/2, | |
y: screen.y + screen.height/2 - mrect.height/2 | |
}; | |
modal.show(); | |
} | |
Space.prototype.moveWindow = function(window) { | |
if(this.windows().includes(window) == false) { | |
_.forEach(window.spaces(), function(s){ | |
if(s !== this) s.removeWindows([window]); | |
}); | |
this.addWindows([window]); | |
} else { | |
showModal("Already there"); | |
} | |
return window; | |
} | |
function moveToSpaceNext(next) { | |
var window = Window.focused(); | |
if(window) { | |
if (next) { Space.active().next().moveWindow(window).focus(); } | |
else { Space.active().previous().moveWindow(window).focus(); } | |
} | |
} | |
function isAlmostEqual(one, other, buffer) { | |
if ( Math.abs(one.x - other.x) < buffer | |
&& Math.abs(one.y - other.y) < buffer | |
&& Math.abs(one.width - other.width) < buffer | |
&& Math.abs(one.height - other.height) < buffer ) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
Window.prototype.isMaximised = function() { | |
var sf = Screen.main().flippedVisibleFrame(); | |
sf.height -= pMan.bottomOffset; | |
var f = this.frame(); | |
var buffer = 20; | |
return isAlmostEqual(f, sf, buffer); | |
} | |
Window.prototype.setRelativeFrame = function(original, relative) { | |
this.setFrame({ | |
x: relative.x * original.width, | |
y: relative.y * original.height, | |
width: relative.width * original.width, | |
height: relative.height * original.height | |
}); | |
} | |
//------------------------------------------------------ | |
// Key Bindings (Can be disabled) | |
//------------------------------------------------------ | |
// Column splits | |
if(pMan.config.colSplits) { | |
pMan.bindShortcut(pMan.shortcuts.leftHalf, function() { | |
setWindowFrame({x: 0, y: 0, width: 0.5, height: 1}); | |
}); | |
pMan.bindShortcut(pMan.shortcuts.rightHalf, function(){ | |
setWindowFrame({x: 0.5, y: 0, width: 0.5, height: 1}); | |
}); | |
} | |
// Row Splits | |
if(pMan.config.rowSplits) { | |
pMan.bindShortcut(pMan.shortcuts.topHalf, function(){ | |
setWindowFrame({x: 0, y: 0, width: 1, height: 0.5}); | |
}); | |
pMan.bindShortcut(pMan.shortcuts.bottomHalf, function(){ | |
setWindowFrame({x: 0, y: 0.5, width: 1, height: 0.5}); | |
}); | |
} | |
// Fullscreen | |
if(pMan.config.fullscreenToggle) { | |
pMan.bindShortcut(pMan.shortcuts.toggleFull, function(){ | |
var window = Window.focused(); | |
if (window) { | |
if (window.isMaximised()) { setWindowFrame(pMan.smallFrame); } | |
else { setWindowFrame(pMan.fullFrame); } | |
} | |
}); | |
} | |
// Quarter splits | |
if(pMan.config.quarterSplits) { | |
pMan.bindShortcut(pMan.shortcuts.topLeft, function(){ | |
setWindowFrame({x: 0, y: 0, width: 0.5, height: 0.5}); | |
}); | |
pMan.bindShortcut(pMan.shortcuts.topRight, function(){ | |
setWindowFrame({x: 0.5, y: 0, width: 0.5, height: 0.5}); | |
}); | |
pMan.bindShortcut(pMan.shortcuts.bottomLeft, function(){ | |
setWindowFrame({x: 0, y: 0.5, width: 0.5, height: 0.5}); | |
}); | |
pMan.bindShortcut(pMan.shortcuts.bottomRight, function(){ | |
setWindowFrame({x: 0.5, y: 0.5, width: 0.5, height: 0.5}); | |
}); | |
} | |
// Third splits | |
if(pMan.config.thirdSplits) { | |
var f = 1.0/3.0; // third fraction | |
pMan.bindShortcut(pMan.shortcuts.leftThird, function(){ | |
setWindowFrame({x: 0, y: 0, width: f, height: 1}); | |
}); | |
pMan.bindShortcut(pMan.shortcuts.centerThird, function(){ | |
setWindowFrame({x: f, y: 0, width: f, height: 1}); | |
}); | |
pMan.bindShortcut(pMan.shortcuts.rightThird, function(){ | |
setWindowFrame({x: 2*f, y: 0, width: f, height: 1}); | |
}); | |
} | |
// Space shifts | |
if(pMan.config.spaceShifts) { | |
pMan.bindShortcut(pMan.shortcuts.prevSpace, function(){ | |
moveToSpaceNext(false); | |
}); | |
pMan.bindShortcut(pMan.shortcuts.nextSpace, function(){ | |
moveToSpaceNext(true); | |
}); | |
} | |
// Auto-splits | |
if(pMan.config.autoSplits) { | |
pMan.bindShortcut(pMan.shortcuts.autoHalves, function(){ | |
var w = Window.recent(); | |
var w1 = w[0], w2 = w[1]; | |
var screen = Screen.main().flippedVisibleFrame(); | |
if(w1) w1.setRelativeFrame(screen, {x: 0, y: 0, width: 0.5, height: 1}); | |
if(w2) w2.setRelativeFrame(screen, {x: 0.5, y: 0, width: 0.5, height: 1}); | |
}); | |
pMan.bindShortcut(pMan.shortcuts.autoThirds, function(){ | |
var w = Window.recent(); | |
var w1 = w[0], w2 = w[1], w3 = w[2]; | |
var screen = Screen.main().flippedVisibleFrame(); | |
var f = 1.0/3.0; // third fraction | |
if(w1) w1.setRelativeFrame(screen, {x: 0, y: 0, width: f, height: 1}); | |
if(w2) w2.setRelativeFrame(screen, {x: f, y: 0, width: f, height: 1}); | |
if(w3) w3.setRelativeFrame(screen, {x: 2*f, y: 0, width: f, height: 1}); | |
}); | |
pMan.bindShortcut(pMan.shortcuts.autoQuarters, function(){ | |
var w = Window.recent(); | |
var w1 = w[0], w2 = w[1], w3 = w[2], w4 = w[3]; | |
var screen = Screen.main().flippedVisibleFrame(); | |
if(w1) w1.setRelativeFrame(screen, {x: 0, y: 0, width: 0.5, height: 0.5}); | |
if(w2) w2.setRelativeFrame(screen, {x: 0.5, y: 0, width: 0.5, height: 0.5}); | |
if(w3) w3.setRelativeFrame(screen, {x: 0, y: 0.5, width: 0.5, height: 0.5}); | |
if(w4) w4.setRelativeFrame(screen, {x: 0.5, y: 0.5, width: 0.5, height: 0.5}); | |
}); | |
} | |
//------------------------------------------------------ | |
// Enable/Disable All other bindings | |
//------------------------------------------------------ | |
var s = pMan.shortcuts.mainToggle; | |
Key.on(s.key, s.mod, function(){ | |
pMan.enabled = !pMan.enabled; | |
for(var i = 0, len = pMan.keys.length; i < len; i++) { | |
if(pMan.enabled) { pMan.keys[i].enable(); } | |
else { pMan.keys[i].disable(); } | |
} | |
var text = "Phoenix keys disabled!"; | |
if(pMan.enabled) { | |
text = "Phoenix keys enabled!"; | |
} | |
showModal(text); | |
}); | |
Phoenix.notify("Configuration loaded."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment