dotfiles/modules/darwin/hammerspoon/Spoons/MoveWindow.spoon/init.lua

44 lines
1.3 KiB
Lua
Raw Normal View History

2022-04-25 14:42:01 +00:00
--- === Move Window ===
local obj = {}
obj.__index = obj
-- Metadata
obj.name = "MoveWindow"
obj.version = "0.1"
obj.license = "MIT - https://opensource.org/licenses/MIT"
function obj:init()
-- bind hotkey
hs.hotkey.bind({ "alt", "ctrl", "cmd" }, "n", function()
-- get the focused window
local win = hs.window.focusedWindow()
-- get the screen where the focused window is displayed, a.k.a. current screen
local screen = win:screen()
2022-05-13 18:46:46 +00:00
-- local nextScreen = screen:next()
2022-04-25 14:42:01 +00:00
-- compute the unitRect of the focused window relative to the current screen
-- and move the window to the next screen setting the same unitRect
2022-05-13 18:46:46 +00:00
win:moveToScreen(screen:next(), true, true, 0)
end)
hs.hotkey.bind({ "alt", "ctrl", "cmd" }, "b", function()
local win = hs.window.focusedWindow()
local screen = win:screen()
win:moveToScreen(screen:previous(), true, true, 0)
2022-04-25 14:42:01 +00:00
end)
2022-04-29 14:50:29 +00:00
hs.hotkey.bind({ "alt", "ctrl", "cmd" }, "m", function()
-- get the focused window
local win = hs.window.focusedWindow()
-- maximize if possible
2022-06-22 13:53:03 +00:00
-- first maximize to grid
hs.grid.maximizeWindow(win)
-- they spam maximize
for i = 1, 8 do
win:maximize()
end
2022-04-29 14:50:29 +00:00
end)
2022-04-25 14:42:01 +00:00
end
return obj