diff --git a/package.json b/package.json index e4c190d..44bc368 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/move-window-next.ts b/src/move-window-next.ts new file mode 100644 index 0000000..779bfcb --- /dev/null +++ b/src/move-window-next.ts @@ -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.", + }); + } +} diff --git a/src/move-window-prev.ts b/src/move-window-prev.ts new file mode 100644 index 0000000..a481acc --- /dev/null +++ b/src/move-window-prev.ts @@ -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.", + }); + } +} diff --git a/src/toggle-bsp.ts b/src/toggle-bsp.ts new file mode 100644 index 0000000..1e0caba --- /dev/null +++ b/src/toggle-bsp.ts @@ -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.", + }); + } +}