Skip to content

Activate SuperPuTTY when an embedded terminal is clicked - #964

Open
greyhair-atx wants to merge 1 commit into
jimradford:masterfrom
greyhair-atx:fix/embedded-putty-focus
Open

Activate SuperPuTTY when an embedded terminal is clicked#964
greyhair-atx wants to merge 1 commit into
jimradford:masterfrom
greyhair-atx:fix/embedded-putty-focus

Conversation

@greyhair-atx

Copy link
Copy Markdown

Problem

When SuperPuTTY is behind another application, clicking directly inside an embedded PuTTY terminal can focus the child PuTTY process without activating the SuperPuTTY host window. Clicking SuperPuTTY-owned controls such as its menu bar activates the host normally.

The existing foreground-event handling was intended to cover this case, but foreground hooks were skipped for embedded windows with WS_DLGFRAME, which includes standard PuTTY windows. The out-of-context WinEvent callback also accessed WinForms controls directly instead of dispatching through the UI thread.

Changes

  • Register EVENT_SYSTEM_FOREGROUND for every successfully embedded terminal window, including framed PuTTY windows.
  • Dispatch foreground and title-change WinEvent handling onto the owning WinForms UI thread.
  • Recheck the foreground window before activating SuperPuTTY so delayed callbacks cannot steal focus.
  • Atomically suppress the one foreground notification generated when SuperPuTTY restores focus to the embedded terminal, preventing activation loops.
  • Clear suppression immediately if SetForegroundWindow fails.
  • Check SetWinEventHook results and log registration failures with the Win32 error.

Verification

  • Removed previous generated SuperPuTTY and unit-test executables/PDBs before building
  • Debug rebuild with Visual Studio 2026 MSBuild 18 / .NET Framework 4.8
  • Release rebuild with Visual Studio 2026 MSBuild 18 / .NET Framework 4.8
  • Unit-test project rebuild
  • Keyboard shortcut and local file-list tests: 4 passed, 0 failed
  • Timing-sensitive LocalViewModel test: passed when run independently
  • Manual verification: focus another application, then click inside an embedded PuTTY terminal and confirm SuperPuTTY becomes the active application while terminal keyboard focus is retained

The legacy LocalViewModel test failed once when run in the combined five-test group because its asynchronous property-change callback arrived after the assertion; it passed immediately when rerun alone. This behavior predates and is unrelated to the foreground-focus changes.

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.

1 participant