Skip to content

Fix Alt modifier stuck after Alt-Tab on Windows#52220

Merged
osiewicz merged 1 commit intozed-industries:mainfrom
HuaGu-Dragon:reset-modifier
Apr 17, 2026
Merged

Fix Alt modifier stuck after Alt-Tab on Windows#52220
osiewicz merged 1 commit intozed-industries:mainfrom
HuaGu-Dragon:reset-modifier

Conversation

@HuaGu-Dragon
Copy link
Copy Markdown
Contributor

@HuaGu-Dragon HuaGu-Dragon commented Mar 23, 2026

Context

Fixes a bug on Windows where the Alt modifier key becomes stuck in the pressed state after using Alt-Tab to switch away from and back to the Zed application.

Root Cause

In crates/gpui_windows/src/events.rs, when the window loses focus during Alt-Tab, the WM_KEYUP event for the Alt key is never delivered to the application. The pending modifier state in GPUI remains as alt=true. When the window regains focus, there is no synchronization point to reset this stale state.

How to Review

In handle_activate_msg() (WM_ACTIVATE handler), when the window is activated:

  1. Reset the cached modifier tracking state (last_reported_modifiers and last_reported_capslock set to None)
  2. Query the actual current modifier state from Windows using GetKeyState() APIs
  3. Dispatch a ModifiersChanged event with the true state to synchronize GPUI

Self-Review Checklist

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

I think it's difficult to add tests for this because it's platform-dependent, but I recorded a video for comparison — sorry I only have an anime‑style app to show the key presses.

Video
previous.mp4
after.mp4

Closes #45485

Release Notes:

  • Fixed Alt modifier key stuck after Alt-Tab on Windows. Modifier state is now synchronized when the window regains focus, ensuring correct key interpretation after window switching.

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Mar 23, 2026
@zed-codeowner-coordinator zed-codeowner-coordinator Bot requested review from a team, Anthony-Eid and osiewicz and removed request for a team March 23, 2026 15:12
@maxdeviant maxdeviant changed the title Fix: Alt modifier stuck after Alt-Tab on Windows Fix Alt modifier stuck after Alt-Tab on Windows Mar 23, 2026
@zed-industries-bot
Copy link
Copy Markdown
Contributor

zed-industries-bot commented Mar 23, 2026

Warnings
⚠️

This PR is missing release notes.

Please add a "Release Notes" section that describes the change:

Release Notes:

- Added/Fixed/Improved ...

If your change is not user-facing, you can use "N/A" for the entry:

Release Notes:

- N/A

Generated by 🚫 dangerJS against a9d1588

@osiewicz
Copy link
Copy Markdown
Member

Thank you!

@osiewicz osiewicz enabled auto-merge (squash) April 16, 2026 16:43
auto-merge was automatically disabled April 16, 2026 17:08

Head branch was pushed to by a user without write access

@HuaGu-Dragon
Copy link
Copy Markdown
Contributor Author

Hi @osiewicz

I noticed the CI failure was due to a git merge-base error after auto-merge. I've rebased the branch onto the latest main and force-pushed to ensure the common ancestor is clean.

Would you mind taking another look? I think the CI should pass now or let me know if any further action is needed on my side? Thanks!

@HuaGu-Dragon HuaGu-Dragon requested a review from osiewicz April 17, 2026 03:38
@osiewicz osiewicz merged commit 38270bc into zed-industries:main Apr 17, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code Action menu hidden after the editor

4 participants