Skip to content

fix(win10): tray popup positioning and global hotkey reliability - #37

Merged
shanselman merged 2 commits into
masterfrom
fix/win10-tray-hotkey-reviewed
Mar 17, 2026
Merged

shanselman merged 2 commits into
masterfrom
fix/win10-tray-hotkey-reviewed

Conversation

@shanselman

Copy link
Copy Markdown
Collaborator

This is based on @xx299x's excellent work in #31, with additional fixes addressing all the Copilot review comments from that PR.

Original changes (by @xx299x)

  • Tray popup positioning: Clamp to monitor work area using AppWindow size with DPI fallback, so the menu doesn't overflow under the taskbar on Windows 10.
  • Global hotkey reliability: Register hotkey on the message-loop thread, dispatch UI creation to the UI thread, and force the Quick Send window to foreground/topmost.

Review fixes applied on top

  1. QuickSendDialog Closed handler race condition — Use ReferenceEquals so a late Closed event from an old dialog doesn't null the reference to a newly-created replacement.
  2. Check PostMessage/Wait results in Register() — Treat failures deterministically with clear logging instead of leaving _registered in an unknown state.
  3. EnsureMessageLoop recovery — Check IsAlive and _hwnd, reset and recreate the thread if the previous message loop died.
  4. Dispose cleanup — Join the thread before DestroyWindow so the loop exits cleanly; dispose ManualResetEventSlim instances.

Supersedes #31. Credit to @xx299x for the original investigation and fix — their commit is preserved with full authorship.

Improve Win10 tray context window positioning and make the Ctrl+Alt+Shift+C Quick Send hotkey reliably register and foreground the dialog.
Fix 1: QuickSendDialog Closed handler race condition (App.xaml.cs)
- Use ReferenceEquals to only null the field when the closing dialog
  is the current one, preventing a late Closed event from clearing
  a newly-created replacement dialog.

Fix 2: Check PostMessage/Wait results in Register() (GlobalHotkeyService.cs)
- Treat PostMessage failure or wait timeout as deterministic failures
  with clear logging, preventing _registered from being out of sync.

Fix 3: EnsureMessageLoop recovery (GlobalHotkeyService.cs)
- Check IsAlive and _hwnd, reset state and recreate the thread if
  the previous message loop died, so the service can recover.

Fix 4: Dispose cleanup (GlobalHotkeyService.cs)
- Join the thread before DestroyWindow so the loop can exit cleanly.
- Dispose ManualResetEventSlim instances to prevent resource leaks.

Co-authored-by: xx299x <[email protected]>
@shanselman
shanselman force-pushed the fix/win10-tray-hotkey-reviewed branch from 6608c88 to 98fa2d5 Compare March 17, 2026 01:15
@shanselman
shanselman merged commit 2e1d414 into master Mar 17, 2026
8 checks passed
@shanselman
shanselman deleted the fix/win10-tray-hotkey-reviewed branch March 17, 2026 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants