From 39fc5685608d0e98c05c1654f2e02bc83ee1f6ad Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Thu, 29 Aug 2019 08:27:55 -0700 Subject: [PATCH] [hammerspoon] basic window management --- .hammerspoon/init.lua | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/.hammerspoon/init.lua b/.hammerspoon/init.lua index 8516cc9..e9d4dce 100644 --- a/.hammerspoon/init.lua +++ b/.hammerspoon/init.lua @@ -2,32 +2,25 @@ local mash = {"cmd", "alt", "ctrl"} local smash = {"cmd", "alt", "ctrl", "shift"} -- Window management +wm = { + left = hs.layout.left50, + right = hs.layout.right50, + ne = { 0.5, 0, 0.5, 0.5 }, + nw = { 0, 0, 0.5, 0.5 }, + se = { 0.5, 0.5, 0.5, 0.5 }, + sw = { 0, 0.5, 0.5, 0.5 }, + max = hs.layout.maximized, +} --- TODO implement desktop and window gaps -hs.urlevent.bind("wm", function(eventName, params) - local log = hs.logger.new("wm", "debug") +function move(key) + local win = hs.window.focusedWindow() + local geo = wm[key] + win:move(geo, nil, true) +end - local win = hs.window.focusedWindow() -- TODO figure out why focusedWindow doesn't work - -- local win = hs.window.frontmostWindow() - local f = win:frame() - local screen = win:screen() - local max = screen:frame() - - local t = { - left = function(f) return hs.layout.left50 end, - right = function(f) return hs.layout.right50 end, - ne = function(f) return { 0.5, 0, 0.5, 0.5 } end, - nw = function(f) return { 0, 0, 0.5, 0.5 } end, - se = function(f) return { 0.5, 0.5, 0.5, 0.5 } end, - sw = function(f) return { 0, 0.5, 0.5, 0.5 } end, - max = function(f) return hs.layout.maximized end, - } - - local unitRect = hs.geometry(t[params["layout"]](f)) - local frame = unitRect:fromUnitRect(max) - win:setFrame(frame) - -- win:focus() -end) +hs.hotkey.bind(mash, "h", function() move("left") end) +hs.hotkey.bind(mash, "l", function() move("right") end) +hs.hotkey.bind(mash, "m", function() move("max") end) hs.loadSpoon("ReloadConfiguration") spoon.ReloadConfiguration:start()