133 lines
4.0 KiB
Lua
133 lines
4.0 KiB
Lua
return (function()
|
|
local grid = hs.grid
|
|
local screen = hs.screen
|
|
local spaces = hs.spaces
|
|
local timer = hs.timer
|
|
local window = hs.window
|
|
|
|
spoon = {
|
|
name = "C3C Workspace";
|
|
version = "0.0.1";
|
|
author = "Arnie";
|
|
license = "MIT";
|
|
}
|
|
|
|
-- DELL S2722DGM: 0F6BDB5B-840D-40BE-AAC9-B467A78E057A
|
|
-- DELL S2721DGF: D3142823-261D-46EF-B9C2-5181C7FE2CA5
|
|
-- AV Receiver: B5A65BB6-E73E-4C3D-977C-33C86798AA5A
|
|
local appScreenMap = {
|
|
Slack = {
|
|
desktop = 1,
|
|
screen = "0F6BDB5B-840D-40BE-AAC9-B467A78E057A",
|
|
fullscreen = true,
|
|
},
|
|
Cursor = {
|
|
desktop = 1,
|
|
screen = "B5A65BB6-E73E-4C3D-977C-33C86798AA5A",
|
|
fullscreen = true,
|
|
},
|
|
Notes = {
|
|
desktop = 2,
|
|
screen = "B5A65BB6-E73E-4C3D-977C-33C86798AA5A"
|
|
},
|
|
Spotify = {
|
|
desktop = 3,
|
|
screen = "B5A65BB6-E73E-4C3D-977C-33C86798AA5A",
|
|
fullscreen = true,
|
|
},
|
|
["zoom.us"] = {
|
|
screen = "B5A65BB6-E73E-4C3D-977C-33C86798AA5A",
|
|
fullscreen = true,
|
|
},
|
|
["Microsoft Outlook"] = {
|
|
desktop = 3,
|
|
screen = "D3142823-261D-46EF-B9C2-5181C7FE2CA5",
|
|
fullscreen = true,
|
|
},
|
|
}
|
|
|
|
local fullscreen = function(win)
|
|
local screen = win:screen()
|
|
|
|
local cell = grid.get(win, screen)
|
|
|
|
cell.x = 0
|
|
cell.y = 0
|
|
cell.w = 24
|
|
cell.h = 24
|
|
|
|
grid.set(win, cell, screen)
|
|
end
|
|
|
|
function spoon:restoreAppsToScreens()
|
|
local screens = {}
|
|
for _, scr in ipairs(screen.allScreens()) do
|
|
screens[scr:getUUID()] = scr
|
|
end
|
|
|
|
local currentSpaces = spaces.allSpaces()
|
|
|
|
local spaceMap = {}
|
|
for _, screenSpaces in pairs(currentSpaces) do
|
|
for _, space in ipairs(screenSpaces) do
|
|
spaceMap[space] = true
|
|
end
|
|
end
|
|
|
|
local spaceIds = {}
|
|
for spaceId, _ in pairs(spaceMap) do
|
|
table.insert(spaceIds, spaceId)
|
|
end
|
|
|
|
local winMap = {}
|
|
for _, spaceId in pairs(spaceIds) do
|
|
for _, winId in ipairs(spaces.windowsForSpace(spaceId)) do
|
|
winMap[winId] = true
|
|
end
|
|
end
|
|
|
|
for winId, _ in pairs(winMap) do
|
|
-- Cannot get windows for non-active spaces, window.filter would have to be used, but performance is crap
|
|
local win = window.get(winId)
|
|
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
|
|
|
|
-- https://github.com/Hammerspoon/hammerspoon/blob/master/SPOONS.md#hotkeys
|
|
function spoon:bindHotKeys(mapping)
|
|
local spec = {
|
|
restoreAppsToScreens = hs.fnutils.partial(self.restoreAppsToScreens, self)
|
|
}
|
|
|
|
hs.spoons.bindHotkeysToSpec(spec, mapping)
|
|
return self
|
|
end
|
|
|
|
return spoon
|
|
end)()
|