Amethyst第三方插件推荐:5个必备扩展

Amethyst第三方插件推荐:5个必备扩展

【免费下载链接】Amethyst Automatic tiling window manager for macOS à la xmonad. 【免费下载链接】Amethyst 项目地址: https://gitcode.com/gh_mirrors/am/Amethyst

作为一款类xmonad风格的macOS自动平铺窗口管理器(Automatic tiling window manager),Amethyst通过自定义布局系统支持第三方扩展。虽然官方未提供插件市场,但通过JavaScript自定义布局功能,用户可实现丰富的窗口管理增强。本文推荐5个实用"插件"(自定义布局脚本),并提供安装与配置指南。

1. 静态比例垂直布局(Static Ratio Tall)

功能特点

固定主窗格比例的垂直分栏布局,解决原生Tall布局比例动态变化问题。适合需要稳定窗口比例的开发者,如代码编辑器与终端分屏场景。

安装方法

# 1. 创建布局目录(若不存在)
mkdir -p ~/Library/Application\ Support/Amethyst/Layouts

# 2. 下载布局文件
curl -o ~/Library/Application\ Support/Amethyst/Layouts/static-ratio-tall.js https://raw.githubusercontent.com/ianyh/Amethyst/main/AmethystTests/Model/CustomLayouts/static-ratio-tall.js

配置示例

修改主窗格比例(默认0.6):

// static-ratio-tall.js
function layout() {
  return {
    name: "Static Ratio Tall",
    initialState: { mainPaneRatio: 0.7 }, // 调整为主窗格占70%宽度
    getFrameAssignments: (windows, screenFrame, state) => {
      // 布局实现代码
    }
  };
}

工作原理

通过继承原生Tall布局(TallLayout.swift),重写getFrameAssignments方法固定比例计算。布局系统架构详见CustomLayout.swift实现。

2. 均匀列布局(Uniform Columns)

功能特点

将所有窗口平均分配到多列布局中,适合多窗口同时参考的场景(如数据分析、多文档编辑)。区别于原生Column布局的权重分配方式,实现真正等宽排列。

安装与使用

# 复制测试用例中的布局文件
cp AmethystTests/Model/CustomLayouts/uniform-columns.js ~/Library/Application\ Support/Amethyst/Layouts/

效果演示

均匀列布局示意图

图1:4个窗口时的均匀列布局效果(每列25%宽度)

核心代码解析

// uniform-columns.js关键逻辑
getFrameAssignments: (windows, screenFrame) => {
  const columnCount = windows.length;
  const columnWidth = screenFrame.width / columnCount;
  
  return windows.reduce((assignments, window, index) => {
    assignments[window.id] = {
      x: screenFrame.x + index * columnWidth,
      y: screenFrame.y,
      width: columnWidth,
      height: screenFrame.height
    };
    return assignments;
  }, {});
}

3. 推荐主窗格比例布局(Recommended Main Pane)

功能特点

智能调整主窗格比例的动态布局,根据窗口内容类型自动优化空间分配。例如:

  • 代码编辑器窗口分配70%空间
  • 终端/日志窗口分配30%空间

实现原理

通过recommendMainPaneRatio方法响应窗口大小变化,结合应用标识符(如VSCode、iTerm)动态调整:

// recommended-main-pane-ratio.js
function layout() {
  return {
    extends: "tall", // 继承Tall布局
    recommendMainPaneRatio: (rawRatio, state, windows) => {
      const hasCodeEditor = windows.some(w => 
        w.title.includes("Visual Studio Code")
      );
      return hasCodeEditor ? Math.max(0.65, rawRatio) : rawRatio;
    }
  };
}

应用识别机制

通过窗口标题和应用Bundle ID实现(Application.swift):

// 应用信息获取示例
let bundleID = NSRunningApplication(processIdentifier: pid)?.bundleIdentifier
let windowTitle = CGWindowListCopyWindowInfo(...).takeRetainedValue() as NSArray

4. 双窗格右侧布局(Two Pane Right)

功能特点

将主窗格放置在右侧的双栏布局,符合右利手用户的视觉习惯。原生TwoPane布局的镜像版本,实现方式参考TwoPaneRightLayout.swift

安装命令

# 从测试布局复制
cp AmethystTests/Model/CustomLayouts/extended.js ~/Library/Application\ Support/Amethyst/Layouts/two-pane-right.js

布局结构

mermaid

图2:双窗格右侧布局的空间分配流程图

5. 全屏增强布局(Enhanced Fullscreen)

功能特点

扩展原生全屏布局,添加以下增强:

  • 窗口激活时自动切换全屏
  • 多显示器环境下的屏幕锁定
  • 退出全屏时恢复原布局位置

安装与激活

# 下载增强版全屏布局
curl -o ~/Library/Application\ Support/Amethyst/Layouts/enhanced-fullscreen.js https://raw.githubusercontent.com/ianyh/Amethyst/main/AmethystTests/Model/CustomLayouts/fullscreen.js

配置界面

在Amethyst偏好设置中启用: 全屏布局设置

图3:在布局偏好设置中选择"Enhanced Fullscreen"

事件处理逻辑

通过监听窗口焦点变化实现自动切换(Window.swift):

// enhanced-fullscreen.js
updateWithChange: (change, state) => {
  if (change.change === "focus_changed") {
    return { ...state, fullscreen: true };
  }
  return state;
}

布局管理与扩展开发

布局切换快捷键

在系统偏好设置中配置:

  1. 打开Amethyst偏好设置 → "Shortcuts"选项卡
  2. 为"Select Layout..."分配全局快捷键
  3. 选择对应布局(如"Static Ratio Tall")

自定义布局开发指南

  1. 基础结构:遵循custom-layouts.md定义规范
  2. 调试工具:使用console.log输出调试信息,通过系统日志查看:
    log show --process Amethyst --predicate 'subsystem == "com.amethyst"' --info
    
  3. 扩展点:支持的生命周期方法包括:
    • updateWithChange: 响应窗口事件
    • recommendMainPaneRatio: 调整窗口比例
    • commands: 自定义布局命令

布局文件位置

所有自定义布局需放置在:

~/Library/Application Support/Amethyst/Layouts/

Amethyst会自动扫描.js文件并在布局菜单中显示(LayoutType.swift)。

总结与扩展资源

本文推荐的5个扩展布局覆盖了比例控制、空间分配、智能调整等核心需求。通过Amethyst的JavaScript扩展系统(CustomLayout.swift),用户可实现更多个性化功能。

更多资源

通过组合使用这些布局扩展,可显著提升macOS窗口管理效率,实现类xmonad的高效工作流。

【免费下载链接】Amethyst Automatic tiling window manager for macOS à la xmonad. 【免费下载链接】Amethyst 项目地址: https://gitcode.com/gh_mirrors/am/Amethyst

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值