feat: move windows between spaces and toggle bsp

This commit is contained in:
Joshua Higgins
2026-02-06 15:43:34 -05:00
parent 4980ef15a5
commit 30f51703d2
4 changed files with 120 additions and 1 deletions

View File

@@ -9,7 +9,8 @@
"rubentsirunyan",
"webdesus",
"d34dh0r53",
"lhy-a"
"lhy-a",
"joshuafhiggins"
],
"categories": [
"Developer Tools",
@@ -49,6 +50,12 @@
"description": "This command will start Yabai using `yabai --start-service` or stop it using `yabai --stop-service`.",
"mode": "no-view"
},
{
"name": "toggle-bsp",
"title": "Toggle BSP Layout",
"description": "Toggle BSP layout for the current space.",
"mode": "no-view"
},
{
"name": "rotate",
"title": "Rotate",
@@ -138,6 +145,20 @@
"description": "Destroys the currently focused space.",
"mode": "no-view"
},
{
"name": "move-window-next",
"title": "Move Window to Next Space",
"subtitle": "Yabai",
"description": "Moves the currently focused window to the next space.",
"mode": "no-view"
},
{
"name": "move-window-prev",
"title": "Move Window to Previous Space",
"subtitle": "Yabai",
"description": "Moves the currently focused window to the previous space.",
"mode": "no-view"
},
{
"name": "focus-window-north",
"title": "Focus Active Window North",

19
src/move-window-next.ts Normal file
View File

@@ -0,0 +1,19 @@
import { showHUD } from "@raycast/api";
import { runYabaiCommand } from "./helpers/scripts";
import { showFailureToast } from "@raycast/utils";
export default async function Command() {
try {
const { stderr } = await runYabaiCommand("-m window --space next --focus");
if (stderr) {
throw new Error(stderr);
}
showHUD(`Moved window to next space`);
} catch (error) {
showFailureToast(error, {
title: "Failed to move window.",
});
}
}

19
src/move-window-prev.ts Normal file
View File

@@ -0,0 +1,19 @@
import { showHUD } from "@raycast/api";
import { runYabaiCommand } from "./helpers/scripts";
import { showFailureToast } from "@raycast/utils";
export default async function Command() {
try {
const { stderr } = await runYabaiCommand("-m window --space prev --focus");
if (stderr) {
throw new Error(stderr);
}
showHUD(`Moved window to previous space`);
} catch (error) {
showFailureToast(error, {
title: "Failed to move window.",
});
}
}

60
src/toggle-bsp.ts Normal file
View File

@@ -0,0 +1,60 @@
import { showHUD } from "@raycast/api";
import { runYabaiCommand } from "./helpers/scripts";
import { showFailureToast } from "@raycast/utils";
export type YabaiSpace = {
id: number;
uuid: string;
index: number;
label: string;
type: string;
display: number;
windows: number[];
"first-window": number;
"last-window": number;
"has-focus": boolean;
"is-visible": boolean;
"is-native-fullscreen": boolean;
};
export default async function Command() {
try {
const { stdout: qstdout, stderr: qstderr } = await runYabaiCommand("-m query --spaces --space");
let layout = "bsp";
if (qstderr) {
throw new Error();
}
try {
const space: YabaiSpace = JSON.parse(qstdout);
if (space.type === "bsp") {
layout = "float";
}
} catch (error) {
throw new Error("Failed to parse Yabai space information.");
}
const { stderr } = await runYabaiCommand(`-m space --layout ${layout}`);
if (stderr) {
throw new Error();
}
if (layout === "bsp") {
layout = "BSP";
} else {
layout = "Float";
}
showHUD(`Switched to ${layout} layout`);
} catch (error) {
if (error instanceof Error && error.message.includes("Yabai executable not found")) {
return;
}
showFailureToast(error, {
title: "Failed to toggle BSP layout.",
});
}
}