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
TrayIconthat 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.
- Tray
Icon - A system tray icon.
- Tray
Icon Attributes - Attributes for creating a tray icon.
- Tray
Icon Builder - Builder for creating a
TrayIcon. - Tray
Icon Id - 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.
- Mouse
Button - Which mouse button was pressed.
- Mouse
Button State - State of a mouse button (pressed or released).
- Tray
Icon Event - Events emitted by a tray icon.
Type Aliases§
- Result
- A specialized
Resulttype for tray operations. - Tray
Icon Event Receiver - Channel receiver for
TrayIconEvents.