-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswap-displays.lua
More file actions
53 lines (46 loc) · 1.57 KB
/
Copy pathswap-displays.lua
File metadata and controls
53 lines (46 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
local function swapDisplays()
local screens = hs.screen.allScreens()
if #screens < 2 then
hs.alert.show("Two displays are required to swap")
return
end
local screenA, screenB = screens[1], screens[2]
local windows = hs.window.visibleWindows()
local moves = {}
for _, win in ipairs(windows) do
if win:isStandard() and not win:isMinimized() then
local winScreen = win:screen()
local target = nil
if winScreen:id() == screenA:id() then
target = screenB
elseif winScreen:id() == screenB:id() then
target = screenA
end
if target then
local src = winScreen:frame()
local dst = target:frame()
local f = win:frame()
local rx = (f.x - src.x) / src.w
local ry = (f.y - src.y) / src.h
local rw = f.w / src.w
local rh = f.h / src.h
table.insert(moves, {
win = win,
frame = hs.geometry.rect(
dst.x + rx * dst.w,
dst.y + ry * dst.h,
rw * dst.w,
rh * dst.h
)
})
end
end
end
hs.window.animationDuration = 0
for _, m in ipairs(moves) do
m.win:setFrame(m.frame)
end
hs.alert.show("Displays swapped (" .. #moves .. " windows)")
end
hs.hotkey.bind({"cmd", "alt"}, "S", swapDisplays)
hs.alert.show("Hammerspoon loaded")