mirror of
https://github.com/jimeh/dotfiles.git
synced 2026-02-19 13:46:41 +00:00
Add fancy window resize/move functionality
This commit is contained in:
@@ -13,6 +13,7 @@ local wm = {
|
|||||||
function wm:init ()
|
function wm:init ()
|
||||||
-- setup
|
-- setup
|
||||||
local bind = require('hs.hotkey').bind
|
local bind = require('hs.hotkey').bind
|
||||||
|
local bindAndRepeat = self.bindAndRepeat
|
||||||
|
|
||||||
hs.window.animationDuration = self.animationDuration
|
hs.window.animationDuration = self.animationDuration
|
||||||
self.grid.setGrid(self.gridSizes.default)
|
self.grid.setGrid(self.gridSizes.default)
|
||||||
@@ -20,7 +21,7 @@ function wm:init ()
|
|||||||
self.grid.ui.textSize = self.gridTextSize
|
self.grid.ui.textSize = self.gridTextSize
|
||||||
|
|
||||||
--
|
--
|
||||||
-- resize to grid
|
-- move and resize to preset grid locations
|
||||||
--
|
--
|
||||||
|
|
||||||
-- show interactive grid menu
|
-- show interactive grid menu
|
||||||
@@ -36,13 +37,13 @@ function wm:init ()
|
|||||||
)
|
)
|
||||||
|
|
||||||
-- left half
|
-- left half
|
||||||
bind({'cmd', 'ctrl'}, 'J', self.adjustWindow(0, 0, 15, 20))
|
bind({'ctrl', 'alt'}, 'J', self.adjustWindow(0, 0, 15, 20))
|
||||||
-- right half
|
-- right half
|
||||||
bind({'cmd', 'ctrl'}, 'L', self.adjustWindow(15, 0, 15, 20))
|
bind({'ctrl', 'alt'}, 'L', self.adjustWindow(15, 0, 15, 20))
|
||||||
-- top half
|
-- top half
|
||||||
bind({'cmd', 'ctrl'}, 'I', self.adjustWindow(0, 0, 30, 10))
|
bind({'ctrl', 'alt'}, 'I', self.adjustWindow(0, 0, 30, 10))
|
||||||
-- bottom half
|
-- bottom half
|
||||||
bind({'cmd', 'ctrl'}, 'K', self.adjustWindow(0, 10, 30, 10))
|
bind({'ctrl', 'alt'}, 'K', self.adjustWindow(0, 10, 30, 10))
|
||||||
|
|
||||||
-- left narrow
|
-- left narrow
|
||||||
bind({'ctrl', 'alt'}, 'U', self.adjustWindow(0, 0, 12, 20))
|
bind({'ctrl', 'alt'}, 'U', self.adjustWindow(0, 0, 12, 20))
|
||||||
@@ -54,24 +55,6 @@ function wm:init ()
|
|||||||
-- right wide
|
-- right wide
|
||||||
bind({'cmd', 'ctrl'}, 'O', self.adjustWindow(12, 0, 18, 20))
|
bind({'cmd', 'ctrl'}, 'O', self.adjustWindow(12, 0, 18, 20))
|
||||||
|
|
||||||
-- left fat
|
|
||||||
bind({'cmd', 'ctrl', 'alt'}, 'J', self.adjustWindow(0, 0, 21, 20))
|
|
||||||
-- right wide
|
|
||||||
bind({'cmd', 'ctrl', 'alt'}, 'L', self.adjustWindow(9, 0, 21, 20))
|
|
||||||
-- top fat
|
|
||||||
bind({'cmd', 'ctrl', 'alt'}, 'I', self.adjustWindow(0, 0, 30, 14))
|
|
||||||
-- bottom wide
|
|
||||||
bind({'cmd', 'ctrl', 'alt'}, 'K', self.adjustWindow(0, 6, 30, 14))
|
|
||||||
|
|
||||||
-- top left quarter
|
|
||||||
bind({'cmd', 'ctrl', 'shift'}, 'J', self.adjustWindow(0, 0, 15, 10))
|
|
||||||
-- top right quarter
|
|
||||||
bind({'cmd', 'ctrl', 'shift'}, 'I', self.adjustWindow(15, 0, 15, 10))
|
|
||||||
-- bottom right quarter
|
|
||||||
bind({'cmd', 'ctrl', 'shift'}, 'L', self.adjustWindow(15, 10, 15, 10))
|
|
||||||
-- bottom left quarter
|
|
||||||
bind({'cmd', 'ctrl', 'shift'}, 'K', self.adjustWindow(0, 10, 15, 10))
|
|
||||||
|
|
||||||
-- center super narrow
|
-- center super narrow
|
||||||
bind({'cmd', 'ctrl', 'alt'}, '\\', self.adjustWindow(10, 0, 10, 20))
|
bind({'cmd', 'ctrl', 'alt'}, '\\', self.adjustWindow(10, 0, 10, 20))
|
||||||
-- center narrow small
|
-- center narrow small
|
||||||
@@ -94,20 +77,30 @@ function wm:init ()
|
|||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- resize to specific sizes
|
-- move and resize windows
|
||||||
--
|
--
|
||||||
|
|
||||||
bind({'cmd', 'ctrl', 'alt'}, 'F', self.resizeWindow(770, 634))
|
bind({'cmd', 'ctrl', 'alt'}, 'F', self.resizeWindow(770, 634))
|
||||||
|
|
||||||
|
-- resize windows
|
||||||
|
bindAndRepeat({'cmd', 'ctrl'}, 'J', self.resizeWindowOnGrid(-1, 0))
|
||||||
|
bindAndRepeat({'cmd', 'ctrl'}, 'L', self.resizeWindowOnGrid(1, 0))
|
||||||
|
bindAndRepeat({'cmd', 'ctrl'}, 'I', self.resizeWindowOnGrid(0, -1))
|
||||||
|
bindAndRepeat({'cmd', 'ctrl'}, 'K', self.resizeWindowOnGrid(0, 1))
|
||||||
|
|
||||||
-- move window relative
|
-- move window relative
|
||||||
bind({'ctrl', 'alt'}, 'J',
|
bindAndRepeat({'cmd', 'ctrl', 'shift'}, 'J', self.moveWindowOnGrid(-1, 0))
|
||||||
self.moveWindowOnGrid(-1, 0), nil, self.moveWindowOnGrid(-1, 0))
|
bindAndRepeat({'cmd', 'ctrl', 'shift'}, 'L', self.moveWindowOnGrid(1, 0))
|
||||||
bind({'ctrl', 'alt'}, 'L',
|
bindAndRepeat({'cmd', 'ctrl', 'shift'}, 'I', self.moveWindowOnGrid(0, -1))
|
||||||
self.moveWindowOnGrid(1, 0), nil, self.moveWindowOnGrid(1, 0))
|
bindAndRepeat({'cmd', 'ctrl', 'shift'}, 'K', self.moveWindowOnGrid(0, 1))
|
||||||
bind({'ctrl', 'alt'}, 'I',
|
|
||||||
self.moveWindowOnGrid(0, -1), nil, self.moveWindowOnGrid(0, -1))
|
-- enlarge horizontally
|
||||||
bind({'ctrl', 'alt'}, 'K',
|
bindAndRepeat({'cmd', 'ctrl', 'shift'}, '\\',
|
||||||
self.moveWindowOnGrid(0, 1), nil, self.moveWindowOnGrid(0, 1))
|
self.resizeWindowOnGridSymmetrically(1, 0))
|
||||||
|
-- shrink horizontally
|
||||||
|
bindAndRepeat({'cmd', 'ctrl', 'shift'}, '\'',
|
||||||
|
self.resizeWindowOnGridSymmetrically(-1, 0))
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- move between displays
|
-- move between displays
|
||||||
@@ -155,6 +148,10 @@ end
|
|||||||
-- private methods
|
-- private methods
|
||||||
--
|
--
|
||||||
|
|
||||||
|
wm.bindAndRepeat = function (mod, key, fn)
|
||||||
|
hs.hotkey.bind(mod, key, fn, nil, fn)
|
||||||
|
end
|
||||||
|
|
||||||
wm.adjustWindow = function (x, y, w, h)
|
wm.adjustWindow = function (x, y, w, h)
|
||||||
return function ()
|
return function ()
|
||||||
wm.grid.adjustWindow(
|
wm.grid.adjustWindow(
|
||||||
@@ -168,24 +165,6 @@ wm.adjustWindow = function (x, y, w, h)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
wm.moveWindowOnGrid = function (x, y)
|
|
||||||
return function ()
|
|
||||||
wm.grid.adjustWindow(
|
|
||||||
function (cell)
|
|
||||||
local gridSize = wm.grid.getGrid()
|
|
||||||
|
|
||||||
if ((cell.x + x) + cell.w) <= gridSize.w then
|
|
||||||
cell.x = cell.x + x
|
|
||||||
end
|
|
||||||
|
|
||||||
if ((cell.y + y) + cell.h) <= gridSize.h then
|
|
||||||
cell.y = cell.y + y
|
|
||||||
end
|
|
||||||
end
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
wm.resizeWindow = function (w, h)
|
wm.resizeWindow = function (w, h)
|
||||||
return function ()
|
return function ()
|
||||||
local win = hs.window.focusedWindow()
|
local win = hs.window.focusedWindow()
|
||||||
@@ -219,6 +198,88 @@ wm.moveWindowRelative = function (x, y)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
wm.moveWindowOnGrid = function (x, y)
|
||||||
|
return function ()
|
||||||
|
wm.grid.adjustWindow(
|
||||||
|
function (cell)
|
||||||
|
local gridSize = wm.grid.getGrid()
|
||||||
|
|
||||||
|
if ((cell.x + x) + cell.w) <= gridSize.w then
|
||||||
|
cell.x = cell.x + x
|
||||||
|
end
|
||||||
|
|
||||||
|
if ((cell.y + y) + cell.h) <= gridSize.h then
|
||||||
|
cell.y = cell.y + y
|
||||||
|
end
|
||||||
|
end
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
wm.resizeWindowOnGrid = function (w, h)
|
||||||
|
return function ()
|
||||||
|
wm.grid.adjustWindow(
|
||||||
|
function (cell)
|
||||||
|
local gridSize = wm.grid.getGrid()
|
||||||
|
|
||||||
|
if cell.x == 0 and cell.w == gridSize.w then
|
||||||
|
if w < 0 then
|
||||||
|
cell.w = cell.w + w
|
||||||
|
else
|
||||||
|
cell.w = cell.w - w
|
||||||
|
cell.x = cell.x + w
|
||||||
|
end
|
||||||
|
elseif (cell.x + cell.w) >= gridSize.w then
|
||||||
|
cell.w = cell.w - w
|
||||||
|
cell.x = cell.x + w
|
||||||
|
elseif cell.x == 0 then
|
||||||
|
cell.w = cell.w + w
|
||||||
|
else
|
||||||
|
cell.w = cell.w + (w * 2)
|
||||||
|
cell.x = cell.x - w
|
||||||
|
end
|
||||||
|
|
||||||
|
if cell.y == 0 and cell.h == gridSize.h then
|
||||||
|
if h < 0 then
|
||||||
|
cell.h = cell.h + h
|
||||||
|
else
|
||||||
|
cell.h = cell.h - h
|
||||||
|
cell.y = cell.y + h
|
||||||
|
end
|
||||||
|
elseif (cell.y + cell.h) >= gridSize.h then
|
||||||
|
cell.h = cell.h - h
|
||||||
|
cell.y = cell.y + h
|
||||||
|
elseif cell.y == 0 then
|
||||||
|
cell.h = cell.h + h
|
||||||
|
else
|
||||||
|
cell.h = cell.h - (h * 2)
|
||||||
|
cell.y = cell.y + h
|
||||||
|
end
|
||||||
|
end
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
wm.resizeWindowOnGridSymmetrically = function (w, h)
|
||||||
|
return function ()
|
||||||
|
wm.grid.adjustWindow(
|
||||||
|
function (cell)
|
||||||
|
local gridSize = wm.grid.getGrid()
|
||||||
|
|
||||||
|
if w ~= 0 and (cell.w + (w * 2)) <= gridSize.w then
|
||||||
|
cell.w = cell.w + (w * 2)
|
||||||
|
cell.x = cell.x - w
|
||||||
|
end
|
||||||
|
|
||||||
|
if h ~= 0 and (cell.h + (h * 2)) <= gridSize.h then
|
||||||
|
cell.h = cell.h + (h * 2)
|
||||||
|
cell.y = cell.y - h
|
||||||
|
end
|
||||||
|
end
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- the end
|
-- the end
|
||||||
return wm
|
return wm
|
||||||
|
|||||||
Reference in New Issue
Block a user