forked from mogenson/PaperWM.spoon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfloating.lua
More file actions
87 lines (74 loc) · 2.68 KB
/
floating.lua
File metadata and controls
87 lines (74 loc) · 2.68 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
local Fnutils <const> = hs.fnutils
local Window <const> = hs.window
local Floating = {}
Floating.__index = Floating
---hs.settings key for persisting is_floating, stored as an array of window id
local IsFloatingKey <const> = "PaperWM_is_floating"
---initialize module with reference to PaperWM
---@param paperwm PaperWM
function Floating.init(paperwm)
Floating.PaperWM = paperwm
end
---save the is floating state to settings
function Floating.persistFloatingList()
local persisted = {}
for k, _ in pairs(Floating.PaperWM.state.is_floating) do
table.insert(persisted, k)
end
hs.settings.set(IsFloatingKey, persisted)
end
---remove window from the floating list before it is destroyed
---@param window Window
function Floating.removeFloating(window)
Floating.PaperWM.state.is_floating[window:id()] = nil
Floating.persistFloatingList()
end
---restore floating windows from persistant settings, filtering for valid windows
function Floating.restoreFloating()
local persisted = hs.settings.get(IsFloatingKey) or {}
for _, id in ipairs(persisted) do
local window = Window.get(id)
if window and Floating.PaperWM.window_filter:isWindowAllowed(window) then
Floating.PaperWM.state.is_floating[id] = true
end
end
Floating.persistFloatingList()
end
---return true if window is floating, false if not or state cannot be determined
---@param window Window
---@return boolean
function Floating.isFloating(window)
return Floating.PaperWM.state.is_floating[window:id()] or false
end
---add or remove focused window from the floating layer and retile the space
---@param window Window|nil optional window to float and focus
function Floating.toggleFloating(window)
window = window or Window.focusedWindow()
if not window then
Floating.PaperWM.logger.d("focused window not found")
return
end
Floating.PaperWM.state.is_floating[window:id()] = (Floating.isFloating(window) == false) and true or nil
Floating.persistFloatingList()
local space = (function()
if Floating.isFloating(window) then
return Floating.PaperWM.windows.removeWindow(window, true)
else
return Floating.PaperWM.windows.addWindow(window)
end
end)()
if space then
window:focus()
Floating.PaperWM:tileSpace(space)
end
end
---focus all floating windows that are not minimized or hidden
function Floating.focusFloating()
local windows_to_focus <const> = Fnutils.ifilter(Window.visibleWindows(), function(win)
return not Floating.PaperWM.state.isTiled(win:id())
end)
for _, window in ipairs(windows_to_focus) do
window:focus()
end
end
return Floating