DioxusLabs / DioxusLabs/dioxus
Add config option to disable window show/focus when tray icon is clicked
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
When an app uses a tray icon (status bar on macOS, system tray on Windows/Linux) with a context menu, left-clicking the tray icon currently **always** shows and focuses the main window. This is implemented in `handle_tray_icon_event` in `packages/desktop/src/app.rs`:
```rust
if button == tray_icon::MouseButton::Left {
for webview in self.webviews.values() {
webview.desktop_context.window.set_visible(true);
webview.desktop_context.window.set_focus();
}
}
```
For many apps this is desired, clicking the tray icon should bring the window to the front. But for **tray/menu bar apps** (apps that live primarily in the status bar with a dropdown menu), the expected behavior is different: clicking the tray icon should show only the context menu, not activate the main window. The window should only appear when the user explicitly chooses "Show Window" (or equivalent) from the menu.
**Current behavior:** Click tray icon → menu appears + window pops up and steals focus
**Desired behavior (opt-in):** Click tray icon → menu appears only; window stays hidden until user selects "Show Window" from the menu
There is no way to opt out of this behavior today. Apps cannot override it from user code because `handle_tray_icon_event` runs before any `use_tray_icon_event_handler` and unconditionally shows the window.
**Related:** I searched for existing issues around tray icon, window focus, and activation and didn't find a duplicate. #3635 (tray icon on macOS not working) and #4495 (use_tray_menu_event_handler) are different concerns.
---
## Implement Suggestion
Add a `Config` option to make this behavior configurable:
**New method:** `Config::with_tray_icon_show_window_on_click(show: bool)`
- Default: `true` (preserves current behavior, no breaking change)
- When `false`: tray icon left-click does not show or focus the window; only the context menu appears
**Implementation:**
1. Add `tray_icon_show_window_on_click: bool` to `Config` (default `true`)
2. Store it in `App` when the app is created
3. In `handle_tray_icon_event`, only call `set_visible(true)` and `set_focus()` when `self.tray_icon_show_window_on_click` is true
**Usage example:**
```rust
Config::new()
.with_close_behaviour(WindowCloseBehaviour::WindowHides)
.with_tray_icon_show_window_on_click(false) // menu only, no window focus
.with_window(window_builder)
```
Other desktop frameworks allow apps to control this via activation policy or similar config. The tray-icon crate itself doesn't handle window focus, it's dioxus-desktop that adds this behavior, so it makes sense for dioxus-desktop to expose a config for it.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.