From 9910152bfe79cfba624fb80be40e242c456e179d Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 10 Jun 2019 21:52:39 +0200 Subject: Add window movement hotkeys Create a new mode activated with that activates hotkeys to do window management. Add hotkeys to move windows up, down, left, and right. One set of hotkeys to move by small increments and another set to move by slightly larger increments. Based on code from 'derekwyatt' (https://github.com/derekwyatt): https://github.com/fikovnik/ShiftIt/issues/296#issuecomment-438386501 > 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 }, > left70 = { x = 0.00, y = 0.00, w = 0.70, 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 = { 'shift', 'ctrl', 'cmd' } > 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) --- window.lua | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 window.lua (limited to 'window.lua') diff --git a/window.lua b/window.lua new file mode 100644 index 0000000..5c1dcb9 --- /dev/null +++ b/window.lua @@ -0,0 +1,65 @@ +units = { + up_small = { x = 0, y = -5 }, + right_small = { x = 5, y = 0 }, + down_small = { x = 0, y = 5 }, + left_small = { x = -5, y = 0 }, + + up_med = { x = 0, y = -20 }, + right_med = { x = 20, y = 0 }, + down_med = { x = 0, y = 20 }, + left_med = { x = -20, y = 0 }, + + maximum = { x = 0.00, y = 0.00, w = 1.00, h = 1.00 } +} + +window = {} +function window.up_small() + hs.window.focusedWindow():move(units.up_small, nil, false, 0) +end + +function window.right_small() + hs.window.focusedWindow():move(units.right_small, nil, false, 0) +end + +function window.down_small() + hs.window.focusedWindow():move(units.down_small, nil, false, 0) +end + +function window.left_small() + hs.window.focusedWindow():move(units.left_small, nil, false, 0) +end + +function window.up_med() + hs.window.focusedWindow():move(units.up_med, nil, false, 0) +end + +function window.right_med() + hs.window.focusedWindow():move(units.right_med, nil, false, 0) +end + +function window.down_med() + hs.window.focusedWindow():move(units.down_med, nil, false, 0) +end + +function window.left_med() + hs.window.focusedWindow():move(units.left_med, nil, false, 0) +end + + +window_mode = hs.hotkey.modal.new({'ctrl', 'option', 'shift'}, 'w', 'Window') +window_mode:bind({'ctrl', 'option', 'shift'}, 'w', 'Window Off', function() + window_mode:exit() +end) + +window_mode:bind({'shift'}, 'k', window.up_small, nil, window.up_small) +window_mode:bind({'shift'}, 'l', window.right_small, nil, window.right_small) +window_mode:bind({'shift'}, 'j', window.down_small, nil, window.down_small) +window_mode:bind({'shift'}, 'h', window.left_small, nil, window.left_small) + +window_mode:bind({}, 'k', window.up_med, nil, window.up_med) +window_mode:bind({}, 'l', window.right_med, nil, window.right_med) +window_mode:bind({}, 'j', window.down_med, nil, window.down_med) +window_mode:bind({}, 'h', window.left_med, nil, window.left_med) + +window_mode:bind({}, ']', nil, nil, function() hs.window.focusedWindow():moveOneScreenEast() end) +window_mode:bind({}, '[', nil, nil, function() hs.window.focusedWindow():moveOneScreenWest() end) -- cgit v1.2.3