mpv: sane-sysvol: dont force system volume to zero on init
This commit is contained in:
parent
976ae65529
commit
b9e107510d
|
@ -96,7 +96,6 @@ function pwmon_parser_new()
|
|||
last_audio_device_id = nil, -- TODO: might not actually be necessary
|
||||
|
||||
-- parser state:
|
||||
in_changed = false,
|
||||
changed_id = nil,
|
||||
in_device = false,
|
||||
in_direction = false,
|
||||
|
@ -106,8 +105,7 @@ function pwmon_parser_new()
|
|||
|
||||
feed_line = function(self, line)
|
||||
line = ltrim(line)
|
||||
if startswith(line, "changed:") then
|
||||
self.in_changed = true
|
||||
if startswith(line, "changed:") or startswith(line, "added:") or startswith(line, "removed:") then
|
||||
self.changed_id = nil
|
||||
self.in_device = false
|
||||
self.in_direction = false
|
||||
|
@ -115,24 +113,15 @@ function pwmon_parser_new()
|
|||
self.in_vol = false
|
||||
self.in_mute = false
|
||||
self.in_properties = false
|
||||
elseif startswith(line, "added:") or startswith(line, "removed:") then
|
||||
self.in_changed = false
|
||||
self.changed_id = nil
|
||||
self.in_device = false
|
||||
self.in_direction = false
|
||||
self.in_output = false
|
||||
self.in_vol = false
|
||||
self.in_mute = false
|
||||
self.in_properties = false
|
||||
elseif startswith(line, "id: ") and self.in_changed then
|
||||
elseif startswith(line, "id: ") then
|
||||
if self.changed_id == nil then
|
||||
self.changed_id = tonumber(strip_prefix(line, "id: "))
|
||||
msg.debug("changed_id:", self.changed_id)
|
||||
end
|
||||
elseif startswith(line, "type: ") and self.in_changed then
|
||||
elseif startswith(line, "type: ") then
|
||||
self.in_device = startswith(line, "type: PipeWire:Interface:Device")
|
||||
msg.trace("parsed type:", line, self.in_device)
|
||||
elseif startswith(line, "Prop: ") and self.in_changed and self.in_device then
|
||||
elseif startswith(line, "Prop: ") and self.in_device then
|
||||
self.in_direction = startswith(line, "Prop: key Spa:Pod:Object:Param:Route:direction")
|
||||
if self.in_direction then
|
||||
self.in_output = false
|
||||
|
@ -144,15 +133,15 @@ function pwmon_parser_new()
|
|||
msg.trace("parsed `Prop:`", line, self.in_vol)
|
||||
elseif line:find("Spa:Enum:Direction:Output", 1, true) and self.in_direction then
|
||||
self.in_output = true
|
||||
elseif startswith(line, "Float ") and self.in_changed and self.in_device and self.in_output and self.in_vol then
|
||||
elseif startswith(line, "Float ") and self.in_device and self.in_output and self.in_vol then
|
||||
value = tonumber(strip_prefix(line, "Float "))
|
||||
self:feed_volume(value)
|
||||
elseif startswith(line, "Bool ") and self.in_changed and self.in_device and self.in_output and self.in_mute then
|
||||
elseif startswith(line, "Bool ") and self.in_device and self.in_output and self.in_mute then
|
||||
value = tonumber(strip_prefix(line, "Bool ")) == "true"
|
||||
self:feed_mute(value)
|
||||
elseif startswith(line, "properties:") and self.in_changed and self.in_device then
|
||||
elseif startswith(line, "properties:") and self.in_device then
|
||||
self.in_properties = true
|
||||
elseif line == 'media.class = "Audio/Device"' and self.in_changed and self.in_device and self.in_properties then
|
||||
elseif line == 'media.class = "Audio/Device"' and self.in_device and self.in_properties then
|
||||
self.last_audio_device_id = self.changed_id
|
||||
msg.debug("last_audio_device_id:", self.changed_id)
|
||||
end
|
||||
|
@ -223,12 +212,18 @@ function pwmon_new()
|
|||
}
|
||||
end
|
||||
|
||||
|
||||
mp.set_property_native("user-data/sane-sysvol/volume", 0)
|
||||
|
||||
local sysvol = sysvol_new()
|
||||
local first_announcement = true
|
||||
mp.observe_property("user-data/sane-sysvol/volume", "native", function(_, val)
|
||||
sysvol:change_sysvol(val)
|
||||
-- we must set the volume property early -- before we actually know the volume
|
||||
-- else other modules will think it's `nil` and error.
|
||||
-- but we DON'T want the value we set to actually impact the system volume
|
||||
if not first_announcement then
|
||||
sysvol:change_sysvol(val)
|
||||
end
|
||||
first_announcement = false
|
||||
end)
|
||||
mp.observe_property("user-data/sane-sysvol/pw-mon-volume", "native", function(_, val)
|
||||
sysvol:on_sysvol_change(val)
|
||||
|
|
Loading…
Reference in New Issue
Block a user