-
Notifications
You must be signed in to change notification settings - Fork 12
/
pipewire-watcher.nix
62 lines (55 loc) · 1.49 KB
/
pipewire-watcher.nix
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
{ pkgs }:
pkgs.writeScriptBin "pipewire-watcher" ''
#!/usr/bin/env wpexec
local INPUT = "Stream/Input/Audio"
local OUTPUT = "Stream/Output/Audio"
local TO_IGNORE = {
'Discord',
'Element',
}
local INHIBIT_LOCK = false
local nodeManager = ObjectManager({
Interest({
type = "node",
Constraint({ "media.class", "in-list", OUTPUT, INPUT }),
}),
})
local linkManager = ObjectManager({
Interest({
type = "link",
}),
})
local function hasActiveLinks(nodeId, linkType)
local constraint = Constraint({ linkType, "=", tostring(nodeId) })
for link in linkManager:iterate({ type = "link", constraint }) do
if link.state == "active" then
return true
end
end
return false
end
local function hasValue (val, tab)
for index, value in ipairs(tab) do
if string.find(val, value) then
return true
end
end
return false
end
nodeManager:connect("installed", function(nodeManager)
for node in nodeManager:iterate() do
local mediaName = node.properties["media.name"]
local mediaClass = node.properties["media.class"]
if not hasValue(mediaName, TO_IGNORE) or mediaClass == INPUT then
if hasActiveLinks(node.bound_id, "link.input.node") or hasActiveLinks(node.bound_id, "link.output.node") then
INHIBIT_LOCK = true
break
end
end
end
print(INHIBIT_LOCK)
Core.quit()
end)
linkManager:activate()
nodeManager:activate()
''