Last active
December 30, 2020 16:21
-
-
Save artburkart/15b62f1a741eef0f74492860ab9dee9d to your computer and use it in GitHub Desktop.
Hammerspoon ShiftIt replacement (50% window tiling, maximize, change display)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- https://www.hammerspoon.org/go/#window-sizing | |
-- https://stackoverflow.com/questions/54151343/how-to-move-an-application-between-monitors-in-hammerspoon | |
-- https://github.com/fikovnik/ShiftIt/issues/296#issuecomment-438386501 | |
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "r", function() | |
hs.reload() | |
end) | |
hs.alert.show("Config loaded") | |
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 } | |
} | |
mash = { 'alt', 'ctrl', 'cmd' } | |
hs.hotkey.bind(mash, 'left', function() hs.window.focusedWindow():move(units.left50, nil, true) end) | |
hs.hotkey.bind(mash, 'right', function() hs.window.focusedWindow():move(units.right50, nil, true) end) | |
hs.hotkey.bind(mash, 'h', function() hs.window.focusedWindow():move(units.left50, nil, true) end) | |
hs.hotkey.bind(mash, 'l', function() hs.window.focusedWindow():move(units.right50, 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, 'k', function() hs.window.focusedWindow():move(units.top50, nil, true) end) | |
hs.hotkey.bind(mash, 'j', 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) | |
hs.hotkey.bind(mash, 'n', function() | |
local focusedWindow = hs.window.focusedWindow() | |
local focusedScreenFrame = focusedWindow:screen():frame() | |
local nextScreenFrame = focusedWindow:screen():next():frame() | |
local windowFrame = focusedWindow:frame() | |
windowFrame.x = ((((windowFrame.x - focusedScreenFrame.x) / focusedScreenFrame.w) * nextScreenFrame.w) + nextScreenFrame.x) | |
windowFrame.y = ((((windowFrame.y - focusedScreenFrame.y) / focusedScreenFrame.h) * nextScreenFrame.h) + nextScreenFrame.y) | |
windowFrame.h = ((windowFrame.h / focusedScreenFrame.h) * nextScreenFrame.h) | |
windowFrame.w = ((windowFrame.w / focusedScreenFrame.w) * nextScreenFrame.w) | |
focusedWindow:setFrame(windowFrame) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment