#tray #tokio #dbusmenu #statusnotifieritem

system-tray

Async StatusNotifierItem and DBusMenu client for custom tray implementations

5 releases (3 breaking)

new 0.4.0 Nov 16, 2024
0.3.0 Nov 8, 2024
0.2.0 Mar 29, 2024
0.1.5 Jan 27, 2024
0.1.4 Aug 13, 2023

#171 in GUI

Download history 83/week @ 2024-07-31 77/week @ 2024-08-07 45/week @ 2024-08-14 28/week @ 2024-08-21 47/week @ 2024-08-28 49/week @ 2024-09-04 78/week @ 2024-09-11 83/week @ 2024-09-18 86/week @ 2024-09-25 89/week @ 2024-10-02 58/week @ 2024-10-09 59/week @ 2024-10-16 52/week @ 2024-10-23 69/week @ 2024-10-30 220/week @ 2024-11-06 253/week @ 2024-11-13

601 downloads per month
Used in ironbar

MIT and maybe LGPL-3.0-only

75KB
1.5K SLoC

System Tray

An async implementation of the StatusNotifierItem and DbusMenu protocols for building system trays.

Requires Tokio.

Example

use system_tray::client::Client;

#[tokio::main]
async fn main() {
    let client = Client::new().await.unwrap();
    let mut tray_rx = client.subscribe();

    let initial_items = client.items();
    
    // do something with initial items...
    
    while let Ok(ev) = tray_rx.recv().await {
        println!("{ev:?}"); // do something with event...
    }
}

dbusmenu-gtk3

Although the library provides a built-in Rust-native implementation of the DBusMenu protocol, this has a few issues:

  • There are some known bugs. For example, opening a file in VLC will break its menu.
  • If you are creating a menu UI, you need to parse the whole tree set up each element, and track all changes manually.

To circumvent this, bindings to the dbusmenu-gtk3 system library are included. When the feature of the same name is enabled, you can listen for UpdateEvent::MenuConnect and create the GTK element based on that:

fn on_update(update: system_tray::Event) {
    match update {
        Event::Update(address, UpdateEvent::MenuConnect(menu)) => {
            let menu: gtk::auto::Menu = system_tray::gtk_menu::Menu::new(&address, &menu);
            // do something with the menu element
        }
    }
}

[!NOTE] This feature is disabled by default to reduce compilation times.

Dependencies

~14–29MB
~473K SLoC