#eww #freedesktop #menu #tray #system #minimalistic #system-tray

stray

A freedesktop StatusNotifierWatcher implementation

3 releases

Uses new Rust 2021

0.1.2 Oct 16, 2022
0.1.1 May 3, 2022
0.1.0 Apr 27, 2022
Download history 21/week @ 2022-08-14 20/week @ 2022-08-21 7/week @ 2022-08-28 21/week @ 2022-09-04 10/week @ 2022-09-11 8/week @ 2022-09-18 6/week @ 2022-09-25 12/week @ 2022-10-02 6/week @ 2022-10-09 36/week @ 2022-10-16 19/week @ 2022-10-23 18/week @ 2022-10-30 22/week @ 2022-11-06 20/week @ 2022-11-13 30/week @ 2022-11-20 33/week @ 2022-11-27

109 downloads per month
Used in ironbar

MIT license

48KB
927 lines

Stray

Stray is a minimal SystemNotifierWatcher implementation which goal is to provide a minimalistic API to access tray icons and menu.

Examples

Start the system tray and listen for changes

use stray::{SystemTray};
use tokio_stream::StreamExt;
use stray::message::NotifierItemMessage;
use stray::message::NotifierItemCommand;

#[tokio::main]
async fn main() {

    // A mpsc channel to send menu activation requests later
    let (ui_tx, ui_rx) = tokio::sync::mpsc::channel(32);
    let mut tray = SystemTray::new(ui_rx).await;

    while let Some(message) = tray.next().await {
        match message {
            NotifierItemMessage::Update { address: id, item, menu } => {
                println!("NotifierItem updated :
                    id   = {id},
                    item = {item:?},
                    menu = {menu:?}"
                )
            }
            NotifierItemMessage::Remove { address: id } => {
                println!("NotifierItem removed : id = {id}");
            }
        }
    }
}

Send menu activation request to the system tray

 // Assuming we stored our menu items in some UI state we can send menu item activation request:
 use stray::message::NotifierItemCommand;

 ui_tx.clone().try_send(NotifierItemCommand::MenuItemClicked {
    // The submenu to activate
    submenu_id: 32,
    // dbus menu path, available in the `StatusNotifierItem`
    menu_path: "/org/ayatana/NotificationItem/Element1/Menu".to_string(),
    // the notifier address we previously got from `NotifierItemMessage::Update`
    notifier_address: ":1.2161".to_string(),
 }).unwrap();

Gtk example

For a detailed, real life example, you can take a look at the gtk-tray.

git clone git@github.com:oknozor/stray.git
cd stray/gtk-tray
cargo run

Dependencies

~10–16MB
~303K SLoC