plat/tray.rs#
Source: lib/plat/tray.rs
tray -- the app's symbol in the notification area (system tray) and system notifications
tray_set(&Tray) -> bool show or update the symbol: icon (None = the program's own:
Windows icon resource 1, Linux the icon named like the app),
tooltip, menu (TrayItem tree; empty = no menu)
tray_remove() take the symbol away
notify(&Note) -> u32 a system notification -> its id (0: not shown); clicking
it reports NoteClicked
notify_close(id)
tray_take() -> Vec<TrayEvent> what happened since the last call; every event calls wake()
tray_supported() -> bool whether this system shows the symbol: a notification area
(Linux: a StatusNotifierWatcher runs -- KDE, Xfce, ...; GNOME
only with the AppIndicator extension); notifications work
without one
set_dry_run(on) print instead of showing from now on (headless UI runs)
Windows (win_tray.rs): Shell_NotifyIconW on a message-only window of the UI thread, the menu
with TrackPopupMenuEx, notifications as the symbol's balloon (Windows 10 / 11 show it as a
toast; without a visible symbol a hidden one is added for the time it is shown). Linux
(linux_tray.rs): StatusNotifierItem with a com.canonical.dbusmenu menu and
org.freedesktop.Notifications, on a session-bus connection of its own thread; clicks on the
symbol and its menu count only from the program that shows it (the owner of the
StatusNotifierWatcher or of a StatusNotifierHost name -- a program of the same user that
claims such a name passes too, so a tray command that destroys something should still ask in
a window). Browser and
Android (web_notify.rs): notifications only -- the Notification API (the permission asked for
from the user's gesture), NotificationManager with POST_NOTIFICATIONS; no symbol. macOS
(apple_mac_services.rs): an NSStatusItem in the menu bar (with a menu a click opens it, the Mac's
way; without one a click is Activate), UNUserNotificationCenter in an app bundle (a program
without a bundle identifier gets no notifications: 0). iOS (apple_ios_services.rs): notifications
only, through UNUserNotificationCenter (asked the first time); no symbol. Elsewhere nothing
is shown. jfgui_TRAY_DRYRUN=1 prints what would be shown instead (tests).
/// TrayItem flags: a check mark
TI_CHECKED: u32 = 1
/// TrayItem flags: greyed out
TI_DISABLED: u32 = 2
/// TrayItem flags: a separator line (id and label are ignored)
TI_SEPARATOR: u32 = 4
struct TrayItemone row of the symbol's menuid: u32-- reported by TrayEvent::Menu (0: a row without action, e.g. a submenu)label: Stringflags: u32-- TI_*sub: Vec<TrayItem>-- a submenu when not empty
struct TrayIconan icon: straight ARGB pixels (0xAARRGGBB), w x hw: u32h: u32px: Vec<u32>
struct Traythe symbolicon: Option<TrayIcon>-- None: the program's own icontooltip: Stringmenu: Vec<TrayItem>
struct Notea system notificationtitle: Stringbody: Stringicon: Option<TrayIcon>-- None: the program's own icon
enum TrayEventwhat happened at the symbol or a notificationActivate-- the symbol was clicked (Linux: activated)SecondaryActivate-- the symbol was double-clicked (Windows) / middle-clicked (Linux)Menu(u32)-- a menu row was chosen: its TrayItem::idNoteClicked(u32)-- a notification was clicked: its idNoteClosed(u32)-- a notification went away without a click (timeout, closed): its id
fn tray_take() -> Vec<TrayEvent>the events since the last call, oldest firstfn set_dry_run(on: bool)print what would be shown instead of showing it (the UI's headless runs: scripts, --shot)fn tray_set(t: &Tray) -> boolshow or update the symbol -> false when this system has no notification areafn tray_remove()take the symbol awayfn notify(n: &Note) -> u32a system notification -> its id (0: not shown)fn notify_close(id: u32)take a notification awayfn tray_supported() -> boolwhether the symbol can be shown here (a notification area; Linux: a StatusNotifierWatcher runs -- GNOME needs the AppIndicator extension); notifications work without one