kondinskis / hyperx-cloud-flight

Simple tray application which shows battery level for HyperX Cloud Flight Wireless Headset.
MIT License
37 stars 10 forks source link

Tray icon support based on libappindicator #12

Open 31KM opened 2 years ago

31KM commented 2 years ago

The current tray icon implementation is based on ksni (using org.kde.StatusNotifierItem) and that standard seems to not be widely supported (anymore?) - see related discussion over at https://github.com/i3/i3/issues/2088. For example, it is not working with i3bar:

31KM: ~ dbus-monitor
...
method call time=1658403699.624431 sender=:1.107 -> destination=org.kde.StatusNotifierWatcher serial=3 path=/StatusNotifierWatcher; interface=org.kde.StatusNotifierWatcher; member=RegisterStatusNotifierItem
   string "org.kde.StatusNotifierItem-1661775-1"
error time=1658403699.624437 sender=org.freedesktop.DBus -> destination=:1.107 error_name=org.freedesktop.DBus.Error.ServiceUnknown reply_serial=3
   string "The name org.kde.StatusNotifierWatcher was not provided by any .service files"
...

Instead, a better approach seems to be to use a lib based on libappindicator, e.g. tray-item-rs.

See https://github.com/kondinskis/hyperx-cloud-flight/issues/11 for related discussion.

31KM commented 2 years ago

So libappindicator requires GTK to implement a menu. This, however, means that GTK will also need to become a dependency - with the consequence that it will dictate the GTK - or probably more general, UI - paradigm of the main loop. The loop { ... } in fn main() thus cannot be implemented that way as it blocks the main loop.

Also note that using libappindicator also introduces a .so dependency to libayatana-appindicator.

I started playing around with tray-item-rs but that apparently lacks the possibility to add a tooltip. So I moved to libappindicator directly as that is more flexible.

Note that I'm neither a rust nor GTK expert by any means, so I might have taken a wrong turn somewhere. But with a naive implementation I was able to get a tray icon - that has no functionality whatsoever (yet) though.