Skip to content

Push window resize and scale factor messages to bevy_window_events#24046

Merged
alice-i-cecile merged 5 commits intobevyengine:mainfrom
ProffDea:window-event
May 4, 2026
Merged

Push window resize and scale factor messages to bevy_window_events#24046
alice-i-cecile merged 5 commits intobevyengine:mainfrom
ProffDea:window-event

Conversation

@ProffDea
Copy link
Copy Markdown
Contributor

I was initially using MessageReader<WindowResized> in my system for my app but once my system grew to use more and more window events, I refactored to using MessageReader<WindowEvent> and matching on its variants. This is where I ran into the issue of the WindowEvent::WindowResized case never matching.

When making this PR, I noticed WindowEvent::WindowBackendScaleFactorChanged and WindowEvent::WindowScaleFactorChanged had the same issue.

Objective

Fixes #15268

Solution

Instead of writing into MessageWriter<WindowResized>, MessageWriter<WindowBackendScaleFactorChanged> and MessageWriter<WindowScaleFactorChanged>, push into bevy_window_events where it gets sent to the forward_bevy_events function for syncing the messages.

Testing

I made local modifications to the window_resizing example to use a MessageReader<WindowEvent> instead of MessageReader<WindowResized> like so:

fn on_resize_system(
    mut text: Single<&mut Text, With<ResolutionText>>,
    mut resize_reader: MessageReader<WindowEvent>,
) {
    for e in resize_reader.read() {
        if let WindowEvent::WindowResized(e) = e {
            // When resolution is being changed
            text.0 = format!("{:.1} x {:.1}", e.width, e.height);
        }
    }
}

I ran this example on linux wayland.

@github-actions
Copy link
Copy Markdown
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide, as well as our policy regarding AI usage, and we look forward to reviewing your pull request shortly ✨

@alice-i-cecile alice-i-cecile added A-Windowing Platform-agnostic interface layer to run your app in C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Needs-Review Needs reviewer attention (from anyone!) to move forward C-Code-Quality A section of code that is hard to understand or change C-Bug An unexpected or incorrect behavior and removed C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Apr 30, 2026
@alice-i-cecile alice-i-cecile requested a review from kfc35 April 30, 2026 21:48
@alice-i-cecile alice-i-cecile removed the C-Code-Quality A section of code that is hard to understand or change label Apr 30, 2026
Comment thread crates/bevy_winit/src/system.rs Outdated
@alice-i-cecile alice-i-cecile changed the title Push window resize and scale factor to bevy_window_events Push window resize and scale factor messages to bevy_window_events Apr 30, 2026
Copy link
Copy Markdown
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

Oh, that explains this bug! Very good fix.

Three things to fix up before we merge:

  1. A small omission in the other code path, see comment.
  2. setup_react_to_scale_factor_change_test_app should more realistic (it doesn't check WindowEvent).
  3. A similar test (or redesigned test) for window resizing.

@alice-i-cecile alice-i-cecile added X-Uncontroversial This work is generally agreed upon D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Apr 30, 2026
@ProffDea ProffDea requested a review from alice-i-cecile April 30, 2026 23:36
@alice-i-cecile alice-i-cecile added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels May 1, 2026
Copy link
Copy Markdown
Contributor

@kfc35 kfc35 left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you for your first contribution 🎊

@kfc35 kfc35 added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels May 1, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue May 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 1, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue May 1, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 1, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue May 2, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 2, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue May 3, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 3, 2026
@alice-i-cecile alice-i-cecile added this pull request to the merge queue May 3, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 4, 2026
@alice-i-cecile
Copy link
Copy Markdown
Member

CI failure in https://github.com/bevyengine/bevy/actions/runs/25295357200/job/74153180619 is real. Let us know if you'd like help; this is quite obscure :)

@ProffDea
Copy link
Copy Markdown
Contributor Author

ProffDea commented May 4, 2026

Sorry about that, I think it's fixed. Thanks for pointing me in the right direction

@alice-i-cecile alice-i-cecile added this pull request to the merge queue May 4, 2026
Merged via the queue into bevyengine:main with commit 739b1e5 May 4, 2026
38 checks passed
cart pushed a commit to chronicl/bevy that referenced this pull request May 4, 2026
…evyengine#24046)

I was initially using `MessageReader<WindowResized>` in my system for my
app but once my system grew to use more and more window events, I
refactored to using `MessageReader<WindowEvent>` and matching on its
variants. This is where I ran into the issue of the
`WindowEvent::WindowResized` case never matching.

When making this PR, I noticed
`WindowEvent::WindowBackendScaleFactorChanged` and
`WindowEvent::WindowScaleFactorChanged` had the same issue.

# Objective

Fixes bevyengine#15268

## Solution

Instead of writing into `MessageWriter<WindowResized>`,
`MessageWriter<WindowBackendScaleFactorChanged>` and
`MessageWriter<WindowScaleFactorChanged>`, push into
`bevy_window_events` where it gets sent to the `forward_bevy_events`
function for syncing the messages.

## Testing

I made local modifications to the `window_resizing` example to use a
`MessageReader<WindowEvent>` instead of `MessageReader<WindowResized>`
like so:
```rs
fn on_resize_system(
    mut text: Single<&mut Text, With<ResolutionText>>,
    mut resize_reader: MessageReader<WindowEvent>,
) {
    for e in resize_reader.read() {
        if let WindowEvent::WindowResized(e) = e {
            // When resolution is being changed
            text.0 = format!("{:.1} x {:.1}", e.width, e.height);
        }
    }
}
```
I ran this example on linux wayland.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Windowing Platform-agnostic interface layer to run your app in C-Bug An unexpected or incorrect behavior D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Uncontroversial This work is generally agreed upon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WindowResized events don't trigger

3 participants