From 388ee0e7861e6c78e116d30d7d909e017dd96a54 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 5 Aug 2017 15:59:33 +0100 Subject: [PATCH] Add window movement on grid keybindings --- hammerspoon/window_management.lua | 67 +++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/hammerspoon/window_management.lua b/hammerspoon/window_management.lua index c484a4c..615c0ee 100644 --- a/hammerspoon/window_management.lua +++ b/hammerspoon/window_management.lua @@ -93,6 +93,22 @@ function wm:init () bind({'cmd', 'ctrl'}, 'H', self.grid.maximizeWindow) + -- + -- resize to specific sizes + -- + + bind({'cmd', 'ctrl', 'alt'}, 'F', self.resizeWindow(770, 634)) + + -- move window relative + bind({'ctrl', 'alt'}, 'J', + self.moveWindowOnGrid(-1, 0), nil, self.moveWindowOnGrid(-1, 0)) + bind({'ctrl', 'alt'}, 'L', + self.moveWindowOnGrid(1, 0), nil, self.moveWindowOnGrid(1, 0)) + bind({'ctrl', 'alt'}, 'I', + self.moveWindowOnGrid(0, -1), nil, self.moveWindowOnGrid(0, -1)) + bind({'ctrl', 'alt'}, 'K', + self.moveWindowOnGrid(0, 1), nil, self.moveWindowOnGrid(0, 1)) + -- -- move between displays -- @@ -152,6 +168,57 @@ wm.adjustWindow = function (x, y, w, h) 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) + return function () + local win = hs.window.focusedWindow() + local f = win:frame() + + f.w = w + f.h = h + win:setFrame(f) + end +end + +wm.moveWindow = function(x, y) + return function () + local win = hs.window.focusedWindow() + local f = win:frame() + + f.x = x + f.y = y + win:setFrame(f) + end +end + +wm.moveWindowRelative = function (x, y) + return function () + local win = hs.window.focusedWindow() + local f = win:frame() + + f.x = f.x + x + f.y = f.y + y + win:setFrame(f) + end +end + -- the end return wm