見出し画像

Amethystでcentered master bottomの配置

function layout() {
  return {
    name: "Centered Master Bottom",
    initialState: {
      topRatio: 0.65,
      mainRatio: 0.5
    },
    commands: {
      "expand-main-pane": (state) => ({ ...state, mainRatio: Math.min(state.mainRatio + 0.05, 0.8) }),
      "shrink-main-pane": (state) => ({ ...state, mainRatio: Math.max(state.mainRatio - 0.05, 0.3) }),
      "increase-main-pane-count": (state) => ({ ...state, topRatio: Math.min(state.topRatio + 0.05, 0.85) }),
      "decrease-main-pane-count": (state) => ({ ...state, topRatio: Math.max(state.topRatio - 0.05, 0.4) })
    },
    getFrameAssignments: (windows, screenFrame, state) => {
      const count = windows.length;
      if (count === 0) return {};

      const { x, y, width, height } = screenFrame;
      const topRatio = state.topRatio;
      const mainRatio = state.mainRatio;
      const sideWidth = (width * (1 - mainRatio)) / 2;
      const mainWidth = width * mainRatio;

      const assignments = {};

      // 1ウィンドウ: フルスクリーン
      if (count === 1) {
        assignments[windows[0].id] = { x, y, width, height };
        return assignments;
      }

      // 2ウィンドウ: メイン中央 + 左
      if (count === 2) {
        assignments[windows[0].id] = { x: x + sideWidth, y, width: mainWidth, height };
        assignments[windows[1].id] = { x, y, width: sideWidth, height };
        return assignments;
      }

      // 3ウィンドウ: メイン中央 + 左右
      if (count === 3) {
        assignments[windows[0].id] = { x: x + sideWidth, y, width: mainWidth, height };
        assignments[windows[1].id] = { x, y, width: sideWidth, height };
        assignments[windows[2].id] = { x: x + sideWidth + mainWidth, y, width: sideWidth, height };
        return assignments;
      }

      // 4ウィンドウ以上: サイドは全高、中央は上下分割
      const topHeight = height * topRatio;
      const bottomHeight = height - topHeight;

      // メイン(上段中央)
      assignments[windows[0].id] = { x: x + sideWidth, y, width: mainWidth, height: topHeight };

      // サイド(全高)
      assignments[windows[1].id] = { x, y, width: sideWidth, height };
      assignments[windows[2].id] = { x: x + sideWidth + mainWidth, y, width: sideWidth, height };

      // 下段中央: 残りを均等分割
      const bottomCount = count - 3;
      const bottomWidth = mainWidth / bottomCount;
      for (let i = 0; i < bottomCount; i++) {
        assignments[windows[3 + i].id] = {
          x: x + sideWidth + (bottomWidth * i),
          y: y + topHeight,
          width: bottomWidth,
          height: bottomHeight
        };
      }

      return assignments;
    }
  };
}

これを
~/Library/Application Support/Amethyst/Layouts
の下に入れる。


いいなと思ったら応援しよう!