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