Created
August 29, 2019 10:48
-
-
Save loa/2cb3d8063d987b784966178c5bfba701 to your computer and use it in GitHub Desktop.
Hammerspoon Window Columns
This file contains hidden or 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
function moveWindowColumn(column, width) | |
local window = hs.window.focusedWindow() | |
local windowFrame = window:frame() | |
local screen = window:screen() | |
local screenFrame = screen:frame() | |
-- minimum 2 columns even on smaller displays | |
local numColumns = math.max(2, math.floor(screenFrame.w / 1100)) | |
local remainder = screenFrame.w % numColumns | |
local columnWidth = math.floor(screenFrame.w / numColumns) | |
windowFrame.x = column * columnWidth | |
windowFrame.y = screenFrame.y | |
windowFrame.h = screenFrame.h | |
if (column + width) == numColumns then | |
-- add remainder of width to windows using last column | |
windowFrame.w = width * columnWidth + remainder | |
else | |
windowFrame.w = width * columnWidth | |
end | |
window:setFrame(windowFrame) | |
end | |
hs.hotkey.bind({"cmd", "ctrl"}, "1", function () moveWindowColumn(0, 1) end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "2", function () moveWindowColumn(1, 1) end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "3", function () moveWindowColumn(2, 1) end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "4", function () moveWindowColumn(0, 2) end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "5", function () moveWindowColumn(1, 2) end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment