A system tray for eww
Find a file
2024-03-29 00:07:55 +00:00
gtk-tray refactor(gtk-tray): fix clippy warning 2024-01-27 00:54:20 +00:00
stray chore(release): v0.1.5 2024-01-27 01:02:18 +00:00
.gitignore chore: First commit 2022-04-21 15:48:09 +02:00
Cargo.lock chore(release): v0.1.5 2024-01-27 01:02:18 +00:00
Cargo.toml chore: use v2 workspace resolver 2024-01-27 00:32:48 +00:00
README.md Update README.md 2024-03-29 00:07:55 +00:00

Note

Archived in favour of system-tray rewrite.

Stray

Stray is a 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