Skip to content

Lightweight native Discord client for Windows, Linux and macOS, written in Rust. No Electron, no browser engine.

Linux: notification-area icon, and close to tray (#33)

ec3ddc766549e
diff --git a/Cargo.lock b/Cargo.lock
index bd97f30..64a9e04 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -309,6 +309,15 @@ dependencies = [
"x11rb",
]
+[[package]]
+name = "arc-swap"
+version = "1.9.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "84a22b5d51209f6de83d37a0b33d320acb8da88823e42a94c075140708f032a5"
+dependencies = [
+ "rustversion",
+]
+
[[package]]
name = "array-init"
version = "2.1.0"
@@ -1257,6 +1266,15 @@ dependencies = [
"crossbeam-utils",
]
+[[package]]
+name = "crossbeam-queue"
+version = "0.3.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "03e8bd762f7479489c70ed6c768ddca99d7296857de437a68dcb2a94365b3fae"
+dependencies = [
+ "crossbeam-utils",
+]
+
[[package]]
name = "crossbeam-utils"
version = "0.8.23"
@@ -3506,6 +3524,21 @@ version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
+[[package]]
+name = "ksni"
+version = "0.3.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d49a7ac89853917f01d75f6bac3e7c8e282ae621dd63fbbfc50fe331304fa580"
+dependencies = [
+ "arc-swap",
+ "crossbeam-queue",
+ "futures-util",
+ "pastey",
+ "serde",
+ "tokio",
+ "zbus 5.19.0",
+]
+
[[package]]
name = "kurbo"
version = "0.9.5"
@@ -4672,6 +4705,12 @@ version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
+[[package]]
+name = "pastey"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2ee67f1008b1ba2321834326597b8e186293b049a023cdef258527550b9935b4"
+
[[package]]
name = "pbkdf2"
version = "0.12.2"
@@ -5522,6 +5561,7 @@ dependencies = [
"gtk",
"image",
"keyring",
+ "ksni",
"libc",
"libmimalloc-sys",
"log",
@@ -6827,8 +6867,10 @@ dependencies = [
"libc",
"mio",
"pin-project-lite",
+ "signal-hook-registry",
"socket2",
"tokio-macros",
+ "tracing",
"windows-sys 0.61.2",
]
@@ -8867,6 +8909,7 @@ dependencies = [
"rustix 1.1.6",
"serde",
"serde_repr",
+ "tokio",
"tracing",
"uds_windows",
"uuid",
diff --git a/README.md b/README.md
index 762f376..9754762 100644
--- a/README.md
+++ b/README.md
@@ -55,6 +55,9 @@ administrator rights needed.
`sudo dnf install webkit2gtk4.1` on Fedora, `sudo pacman -S webkit2gtk-4.1` on Arch.
- Chat, voice calls and everything else work; Go Live screen sharing and the camera are
Windows-only for now. On a Wayland desktop RustCord runs through XWayland.
+- RustCord has a notification-area icon, and clicking X can leave it running there instead of
+ quitting (System → General → Minimize RustCord to System Tray). KDE, XFCE and Cinnamon show
+ the icon out of the box; on GNOME, install the AppIndicator extension first.
- New on Linux, so please [report problems](https://github.com/VRonGitHub/RustCord/issues).
Check your download with `sha256sum -c RustCord-<version>-linux-x86_64.tar.gz.sha256`.
diff --git a/apps/rustcord/Cargo.toml b/apps/rustcord/Cargo.toml
index 2c62876..2ab2cb0 100644
--- a/apps/rustcord/Cargo.toml
+++ b/apps/rustcord/Cargo.toml
@@ -58,6 +58,9 @@ dev-hooks = []
embed-resource = "2"
[target.'cfg(target_os = "linux")'.dependencies]
+# The notification-area icon (StatusNotifierItem over D-Bus). Pure Rust: no
+# extra C library to install, unlike the AppIndicator bindings.
+ksni = { version = "0.3", features = ["blocking"] }
# The embedded web pages are WebKitGTK views there: GTK is started and pumped
# by src/linux.rs. The version wry 0.57 uses.
gtk = "0.18"
diff --git a/apps/rustcord/src/app.rs b/apps/rustcord/src/app.rs
index 8fca593..a55ddb6 100644
--- a/apps/rustcord/src/app.rs
+++ b/apps/rustcord/src/app.rs
@@ -446,6 +446,10 @@ pub struct RustCord {
device_theme_at: Option<Instant>,
/// The notification-area icon's picks (Open, About, Reset, Restart, Quit).
tray: Option<std::sync::mpsc::Receiver<crate::tray::TrayAction>>,
+ /// Whether the tray icon is actually on screen (a Linux panel can restart).
+ tray_usable: bool,
+ /// The window is hidden in the notification area.
+ window_hidden: bool,
/// Automatic updates (an installed copy on Windows only).
pub updater: Option<crate::updater::Updater>,
/// Discord's "Briefly leave voice?" before restarting into an update.
@@ -558,6 +562,8 @@ impl RustCord {
crate::features::apply_prefs(&prefs);
let Launch { accounts, session } = launch;
let nav = crate::features::load_nav(crate::features::nav_file(session.as_ref().map(|(id, _)| *id)).as_deref());
+ let tray = crate::tray::start(cc.egui_ctx.clone());
+ let tray_usable = tray.is_some();
let mut app = Self {
ctx: cc.egui_ctx.clone(),
@@ -746,7 +752,9 @@ impl RustCord {
badge_at: None,
notified: None,
device_theme_at: None,
- tray: crate::tray::start(cc.egui_ctx.clone()),
+ tray,
+ tray_usable,
+ window_hidden: false,
updater: crate::updater::Updater::start(&cc.egui_ctx),
update_confirm: false,
corners_rounded: false,
@@ -914,6 +922,31 @@ impl RustCord {
self.restore_nav = nav.as_ref().map(|n| (n.guild, n.channel));
}
+ /// Whether the title bar's X can hide the window in the notification
+ /// area. Linux only for now: on Windows a hidden window gets no frames,
+ /// so RustCord would stop handling anything (the tray's picks included)
+ /// until it is shown again.
+ pub fn tray_available(&self) -> bool {
+ cfg!(target_os = "linux") && self.tray.is_some() && self.tray_usable
+ }
+
+ /// "Minimize RustCord to System Tray": the title bar's X hides the window
+ /// (only that X: a close from outside, like the updater's or a second
+ /// launch's, still quits, so settings get saved).
+ pub fn hide_to_tray(&mut self, ctx: &egui::Context) {
+ ctx.send_viewport_cmd(egui::ViewportCommand::Visible(false));
+ self.window_hidden = true;
+ log::info!("window: hidden in the notification area");
+ }
+
+ /// Bring the window back from the notification area.
+ fn show_window(&mut self, ctx: &egui::Context) {
+ ctx.send_viewport_cmd(egui::ViewportCommand::Visible(true));
+ ctx.send_viewport_cmd(egui::ViewportCommand::Minimized(false));
+ ctx.send_viewport_cmd(egui::ViewportCommand::Focus);
+ self.window_hidden = false;
+ }
+
/// What was picked on the tray icon.
fn tray_actions(&mut self, ctx: &egui::Context) {
let picks: Vec<crate::tray::TrayAction> = match &self.tray {
@@ -924,18 +957,14 @@ impl RustCord {
for pick in picks {
match pick {
TrayAction::Open | TrayAction::About => {
- ctx.send_viewport_cmd(egui::ViewportCommand::Visible(true));
- ctx.send_viewport_cmd(egui::ViewportCommand::Minimized(false));
- ctx.send_viewport_cmd(egui::ViewportCommand::Focus);
+ self.show_window(ctx);
if pick == TrayAction::About {
self.settings_tab = SettingsTab::About;
self.settings_open = true;
}
}
TrayAction::Notification => {
- ctx.send_viewport_cmd(egui::ViewportCommand::Visible(true));
- ctx.send_viewport_cmd(egui::ViewportCommand::Minimized(false));
- ctx.send_viewport_cmd(egui::ViewportCommand::Focus);
+ self.show_window(ctx);
if let Some((guild, channel)) = self.notified.take().filter(|(_, c)| self.store.channels.contains_key(c)) {
self.settings_open = false;
self.select_guild(guild);
@@ -944,6 +973,17 @@ impl RustCord {
}
TrayAction::Quit => ctx.send_viewport_cmd(egui::ViewportCommand::Close),
TrayAction::Restart => self.restart(ctx),
+ // Linux: the desktop's notification-area host went away or
+ // came back. Never leave the window hidden without an icon.
+ #[cfg(target_os = "linux")]
+ TrayAction::TrayUp => self.tray_usable = true,
+ #[cfg(target_os = "linux")]
+ TrayAction::TrayDown => {
+ self.tray_usable = false;
+ if self.window_hidden {
+ self.show_window(ctx);
+ }
+ }
TrayAction::Reset => {
// Like Vesktop's "Reset": log out, forget every setting and
// the cache, start fresh. (The log stays for diagnostics.)
diff --git a/apps/rustcord/src/features.rs b/apps/rustcord/src/features.rs
index d49386a..e942776 100644
--- a/apps/rustcord/src/features.rs
+++ b/apps/rustcord/src/features.rs
@@ -394,6 +394,8 @@ pub struct LocalPrefs {
pub share_rustcord: bool,
/// The emoji picker's skin tone: 0 none, 1 light … 5 dark.
pub skin_tone: u8,
+ /// Closing the window keeps RustCord running in the notification area.
+ pub close_to_tray: bool,
// ---- Notifications ----
/// Windows notifications for DMs and mentions while you're elsewhere.
pub desktop_notifications: bool,
@@ -518,6 +520,7 @@ impl Default for LocalPrefs {
// Off until switched on: it contacts RustCord's own server.
share_rustcord: false,
skin_tone: 0,
+ close_to_tray: false,
desktop_notifications: true,
unread_badge: true,
sound_message: true,
diff --git a/apps/rustcord/src/tray.rs b/apps/rustcord/src/tray.rs
index da7de51..2d1e062 100644
--- a/apps/rustcord/src/tray.rs
+++ b/apps/rustcord/src/tray.rs
@@ -5,9 +5,10 @@
//!
//! The icon lives on its own thread with a hidden window for its messages
//! (plain Win32: Shell_NotifyIcon, TrackPopupMenu); picks reach the app over a
-//! channel and wake it.
+//! channel and wake it. On Linux it is a StatusNotifierItem on the session bus
+//! (`ksni`), which is what KDE, XFCE and Cinnamon panels show.
-#[cfg(not(windows))]
+#[cfg(not(any(windows, target_os = "linux")))]
use std::sync::mpsc::Receiver;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -20,16 +21,25 @@ pub enum TrayAction {
Quit,
/// A notification of ours was clicked.
Notification,
+ /// Linux: the desktop started showing status notifier items again.
+ #[cfg(target_os = "linux")]
+ TrayUp,
+ /// Linux: the desktop stopped showing them (a panel restart, or GNOME
+ /// without the AppIndicator extension). The window must not stay hidden.
+ #[cfg(target_os = "linux")]
+ TrayDown,
}
#[cfg(windows)]
pub use win::{is_foreground, notify, remove, round_corners, set_badge, set_window_icons, start, system_animations, system_high_contrast, system_light_theme, take_keyboard_focus};
+#[cfg(target_os = "linux")]
+pub use linux::{remove, start};
-#[cfg(not(windows))]
+#[cfg(not(any(windows, target_os = "linux")))]
pub fn start(_: eframe::egui::Context) -> Option<Receiver<TrayAction>> {
None
}
-#[cfg(not(windows))]
+#[cfg(not(any(windows, target_os = "linux")))]
pub fn remove() {}
#[cfg(not(windows))]
pub fn round_corners(_: isize) {}
@@ -74,6 +84,123 @@ pub fn system_high_contrast() -> bool {
false
}
+/// Linux: the notification-area icon, a StatusNotifierItem on D-Bus (what
+/// KDE, XFCE and Cinnamon show; GNOME needs the AppIndicator extension).
+#[cfg(target_os = "linux")]
+mod linux {
+ use super::TrayAction;
+ use std::sync::mpsc::{Receiver, Sender};
+ use std::sync::{Mutex, OnceLock};
+
+ /// The running tray service, kept so it can be taken down before exiting.
+ static TRAY: OnceLock<Mutex<Option<ksni::blocking::Handle<Tray>>>> = OnceLock::new();
+
+ struct Tray {
+ tx: Sender<TrayAction>,
+ ctx: eframe::egui::Context,
+ }
+
+ impl Tray {
+ fn send(&self, action: TrayAction) {
+ let _ = self.tx.send(action);
+ // The window may be hidden: wake the UI so it sees the pick.
+ self.ctx.request_repaint();
+ }
+ }
+
+ impl ksni::Tray for Tray {
+ fn id(&self) -> String {
+ "rustcord".into()
+ }
+ fn title(&self) -> String {
+ "RustCord".into()
+ }
+ fn icon_pixmap(&self) -> Vec<ksni::Icon> {
+ icon()
+ }
+ /// Left click, like Windows' tray icon: bring RustCord up.
+ fn activate(&mut self, _x: i32, _y: i32) {
+ self.send(TrayAction::Open);
+ }
+ fn menu(&self) -> Vec<ksni::MenuItem<Self>> {
+ use ksni::menu::{MenuItem, StandardItem};
+ // (Windows also offers Reset; its native message box asks first.
+ // There's no confirmation dialog here yet, so it's left out.)
+ vec![
+ StandardItem { label: "Open".into(), activate: Box::new(|t: &mut Tray| t.send(TrayAction::Open)), ..Default::default() }.into(),
+ StandardItem { label: "About".into(), activate: Box::new(|t: &mut Tray| t.send(TrayAction::About)), ..Default::default() }.into(),
+ StandardItem { label: "Restart".into(), activate: Box::new(|t: &mut Tray| t.send(TrayAction::Restart)), ..Default::default() }.into(),
+ MenuItem::Separator,
+ StandardItem { label: "Quit".into(), activate: Box::new(|t: &mut Tray| t.send(TrayAction::Quit)), ..Default::default() }.into(),
+ ]
+ }
+ /// A panel restart takes the watcher away for a moment: keep the
+ /// service waiting, and tell the app so a hidden window comes back.
+ fn watcher_offline(&self, _reason: ksni::OfflineReason) -> bool {
+ self.send(TrayAction::TrayDown);
+ true
+ }
+ fn watcher_online(&self) {
+ self.send(TrayAction::TrayUp);
+ }
+ }
+
+ /// RustCord's icon at the sizes panels ask for. A host scales whatever it
+ /// gets, but a few exact sizes stay crisp.
+ fn icon() -> Vec<ksni::Icon> {
+ static ICON: OnceLock<Vec<ksni::Icon>> = OnceLock::new();
+ ICON.get_or_init(|| {
+ let img = match image::load_from_memory(include_bytes!("../assets/icon-256.png")) {
+ Ok(img) => img,
+ Err(e) => {
+ log::warn!("tray: couldn't decode the icon ({e})");
+ return Vec::new();
+ }
+ };
+ [16u32, 22, 24, 32, 48]
+ .into_iter()
+ .map(|size| {
+ let img = img.resize_exact(size, size, image::imageops::FilterType::Lanczos3).into_rgba8();
+ let (width, height) = img.dimensions();
+ let mut data = img.into_vec();
+ // ksni wants ARGB32 in network byte order; image gives RGBA.
+ for pixel in data.as_chunks_mut::<4>().0 {
+ pixel.rotate_right(1);
+ }
+ ksni::Icon { width: width as i32, height: height as i32, data }
+ })
+ .collect()
+ })
+ .clone()
+ }
+
+ /// Start the tray icon. Picks arrive on the returned channel. `None` when
+ /// the desktop has no StatusNotifier host.
+ pub fn start(ctx: eframe::egui::Context) -> Option<Receiver<TrayAction>> {
+ use ksni::blocking::TrayMethods;
+ let (tx, rx) = std::sync::mpsc::channel();
+ match (Tray { tx, ctx }).spawn() {
+ Ok(handle) => {
+ *TRAY.get_or_init(|| Mutex::new(None)).lock().ok()? = Some(handle);
+ log::info!("tray: Linux status notifier started");
+ Some(rx)
+ }
+ Err(e) => {
+ // GNOME without its AppIndicator extension is the usual case.
+ log::info!("tray: no notification-area icon on this desktop ({e})");
+ None
+ }
+ }
+ }
+
+ /// Take the icon away before exiting.
+ pub fn remove() {
+ if let Some(handle) = TRAY.get().and_then(|t| t.lock().ok()).and_then(|mut slot| slot.take()) {
+ let _ = handle.shutdown();
+ }
+ }
+}
+
/// What the taskbar button's badge shows.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Badge {
diff --git a/apps/rustcord/src/ui/mod.rs b/apps/rustcord/src/ui/mod.rs
index bd12a1f..98dfbd5 100644
--- a/apps/rustcord/src/ui/mod.rs
+++ b/apps/rustcord/src/ui/mod.rs
@@ -129,11 +129,12 @@ impl RustCord {
let c = if b.hovered() && cmd == 0 { Color32::WHITE } else { t.interactive_normal };
paint_caption_glyph(ui.painter(), ui.painter().round_pos_to_pixels(r.center()), cmd, maximized, c);
if b.on_hover_text(tip).clicked() {
- ctx.send_viewport_cmd(match cmd {
- 0 => ViewportCommand::Close,
- 1 => ViewportCommand::Maximized(!maximized),
- _ => ViewportCommand::Minimized(true),
- });
+ match cmd {
+ 0 if self.prefs.close_to_tray && self.tray_available() => self.hide_to_tray(ctx),
+ 0 => ctx.send_viewport_cmd(ViewportCommand::Close),
+ 1 => ctx.send_viewport_cmd(ViewportCommand::Maximized(!maximized)),
+ _ => ctx.send_viewport_cmd(ViewportCommand::Minimized(true)),
+ }
}
}
let main = self.screen == Screen::Main;
diff --git a/apps/rustcord/src/ui/settings.rs b/apps/rustcord/src/ui/settings.rs
index 2eff9fb..014f4c1 100644
--- a/apps/rustcord/src/ui/settings.rs
+++ b/apps/rustcord/src/ui/settings.rs
@@ -546,6 +546,10 @@ const fn page(tab: SettingsTab, label: &'static str, icon: &'static str, subs: &
}
/// The sidebar, as Discord's (2026): group, pages, each page's sections.
+/// System's sections. Discord's General (what the title bar's X does) is on
+/// Linux only for now (see `RustCord::tray_available`).
+const SYSTEM_SECTIONS: &[&str] = if cfg!(target_os = "linux") { &["General", "Custom Keybinds", "Default Keybinds"] } else { &["Custom Keybinds", "Default Keybinds"] };
+
const NAV: &[(&str, &[Page])] = &[
(
"General",
@@ -572,7 +576,7 @@ const NAV: &[(&str, &[Page])] = &[
page(SettingsTab::VoiceVideo, "Voice & Video", "voice", &["Voice", "Camera", "Streaming", "Sounds", "Soundboard", "Advanced"]),
page(SettingsTab::Appearance, "Appearance", "appearance", &["Theme", "App Icon", "Messages", "Chat Box", "Typing Effects", "Search", "Streamer Mode"]),
page(SettingsTab::Accessibility, "Accessibility", "accessibility", &["Text Readability", "Visual Density", "Colour & Contrast", "Reduced Motion", "Audio & Screen Reader"]),
- page(SettingsTab::System, "System", "system", &["Custom Keybinds", "Default Keybinds"]),
+ page(SettingsTab::System, "System", "system", SYSTEM_SECTIONS),
page(SettingsTab::Language, "Language & Time", "language", &[]),
],
),
@@ -2731,7 +2735,20 @@ impl RustCord {
}
fn system_tab(&mut self, ui: &mut Ui, t: &Theme) {
- section(ui, t, 0, "Custom Keybinds");
+ // Discord's General: what the title bar's X does (Linux only for now).
+ let general = usize::from(cfg!(target_os = "linux"));
+ if general == 1 {
+ section(ui, t, 0, "General");
+ if self.tray_available() {
+ if let Some(v) = toggle_row(ui, t, "Minimize RustCord to System Tray", "Clicking X minimizes RustCord instead of closing it completely.", self.prefs.close_to_tray) {
+ self.prefs.close_to_tray = v;
+ self.save_prefs();
+ }
+ } else {
+ note(ui, t, "Clicking X closes RustCord: this desktop doesn't show notification-area icons.");
+ }
+ }
+ section(ui, t, general, "Custom Keybinds");
note(ui, t, "Keybinds are custom keyboard shortcuts that let you perform specific actions without needing to click through menus. The Push to Talk shortcut works in any app.");
if let Some(v) = toggle_row(ui, t, "Push to Talk", "Send your microphone only while the shortcut is held (Voice & Video → Input Mode).", self.voice_ui.prefs.push_to_talk) {
self.voice_ui.prefs.push_to_talk = v;
@@ -2739,7 +2756,7 @@ impl RustCord {
}
self.ptt_shortcut_row(ui, t);
- section(ui, t, 1, "Default Keybinds");
+ section(ui, t, general + 1, "Default Keybinds");
note(ui, t, "RustCord's built-in keyboard shortcuts.");
let groups: &[(&str, &[(&str, &[&str])])] = &[
(