Skip to content

Initialise GTK before the Linux tray, run headless if it cannot start - #30

Open
onyxhq-dev wants to merge 1 commit into
OpenMouse-Project:mainfrom
onyxhq-dev:fix/linux-gtk-init
Open

onyxhq-dev wants to merge 1 commit into
OpenMouse-Project:mainfrom
onyxhq-dev:fix/linux-gtk-init

Conversation

@onyxhq-dev

@onyxhq-dev onyxhq-dev commented Oct 18, 2026 •

Copy link
Copy Markdown

Fixes #26.

On Linux, tray-icon builds its menu with GTK, which panics on first use unless gtk::init() ran on the main thread. Bridge never called it, so the tray panel panicked ("GTK has not been initialized"), relaunched, and after a few quick relaunches the whole process exited, taking the HTTP API, HID and game profiles with it.

  • Call gtk::init() before the tray panel starts (Linux only, new gtk = "0.18" dependency; gtk 0.18.2 is already in Cargo.lock via tray-icon).
  • If GTK cannot start, take the existing headless path instead of crash-looping.

Tested in an Ubuntu 24.04 container under a headless Weston Wayland session (WAYLAND_DISPLAY set, no DISPLAY):

  • Before: same output as the issue, panic then relaunch generation 1, 2, 3.
  • After: runs with no panic and no relaunch.
  • Unusable Wayland socket: logs "GTK could not start" and keeps running headless.

Not tested: a real KDE or GNOME session. Headless Weston has no tray host or input device, so I could not check the tray icon or its menu. The tray menu may also need the GTK loop pumped on some desktops; that is not part of this change. A build from this branch needs a try on a real desktop, ideally by the reporter.

Summary by CodeRabbit

  • Bug Fixes
    • On Linux, the app now checks that GTK starts successfully before attempting to create the tray menu. If GTK startup fails, it continues in headless mode instead of trying to open an unavailable tray.
    • The warning shown when desktop support is unavailable now clarifies that both a display environment and successful GTK startup are required.

tray-icon builds its menu with GTK, which panics on first use unless gtk::init() ran on the main thread. On Wayland the tray panel panicked, relaunched and eventually exited, taking the HTTP API with it. Initialise GTK first and fall back to headless mode when it fails. Fixes OpenMouse-Project#26.
@github-actions github-actions Bot added area: native Native bridge and platform services area: dependencies Dependency manifests and lockfiles labels Oct 18, 2026
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: OpenMouse-Project/OpenMouse-Bridge/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 819087fe-36a2-46ed-9baf-fc5b08de65de
📥 Commits

Reviewing files that changed from the base of the PR and between a197906 and bd042fc.

⛔ Files ignored due to path filters: 1
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing: 2
  • Cargo.toml
  • src/desktop.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

📝 Walkthrough

On Linux, GUI availability now requires a display variable and successful GTK initialization. If initialization fails, the application logs a warning and uses the headless path. Other platforms retain their existing GUI availability behavior.

Changes: Linux GUI startup

Layer / File(s) Summary
GTK initialization and GUI fallback
Cargo.toml, src/desktop.rs
Adds the Linux gtk dependency. Linux GUI availability now checks for a display variable and initializes GTK. If GTK initialization fails, the application logs a warning and uses the headless path.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: snekxs

Merge Risk: 🟡 Moderate · up to bd042

Linux users may see the tray but be unable to use its actions; integrate GTK event processing before merging.

### Architecture Summary

Architecture risk: 🟡 Medium · up to bd042

The change affects 2 systems.

Changed systems: src, Cargo.toml

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 1 changed file maps to changed impact.
  • observed — Cargo.toml (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in Cargo.toml: Adds the Linux-targeted gtk dependency at version 0.18; the accompanying comment states it is needed to initialize GTK on the main thread before building the tray-icon menu.
  • observed — Modified behavior in src/desktop.rs: On Linux, GUI availability now requires WAYLAND_DISPLAY or DISPLAY to be set and gtk_ready() to succeed; other platforms still report GUI availability as true.
  • observed — Modified behavior in src/desktop.rs: Adds Linux-only gtk_ready, which initializes GTK on the current thread, returns true on success, and logs a warning and returns false on failure.
  • observed — Modified behavior in src/desktop.rs: The headless fallback warning now says the tray requires both a display variable and GTK startup; the previous warning mentioned only the display variable.

Reliability and maintainability

  • inferred — Risk-relevant change factors for src: blast_radius_1; blast_radius_2; direct_dependents_1
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main changes: initializing GTK before the Linux tray and using headless mode when GTK cannot start.
Linked Issues check Passed Issue #26 requires GTK initialization before Linux tray startup and prevention of restart loops after GTK failure. src/desktop.rs now requires successful GTK initialization before the tray path and …
Out of Scope Changes check Passed The Linux-only gtk = "0.18" dependency and the src/desktop.rs changes directly support issue #26. The changes only control GTK startup and the existing headless fallback. No unrelated change is es…
Full details: Linked Issues check

Explanation

Issue #26 requires GTK initialization before Linux tray startup and prevention of restart loops after GTK failure. src/desktop.rs now requires successful GTK initialization before the tray path and uses the existing headless path when initialization fails. The reported headless Weston and unusable-socket runs show no panic or relaunch. These changes address the linked coding requirements. The lack of a real KDE or GNOME test does not show a coding requirement failure.

Full details: Out of Scope Changes check

Explanation

The Linux-only gtk = "0.18" dependency and the src/desktop.rs changes directly support issue #26. The changes only control GTK startup and the existing headless fallback. No unrelated change is established by the pull request summary.

Full details: Docstring Coverage

Explanation

Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: dependencies Dependency manifests and lockfiles area: native Native bridge and platform services

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Program errors out and restarts several times trying to display the window

1 participant