Skip to main content

TrayHandle

Struct TrayHandle 

Source
pub struct TrayHandle { /* private fields */ }
Expand description

A cheap, Clone + Send remote control for a running Tray.

Tray::run consumes the tray, so TrayHandle closes the gap: obtain one with Tray::handle before run, move it to any thread, and post commands the backend applies on its UI thread. Commands posted before the run loop is live simply buffer and apply once it starts.

Implementations§

Source§

impl TrayHandle

Source

pub fn set_menu(&self, menu: Menu)

Replace the menu shown on the next open (and repaint + refresh the accessibility tree live if the popup is already open).

Source

pub fn set_icon(&self, icon: Icon)

Replace the tray icon.

Source

pub fn set_tooltip(&self, tooltip: Option<impl Into<String>>)

Replace the tooltip / accessible name.

Source

pub fn set_title(&self, title: Option<impl Into<String>>)

Replace the status-item text title (macOS menu-bar text, e.g. a live “45%”). A no-op on the drawn item on Windows/Linux.

Source

pub fn set_visible(&self, visible: bool)

Show or hide the tray status item.

Source

pub fn open(&self)

Programmatically open the popup anchored to the tray icon.

Source

pub fn close(&self)

Dismiss the popup if shown.

Source

pub fn shutdown(&self)

Stop the tray: remove the OS status item and end its backend run loop (and background thread, for a spawned tray). Best-effort and asynchronous — the removal is applied on the backend’s UI thread. Used by the compat facade to remove the icon when its TrayIcon is dropped, matching tray-icon.

Source

pub fn set_theme(&self, theme: ThemeSource)

Swap the live theme source (issue #45). Applied asynchronously on the backend’s UI thread: the next popup open uses it, and any currently-open popup is repainted — so a consumer can wire an in-menu “Preview theme” submenu. See TrayCommand::SetTheme for the Linux SNI-tray caveat.

Source

pub fn set_options(&self, options: MenuOptions)

Swap the live MenuOptions wholesale — theme, width bounds, gutter policy (issue #45). Applied like set_theme.

Source

pub fn anchor_rect(&self) -> Option<LogicalRect>

Best-effort cross-thread query for the tray icon’s current on-screen rectangle (issue #48). The native, main-thread counterpart is Tray::anchor_rect.

Posts a TrayCommand::QueryAnchorRect and waits briefly for the backend to reply on its UI thread. Returns None if the run loop is not yet live, the query times out, or the platform can’t report geometry (the Linux SNI tray never can — its host owns the icon).

Trait Implementations§

Source§

impl Clone for TrayHandle

Source§

fn clone(&self) -> TrayHandle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TrayHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,

Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.