aboutsummaryrefslogtreecommitdiffstats
path: root/meta-pipewire/recipes-multimedia/wireplumber/wireplumber-config-agl/alsa-suspend.lua
blob: 55edd12cfccdd067364015b9082dad4d729a188b (plain)
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
-- WirePlumber
--
-- This script mutes all ALSA sinks when the "suspend.playback" metadata
-- key is set to 1; compliments pipewire-ic-ipc and the respective support
-- for handling "suspend.playback" in the policy scripts
--
-- Copyright © 2021 Collabora Ltd.
--    @author George Kiagiadakis <george.kiagiadakis@collabora.com>
--
-- SPDX-License-Identifier: MIT

mixer_api = Plugin.find("mixer-api")

nodes_om = ObjectManager {
  Interest { type = "node",
    Constraint { "media.class", "matches", "Audio/Sink" },
    Constraint { "object.path", "matches", "alsa:pcm:*" },
  },
}

metadata_om = ObjectManager {
  Interest { type = "metadata",
    Constraint { "metadata.name", "=", "default" },
  }
}

metadata_om:connect("object-added", function (om, metadata)
  metadata:connect("changed", function (m, subject, key, t, value)
    if key == "suspend.playback" then
      local suspended = (value == "1")

      Log.info(string.format("%s ALSA nodes for IC sound",
                             suspended and "muting" or "unmuting"))

      for n in nodes_om:iterate() do
        mixer_api:call("set-volume", n["bound-id"], {
          ["mute"] = suspended,
        })
      end
    end
  end)
end)

nodes_om:activate()
metadata_om:activate()