linux: run as tray icon app with StatusNotifierItem#466
Open
inaiii wants to merge 2 commits into
Open
Conversation
Mirror the macOS menu bar behavior on Linux: closing the window hides it into the tray, the tray menu re-opens or quits the app, and LAN_MOUSE_HIDDEN=1 starts quietly into the tray. Implemented with ksni (StatusNotifierItem over D-Bus, no GTK3 dependency); desktops without an SNI host (e.g. GNOME without the AppIndicator extension) fall back to the previous close-means-quit behavior. The tray follows service ownership: when an external daemon (e.g. the systemd service) already owns the lan-mouse socket, the GUI runs as a plain client window without a tray icon, so quitting it does not suggest stopping the service. The socket is probed before spawning the service child, which is still spawned either way so it takes over if the external daemon exits right after. Launching the binary while an instance is running now re-presents the existing window instead of building a duplicate UI. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Keep run(local_commit) as the backward-compatible entry point and expose service ownership through documented RunOptions. Limit StatusNotifierItem dependencies and code paths to Linux while retaining the default window behavior on other platforms. Co-Authored-By: Codex (GPT-5) <noreply@openai.com>
18 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add Linux system-tray support through the StatusNotifierItem D-Bus specification, mirroring the existing macOS menu-bar application behavior:
LAN_MOUSE_HIDDEN=1starts the application quietly in the tray;Related to #291.
Windows notification-area support is intentionally being submitted separately,so this PR does not close the issue.
Behavior
The tray is owned by the graphical frontend rather than the daemon. A standalone daemon may run without a graphical session or session D-Bus, so making it own desktop UI would couple headless operation to the desktop environment. The frontend therefore creates the tray only when it also owns the service lifecycle.
The socket is probed before spawning the normal service child. The child is still spawned so it can win the bind if the external daemon exits during that startup race.
Implementation
ksnifor StatusNotifierItem registration without introducing a GTK3 tray dependency.target_os = "linux".gio::Applicationwhile the window is hidden so the frontend stays alive.lan_mouse_gtk::run(local_commit)API. The main binary uses documentedRunOptionsonly when it needs to describe external service ownership.LAN_MOUSE_HIDDENin the README.Desktop compatibility and fallback
StatusNotifierItem is supported by environments such as KDE Plasma, XFCE, and panels such as waybar. GNOME does not expose an SNI host by default and requires an extension such as AppIndicator and KStatusNotifierItem Support.
Registration failure is intentionally non-fatal. If no host is available, the window is always shown and closing it quits the application, preventing an unreachable hidden process.
The xdg background portal and automatic installation of desktop extensions are outside the scope of this PR.
Relationship to #407
This PR partially overlaps #407 in two limited startup areas:
GApplication::activatehandler presents an existing hidden window instead of constructing another window.It does not attempt to replace #407's broader daemon-reuse, reconnect, or cross-platform singleton design. If #407 lands first, the overlapping startup code can be reconciled during rebase while keeping the Linux tray behavior unchanged.
Test plan
Automated checks completed locally on Linux:
cargo fmt --all -- --checkcargo clippy --workspace --all-targets --all-features -- -D warningscargo test --workspace --all-featuresmainbranch, and its source jobs checked outfeature/linux-tray-iconate93f769.Manual smoke test environment:
7.1.3-arch1-226.04(8ed0da4)0.15.0, with itstraymodule enabledSmoke tests completed on this environment:
LAN_MOUSE_HIDDEN=1 lan-mousestarts both the frontend and child daemon without mapping a Lan Mouse window.Open Lan MouseandQuit Lan Mouseactions.lan-mouse daemonalready running, the GUI creates no tray icon and closing it leaves the daemon running.All manual smoke-test cases above were completed successfully.
No protocol or serialization changes are included, so no protocol version bump is required.