强大的 Mac OS X 窗口管理器 Slate

/

Mac OS X 上的窗口管理器软件很多,比如收费的 Moomdivvy 等,相比这些软件有限的功能,有很多开源免费的工具,功能更加强大,更富有 Geek 精神,如果你喜欢让窗口管理完全按照你的意图来定制,那么这些工具将是你的首选,比如 Slate

Slate 有着丰富的文档,支持常规设置(设置文件为 .slate)和利用 javascript 书写设置文件(设置文件为 .slate.js)。下面以我的设置为例。

常规设置:

#  config
config defaultToCurrentScreen true
config nudgePercentOf screenSize
config resizePercentOf screenSize
config secondsBetweenRepeat 0.1
config checkDefaultsOnLoad true
config focusCheckWidthMax 3000
config windowHintsShowIcons true
config windowHintsIgnoreHiddenWindows false
config windowHintsSpread true

#  alias
alias mon-laptop 0
alias mon-asus 1
alias hint QWEASDZXC
alias full move screenOriginX;screenOriginY screenSizeX;screenSizeY
alias lefthalf move screenOriginX;screenOriginY screenSizeX/2;screenSizeY
alias righthalf move screenOriginX+screenSizeX/2;screenOriginY screenSizeX/2;screenSizeY
alias tophalf move screenOriginX;screenOriginY screenSizeX;screenSizeY/2
alias bottomhalf move screenOriginX;screenOriginY+screenSizeY/2 screenSizeX;screenSizeY/2
alias topleft corner top-left resize:screenSizeX/2;screenSizeY/2
alias topright corner top-right resize:screenSizeX/2;screenSizeY/2
alias bottomleft corner bottom-left resize:screenSizeX/2;screenSizeY/2
alias bottomright corner bottom-right resize:screenSizeX/2;screenSizeY/2
alias leftmost move screenOriginX;screenOriginY screenSizeX*0.6;screenSizeY
alias toprightless corner top-right resize:screenSizeX*0.4;screenSizeY/2
alias bottomrightless corner bottom-right resize:screenSizeX*0.4;screenSizeY/2

#  bind
bind return:shift;alt ${full}
bind h:shift;alt ${lefthalf}
bind l:shift;alt ${righthalf}
bind j:shift;alt ${bottomhalf}
bind k:shift;alt ${tophalf}
bind ]:shift;alt chain ${topright} | ${bottomright} | ${bottomleft} | ${topleft}
bind [:shift;alt chain ${bottomright} | ${topright} | ${topleft} | ${bottomleft}

bind left:shift;alt resize -10% +0
bind right:shift;alt resize +10% +0
bind up:shift;alt resize +0 -10%
bind down:shift;alt resize +0 +10%

bind left:shift;cmd nudge -10% +0
bind right:shift;cmd nudge +10% +0
bind up:shift;cmd nudge +0 -10%
bind down:shift;cmd nudge +0 +10%

bind space:shift;alt hint ${hint}
bind ,:shift;alt focus left
bind .:shift;alt focus right
bind /:shift;alt focus behind
bind m:shift;alt focus 'MacVim'
bind i:shift;alt focus 'iTerm'
bind f:shift;alt focus 'Finder'
bind b:shift;alt focus 'Firefox'

bind g:shift;alt grid padding:5 ${mon-asus}:16,9

bind n:shift;alt throw next resize

bind 1:shift;alt sequence focus 'Firefox' | throw ${mon-asus} | focus 'MacVim' > ${righthalf} | ${lefthalf}
bind 2:shift;alt sequence focus 'Firefox' | focus 'Finder' > throw ${mon-laptop} resize | focus 'iTerm' > ${toprightless} | focus 'MacVim' > ${bottomrightless} | ${leftmost}

利用 javascript 书写设置:

// config
S.cfga({
  "defaultToCurrentScreen" : true,
  "secondsBetweenRepeat" : 0.1,
  "checkDefaultsOnLoad" : true,
  "focusCheckWidthMax" : 3000,
  "windowHintsShowIcons" : true,
  "windowHintsIgnoreHiddenWindows": false,
  "windowHintsSpread": true,
  "windowHintsFontColor": [255, 0, 0, 0.8]
});

var monLap = "1366x768";
var monAsus = "1920x1080";

var fullscreen = S.op("move", { "x": "screenOriginX", "y": "screenOriginY", "width": "screenSizeX", "height": "screenSizeY" });
var lefthalf = fullscreen.dup({ "width": "screenSizeX/2" });
var righthalf = lefthalf.dup({ "x": "screenOriginX+screenSizeX/2" });
var tophalf = fullscreen.dup({ "height": "screenSizeY/2" });
var bottomhalf = tophalf.dup({ "y": "screenOriginY+screenSizeY/2" });
var topleft = S.op("corner", { "direction": "top-left", "width": "screenSizeX/2", "height": "screenSizeY/2" });
var topright = topleft.dup({ "direction": "top-right" });
var bottomleft = topleft.dup({ "direction": "bottom-left" });
var bottomright = topleft.dup({ "direction": "bottom-right" });

var appUp = function(application) {
  S.eapp(function(appObject) {
    if (appObject.name() === application) {
      appObject.eachWindow(function(winObject) {
        if (winObject.focus() === 'true') {
          return S.op("focus", { "app": +application });
        }
      });
    }
  });
  return S.op("shell", { "command": "/usr/bin/open /Applications/"+application+".app" });
};

// key binding
S.bnda({
  // resize
  "left:shift,alt": S.op("resize", { "width": "-10%", "height": "+0" }),
  "right:shift,alt": S.op("resize", { "width": "+10%", "height": "+0" }),
  "up:shift,alt": S.op("resize", { "width": "+0", "height": "-10%" }),
  "down:shift,alt": S.op("resize", { "width": "+0", "height": "+10%" }),
  // nudge
  "left:shift,cmd": S.op("nudge", { "x": "-10%", "y": "+0" }),
  "right:shift,cmd": S.op("nudge", { "x": "+10%", "y": "+0" }),
  "up:shift,cmd": S.op("nudge", { "x": "+0", "y": "-10%" }),
  "down:shift,cmd": S.op("nudge", { "x": "+0", "y": "+10%" }),
  // move
  "return:shift,alt": fullscreen,
  "h:shift,alt": lefthalf,
  "l:shift,alt": righthalf,
  "k:shift,alt": tophalf,
  "j:shift,alt": bottomhalf,
  "]:shift,alt": S.op("chain", { "operations": [ topright, bottomright, bottomleft, topleft ] }),
  "[:shift,alt": S.op("chain", { "operations": [ topright, topleft, bottomleft, bottomright ] }),
  // hint
  "space:shift,alt": S.op("hint", { "characters": "QWEASDZXC" }),
  // grid
  "g:shift,alt": S.op("grid", { "grids": { monAsus: { "width": 16, "height": 9 }}, "padding": 5 }),
  // focus
  ",:shift,alt": S.op("focus", { "direction": "left" }),
  ".:shift,alt": S.op("focus", { "direction": "right" }),
  "/:shift,alt": S.op("focus", { "direction": "below" }),
  "v:shift,alt": appUp("MacVim"),
  "i:shift,alt": appUp("iTerm"),
  "f:shift,alt": appUp("Finder"),
  "b:shift,alt": appUp("Firefox"),
  "c:shift,alt": appUp("Clearview"),
});

Comments