2022-11-07 16:03:41 +02:00
|
|
|
-- WirePlumber
|
|
|
|
|
--
|
|
|
|
|
-- Copyright © 2022 Collabora Ltd.
|
|
|
|
|
--
|
|
|
|
|
-- SPDX-License-Identifier: MIT
|
|
|
|
|
--
|
|
|
|
|
-- Check if default nodes can be picked up as target node.
|
|
|
|
|
|
2024-01-03 11:10:56 +02:00
|
|
|
lutils = require ("linking-utils")
|
2023-05-19 20:12:08 +03:00
|
|
|
log = Log.open_topic ("s-linking")
|
2022-11-07 16:03:41 +02:00
|
|
|
|
|
|
|
|
SimpleEventHook {
|
2023-01-04 20:43:15 +02:00
|
|
|
name = "linking/find-default-target",
|
2024-06-27 19:11:00 +03:00
|
|
|
after = { "linking/find-defined-target",
|
|
|
|
|
"linking/find-filter-target",
|
2025-10-25 10:07:50 +02:00
|
|
|
"linking/find-media-role-target",
|
|
|
|
|
"linking/find-media-role-sink-target" },
|
2024-06-27 19:11:00 +03:00
|
|
|
before = "linking/prepare-link",
|
2022-11-07 16:03:41 +02:00
|
|
|
interests = {
|
|
|
|
|
EventInterest {
|
2022-12-25 11:11:36 +02:00
|
|
|
Constraint { "event.type", "=", "select-target" },
|
2022-11-07 16:03:41 +02:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
execute = function (event)
|
2022-11-08 12:40:21 +02:00
|
|
|
local source, om, si, si_props, si_flags, target =
|
2024-01-03 11:10:56 +02:00
|
|
|
lutils:unwrap_select_target_event (event)
|
2022-11-07 16:03:41 +02:00
|
|
|
|
2022-11-08 12:40:21 +02:00
|
|
|
-- bypass the hook if the target is already picked up
|
|
|
|
|
if target then
|
2022-11-07 16:03:41 +02:00
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local target_picked = false
|
|
|
|
|
|
2023-05-19 20:12:08 +03:00
|
|
|
log:info (si, string.format ("handling item: %s (%s)",
|
2022-11-08 12:40:21 +02:00
|
|
|
tostring (si_props ["node.name"]), tostring (si_props ["node.id"])))
|
2022-11-07 16:03:41 +02:00
|
|
|
|
2024-01-03 11:10:56 +02:00
|
|
|
target = lutils.findDefaultLinkable (si)
|
2022-11-07 16:03:41 +02:00
|
|
|
|
|
|
|
|
local can_passthrough, passthrough_compatible
|
2022-11-08 12:40:21 +02:00
|
|
|
if target then
|
2022-11-07 16:03:41 +02:00
|
|
|
passthrough_compatible, can_passthrough =
|
2024-01-03 11:10:56 +02:00
|
|
|
lutils.checkPassthroughCompatibility (si, target)
|
|
|
|
|
if lutils.canLink (si_props, target) and passthrough_compatible then
|
2022-11-07 16:03:41 +02:00
|
|
|
target_picked = true;
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if target_picked then
|
2023-05-19 20:12:08 +03:00
|
|
|
log:info (si,
|
2022-11-07 16:03:41 +02:00
|
|
|
string.format ("... default target picked: %s (%s), can_passthrough:%s",
|
2022-11-08 12:40:21 +02:00
|
|
|
tostring (target.properties ["node.name"]),
|
|
|
|
|
tostring (target.properties ["node.id"]),
|
2022-11-07 16:03:41 +02:00
|
|
|
tostring (can_passthrough)))
|
|
|
|
|
si_flags.can_passthrough = can_passthrough
|
2022-11-08 12:40:21 +02:00
|
|
|
event:set_data ("target", target)
|
2022-11-07 16:03:41 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
}:register ()
|