Last active
April 9, 2021 18:19
-
-
Save djvs/a9161ad27431e46f3f05918907596c54 to your computer and use it in GitHub Desktop.
sway script - align focused window to given side of focused workspace
This file contains 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
const c = require("child_process") | |
const workspaces = JSON.parse( | |
c.execSync("swaymsg -t get_workspaces", { encoding: "utf8" }) | |
) | |
const ws = workspaces.find((x) => x.focused) | |
const win = ws.floating_nodes.find((x) => x.focused) | |
switch (process.argv[2]) { | |
case "left": { | |
x = 0 | |
y = win.rect.y - win.deco_rect.height - ws.rect.y | |
break | |
} | |
case "down": { | |
x = win.rect.x - ws.rect.x | |
y = ws.rect.height - win.rect.height - win.deco_rect.height | |
break | |
} | |
case "up": { | |
x = win.rect.x - ws.rect.x | |
y = 0 | |
break | |
} | |
case "right": { | |
x = ws.rect.width - win.rect.width | |
y = win.rect.y - win.deco_rect.height - ws.rect.y | |
break | |
} | |
default: { | |
process.exit() | |
} | |
} | |
c.execSync(`swaymsg move position ${x} ${y}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment