Crate tray

Crate tray 

Source
Expand description

Cross-platform system tray icon library.

This crate provides a cross-platform API for creating and managing system tray icons with native X11 support on Linux, Shell_NotifyIcon on Windows, and NSStatusItem on macOS.

§Features

  • Native X11 system tray support on Linux
  • Full mouse event support: click, double-click, enter, leave, move
  • Thread-safe TrayIcon that can be used with async runtimes

§Example

use tray::{Icon, TrayIconBuilder, TrayIconEvent, MouseButton};

// Create an icon from RGBA data
let icon = Icon::from_rgba(vec![0; 64 * 64 * 4], 64, 64).unwrap();

// Build the tray icon
let tray = TrayIconBuilder::new()
    .with_icon(icon)
    .with_tooltip("My App")
    .build()
    .unwrap();

// Handle events
let receiver = TrayIconEvent::receiver();
loop {
    if let Ok(event) = receiver.try_recv() {
        match event {
            TrayIconEvent::Click { button: MouseButton::Right, .. } => {
                // Show context menu
            }
            _ => {}
        }
    }
    std::thread::sleep(std::time::Duration::from_millis(100));
}

Re-exports§

pub use dpi;

Structs§

Icon
A tray icon image.
Rect
Rectangle representing the tray icon’s position and size.
TrayIcon
A system tray icon.
TrayIconAttributes
Attributes for creating a tray icon.
TrayIconBuilder
Builder for creating a TrayIcon.
TrayIconId
Unique identifier for a tray icon.

Enums§

BadIcon
Errors that can occur when creating an Icon.
Error
Errors that can occur when creating or interacting with a tray icon.
MouseButton
Which mouse button was pressed.
MouseButtonState
State of a mouse button (pressed or released).
TrayIconEvent
Events emitted by a tray icon.

Type Aliases§

Result
A specialized Result type for tray operations.
TrayIconEventReceiver
Channel receiver for TrayIconEvents.