// Name: Window Manager // Description: Move windows between monitors and tile them to various positions // Author: aquillano // GitHub: aquillano import "@johnlindquist/kit" interface WindowInfo { process: string title: string index: number } interface Display { id: number bounds: { x: number y: number width: number height: number } workArea: { x: number y: number width: number height: number } } const getWindowChoices = async (): Promise<Choice[]> => { const windows = await getWindows() return windows.map((window, index) => ({ name: `${window.process} - ${window.title}`, value: window, description: `Window ${index + 1}`, })) } const getTilePositions = (workArea: any) => { const { x, y, width, height } = workArea return [ // Thirds { name: "Left 1/3", x, y, width: Math.floor(width / 3), height }, { name: "Middle 1/3", x: x + Math.floor(width / 3), y, width: Math.floor(width / 3), height }, { name: "Right 1/3", x: x + Math.floor(width * 2 / 3), y, width: Math.floor(width / 3), height }, // Halves { name: "Top 1/2", x, y, width, height: Math.floor(height / 2) }, { name: "Bottom 1/2", x, y: y + Math.floor(height / 2), width, height: Math.floor(height / 2) }, { name: "Left 1/2", x, y, width: Math.floor(width / 2), height }, { name: "Right 1/2", x: x + Math.floor(width / 2), y, width: Math.floor(width / 2), height }, // Quarters { name: "Top-Left Quarter", x, y, width: Math.floor(width / 2), height: Math.floor(height / 2) }, { name: "Top-Right Quarter", x: x + Math.floor(width / 2), y, width: Math.floor(width / 2), height: Math.floor(height / 2) }, { name: "Bottom-Left Quarter", x, y: y + Math.floor(height / 2), width: Math.floor(width / 2), height: Math.floor(height / 2) }, { name: "Bottom-Right Quarter", x: x + Math.floor(width / 2), y: y + Math.floor(height / 2), width: Math.floor(width / 2), height: Math.floor(height / 2) }, ] } const selectedWindow = await arg("Select a window to manage:", getWindowChoices) const action = await arg("Choose an action:", [ { name: "Move to Monitor", value: "move" }, { name: "Tile Window", value: "tile" }, { name: "Bring to Front", value: "focus" }, ]) if (action === "move") { const screens = await getScreens() const screenChoices = screens.map((screen, index) => ({ name: `Monitor ${index + 1} (${screen.bounds.width}x${screen.bounds.height})`, value: screen, description: `Position: ${screen.bounds.x}, ${screen.bounds.y}`, })) const targetScreen = await arg("Select target monitor:", screenChoices) // Move window to center of target screen const centerX = targetScreen.workArea.x + Math.floor(targetScreen.workArea.width / 4) const centerY = targetScreen.workArea.y + Math.floor(targetScreen.workArea.height / 4) const windowWidth = Math.floor(targetScreen.workArea.width / 2) const windowHeight = Math.floor(targetScreen.workArea.height / 2) await setWindowBoundsByIndex( selectedWindow.process, selectedWindow.index, centerX, centerY, windowWidth, windowHeight ) await toast(`Moved ${selectedWindow.process} to Monitor`) } else if (action === "tile") { const currentScreen = await getActiveScreen() const positions = getTilePositions(currentScreen.workArea) const positionChoices = positions.map(pos => ({ name: pos.name, value: pos, })) const selectedPosition = await arg("Select tile position:", positionChoices) await setWindowBoundsByIndex( selectedWindow.process, selectedWindow.index, selectedPosition.x, selectedPosition.y, selectedPosition.width, selectedPosition.height ) await toast(`Tiled ${selectedWindow.process} to ${selectedPosition.name}`) } else if (action === "focus") { await focusWindow(selectedWindow.process, selectedWindow.title) await toast(`Brought ${selectedWindow.process} to front`) }