Skip to content

Instantly share code, notes, and snippets.

@gcnyin
Created May 26, 2021 15:44
Show Gist options
  • Save gcnyin/23561fce0c7bcb029e1517738e0156c9 to your computer and use it in GitHub Desktop.
Save gcnyin/23561fce0c7bcb029e1517738e0156c9 to your computer and use it in GitHub Desktop.
Hammerspoon窗口管理器
hs.window.animationDuration = 0
units = {
right50 = { x = 0.50, y = 0.00, w = 0.50, h = 1.00 },
left50 = { x = 0.00, y = 0.00, w = 0.50, h = 1.00 },
top50 = { x = 0.00, y = 0.00, w = 1.00, h = 0.50 },
bot50 = { x = 0.00, y = 0.50, w = 1.00, h = 0.50 },
maximum = { x = 0.00, y = 0.00, w = 1.00, h = 1.00 }
}
hs.hotkey.bind({ 'ctrl', 'alt', 'cmd'}, 'n', function()
local win = hs.window.focusedWindow()
-- get the screen where the focused window is displayed, a.k.a. current screen
local screen = win:screen()
-- compute the unitRect of the focused window relative to the current screen
-- and move the window to the next screen setting the same unitRect
win:move(win:frame():toUnitRect(screen:frame()), screen:next(), true, 0)
end)
hs.hotkey.bind({ 'ctrl', 'alt', 'cmd'}, 'p', function()
local win = hs.window.focusedWindow()
-- get the screen where the focused window is displayed, a.k.a. current screen
local screen = win:screen()
-- compute the unitRect of the focused window relative to the current screen
-- and move the window to the next screen setting the same unitRect
win:move(win:frame():toUnitRect(screen:frame()), screen:previous(), true, 0)
end)
mash = { 'ctrl', 'alt', 'cmd' }
hs.hotkey.bind(mash, 'right', function() hs.window.focusedWindow():move(units.right50, nil, true) end)
hs.hotkey.bind(mash, 'left', function() hs.window.focusedWindow():move(units.left50, nil, true) end)
hs.hotkey.bind(mash, 'up', function() hs.window.focusedWindow():move(units.top50, nil, true) end)
hs.hotkey.bind(mash, 'down', function() hs.window.focusedWindow():move(units.bot50, nil, true) end)
hs.hotkey.bind(mash, 'm', function() hs.window.focusedWindow():move(units.maximum, nil, true) end)
@gcnyin
Copy link
Author

gcnyin commented May 26, 2021

mkdir ~/.hammerspoon
cd ~/.hammerspoon
touch init.lua

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