Last active
July 11, 2020 20:18
-
-
Save MaxMusing/e856b265f8487266ba1274e6879c39e3 to your computer and use it in GitHub Desktop.
Hammerspoon config with support for simple window management.
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
-- Hot Config Reloading | |
function reloadConfig(files) | |
for _, file in pairs(files) do | |
if file:sub(-4) == ".lua" then | |
hs.reload() | |
break | |
end | |
end | |
end | |
hs.pathwatcher.new(os.getenv("HOME") .. "/.hammerspoon/", reloadConfig):start() | |
hs.alert.show("Config loaded") | |
-- Window Management | |
local currentlyFullscreen = false | |
local win = hs.window.focusedWindow() | |
local screen = win:screen() | |
local max = screen:frame() | |
local displayAreaFractionX = 0.88 | |
local displayAreaFractionY = 0.85 | |
local displayAreaW = max.w * displayAreaFractionX | |
local displayAreaH = max.h * displayAreaFractionY | |
local displayAreaX = max.x + max.w * (1 - displayAreaFractionX) / 2 | |
local displayAreaY = max.y + max.h * (1 - displayAreaFractionY) / 2 | |
local displayAreaSmallFractionX = 0.62 | |
local displayAreaSmallFractionY = 0.68 | |
local displayAreaSmallW = max.w * displayAreaSmallFractionX | |
local displayAreaSmallH = max.h * displayAreaSmallFractionY | |
local displayAreaSmallX = max.x + max.w * (1 - displayAreaSmallFractionX) / 2 | |
local displayAreaSmallY = max.y + max.h * (1 - displayAreaSmallFractionY) / 2 | |
hs.hotkey.bind({"ctrl", "alt"}, "return", function() | |
local windows = hs.window.orderedWindows() | |
for key, win in pairs(windows) do | |
local f = win:frame() | |
local title = win:title() | |
if string.len(title) == 0 then | |
goto continue | |
end | |
local small = false | |
local application = win:application() | |
if application == nil then | |
goto continue | |
end | |
local appName = application:title() | |
local small = appName == "Finder" or appName == "Notes" or appName == "Terminal" or appName == "Activity Monitor" | |
if small then | |
f.x = displayAreaSmallX | |
f.y = displayAreaSmallY | |
f.w = displayAreaSmallW | |
f.h = displayAreaSmallH | |
else | |
if currentlyFullscreen then | |
f.x = displayAreaX | |
f.y = displayAreaY | |
f.w = displayAreaW | |
f.h = displayAreaH | |
else | |
f.x = max.x | |
f.y = max.y | |
f.w = max.w | |
f.h = max.h | |
end | |
end | |
win:setFrame(f, 0) | |
::continue:: | |
end | |
currentlyFullscreen = not currentlyFullscreen | |
end) | |
hs.hotkey.bind({"ctrl", "alt"}, "Left", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x | |
f.y = max.y | |
f.w = max.w / 2 | |
f.h = max.h | |
win:setFrame(f, 0) | |
end) | |
hs.hotkey.bind({"ctrl", "alt"}, "Right", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x + max.w / 2 | |
f.y = max.y | |
f.w = max.w / 2 | |
f.h = max.h | |
win:setFrame(f, 0) | |
end) | |
hs.hotkey.bind({"ctrl", "alt"}, "Up", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x | |
f.y = max.y | |
f.w = max.w | |
f.h = max.h / 2 | |
win:setFrame(f, 0) | |
end) | |
hs.hotkey.bind({"ctrl", "alt"}, "Down", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x | |
f.y = max.y + max.h / 2 | |
f.w = max.w | |
f.h = max.h / 2 | |
win:setFrame(f, 0) | |
end) | |
hs.hotkey.bind({"ctrl", "alt"}, "C", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x + (max.w - f.w) / 2 | |
f.y = max.y + (max.h - f.h) / 2 | |
win:setFrame(f, 0) | |
end) | |
-- Brightness | |
hs.hotkey.bind({"ctrl", "alt"}, "-", function() | |
hs.brightness.set(1) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment