Update hammerspoon window management
This commit is contained in:
parent
0d2531afb4
commit
51433e6aca
@ -1,4 +1,11 @@
|
|||||||
return (function()
|
return (function()
|
||||||
|
local application = hs.application
|
||||||
|
local grid = hs.grid
|
||||||
|
local screen = hs.screen
|
||||||
|
local spaces = hs.spaces
|
||||||
|
local timer = hs.timer
|
||||||
|
local wf = hs.window.filter
|
||||||
|
|
||||||
spoon = {
|
spoon = {
|
||||||
name = "C3C Workspace";
|
name = "C3C Workspace";
|
||||||
version = "0.0.1";
|
version = "0.0.1";
|
||||||
@ -15,43 +22,88 @@ return (function()
|
|||||||
screen = "0F6BDB5B-840D-40BE-AAC9-B467A78E057A",
|
screen = "0F6BDB5B-840D-40BE-AAC9-B467A78E057A",
|
||||||
fullscreen = true,
|
fullscreen = true,
|
||||||
},
|
},
|
||||||
|
Cursor = {
|
||||||
|
desktop = 1,
|
||||||
|
screen = "B5A65BB6-E73E-4C3D-977C-33C86798AA5A",
|
||||||
|
fullscreen = true,
|
||||||
|
},
|
||||||
|
Spotify = {
|
||||||
|
desktop = 3,
|
||||||
|
screen = "B5A65BB6-E73E-4C3D-977C-33C86798AA5A",
|
||||||
|
fullscreen = true,
|
||||||
|
},
|
||||||
|
["zoom.us"] = {
|
||||||
|
desktop = 2,
|
||||||
|
screen = "D3142823-261D-46EF-B9C2-5181C7FE2CA5",
|
||||||
|
fullscreen = true,
|
||||||
|
},
|
||||||
|
["Microsoft Outlook"] = {
|
||||||
|
desktop = 3,
|
||||||
|
screen = "D3142823-261D-46EF-B9C2-5181C7FE2CA5",
|
||||||
|
fullscreen = true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local fullscreen = function(win)
|
local fullscreen = function(win)
|
||||||
local screen = win:screen()
|
local screen = win:screen()
|
||||||
|
|
||||||
local cell = hs.grid.get(win, screen)
|
local cell = grid.get(win, screen)
|
||||||
|
|
||||||
cell.x = 0
|
cell.x = 0
|
||||||
cell.y = 0
|
cell.y = 0
|
||||||
cell.w = 24
|
cell.w = 24
|
||||||
cell.h = 24
|
cell.h = 24
|
||||||
|
|
||||||
hs.grid.set(win, cell, screen)
|
grid.set(win, cell, screen)
|
||||||
end
|
end
|
||||||
|
|
||||||
function spoon:restoreAppsToScreens()
|
function spoon:restoreAppsToScreens()
|
||||||
local screens = {}
|
local screens = {}
|
||||||
for _, screen in ipairs(hs.screen.allScreens()) do
|
for _, scr in ipairs(screen.allScreens()) do
|
||||||
screens[screen:getUUID()] = screen
|
screens[scr:getUUID()] = scr
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local currentSpaces = spaces.allSpaces()
|
||||||
|
|
||||||
|
local foundWindows = {}
|
||||||
|
|
||||||
for appName, def in pairs(appScreenMap) do
|
for appName, def in pairs(appScreenMap) do
|
||||||
local scr = screens[def.screen]
|
local scr = screens[def.screen]
|
||||||
if scr ~= nil then
|
if scr ~= nil then
|
||||||
local app = hs.application.get(appName)
|
local app = application.get(appName)
|
||||||
if app then
|
if app then
|
||||||
local wf = hs.window.filter.new(appName)
|
local appFilter = wf.new(appName)
|
||||||
if wf then
|
if appFilter then
|
||||||
-- TODO: Really bad performance
|
-- TODO: Really bad performance
|
||||||
for _, win in pairs(wf:getWindows()) do
|
foundWindows[appName] = appFilter:getWindows()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for appName, windows in pairs(foundWindows) do
|
||||||
|
local def = appScreenMap[appName]
|
||||||
|
local scr = screens[def.screen]
|
||||||
|
|
||||||
|
for _, win in pairs(windows) do
|
||||||
|
if currentSpaces[def.screen] ~= nil then
|
||||||
|
print(appName .. " moving window into an index " .. def.desktop .. " which is space " .. currentSpaces[def.screen][def.desktop])
|
||||||
|
spaces.moveWindowToSpace(win, currentSpaces[def.screen][def.desktop])
|
||||||
|
end
|
||||||
|
|
||||||
|
print(appName .. " scheduling timer to move window into a screen")
|
||||||
|
timer.doAfter(1, function()
|
||||||
|
print(appName .. " moving window into a screen " .. def.screen)
|
||||||
|
|
||||||
win:moveToScreen(scr)
|
win:moveToScreen(scr)
|
||||||
if def.fullscreen then
|
if def.fullscreen then
|
||||||
|
timer.doAfter(1, function()
|
||||||
|
print(appName .. " fullscreening window")
|
||||||
|
|
||||||
fullscreen(win)
|
fullscreen(win)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
end
|
end)
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,27 +1,32 @@
|
|||||||
windowMove = function()
|
windowMove = function()
|
||||||
|
local grid = hs.grid
|
||||||
|
local screen = hs.screen
|
||||||
|
local timer = hs.timer
|
||||||
|
local window = hs.window
|
||||||
|
|
||||||
-- move window to next screen
|
-- move window to next screen
|
||||||
hs.hotkey.bind({ "ctrl", "alt", "cmd" }, "N", function()
|
hs.hotkey.bind({ "ctrl", "alt", "cmd" }, "N", function()
|
||||||
local win = hs.window.focusedWindow()
|
local win = window.focusedWindow()
|
||||||
win:moveToScreen(win:screen():next())
|
win:moveToScreen(win:screen():next())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local fullscreen = function(win)
|
local fullscreen = function(win)
|
||||||
local screen = win:screen()
|
local scr = win:screen()
|
||||||
|
|
||||||
local cell = hs.grid.get(win, screen)
|
local cell = grid.get(win, scr)
|
||||||
|
|
||||||
cell.x = 0
|
cell.x = 0
|
||||||
cell.y = 0
|
cell.y = 0
|
||||||
cell.w = 24
|
cell.w = 24
|
||||||
cell.h = 24
|
cell.h = 24
|
||||||
|
|
||||||
hs.grid.set(win, cell, screen)
|
grid.set(win, cell, scr)
|
||||||
end
|
end
|
||||||
|
|
||||||
local getScreenById = function(id)
|
local getScreenById = function(id)
|
||||||
for _, screen in ipairs(hs.screen.allScreens()) do
|
for _, scr in ipairs(screen.allScreens()) do
|
||||||
if screen:getUUID() == id then
|
if scr:getUUID() == id then
|
||||||
return screen
|
return scr
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -30,39 +35,45 @@ windowMove = function()
|
|||||||
|
|
||||||
hs.hotkey.bind({ "ctrl", "alt", "cmd" }, "pad1", function()
|
hs.hotkey.bind({ "ctrl", "alt", "cmd" }, "pad1", function()
|
||||||
-- DELL S2722DGM
|
-- DELL S2722DGM
|
||||||
local screen = getScreenById("0F6BDB5B-840D-40BE-AAC9-B467A78E057A")
|
local scr = getScreenById("0F6BDB5B-840D-40BE-AAC9-B467A78E057A")
|
||||||
if screen == nil then
|
if scr == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local win = hs.window.focusedWindow()
|
local win = window.focusedWindow()
|
||||||
win:moveToScreen(screen)
|
win:moveToScreen(scr)
|
||||||
|
timer.doAfter(1, function()
|
||||||
fullscreen(win)
|
fullscreen(win)
|
||||||
end)
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
hs.hotkey.bind({ "ctrl", "alt", "cmd" }, "pad2", function()
|
hs.hotkey.bind({ "ctrl", "alt", "cmd" }, "pad2", function()
|
||||||
-- DELL S2721DGF
|
-- DELL S2721DGF
|
||||||
local screen = getScreenById("D3142823-261D-46EF-B9C2-5181C7FE2CA5")
|
local scr = getScreenById("D3142823-261D-46EF-B9C2-5181C7FE2CA5")
|
||||||
if screen == nil then
|
if scr == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local win = hs.window.focusedWindow()
|
local win = window.focusedWindow()
|
||||||
win:moveToScreen(screen)
|
win:moveToScreen(scr)
|
||||||
|
timer.doAfter(1, function()
|
||||||
fullscreen(win)
|
fullscreen(win)
|
||||||
end)
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
hs.hotkey.bind({ "ctrl", "alt", "cmd" }, "pad3", function()
|
hs.hotkey.bind({ "ctrl", "alt", "cmd" }, "pad3", function()
|
||||||
-- AV Receiver
|
-- AV Receiver
|
||||||
local screen = getScreenById("B5A65BB6-E73E-4C3D-977C-33C86798AA5A")
|
local scr = getScreenById("B5A65BB6-E73E-4C3D-977C-33C86798AA5A")
|
||||||
if screen == nil then
|
if scr == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local win = hs.window.focusedWindow()
|
local win = window.focusedWindow()
|
||||||
win:moveToScreen(screen)
|
win:moveToScreen(scr)
|
||||||
|
timer.doAfter(1, function()
|
||||||
fullscreen(win)
|
fullscreen(win)
|
||||||
end)
|
end)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
windowMove()
|
windowMove()
|
||||||
|
|||||||
@ -1,4 +1,8 @@
|
|||||||
windowTiling =function()
|
windowTiling =function()
|
||||||
|
local window = hs.window
|
||||||
|
local grid = hs.grid
|
||||||
|
local screen = hs.screen
|
||||||
|
|
||||||
hs.window.animationDuration = 0
|
hs.window.animationDuration = 0
|
||||||
hs.window.setShadows(false)
|
hs.window.setShadows(false)
|
||||||
local hyper = { "ctrl", "alt", "cmd" }
|
local hyper = { "ctrl", "alt", "cmd" }
|
||||||
@ -8,14 +12,14 @@ windowTiling =function()
|
|||||||
}
|
}
|
||||||
|
|
||||||
function wm:_nextStep(dim, offs, cb)
|
function wm:_nextStep(dim, offs, cb)
|
||||||
if hs.window.focusedWindow() then
|
if window.focusedWindow() then
|
||||||
local axis = dim == "w" and "x" or "y"
|
local axis = dim == "w" and "x" or "y"
|
||||||
local oppDim = dim == "w" and "h" or "w"
|
local oppDim = dim == "w" and "h" or "w"
|
||||||
local oppAxis = dim == "w" and "y" or "x"
|
local oppAxis = dim == "w" and "y" or "x"
|
||||||
local win = hs.window.frontmostWindow()
|
local win = window.frontmostWindow()
|
||||||
local screen = win:screen()
|
local scr = win:screen()
|
||||||
|
|
||||||
local cell = hs.grid.get(win, screen)
|
local cell = grid.get(win, scr)
|
||||||
|
|
||||||
local nextSize = self.sizes[1]
|
local nextSize = self.sizes[1]
|
||||||
for i = 1, #self.sizes do
|
for i = 1, #self.sizes do
|
||||||
@ -34,32 +38,31 @@ windowTiling =function()
|
|||||||
cell[oppAxis] = 0
|
cell[oppAxis] = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
hs.grid.set(win, cell, screen)
|
grid.set(win, cell, scr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function wm:_fullscreen()
|
function wm:_fullscreen()
|
||||||
if hs.window.focusedWindow() then
|
if hs.window.focusedWindow() then
|
||||||
local win = hs.window.frontmostWindow()
|
local win = window.frontmostWindow()
|
||||||
local screen = win:screen()
|
local scr = win:screen()
|
||||||
|
|
||||||
local cell = hs.grid.get(win, screen)
|
local cell = grid.get(win, scr)
|
||||||
|
|
||||||
cell.x = 0
|
cell.x = 0
|
||||||
cell.y = 0
|
cell.y = 0
|
||||||
cell.w = self.GRID.w
|
cell.w = self.GRID.w
|
||||||
cell.h = self.GRID.h
|
cell.h = self.GRID.h
|
||||||
|
|
||||||
hs.grid.set(win, cell, screen)
|
grid.set(win, cell, scr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function wm:_fullDimension(dim)
|
function wm:_fullDimension(dim)
|
||||||
if hs.window.focusedWindow() then
|
if window.focusedWindow() then
|
||||||
local win = hs.window.frontmostWindow()
|
local win = window.frontmostWindow()
|
||||||
local id = win:id()
|
local scr = win:screen()
|
||||||
local screen = win:screen()
|
local cell = grid.get(win, scr)
|
||||||
local cell = hs.grid.get(win, screen)
|
|
||||||
|
|
||||||
if dim == "x" then
|
if dim == "x" then
|
||||||
cell = "0,0 " .. self.GRID.w .. "x" .. self.GRID.h
|
cell = "0,0 " .. self.GRID.w .. "x" .. self.GRID.h
|
||||||
@ -68,7 +71,7 @@ windowTiling =function()
|
|||||||
cell[dim == "w" and "x" or "y"] = 0
|
cell[dim == "w" and "x" or "y"] = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
hs.grid.set(win, cell, screen)
|
grid.set(win, cell, scr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -81,9 +84,9 @@ windowTiling =function()
|
|||||||
}
|
}
|
||||||
self.GRID = { w = 24, h = 24 }
|
self.GRID = { w = 24, h = 24 }
|
||||||
|
|
||||||
hs.grid.setGrid(self.GRID.w .. "x" .. self.GRID.h)
|
grid.setGrid(self.GRID.w .. "x" .. self.GRID.h)
|
||||||
hs.grid.MARGINX = 0
|
grid.MARGINX = 0
|
||||||
hs.grid.MARGINY = 0
|
grid.MARGINY = 0
|
||||||
|
|
||||||
hs.hotkey.bind(hyper, "down", function()
|
hs.hotkey.bind(hyper, "down", function()
|
||||||
self._pressed.down = true
|
self._pressed.down = true
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user