wpsettings: switch settings in main.lua.d to JSON

- switch stream based lua script and their configs to wpsettings,
  remove all the config/lua references
- move last remaining scripts and modules from 90-enable-all.lua to
  wireplumber.conf
- delete all files in main.lua.d
This commit is contained in:
Ashok Sidipotu 2022-05-12 10:37:01 +05:30 committed by Julian Bouzas
parent e180ff2f94
commit 4282dff187
8 changed files with 50 additions and 101 deletions

View file

@ -1 +0,0 @@
../common/00-functions.lua

View file

@ -1,42 +0,0 @@
stream_defaults = {}
stream_defaults.enabled = true
stream_defaults.properties = {
-- whether to restore the last stream properties or not
["restore-props"] = true,
-- whether to restore the last stream target or not
["restore-target"] = true,
-- the default channel volume for new streams whose props were never saved
-- previously. This is only used if "restore-props" is set to true.
["default-channel-volume"] = 1.0,
}
stream_defaults.rules = {
-- Rules to override settings per node
-- {
-- matches = {
-- {
-- { "application.name", "matches", "pw-play" },
-- },
-- },
-- apply_properties = {
-- ["state.restore-props"] = false,
-- ["state.restore-target"] = false,
-- ["state.default-channel-volume"] = 0.5,
-- },
-- },
}
function stream_defaults.enable()
if stream_defaults.enabled == false then
return
end
-- Save and restore stream-specific properties
load_script("restore-stream.lua", {
properties = stream_defaults.properties,
rules = stream_defaults.rules,
})
end

View file

@ -1,12 +0,0 @@
-- Provide the "default" pw_metadata, which stores
-- dynamic properties of pipewire objects in RAM
load_module("metadata")
-- Track/store/restore user choices about streams
stream_defaults.enable()
-- Link nodes by stream role and device intended role
load_script("intended-roles.lua")
-- Automatically suspends idle nodes after 3 seconds
load_script("suspend-node.lua")

View file

@ -85,9 +85,18 @@ wireplumber.components = [
# The lua scripting engine
{ name = libwireplumber-module-lua-scripting, type = module }
# Provide the "default" pw_metadata, which stores
# dynamic properties of pipewire objects in RAM
{ name = libwireplumber-module-metadata, type = module }
# Link nodes by stream role and device intended role
{ name = intended-roles.lua, type = script/lua }
# Automatically suspends idle nodes after 3 seconds
{ name = suspend-node.lua, type = script/lua }
# The lua configuration file(s)
# Other components are loaded from there
{ name = main.lua, type = config/lua }
{ name = policy.lua, type = config/lua }
{ name = bluetooth.lua, type = config/lua }
]

View file

@ -1,20 +1,31 @@
# Settings to Track/store/restore user choices about streams
wireplumber.components = [
# Save and restore stream-specific properties
{ name = restore-stream.lua, type = script/lua }
]
wireplumber.settings = {
stream_default.restore-props = true
stream_default.restore-target = true
## The default channel volume for new streams whose props were never saved
## previously. This is only used if "restore-props" is set to true.
# stream.default-channel-volume = 1.0,
stream_default = [
# Rules to override settings per application/node
{
matches = [
# Matches all devices
{ application.name = "pw-play" }
]
actions = {
update-props = {
state.restore-props = false
state.restore-target = false
}
}
# matches = [
# # Matches all devices
# { application.name = "pw-play" }
# ]
# actions = {
# update-props = {
# state.restore-props = false
# state.restore-target = false
# state.default-channel-volume = 1.0
# }
# }
}
]
}

View file

@ -26,6 +26,7 @@ local config_settings = {
device_names_table = nil
node_names_table = nil
-- applies rules from alsa-settings.conf when asked to
function rulesApplyProperties(properties)
local matched, mprops = Settings.apply_rule ("alsa_monitor", properties)

View file

@ -37,7 +37,7 @@ for _, r in ipairs(config.rules or {}) do
r.matches = nil
end
-- applies properties from config.rules when asked to
-- applies rules from bluez-settings.conf when asked to
function rulesApplyProperties(properties)
for _, r in ipairs(config.rules or {}) do
if r.apply_properties then

View file

@ -9,40 +9,23 @@
-- SPDX-License-Identifier: MIT
-- Receive script arguments from config.lua
local config = ... or {}
config.properties = config.properties or {}
config_restore_props = config.properties["restore-props"] or false
config_restore_target = config.properties["restore-target"] or false
config_default_channel_volume = config.properties["default-channel-volume"] or 1.0
config_restore_props = Settings.get_boolean ("stream_default.restore-props")
or false
config_restore_target = Settings.get_boolean ("stream_default.restore-target")
or false
config_default_channel_volume = Settings.get_float ("stream.default-channel-volume")
or 1.0
-- preprocess rules and create Interest objects
for _, r in ipairs(config.rules or {}) do
r.interests = {}
for _, i in ipairs(r.matches) do
local interest_desc = { type = "properties" }
for _, c in ipairs(i) do
c.type = "pw"
table.insert(interest_desc, Constraint(c))
end
local interest = Interest(interest_desc)
table.insert(r.interests, interest)
end
r.matches = nil
end
-- applies properties from config.rules when asked to
-- applies rules from stream-settings.conf when asked to
function rulesApplyProperties(properties)
for _, r in ipairs(config.rules or {}) do
if r.apply_properties then
for _, interest in ipairs(r.interests) do
if interest:matches(properties) then
for k, v in pairs(r.apply_properties) do
properties[k] = v
end
end
end
local matched, mprops = Settings.apply_rule ("stream_default", properties)
if (matched and mprops) then
for k, v in pairs(mprops) do
properties[k] = v
end
end
end
-- the state storage
@ -140,7 +123,7 @@ function saveTarget(subject, target_key, type, value)
local stream_props = node.properties
rulesApplyProperties(stream_props)
if stream_props["state.restore-target"] == false then
if stream_props["state.restore-target"] == "false" then
return
end
@ -288,7 +271,7 @@ function saveStream(node)
local stream_props = node.properties
rulesApplyProperties(stream_props)
if config_restore_props and stream_props["state.restore-props"] ~= false then
if config_restore_props and stream_props["state.restore-props"] ~= "false" then
local key_base = findSuitableKey(stream_props)
if not key_base then
return
@ -357,7 +340,7 @@ function restoreStream(node)
return
end
if config_restore_props and stream_props["state.restore-props"] ~= false then
if config_restore_props and stream_props["state.restore-props"] ~= "false" then
local props = { "Spa:Pod:Object:Param:Props", "Props" }
local str = state_table[key_base .. ":volume"]
@ -389,7 +372,7 @@ function restoreStream(node)
node:set_param("Props", param)
end
if config_restore_target and stream_props["state.restore-target"] ~= false then
if config_restore_target and stream_props["state.restore-target"] ~= "false" then
local str = state_table[key_base .. ":target"]
if str then
restoreTarget(node, str)