Improve hammerspoon workspace management

This commit is contained in:
Arnie 2025-03-20 11:12:28 +01:00
parent a12585068a
commit 143830ce27
No known key found for this signature in database
GPG Key ID: 4BDFA3BCF2999D11

View File

@ -1,10 +1,9 @@
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
local window = hs.window
spoon = {
name = "C3C Workspace";
@ -33,8 +32,7 @@ return (function()
fullscreen = true,
},
["zoom.us"] = {
desktop = 2,
screen = "D3142823-261D-46EF-B9C2-5181C7FE2CA5",
screen = "B5A65BB6-E73E-4C3D-977C-33C86798AA5A",
fullscreen = true,
},
["Microsoft Outlook"] = {
@ -65,40 +63,24 @@ return (function()
local currentSpaces = spaces.allSpaces()
local foundWindows = {}
for appName, def in pairs(appScreenMap) do
local scr = screens[def.screen]
if scr ~= nil then
local app = application.get(appName)
if app then
local appFilter = wf.new(appName)
if appFilter then
-- TODO: Really bad performance
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])
for _, v in pairs(window.list()) do
local def = appScreenMap[v.kCGWindowOwnerName]
local win = window.get(v.kCGWindowNumber)
if def ~= nil and win ~= nil then
if def.desktop ~= nil and currentSpaces[def.screen] ~= nil then
print(v.kCGWindowOwnerName .. " 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")
local scr = screens[def.screen]
if scr ~= nil then
timer.doAfter(1, function()
print(appName .. " moving window into a screen " .. def.screen)
print(v.kCGWindowOwnerName .. " moving window into a screen " .. def.screen)
win:moveToScreen(scr)
if def.fullscreen then
timer.doAfter(1, function()
print(appName .. " fullscreening window")
print(v.kCGWindowOwnerName .. " fullscreening window")
fullscreen(win)
end)
@ -107,6 +89,7 @@ return (function()
end
end
end
end
-- https://github.com/Hammerspoon/hammerspoon/blob/master/SPOONS.md#hotkeys
function spoon:bindHotKeys(mapping)