Skip to content

Instantly share code, notes, and snippets.

@rainyear
Last active October 31, 2022 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save rainyear/2ec3b464cda37573c240e1ded78c176b to your computer and use it in GitHub Desktop.
Save rainyear/2ec3b464cda37573c240e1ded78c176b to your computer and use it in GitHub Desktop.
hammerspoon.init.lua
local hyper = {'shift', 'cmd'}
local hyper2 = {'ctrl', 'cmd'}
-- hyper + up maximize the current window
hs.hotkey.bind(hyper, 'up', function()
hs.grid.maximizeWindow()
end)
hs.hotkey.bind(hyper, "Left", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w / 2
f.h = max.h
win:setFrame(f)
end)
hs.hotkey.bind(hyper, "Right", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x + (max.w / 2)
f.y = max.y
f.w = max.w / 2
f.h = max.h
win:setFrame(f)
end)
moveto = function(win, n)
local screens = hs.screen.allScreens()
if n > #screens then
hs.alert.show("No enough screens " .. #screens)
else
local toWin = hs.screen.allScreens()[n]:name()
hs.alert.show("Move " .. win:application():name() .. " to " .. toWin)
hs.layout.apply({{nil, win:title(), toWin, hs.layout.maximized, nil, nil}})
end
end
hs.hotkey.bind(hyper2, "1", function()
local win = hs.window.focusedWindow()
moveto(win, 1)
end)
hs.hotkey.bind(hyper2, "2", function()
local win = hs.window.focusedWindow()
moveto(win, 2)
end)
hs.hotkey.bind(hyper2, "3", function()
local win = hs.window.focusedWindow()
moveto(win, 3)
end)
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "R", function()
hs.reload()
end)
hs.alert.show("Config loaded")
@prife
Copy link

prife commented Jan 21, 2017

maximizeWindow 这个函数有点问题。全屏的时候四周有缝隙,系统是serria版本。直接设置坐标的方式比较完美。

hs.hotkey.bind(hyper, 'up', function()
  -- hs.grid.maximizeWindow()
  local win = hs.window.focusedWindow()
  local f = win:frame()
  local screen = win:screen()
  local max = screen:frame()

  f.x = max.x
  f.y = max.y
  f.w = max.w
  f.h = max.h
  win:setFrame(f)
end)

@Dbraum
Copy link

Dbraum commented Mar 7, 2017

请问,如果是接上显示器后,能在电脑屏幕和显示器之间切换吗,拖拉鼠标的方式感觉有点难受,求实现

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment