feat: move windows between spaces and toggle bsp
This commit is contained in:
23
package.json
23
package.json
@@ -9,7 +9,8 @@
|
|||||||
"rubentsirunyan",
|
"rubentsirunyan",
|
||||||
"webdesus",
|
"webdesus",
|
||||||
"d34dh0r53",
|
"d34dh0r53",
|
||||||
"lhy-a"
|
"lhy-a",
|
||||||
|
"joshuafhiggins"
|
||||||
],
|
],
|
||||||
"categories": [
|
"categories": [
|
||||||
"Developer Tools",
|
"Developer Tools",
|
||||||
@@ -49,6 +50,12 @@
|
|||||||
"description": "This command will start Yabai using `yabai --start-service` or stop it using `yabai --stop-service`.",
|
"description": "This command will start Yabai using `yabai --start-service` or stop it using `yabai --stop-service`.",
|
||||||
"mode": "no-view"
|
"mode": "no-view"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "toggle-bsp",
|
||||||
|
"title": "Toggle BSP Layout",
|
||||||
|
"description": "Toggle BSP layout for the current space.",
|
||||||
|
"mode": "no-view"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "rotate",
|
"name": "rotate",
|
||||||
"title": "Rotate",
|
"title": "Rotate",
|
||||||
@@ -138,6 +145,20 @@
|
|||||||
"description": "Destroys the currently focused space.",
|
"description": "Destroys the currently focused space.",
|
||||||
"mode": "no-view"
|
"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",
|
"name": "focus-window-north",
|
||||||
"title": "Focus Active Window North",
|
"title": "Focus Active Window North",
|
||||||
|
|||||||
19
src/move-window-next.ts
Normal file
19
src/move-window-next.ts
Normal 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
19
src/move-window-prev.ts
Normal 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
60
src/toggle-bsp.ts
Normal 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.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user