From df3e8e60d7855fff5762f550d7d8253a04d0a3c4 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Wed, 6 Jul 2022 10:35:00 -0400 Subject: [PATCH] hammerspoon worklayout functional --- .../Spoons/MoveWindow.spoon/init.lua | 21 +++++-- .../Spoons/MoveWindow.spoon/worklayout.lua | 59 +++++++++++++++++++ 2 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 modules/darwin/hammerspoon/Spoons/MoveWindow.spoon/worklayout.lua diff --git a/modules/darwin/hammerspoon/Spoons/MoveWindow.spoon/init.lua b/modules/darwin/hammerspoon/Spoons/MoveWindow.spoon/init.lua index d6346d7..57915c8 100644 --- a/modules/darwin/hammerspoon/Spoons/MoveWindow.spoon/init.lua +++ b/modules/darwin/hammerspoon/Spoons/MoveWindow.spoon/init.lua @@ -9,6 +9,8 @@ obj.version = "0.1" obj.license = "MIT - https://opensource.org/licenses/MIT" function obj:init() + hs.window.animationDuration = 0 + dofile(hs.spoons.resourcePath("worklayout.lua"))() -- bind hotkey hs.hotkey.bind({ "alt", "ctrl", "cmd" }, "n", function() -- get the focused window @@ -30,13 +32,20 @@ function obj:init() hs.hotkey.bind({ "alt", "ctrl", "cmd" }, "m", function() -- get the focused window local win = hs.window.focusedWindow() + local frame = win:frame() -- maximize if possible - -- first maximize to grid - hs.grid.maximizeWindow(win) - -- they spam maximize - for i = 1, 8 do - win:maximize() - end + local max = win:screen():fullFrame() + frame.x = max.x + frame.y = max.y + frame.w = max.w + frame.h = max.h + win:setFrame(frame) + -- -- first maximize to grid + -- hs.grid.maximizeWindow(win) + -- -- then spam maximize + -- for i = 1, 8 do + -- win:maximize() + -- end end) end diff --git a/modules/darwin/hammerspoon/Spoons/MoveWindow.spoon/worklayout.lua b/modules/darwin/hammerspoon/Spoons/MoveWindow.spoon/worklayout.lua new file mode 100644 index 0000000..c7cc53d --- /dev/null +++ b/modules/darwin/hammerspoon/Spoons/MoveWindow.spoon/worklayout.lua @@ -0,0 +1,59 @@ +--- === Work Layout === +-- Portions of this is adopted from: +-- https://github.com/anishathalye/dotfiles-local/tree/ffdadd313e58514eb622736b09b91a7d7eb7c6c9/hammerspoon +-- License is also available: +-- https://github.com/anishathalye/dotfiles-local/blob/ffdadd313e58514eb622736b09b91a7d7eb7c6c9/LICENSE.md + +WORK_LEFT_MONITOR = "DELL U2415 (2)" +WORK_RIGHT_MONITOR = "DELL U2415 (1)" +LAPTOP_MONITOR = "Built-in Retina Display" + +-- Used to find out the name of the monitor in Hammerspoon +function dump(o) + if type(o) == "table" then + local s = "{ " + for k, v in pairs(o) do + if type(k) ~= "number" then + k = '"' .. k .. '"' + end + s = s .. "[" .. k .. "] = " .. dump(v) .. "," + end + return s .. "} " + else + return tostring(o) + end +end +-- Turn on when looking for the monitor name +-- print(dump(hs.screen.allScreens())) + +function concat(...) + local res = {} + for _, tab in ipairs({ ... }) do + for _, elem in ipairs(tab) do + table.insert(res, elem) + end + end + return res +end + +function worklayout() + hs.hotkey.bind({ "alt", "ctrl", "cmd" }, "l", function() + local u = hs.geometry.unitrect + -- set the layout + local left = { + { "Alacritty", nil, WORK_LEFT_MONITOR, u(0, 0, 1, 1), nil, nil, visible = true }, + } + local right = { + { "Slack", nil, WORK_RIGHT_MONITOR, u(0, 0, 1, 1), nil, nil, visible = true }, + { "Mail", nil, WORK_RIGHT_MONITOR, u(0, 0, 1, 1), nil, nil, visible = true }, + { "zoom.us", nil, WORK_RIGHT_MONITOR, u(1 / 4, 1 / 4, 1 / 2, 1 / 2), nil, nil, visible = true }, + } + local laptop = { + { "Firefox", nil, LAPTOP_MONITOR, u(0, 0, 1, 1), nil, nil, visible = true }, + } + local layout = concat(left, right, laptop) + hs.layout.apply(layout) + end) +end + +return worklayout