Debian Codegraph @

src/scripts/linking/find-user-target.lua.example

raw
1 -- WirePlumber
2 --
3 -- Copyright © 2022 Collabora Ltd.
4 --
5 -- SPDX-License-Identifier: MIT
6 --
7 -- example of a user injectible hook to link a node to a custom target
8
9 lutils = require ("linking-utils")
10 log = Log.open_topic ("s-linking")
11
12 SimpleEventHook {
13 name = "linking/sample-find-user-target",
14 before = "linking/find-defined-target",
15 interests = {
16 EventInterest {
17 Constraint { "event.type", "=", "select-target" },
18 },
19 },
20 execute = function (event)
21 local source, om, si, si_props, si_flags, target =
22 lutils:unwrap_select_target_event (event)
23
24 -- bypass the hook if the target is already picked up
25 if target then
26 return
27 end
28
29 log:info (si, "in find-user-target")
30
31 -- implement logic here to find a suitable target
32
33 -- store the found target on the event,
34 -- the next hooks will take care of linking
35 event:set_data ("target", target)
36 end
37 }:register ()