Files
wireplumber/src/scripts/policy-desktop/find-default-target.lua
George Kiagiadakis b100bdda4a event-hook: remove the exec type property & enumeration
With the latest changes, we can implement the "after-events" type
with external code that pushes a very low priority event that is
the "rescan" event.
2023-04-17 07:48:18 -04:00

55 lines
1.5 KiB
Lua

-- WirePlumber
--
-- Copyright © 2022 Collabora Ltd.
--
-- SPDX-License-Identifier: MIT
--
-- Check if default nodes can be picked up as target node.
local putils = require ("policy-utils")
SimpleEventHook {
name = "find-default-target@policy-desktop",
priority = HookPriority.NORMAL,
interests = {
EventInterest {
Constraint { "event.type", "=", "find-target-si-and-link" },
},
},
execute = function (event)
local source, om, si, si_props, si_flags, target =
putils:unwrap_find_target_event (event)
-- bypass the hook if the target is already picked up
if target then
return
end
local target_picked = false
Log.info (si, string.format ("handling item: %s (%s)",
tostring (si_props ["node.name"]), tostring (si_props ["node.id"])))
target = putils.findDefaultLinkable (si)
local can_passthrough, passthrough_compatible
if target then
passthrough_compatible, can_passthrough =
putils.checkPassthroughCompatibility (si, target)
if putils.canLink (si_props, target) and passthrough_compatible then
target_picked = true;
end
end
if target_picked then
Log.info (si,
string.format ("... default target picked: %s (%s), can_passthrough:%s",
tostring (target.properties ["node.name"]),
tostring (target.properties ["node.id"]),
tostring (can_passthrough)))
si_flags.can_passthrough = can_passthrough
event:set_data ("target", target)
end
end
}:register ()