Mac 下的窗口管理器

2,770 阅读4分钟

窗口管理器根据管理窗口的方式不同,被分为几个门类。

  • 合成式窗口管理器(compositing window manager)
  • 堆叠式窗口管理器(stacking window manager)
  • 瓦片式窗口管理器(tiling window manager)
  • 动态窗口管理器(dynamic window manager)

这里的介绍涉及瓦片式,俗称平辅式,以及堆叠式。大部分系统默认窗口都属于堆叠式的,包括Mac、Linux、Window

Amethyst

平辅式窗口管理器

它的Keyboard Shortcuts

Amethyst uses two modifier combinations.

mod1 - option + shift
mod2 - ctrl + option + shift
And defines the following commands, mostly a mapping to xmonad key combinations. mod1 + space — cycle to next layout
mod2 + space - cycle to previous layout
mod1 + w - focus 1st screen
mod1 + e - focus 2nd screen
mod1 + r - focus 3rd screen
mod2 + w - move focused window to 1st screen
mod2 + e - move focused window to 2nd screen
mod2 + r - move focused window to 3rd screen
mod2 + [n] - move focused window to nth space
mod2 + left - move focused window left one space
mod2 + right - move focused window right one space
mod1 + h - shrink the main pane
mod1 + l - expand the main pane
mod1 + , - increase the number of windows in the main pane
mod1 + . - decrease the number of windows in the main pane
mod1 + j - focus the next window counterclockwise
mod1 + k - focus the next window clockwise
mod2 + j - move the focused window one space counterclockwise
mod2 + k - move the focused window one space clockwise
mod2 + h - move the focused window one window counterclockwise
mod2 + l - move the focused window one window clockwise
mod1 + return - swap the focused window with the main window
mod1 + t - toggle whether or not the focused window is floating
mod2 + t - toggle globally whether or not Amethyst tiles windows
mod1 + i - display the current layout for each screen
mod1 + z - force windows to be reevalulated

它支持多屏聚焦、窗口多屏多space转移。至于Space的切换,官方推荐使用系统自带的设置:

Spaces are, unfortunately, not supported right out of the box. To enable it you must activate Mission Control’s keyboard shortcuts for switching to specific Desktops, as Mac OS X calls them. This option is in the Keyboard Shortcuts tab of the Keyboard preferences pane. The shortcuts will be of the form ctrl + [n]. Amethyst is only able to send a window to the nth space if the shortcut ctrl + n is enabled.

缺点: space需要手动创建,未提供space设置,当前layout窗口的位置等等

Hammerspoon & Phoenix

这两个都是堆叠式的,都为 cocoa 提供上层API,如下。区别是一个需要额外写lua脚本,一个是js

* Keys
* Events
* Preferences
* Require
* Phoenix
* Storage
* Point
* Size
* Rectangle
* Identifiable
* Iterable
* Key
* Event
* Timer
* Task
* Modal
* Screen
* Space
* Mouse
* App
* Window

另外,因为 cocoa 并没有提供太多关于spaces的api,所以无论是 hammerspoon 还是 phoenix 对spaces的支持都不是很完美。以下是作者的原话:

I’ve been hacking around and adding support for moving windows between spaces is doable and works rather well. However, I cannot figure out a way to get a list of all the spaces in the order the user has them sorted in Mission Control.

后来 phoenix 作者想到了一些办法,但结果也是类似 Amethyst 只能将窗口移动至Spaces,而不能决定Spaces的状态。Hammerspoon的作者将spaces module列入undocumented,提供了更多关于Space的接口,但并不推荐尝试。反正我试了下,出现一个特别严重的问题是接入双屏时,系统自动创建了一个space,但不是由 hammerspoon 提供的api创建,所以你不能对它进行任何操作。但我还是把这undocumented写在配置文件里了…

至于TotalSpaces2, 它是完美支持spaces的,但是:

the TotalSpaces2 page state that they do some code injection, which is the reason why you need to disable some security feature in El Capitan for it to work.

Kwm

Kwm的作者把 hammerspoon 中undocumented关于spaces的api整合进去了

# Change focus between spaces, skipping transitions animation
# (mission control does not update, requires `killall Dock`)
kwmc space -fExperimental {space} {space}: workspace_id | name | previous | left | right

大家也看到了,是experimental,多多少少会有些问题。这里作者想到了一个解决办法

Considering how the scratchpad system works, I’ve been thinking of extending / revamping or simply just implement a separate feature that allow windows to be tagged.

为窗口打标签…而后实现下面这样的分组,这样我们就可以不用关注space的切换,心里默默的给作者点赞…

Dev : editor + compiler + terminal + man pages
Web: browser + irc / slack
Monitoring : netstat + ps

再说明一点,Kwm比较纯粹,只关注平辅式窗口管理,这点比较符合unix思想。而且它搭配 Übersicht 真的很酷,这里有视频介绍 Youtube

它的功能目录:

Create Window Rules Window Filter Window Properties Example Rules
Configure Kwm Window Borders Global Defaults Display Defaults Space Defaults
Interact with Kwm Windows Displays Spaces Tree Scratchpad
Query current state Windows Tiling Spaces Scratchpad

其它

  • Slate 多年未更新
  • Mjolnir hammerspoon是fork它的,同样多年未更新
  • 对于非平辅窗口管理,如果你正在使用Moom, Divvy, SizeUp,那么我推荐 Spectacle ,开箱即用且免费

到现在才发现可弃CatchMouse。不过目前多屏办公还是在linux下开着i3wm来的舒服。

参考