Skip to content

fix(windows): make auto-paste actually restore the target window - #269

Merged
omercelikdev merged 1 commit into
mainfrom
fix/windows-paste-foreground
Jul 20, 2026
Merged

fix(windows): make auto-paste actually restore the target window#269
omercelikdev merged 1 commit into
mainfrom
fix/windows-paste-foreground

Conversation

@omercelikdev

Copy link
Copy Markdown
Owner

The bug

On Windows, paste often lands nowhere — the headline reason the app "feels broken" there. simulate_paste hides QlipLab's own window and then calls a bare SetForegroundWindow on the previously-focused window. But by that point QlipLab is no longer the foreground process, so Windows' foreground lock denies the call and merely flashes the taskbar button. The synthesized Ctrl+V then goes to whatever the OS happened to leave focused.

The fix

New restore_foreground_window() brings the target back reliably, the way Ditto does:

  • IsWindow guard against a stale handle
  • SW_RESTORE if the target was minimized
  • AllowSetForegroundWindow + AttachThreadInput to both the outgoing foreground thread and the target's thread, so the foreground-lock check treats the request as cooperating rather than a background grab
  • verify with GetForegroundWindow, retry once, then settle before Ctrl+V

macOS and Linux paths are unchanged.

Verification

Win32 signatures checked against windows 0.61.3 source (AttachThreadInput lives in Win32::System::Threading, already an enabled feature — no Cargo.toml change needed). Full cargo check --target x86_64-pc-windows-msvc can't run from macOS (the ring C dep won't cross-compile without the Windows SDK), so the CI Windows job is the real compile gate, and runtime behavior needs a check on an actual Windows machine.

🤖 Generated with Claude Code

On Windows, simulate_paste hid QlipLab's own window and then called a bare
SetForegroundWindow on the previously-focused window. By that point QlipLab is
no longer the foreground process, so Windows' foreground lock denies the call
and merely flashes the taskbar button — the synthesized Ctrl+V then lands
nowhere, making paste look broken.

Add restore_foreground_window(), which brings the target back reliably the way
Ditto does:
- IsWindow guard against a stale handle
- SW_RESTORE if the target was minimized
- AllowSetForegroundWindow + AttachThreadInput to both the outgoing foreground
  thread and the target's thread, so the foreground-lock check treats the
  request as cooperating
- verify via GetForegroundWindow and retry once, then settle before Ctrl+V

macOS/Linux paths are unchanged. Win32 signatures verified against
windows 0.61.3 (AttachThreadInput lives in Win32::System::Threading, already
enabled — no new crate feature needed).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@omercelikdev
omercelikdev merged commit d3df1ae into main Jul 20, 2026
5 of 6 checks passed
@omercelikdev
omercelikdev deleted the fix/windows-paste-foreground branch July 20, 2026 21:18
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