improve ignoring of playerctld
also now ignores signals from it by storing its unique sender name on startup and checking each signal.
This commit is contained in:
parent
bcd2a83dd9
commit
233b5dd1ca
@ -229,6 +229,8 @@ type Mpris2 struct {
|
|||||||
interpolate bool
|
interpolate bool
|
||||||
poll int
|
poll int
|
||||||
autofocus bool
|
autofocus bool
|
||||||
|
// playerctld mirrors property changes of other players, so we store its UID here to ignore it.
|
||||||
|
playerctldUID string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMpris2(conn *dbus.Conn, interpolate bool, poll int, autofocus bool) *Mpris2 {
|
func NewMpris2(conn *dbus.Conn, interpolate bool, poll int, autofocus bool) *Mpris2 {
|
||||||
@ -254,8 +256,11 @@ func (pl *Mpris2) Listen() {
|
|||||||
case string:
|
case string:
|
||||||
var pid uint32
|
var pid uint32
|
||||||
pl.conn.BusObject().Call("org.freedesktop.DBus.GetConnectionUnixProcessID", 0, name).Store(&pid)
|
pl.conn.BusObject().Call("org.freedesktop.DBus.GetConnectionUnixProcessID", 0, name).Store(&pid)
|
||||||
// Ignore playerctld again
|
// Ignore playerctld
|
||||||
if strings.Contains(name, INTERFACE) && !strings.Contains(name, "playerctld") {
|
if strings.Contains(name, "playerctld") {
|
||||||
|
// Store UID so we know to ignore it later
|
||||||
|
pl.playerctldUID = v.Sender
|
||||||
|
} else if strings.Contains(name, INTERFACE) {
|
||||||
if pid == 0 {
|
if pid == 0 {
|
||||||
pl.Remove(name)
|
pl.Remove(name)
|
||||||
pl.Messages <- Message{Name: "remove", Value: name}
|
pl.Messages <- Message{Name: "remove", Value: name}
|
||||||
@ -265,7 +270,7 @@ func (pl *Mpris2) Listen() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if strings.Contains(v.Name, "PropertiesChanged") && strings.Contains(v.Body[0].(string), INTERFACE+".Player") {
|
} else if strings.Contains(v.Name, "PropertiesChanged") && strings.Contains(v.Body[0].(string), INTERFACE+".Player") && v.Sender != pl.playerctldUID {
|
||||||
pl.Refresh()
|
pl.Refresh()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -310,7 +315,12 @@ func (pl *Mpris2) Reload() error {
|
|||||||
}
|
}
|
||||||
for _, name := range buses {
|
for _, name := range buses {
|
||||||
// Don't add playerctld, it just duplicates other players
|
// Don't add playerctld, it just duplicates other players
|
||||||
if strings.HasPrefix(name, INTERFACE) && !strings.Contains(name, "playerctld") {
|
if strings.Contains(name, "playerctld") {
|
||||||
|
// Store its UID
|
||||||
|
uid := ""
|
||||||
|
pl.conn.BusObject().Call("org.freedesktop.DBus.GetNameOwner", 0, name).Store(&uid)
|
||||||
|
pl.playerctldUID = uid
|
||||||
|
} else if strings.HasPrefix(name, INTERFACE) {
|
||||||
pl.New(name)
|
pl.New(name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BIN
waybar-mpris
BIN
waybar-mpris
Binary file not shown.
Loading…
Reference in New Issue
Block a user