Skip to main content

Module tray

Module tray 

Source
Expand description

A tray icon (a status icon in the panel, the notification area, the menu bar) with a declared menu.

Experimental: may change in any release (docs/stability.md).

The tray’s menu is an egui-pop menu, MENU_TRAY: plugins fill it as any other (CommandSpec::menu(MENU_TRAY, ...), Ctx::menu_item, submenus, lists), its items’ titles, when clauses, ticks and greying come from the commands, and a pick runs the command through the host. The plugin keeps the system’s menu current at each pass.

Its step (ADR 0011):

  • tray.activate: the icon was clicked, { "button" } (left, middle, double; the right button opens the menu). By default the main window comes to the front (crate::window::raise). Replace it to toggle a quick panel, veto it to do nothing.

System is the system’s tray through tray-icon (StatusNotifierItem over D-Bus on Linux and BSD, through ksni, with no GTK; the notification area on Windows; the menu bar on macOS). Simulated records the menu and clicks as a user would, for tests and the gallery.

use egui_pop_api::{App, Ctx, Plugin, PluginError};
use egui_pop_model::commands::CommandSpec;
use egui_pop_model::ids::{CommandId, PluginId};
use egui_pop_platform::tray::{Entry, MENU_TRAY, Simulated, TrayPlugin};

struct Sync;

impl Plugin for Sync {
    fn id(&self) -> PluginId { PluginId::from_static("sync") }
    fn connect(&mut self, ctx: &mut Ctx<'_>) -> Result<(), PluginError> {
        ctx.command(
            CommandSpec::new(CommandId::from_static("sync.now"), "Sync now", "Sync")
                .menu(MENU_TRAY, "1_sync", 0),
            |_| Ok(serde_json::Value::Null),
        )?;
        Ok(())
    }
}

let tray = Simulated::default();
let ctx = egui::Context::default();
let mut app = App::builder()
    .plugin(Sync)
    .plugin(TrayPlugin::new("Demo").backend(tray.clone()))
    .build(&ctx)
    .unwrap();
app.logic(&ctx);
assert!(matches!(&tray.menu()[0], Entry::Item { label, .. } if label == "Sync now"));

Structs§

Events
Hands events to the plugin from any thread, waking the interface.
Icon
The icon’s picture: RGBA pixels, row by row.
Simulated
A tray that records what it shows and clicks as a user would. For tests and the gallery.
Spec
What the tray shows besides its menu.
System
The system’s tray, through tray-icon (see the module).
Tray
The tray’s state, as a service.
TrayPlugin
The tray icon, as a plugin (see the module).

Enums§

Entry
A menu entry as the tray shows it.
Event
What the tray says back.

Constants§

MENU_TRAY
The tray icon’s menu.
PLUGIN
The plugin’s id.
STEP_ACTIVATE
The icon was clicked: { "button" }.
TRAY
The tray, as a service: what it shows, whether it is there.

Traits§

Backend
What shows the tray icon. It lives on the interface thread (the system’s tray objects are tied to it on Windows and macOS).

Functions§

entries
The tray’s menu now, and what each entry runs.

Type Aliases§

Targets
What each entry runs, by the entry’s id.