Add window moving to hammerspoon
This commit is contained in:
parent
46f71fabdd
commit
908d8e22b1
15
home-manager/hammerspoon/window-move.lua
Normal file
15
home-manager/hammerspoon/window-move.lua
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
(function()
|
||||||
|
local hyper = { "ctrl", "alt", "cmd" }
|
||||||
|
|
||||||
|
-- move window to next screen
|
||||||
|
hs.hotkey.bind(hyper, "N", function()
|
||||||
|
local win = hs.window.focusedWindow()
|
||||||
|
win:moveToScreen(win:screen():next())
|
||||||
|
end)
|
||||||
|
|
||||||
|
for i = 1, 3 do
|
||||||
|
hs.hotkey.bind(hyper, "pad" .. i, function()
|
||||||
|
hs.window.focusedWindow():moveToScreen(i)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end)()
|
||||||
@ -1,156 +1,153 @@
|
|||||||
hs.window.animationDuration = 0
|
(function()
|
||||||
hs.window.setShadows(false)
|
hs.window.animationDuration = 0
|
||||||
local hyper = { "ctrl", "alt", "cmd" }
|
hs.window.setShadows(false)
|
||||||
|
local hyper = { "ctrl", "alt", "cmd" }
|
||||||
|
|
||||||
-- move window to next screen
|
local wm = {
|
||||||
hs.hotkey.bind(hyper, "N", function()
|
sizes = { 1 / 2, 2 / 3, 1 / 3 },
|
||||||
local win = hs.window.focusedWindow()
|
|
||||||
win:moveToScreen(win:screen():next())
|
|
||||||
end)
|
|
||||||
|
|
||||||
local wm = {
|
|
||||||
sizes = { 1 / 2, 2 / 3, 1 / 3 },
|
|
||||||
}
|
|
||||||
|
|
||||||
function wm:_nextStep(dim, offs, cb)
|
|
||||||
if hs.window.focusedWindow() then
|
|
||||||
local axis = dim == "w" and "x" or "y"
|
|
||||||
local oppDim = dim == "w" and "h" or "w"
|
|
||||||
local oppAxis = dim == "w" and "y" or "x"
|
|
||||||
local win = hs.window.frontmostWindow()
|
|
||||||
local screen = win:screen()
|
|
||||||
|
|
||||||
local cell = hs.grid.get(win, screen)
|
|
||||||
|
|
||||||
local nextSize = self.sizes[1]
|
|
||||||
for i = 1, #self.sizes do
|
|
||||||
if
|
|
||||||
cell[dim] == self.GRID[dim] * self.sizes[i]
|
|
||||||
and (cell[axis] + (offs and cell[dim] or 0)) == (offs and self.GRID[dim] or 0)
|
|
||||||
then
|
|
||||||
nextSize = self.sizes[(i % #self.sizes) + 1]
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
cb(cell, nextSize)
|
|
||||||
if cell[oppAxis] ~= 0 and cell[oppAxis] + cell[oppDim] ~= self.GRID[oppDim] then
|
|
||||||
cell[oppDim] = self.GRID[oppDim]
|
|
||||||
cell[oppAxis] = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
hs.grid.set(win, cell, screen)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function wm:_fullscreen()
|
|
||||||
if hs.window.focusedWindow() then
|
|
||||||
local win = hs.window.frontmostWindow()
|
|
||||||
local screen = win:screen()
|
|
||||||
|
|
||||||
local cell = hs.grid.get(win, screen)
|
|
||||||
|
|
||||||
cell.x = 0
|
|
||||||
cell.y = 0
|
|
||||||
cell.w = self.GRID.w
|
|
||||||
cell.h = self.GRID.h
|
|
||||||
|
|
||||||
hs.grid.set(win, cell, screen)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function wm:_fullDimension(dim)
|
|
||||||
if hs.window.focusedWindow() then
|
|
||||||
local win = hs.window.frontmostWindow()
|
|
||||||
local id = win:id()
|
|
||||||
local screen = win:screen()
|
|
||||||
local cell = hs.grid.get(win, screen)
|
|
||||||
|
|
||||||
if dim == "x" then
|
|
||||||
cell = "0,0 " .. self.GRID.w .. "x" .. self.GRID.h
|
|
||||||
else
|
|
||||||
cell[dim] = self.GRID[dim]
|
|
||||||
cell[dim == "w" and "x" or "y"] = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
hs.grid.set(win, cell, screen)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function wm:init()
|
|
||||||
self._pressed = {
|
|
||||||
up = false,
|
|
||||||
down = false,
|
|
||||||
left = false,
|
|
||||||
right = false,
|
|
||||||
}
|
}
|
||||||
self.GRID = { w = 24, h = 24 }
|
|
||||||
|
|
||||||
hs.grid.setGrid(self.GRID.w .. "x" .. self.GRID.h)
|
function wm:_nextStep(dim, offs, cb)
|
||||||
hs.grid.MARGINX = 0
|
if hs.window.focusedWindow() then
|
||||||
hs.grid.MARGINY = 0
|
local axis = dim == "w" and "x" or "y"
|
||||||
|
local oppDim = dim == "w" and "h" or "w"
|
||||||
|
local oppAxis = dim == "w" and "y" or "x"
|
||||||
|
local win = hs.window.frontmostWindow()
|
||||||
|
local screen = win:screen()
|
||||||
|
|
||||||
hs.hotkey.bind(hyper, "down", function()
|
local cell = hs.grid.get(win, screen)
|
||||||
self._pressed.down = true
|
|
||||||
if self._pressed.up then
|
local nextSize = self.sizes[1]
|
||||||
self:_fullDimension("h")
|
for i = 1, #self.sizes do
|
||||||
else
|
if
|
||||||
self:_nextStep("h", true, function(cell, nextSize)
|
cell[dim] == self.GRID[dim] * self.sizes[i]
|
||||||
cell.y = self.GRID.h - self.GRID.h * nextSize
|
and (cell[axis] + (offs and cell[dim] or 0)) == (offs and self.GRID[dim] or 0)
|
||||||
cell.h = self.GRID.h * nextSize
|
then
|
||||||
end)
|
nextSize = self.sizes[(i % #self.sizes) + 1]
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
cb(cell, nextSize)
|
||||||
|
if cell[oppAxis] ~= 0 and cell[oppAxis] + cell[oppDim] ~= self.GRID[oppDim] then
|
||||||
|
cell[oppDim] = self.GRID[oppDim]
|
||||||
|
cell[oppAxis] = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
hs.grid.set(win, cell, screen)
|
||||||
end
|
end
|
||||||
end, function()
|
end
|
||||||
self._pressed.down = false
|
|
||||||
end)
|
|
||||||
|
|
||||||
hs.hotkey.bind(hyper, "right", function()
|
function wm:_fullscreen()
|
||||||
self._pressed.right = true
|
if hs.window.focusedWindow() then
|
||||||
if self._pressed.left then
|
local win = hs.window.frontmostWindow()
|
||||||
self:_fullDimension("w")
|
local screen = win:screen()
|
||||||
else
|
|
||||||
self:_nextStep("w", true, function(cell, nextSize)
|
local cell = hs.grid.get(win, screen)
|
||||||
cell.x = self.GRID.w - self.GRID.w * nextSize
|
|
||||||
cell.w = self.GRID.w * nextSize
|
cell.x = 0
|
||||||
end)
|
cell.y = 0
|
||||||
|
cell.w = self.GRID.w
|
||||||
|
cell.h = self.GRID.h
|
||||||
|
|
||||||
|
hs.grid.set(win, cell, screen)
|
||||||
end
|
end
|
||||||
end, function()
|
end
|
||||||
self._pressed.right = false
|
|
||||||
end)
|
|
||||||
|
|
||||||
hs.hotkey.bind(hyper, "left", function()
|
function wm:_fullDimension(dim)
|
||||||
self._pressed.left = true
|
if hs.window.focusedWindow() then
|
||||||
if self._pressed.right then
|
local win = hs.window.frontmostWindow()
|
||||||
self:_fullDimension("w")
|
local id = win:id()
|
||||||
else
|
local screen = win:screen()
|
||||||
self:_nextStep("w", false, function(cell, nextSize)
|
local cell = hs.grid.get(win, screen)
|
||||||
cell.x = 0
|
|
||||||
cell.w = self.GRID.w * nextSize
|
if dim == "x" then
|
||||||
end)
|
cell = "0,0 " .. self.GRID.w .. "x" .. self.GRID.h
|
||||||
|
else
|
||||||
|
cell[dim] = self.GRID[dim]
|
||||||
|
cell[dim == "w" and "x" or "y"] = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
hs.grid.set(win, cell, screen)
|
||||||
end
|
end
|
||||||
end, function()
|
end
|
||||||
self._pressed.left = false
|
|
||||||
end)
|
|
||||||
|
|
||||||
hs.hotkey.bind(hyper, "up", function()
|
function wm:init()
|
||||||
self._pressed.up = true
|
self._pressed = {
|
||||||
if self._pressed.down then
|
up = false,
|
||||||
self:_fullDimension("h")
|
down = false,
|
||||||
else
|
left = false,
|
||||||
self:_nextStep("h", false, function(cell, nextSize)
|
right = false,
|
||||||
cell.y = 0
|
}
|
||||||
cell.h = self.GRID.h * nextSize
|
self.GRID = { w = 24, h = 24 }
|
||||||
end)
|
|
||||||
end
|
|
||||||
end, function()
|
|
||||||
self._pressed.up = false
|
|
||||||
end)
|
|
||||||
|
|
||||||
hs.hotkey.bind(hyper, "m", function()
|
hs.grid.setGrid(self.GRID.w .. "x" .. self.GRID.h)
|
||||||
self:_fullscreen()
|
hs.grid.MARGINX = 0
|
||||||
end)
|
hs.grid.MARGINY = 0
|
||||||
end
|
|
||||||
|
|
||||||
wm:init()
|
hs.hotkey.bind(hyper, "down", function()
|
||||||
|
self._pressed.down = true
|
||||||
|
if self._pressed.up then
|
||||||
|
self:_fullDimension("h")
|
||||||
|
else
|
||||||
|
self:_nextStep("h", true, function(cell, nextSize)
|
||||||
|
cell.y = self.GRID.h - self.GRID.h * nextSize
|
||||||
|
cell.h = self.GRID.h * nextSize
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end, function()
|
||||||
|
self._pressed.down = false
|
||||||
|
end)
|
||||||
|
|
||||||
hs.notify.show("Welcome to Hammerspoon", "Have fun!", "")
|
hs.hotkey.bind(hyper, "right", function()
|
||||||
|
self._pressed.right = true
|
||||||
|
if self._pressed.left then
|
||||||
|
self:_fullDimension("w")
|
||||||
|
else
|
||||||
|
self:_nextStep("w", true, function(cell, nextSize)
|
||||||
|
cell.x = self.GRID.w - self.GRID.w * nextSize
|
||||||
|
cell.w = self.GRID.w * nextSize
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end, function()
|
||||||
|
self._pressed.right = false
|
||||||
|
end)
|
||||||
|
|
||||||
|
hs.hotkey.bind(hyper, "left", function()
|
||||||
|
self._pressed.left = true
|
||||||
|
if self._pressed.right then
|
||||||
|
self:_fullDimension("w")
|
||||||
|
else
|
||||||
|
self:_nextStep("w", false, function(cell, nextSize)
|
||||||
|
cell.x = 0
|
||||||
|
cell.w = self.GRID.w * nextSize
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end, function()
|
||||||
|
self._pressed.left = false
|
||||||
|
end)
|
||||||
|
|
||||||
|
hs.hotkey.bind(hyper, "up", function()
|
||||||
|
self._pressed.up = true
|
||||||
|
if self._pressed.down then
|
||||||
|
self:_fullDimension("h")
|
||||||
|
else
|
||||||
|
self:_nextStep("h", false, function(cell, nextSize)
|
||||||
|
cell.y = 0
|
||||||
|
cell.h = self.GRID.h * nextSize
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end, function()
|
||||||
|
self._pressed.up = false
|
||||||
|
end)
|
||||||
|
|
||||||
|
hs.hotkey.bind(hyper, "m", function()
|
||||||
|
self:_fullscreen()
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
wm:init()
|
||||||
|
|
||||||
|
hs.notify.show("Welcome to Hammerspoon", "Have fun!", "")
|
||||||
|
|
||||||
|
end)()
|
||||||
|
|||||||
@ -43,6 +43,7 @@ in
|
|||||||
"${homedir}/.hammerspoon/init.lua" = {
|
"${homedir}/.hammerspoon/init.lua" = {
|
||||||
text = ''
|
text = ''
|
||||||
${builtins.readFile ./hammerspoon/window-tiling.lua}
|
${builtins.readFile ./hammerspoon/window-tiling.lua}
|
||||||
|
${builtins.readFile ./hammerspoon/window-move.lua}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user