Skip to content

feat(panel): close the panel when you click elsewhere - #113

Open
lmaoskript wants to merge 1 commit into
OpenMouse-Project:mainfrom
lmaoskript:feat/close-panel-on-click-outside
Open

lmaoskript wants to merge 1 commit into
OpenMouse-Project:mainfrom
lmaoskript:feat/close-panel-on-click-outside

Conversation

@lmaoskript

@lmaoskript lmaoskript commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

The tray panel now hides to the tray when you click anywhere outside it, like a popup.

This builds on #112 and includes its commit. Merge that one first; after it lands, this diff is just the last commit.

What changed:

  • The panel observes its window's activation and hides to the tray when it loses focus. This applies on Windows, macOS and the Wayland layer-shell panel. A normal Linux window (X11, or no layer-shell) keeps its taskbar behaviour and stays open.
  • Pressing the tray icon takes focus from the panel before the click arrives, so the panel would hide and then the toggle would open it straight back. A click on the icon within 500 ms of a focus-loss hide now leaves the panel closed.

On Wayland this only works if the panel got keyboard focus when it opened (the existing activation-token code, which also makes Escape work). If the compositor never gives it focus, clicking elsewhere leaves it open, as before.

Tested:

  • cargo fmt --check, cargo test --locked, and clippy with -D warnings pass on Linux.
  • No new unit test for the focus-loss path, since it needs a real window.
  • Not compiled for Windows or macOS here, and not tested in the running app yet.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Panels now hide automatically when they lose focus on supported tray-enabled platforms. On Linux, this behavior applies to panels using layer-shell.
  • Bug Fixes
    • Prevented a tray click immediately after a panel hides from focus loss from accidentally reopening or toggling the panel.

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The panel now hides when it loses activation on supported tray configurations. Tray clicks within 500 ms of a blur-triggered hide no longer toggle the panel. Double-clicks still issue Show.

Changes: Panel blur and tray interaction

Layer / File(s) Summary
Hide the panel on loss of activation
src/gpui_shell/mod.rs, src/gpui_shell/tray.rs
The initial panel and newly opened layer-shell panels register an activation observer. When blur hiding is supported and the panel becomes inactive, the observer hides it and records the time.
Filter tray clicks after blur hides
src/gpui_shell/tray.rs, src/gpui_shell/tray_linux.rs
Ordinary tray clicks use click_command, which suppresses a toggle within 500 ms of a blur-triggered hide. Linux tray activation sends a command only when one is returned. Double-clicks still send Show.

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

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Window
  participant Observer as hide_when_unfocused
  participant Support as tray hides_on_blur
  participant Hide as tray hide_on_blur
  participant Click as click_command
  Window->>Observer: becomes inactive
  Observer->>Support: check blur-hiding support
  Support-->>Observer: return support status
  Observer->>Hide: hide panel and record time when supported
  Click->>Click: suppress toggle within 500 ms of recorded hide
Loading

Suggested reviewers: snekxs

Merge Risk: Minimal · up to 15637

The panel now hides when it loses focus and ignores a tray click within 500 ms of that hide. No concrete merge-blocking defect was found. Windows and macOS behavior has not been tested on real systems, so a manual check there would still be useful.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "feat(panel): close the panel when you click elsewhere" matches the main change. The PR hides the tray panel when its window loses focus (blur), which is the same as closing it when the user…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat(panel): close the panel when you click elsewhere" matches the main change. The PR hides the tray panel when its window loses focus (blur), which is the same as closing it when the user clicks elsewhere. The title is specific and short. The 500 ms tray-click filter is a supporting detail, so the title does not need to cover it.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 66ba469 and 156379e.

Files selected for processing: 3

  • src/gpui_shell/mod.rs
  • src/gpui_shell/tray.rs
  • src/gpui_shell/tray_linux.rs

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

@github-actions github-actions Bot added type: enhancement PR title category: enhancement area: native Native bridge and platform services labels Nov 12, 2026
@snekxs

snekxs commented Nov 13, 2026

Copy link
Copy Markdown
Member

Thanks for this. Two things before it can merge:

1. Needs a rebase. #112 has landed on main (ee62fe1), but this branch still carries its original commit, so the diff shows ~197 lines instead of just the focus-loss change. Please rebase onto main so only the last commit remains.

2. Manual testing on Windows and macOS. The blur-to-hide path isn't covered by tests and CI only compiles it on those platforms. Could you confirm in the running app:

  • Clicking outside the panel hides it.
  • Clicking the tray icon while the panel is open closes it and doesn't immediately reopen it (the 500 ms click_command window).
  • Double-clicking the icon opens the panel and leaves it open (the skipped second "up" depends on event ordering that varies by platform).
  • On Windows, a panel opened from the tray actually receives focus. If it doesn't, outside-click-to-close never fires (this fails safe, the panel just stays open).

Minor, no change needed: if the panel blurs for an unrelated reason, a tray click within 500 ms is swallowed.

The panel_wanted_after logic and its test look good.

The tray panel now hides to the tray when it loses focus, like a popup,
on Windows, macOS and the Wayland layer-shell panel. A normal Linux
window (no layer-shell) keeps its taskbar behaviour and stays open.

Pressing the tray icon takes the panel's focus before the click arrives,
so a click on the icon within half a second of that hide leaves the
panel closed instead of toggling it straight back open.
@lmaoskript

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Rebased onto main, so it's just the focus-loss commit now.

I'm on Linux, so I can't test it on Windows or macOS, sorry. If someone with either of those could run through your checklist, that'd be great.

@lmaoskript
lmaoskript force-pushed the feat/close-panel-on-click-outside branch from 35222b7 to 156379e Compare November 15, 2026 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native bridge and platform services type: enhancement PR title category: enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants