Prepare window switching for all spaces

This commit is contained in:
Arnie 2025-04-30 09:21:52 +02:00
parent f8807df81c
commit a9f26cfd6b
No known key found for this signature in database
GPG Key ID: 4BDFA3BCF2999D11

View File

@ -26,6 +26,10 @@ return (function()
screen = "B5A65BB6-E73E-4C3D-977C-33C86798AA5A", screen = "B5A65BB6-E73E-4C3D-977C-33C86798AA5A",
fullscreen = true, fullscreen = true,
}, },
Notes = {
desktop = 2,
screen = "B5A65BB6-E73E-4C3D-977C-33C86798AA5A"
},
Spotify = { Spotify = {
desktop = 3, desktop = 3,
screen = "B5A65BB6-E73E-4C3D-977C-33C86798AA5A", screen = "B5A65BB6-E73E-4C3D-977C-33C86798AA5A",
@ -63,29 +67,52 @@ return (function()
local currentSpaces = spaces.allSpaces() local currentSpaces = spaces.allSpaces()
for _, v in pairs(window.list()) do local spaceMap = {}
local def = appScreenMap[v.kCGWindowOwnerName] for _, screenSpaces in pairs(currentSpaces) do
local win = window.get(v.kCGWindowNumber) for _, space in ipairs(screenSpaces) do
if def ~= nil and win ~= nil then spaceMap[space] = true
if def.desktop ~= nil and currentSpaces[def.screen] ~= nil then end
print(v.kCGWindowOwnerName .. " moving window into an index " .. def.desktop .. " which is space " .. currentSpaces[def.screen][def.desktop]) end
spaces.moveWindowToSpace(win, currentSpaces[def.screen][def.desktop])
end
local scr = screens[def.screen] local spaceIds = {}
if scr ~= nil then for spaceId, _ in pairs(spaceMap) do
timer.doAfter(1, function() table.insert(spaceIds, spaceId)
print(v.kCGWindowOwnerName .. " moving window into a screen " .. def.screen) end
win:moveToScreen(scr) local winMap = {}
if def.fullscreen then for _, spaceId in pairs(spaceIds) do
timer.doAfter(1, function() for _, winId in ipairs(spaces.windowsForSpace(spaceId)) do
print(v.kCGWindowOwnerName .. " fullscreening window") winMap[winId] = true
end
end
fullscreen(win) for winId, _ in pairs(winMap) do
end) -- Cannot get windows for non-active spaces, window.filter would have to be used, but performance is crap
end local win = window.get(winId)
end) if win ~= nil then
local name = win:application():name()
local def = appScreenMap[name]
if def ~= nil then
if def.desktop ~= nil and currentSpaces[def.screen] ~= nil then
print(name .. " moving window into an index " .. def.desktop .. " which is space " .. currentSpaces[def.screen][def.desktop])
spaces.moveWindowToSpace(win, currentSpaces[def.screen][def.desktop])
end
local scr = screens[def.screen]
if scr ~= nil then
timer.doAfter(1, function()
print(name .. " moving window into a screen " .. def.screen)
win:moveToScreen(scr)
if def.fullscreen then
timer.doAfter(1, function()
print(name .. " fullscreening window")
fullscreen(win)
end)
end
end)
end
end end
end end
end end