Skip to content

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

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

osiewicz merged 1 commit into
zed-industries:mainfrom
HuaGu-Dragon:reset-modifier

Conversation

@HuaGu-Dragon

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

Copy link
Copy Markdown
Contributor

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

zed-industries-bot commented Mar 23, 2026

Copy link
Copy Markdown
Contributor
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
kathbigra pushed a commit to kathbigra/zed that referenced this pull request May 10, 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

<!-- Check before requesting review: -->
- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [x] 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.

<details>
  <summary>Video</summary>
  


https://github.com/user-attachments/assets/b545178c-b360-4e2b-8d60-d6f95a0b4b79



https://github.com/user-attachments/assets/bc4d41eb-6f42-4040-a588-0fc46c576db7


</details>

Closes zed-industries#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.
@HuaGu-Dragon
HuaGu-Dragon deleted the reset-modifier branch May 19, 2026 05:28
Zenor27 pushed a commit to Zenor27/zed that referenced this pull request Jul 4, 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

<!-- Check before requesting review: -->
- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [x] 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.

<details>
  <summary>Video</summary>
  


https://github.com/user-attachments/assets/b545178c-b360-4e2b-8d60-d6f95a0b4b79



https://github.com/user-attachments/assets/bc4d41eb-6f42-4040-a588-0fc46c576db7


</details>

Closes zed-industries#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.
jonx pushed a commit to jonx/zed-aros that referenced this pull request Jul 17, 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

<!-- Check before requesting review: -->
- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [x] 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.

<details>
  <summary>Video</summary>
  


https://github.com/user-attachments/assets/b545178c-b360-4e2b-8d60-d6f95a0b4b79



https://github.com/user-attachments/assets/bc4d41eb-6f42-4040-a588-0fc46c576db7


</details>

Closes zed-industries#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.
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 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

<!-- Check before requesting review: -->
- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [x] 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.

<details>
  <summary>Video</summary>
  


https://github.com/user-attachments/assets/b545178c-b360-4e2b-8d60-d6f95a0b4b79



https://github.com/user-attachments/assets/bc4d41eb-6f42-4040-a588-0fc46c576db7


</details>

Closes zed-industries#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.
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