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
-- to be used in init.lua | |
-- based on https://github.com/fikovnik/ShiftIt/wiki/The-Hammerspoon-Alternative | |
-- replicates ShiftIt functionality | |
function setScreenPrimary() | |
local currentScreen = hs.screen.mainScreen() | |
currentScreen:setPrimary() | |
end | |
function moveToNextScreen() | |
local log = hs.logger.new('my-shiftit') | |
local win = hs.window.focusedWindow() | |
local currentScreen = hs.screen.mainScreen() | |
local nextScreen = currentScreen:next() | |
log.e("Moving window") | |
log.e(nextScreen:name()) | |
win:moveToScreen(nextScreen) | |
-- Now hide and unhide and setfocus on the window.. | |
-- this is because `moveToScreen` only moves the window, | |
-- but the active menu bar remains in the old screen. | |
-- so pressing CMD+N again won't work because the focus | |
-- is on the old screen. doing this hide+unhide+focus | |
-- shifts the menu focus also. | |
-- Jasim. | |
win:application():hide() | |
hs.timer.doAfter(0.1, function() | |
win:application():unhide() | |
win:application():activate(true) | |
-- win:becomeMain() | |
-- win:focus() | |
-- win:raise() | |
end) | |
end | |
hs.window.animationDuration = 0 | |
units = { | |
right30 = { x = 0.70, y = 0.00, w = 0.30, h = 1.00 }, | |
right70 = { x = 0.30, y = 0.00, w = 0.70, h = 1.00 }, | |
right50 = { x = 0.50, y = 0.00, w = 0.50, h = 1.00 }, | |
left70 = { x = 0.00, y = 0.00, w = 0.70, h = 1.00 }, | |
left50 = { x = 0.00, y = 0.00, w = 0.50, h = 1.00 }, | |
left30 = { x = 0.00, y = 0.00, w = 0.30, 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 }, | |
upright30 = { x = 0.70, y = 0.00, w = 0.30, h = 0.50 }, | |
botright30 = { x = 0.70, y = 0.50, w = 0.30, h = 0.50 }, | |
upleft70 = { x = 0.00, y = 0.00, w = 0.70, h = 0.50 }, | |
botleft70 = { x = 0.00, y = 0.50, w = 0.70, h = 0.50 }, | |
maximum = { x = 0.00, y = 0.00, w = 1.00, h = 1.00 } | |
} | |
mash = { 'ctrl', 'option', 'cmd' } | |
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, '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, 'm', function() hs.window.focusedWindow():move(units.maximum, nil, true) end) | |
hs.hotkey.bind(mash, 'n', moveToNextScreen) | |
hs.hotkey.bind(mash, 'p', setScreenPrimary) | |
-- hs.hotkey.bind(mash, 'l', function() hs.window.focusedWindow():move(units.right30, nil, true) end) | |
-- hs.hotkey.bind(mash, 'h', function() hs.window.focusedWindow():move(units.left70, 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, ']', function() hs.window.focusedWindow():move(units.upright30, nil, true) end) | |
-- hs.hotkey.bind(mash, '[', function() hs.window.focusedWindow():move(units.upleft70, nil, true) end) | |
-- hs.hotkey.bind(mash, ';', function() hs.window.focusedWindow():move(units.botleft70, nil, true) end) | |
-- hs.hotkey.bind(mash, "'", function() hs.window.focusedWindow():move(units.botright30, nil, true) end) | |
-- hs.hotkey.bind(mash, 'm', function() hs.window.focusedWindow():move(units.maximum, nil, true) end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment