Skip to content

Instantly share code, notes, and snippets.

@QuadFlask
Last active May 23, 2022 03:58
Show Gist options
  • Save QuadFlask/a81cac3ef8aee403002f43ed9be5a66a to your computer and use it in GitHub Desktop.
Save QuadFlask/a81cac3ef8aee403002f43ed9be5a66a to your computer and use it in GitHub Desktop.
phoenix screen config
Key.on("left", ["ctrl", "alt", "cmd"], function () {
const window = Window.focused();
if (window) {
const currentFocusedScreen = window.screen();
const screen = currentFocusedScreen.flippedVisibleFrame();
// const screen = currentFocusedScreen.next().flippedVisibleFrame();
if (isCloseRect(window.frame(), {x: screen.x, y: screen.y, width: screen.width / 2, height: screen.height})) {
if (closeTo(window.frame().width, screen.width / 2)) {
window.setFrame({
x: screen.x,
y: screen.y,
width: screen.width / 3,
height: screen.height,
});
return;
}
}
window.setFrame({
x: screen.x,
y: screen.y,
width: screen.width / 2,
height: screen.height,
});
// window.setTopLeft({
// x: screen.x + screen.width / 2 - window.frame().width / 2,
// y: screen.y + screen.height / 2 - window.frame().height / 2
// });
// window.maximize();
}
});
Key.on("right", ["ctrl", "alt", "cmd"], function () {
const window = Window.focused();
if (window) {
const currentFocusedScreen = window.screen();
const screen = currentFocusedScreen.flippedVisibleFrame();
// const screen = currentFocusedScreen.next().flippedVisibleFrame();
if (isCloseRect(window.frame(), {
x: screen.x + screen.width / 2,
y: screen.y,
width: screen.width / 2,
height: screen.height
})) {
if (closeTo(window.frame().width, screen.width / 2)) {
window.setFrame({
x: screen.x + screen.width * 2 / 3,
y: screen.y,
width: screen.width / 3,
height: screen.height,
});
return;
}
}
window.setFrame({
x: screen.x + screen.width / 2,
y: screen.y,
width: screen.width / 2,
height: screen.height,
});
// window.setTopLeft({
// x: screen.x + screen.width / 2 - window.frame().width / 2,
// y: screen.y + screen.height / 2 - window.frame().height / 2
// });
// window.maximize();
}
});
Key.on("up", ["ctrl", "alt", "cmd"], function () {
const window = Window.focused();
if (window) {
const currentFocusedScreen = window.screen();
const screen = currentFocusedScreen.flippedVisibleFrame();
window.setFrame({
x: screen.x,
y: screen.y,
width: screen.width,
height: screen.height,
});
// window.setTopLeft({
// x: screen.x + screen.width / 2 - window.frame().width / 2,
// y: screen.y + screen.height / 2 - window.frame().height / 2
// });
// window.maximize();
}
});
Key.on("left", ["ctrl", "cmd"], function () {
const space = Space.active();
const window = Window.focused();
space.previous().moveWindows([window]);
window.focus();
})
Key.on("right", ["ctrl", "cmd"], function () {
const space = Space.active();
const window = Window.focused();
space.next().moveWindows([window]);
window.focus();
})
function closeTo(a, b, error = 5) {
return Math.abs(a - b) < error;
}
function isCloseRect(r1, r2) {
return closeTo(r1.width, r2.width) &&
closeTo(r1.height, r2.height) &&
closeTo(r1.x, r2.x) &&
closeTo(r1.y, r2.y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment