Skip to content

Add click-to-focus: clicking notification brings Windows Terminal to foreground#6

Merged
congmnguyen merged 1 commit into
mainfrom
click-to-focus-wt
Feb 25, 2026
Merged

Add click-to-focus: clicking notification brings Windows Terminal to foreground#6
congmnguyen merged 1 commit into
mainfrom
click-to-focus-wt

Conversation

@congmnguyen
Copy link
Copy Markdown
Owner

Summary

  • Replaces Start-Sleep -Seconds 6 with a WinForms message loop (Application.Run()) so click events can be handled
  • Adds SetForegroundWindow and ShowWindow (SW_RESTORE) to the Win32 P/Invoke class
  • BalloonTipClicked handler restores Windows Terminal (if minimised) and brings it to the foreground
  • BalloonTipClosed handler exits the loop cleanly on timeout or dismiss
  • Updates docs: How It Works, Result, and Troubleshooting sections

Test plan

  • Trigger a PermissionRequest (e.g. run a command that needs approval) and alt-tab away
  • Balloon tip appears as before
  • Clicking the balloon switches focus to Windows Terminal
  • Dismissing/ignoring the balloon still exits cleanly after ~5 s

…foreground

Replace Start-Sleep with a WinForms message loop so BalloonTipClicked can be
handled. On click, ShowWindow (SW_RESTORE) + SetForegroundWindow focus the
Windows Terminal window immediately.
Copilot AI review requested due to automatic review settings February 25, 2026 08:22
@congmnguyen congmnguyen merged commit f1b3b80 into main Feb 25, 2026
2 checks passed
@congmnguyen congmnguyen deleted the click-to-focus-wt branch February 25, 2026 08:22
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the Windows notification system for Claude Code on WSL2 by adding click-to-focus functionality. When a user clicks the balloon notification, Windows Terminal is automatically restored and brought to the foreground, eliminating the need to manually switch windows.

Changes:

  • Replaced sleep-based timing with a WinForms message loop to enable event handling
  • Added Win32 API functions (SetForegroundWindow, ShowWindow) for window manipulation
  • Implemented BalloonTipClicked and BalloonTipClosed event handlers to focus Windows Terminal and exit gracefully
  • Updated documentation to reflect the new architecture and added troubleshooting guidance for click-to-focus issues

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread claude-notify.md
\$notification.add_BalloonTipClicked({
\$wt = Get-Process -Name 'WindowsTerminal' -ErrorAction SilentlyContinue | Select-Object -First 1
if (\$wt -and \$wt.MainWindowHandle -ne [IntPtr]::Zero) {
[Win32]::ShowWindow(\$wt.MainWindowHandle, 9) | Out-Null
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magic number 9 should be documented or replaced with a named constant for clarity. In Win32 API, 9 corresponds to SW_RESTORE, which restores a minimized window. Consider adding a comment explaining this value, such as: [Win32]::ShowWindow(\$wt.MainWindowHandle, 9) | Out-Null # SW_RESTORE

Suggested change
[Win32]::ShowWindow(\$wt.MainWindowHandle, 9) | Out-Null
[Win32]::ShowWindow(\$wt.MainWindowHandle, 9) | Out-Null # SW_RESTORE

Copilot uses AI. Check for mistakes.
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