aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarvey Tindall <hrfee@protonmail.ch>2020-08-23 16:25:27 +0100
committerHarvey Tindall <hrfee@protonmail.ch>2020-08-23 16:25:27 +0100
commit623adf487e56da10d9d0fbac914ab90cbdc68a1e (patch)
treeff1cbd9b4cf5136cdb0e15101fdda0922c6c8789
parent840130680e3aee2d202e23d684343cf48e24e885 (diff)
downloadwaybar-mpris-623adf487e56da10d9d0fbac914ab90cbdc68a1e.tar.gz
waybar-mpris-623adf487e56da10d9d0fbac914ab90cbdc68a1e.zip
display browser name in tooltip
reads /proc/<pid>/cmdline directly instead of using a library.
-rw-r--r--README.md2
-rw-r--r--main.go21
-rwxr-xr-xwaybar-mprisbin4469393 -> 4473532 bytes
3 files changed, 22 insertions, 1 deletions
diff --git a/README.md b/README.md
index 51747bc..d2ff7dd 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ MPRIS2 is widely supported, so this component should work with:
* Most other music/media players
## Install
-`go get github.com/hrfee/waybar-mpris`
+`go get github.com/hrfee/waybar-mpris` will install the program, as well as the go dbus bindings and pflags for command-line arguments.
or just grab the `waybar-mpris` binary from here and place it in your PATH.
diff --git a/main.go b/main.go
index e018f15..8b7a3ab 100644
--- a/main.go
+++ b/main.go
@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/godbus/dbus/v5"
flag "github.com/spf13/pflag"
+ "io/ioutil"
"log"
"net"
"os"
@@ -17,6 +18,12 @@ var knownPlayers = map[string]string{
"noson": "Noson",
}
+var knownBrowsers = map[string]string{
+ "mozilla": "Firefox",
+ "chrome": "Chrome",
+ "chromium": "Chromium",
+}
+
type Player struct {
player dbus.BusObject
fullName, name, title, artist, album string
@@ -50,6 +57,20 @@ func NewPlayer(conn *dbus.Conn, name string) (p *Player) {
for key, val := range knownPlayers {
if strings.Contains(name, key) {
playerName = val
+ if val == "Browser" {
+ var pid uint32
+ conn.BusObject().Call("org.freedesktop.DBus.GetConnectionUnixProcessID", 0, name).Store(&pid)
+ file, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/cmdline", pid))
+ if err == nil {
+ cmd := string(file)
+ for k, v := range knownBrowsers {
+ if strings.Contains(cmd, k) {
+ playerName = v
+ break
+ }
+ }
+ }
+ }
break
}
}
diff --git a/waybar-mpris b/waybar-mpris
index 1492d17..07e2232 100755
--- a/waybar-mpris
+++ b/waybar-mpris
Binary files differ