hex/src/linux_tray.rs
Kit Langton 6f7a485e37
HUD: Rune a7c643b0 pin and no empty UI pass (#351)
* Bump Rune pin to 54825236 (staged uploads, playground keys)

* HUD: skip Rune's empty UI pass and clear in Hex's own

* Test: the shortcut recorder keeps Space and Enter after a menu closes

* Tests: build macos_rune::Runtime with listener_failure

* Test: a playground scene hears ⌘-digits as soon as it opens

* Bump Rune pin to a7c643b0 (scaled-layer pixel snap, Linux portal appearance)
2026-10-29 03:08:03 -07:00

45 lines
1.7 KiB
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! The Linux tray icon, a Rune tray (StatusNotifierItem). A click shows the
//! window; the menu offers Show Hex and Quit Hex. A desktop without a tray
//! host (GNOME without an extension, i3bar) shows nothing, and Hex runs on
//! as before.
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::SyncSender;
use crate::desktop_i18n::tr;
use crate::linux_service::{Activation, Control};
/// The white Hex mark the Windows tray uses, raw 32×32 RGBA.
const ICON_RGBA: &[u8] = include_bytes!("../resources/windows/tray-32.rgba");
const ICON_SIZE: u32 = 32;
/// Shows the tray icon until the returned tray drops.
pub(crate) fn start(
control: SyncSender<Control>,
shutdown: &'static AtomicBool,
) -> Option<rune::Tray> {
let icon = rune::TrayIcon::rgba(ICON_SIZE, ICON_SIZE, ICON_RGBA.to_vec());
let spec = rune::TraySpec::new("hex", "Hex", icon)
.tooltip(tr("Hex Dictation"))
.menu(vec![
rune::TrayItem::action("show", tr("Show Hex")),
rune::TrayItem::Separator,
rune::TrayItem::action("quit", tr("Quit Hex")),
]);
let show = move |token| {
let activation = Activation {
token,
startup_id: None,
};
let _ = control.try_send(Control::Activate(activation));
};
let tray = rune::Tray::new(spec, move |event| match event {
rune::TrayEvent::Activate { token } => show(token),
rune::TrayEvent::Menu(id) if id == "show" => show(None),
// As the window's Quit Hex: drains accepted work, then exits.
rune::TrayEvent::Menu(id) if id == "quit" => shutdown.store(true, Ordering::Release),
_ => {}
});
tray.inspect_err(|error| tracing::warn!(%error, "Hex has no tray icon"))
.ok()
}