bevyengine / bevyengine/bevy

Game window opens off-screen on Windows

Open
#5,358 2 comments 0 reactions 0 assignees View on GitHub
A-Windowing C-Bug O-Windows
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version

0.7

## Relevant system information

Windows 10

## What you did

Running a game with 1920x1080 resolution on a 3440x1440 monitor, with `WindowDescriptor` being simply the following

```rust
App::new()
.insert_resource(WindowDescriptor {
width: 1920.0,
height: 1080.0,
..Default::default()
})
```

## What went wrong

The window opens about 1/3 from both top/left, and the bottom half of the game window is off-screen. Since there is no way to center the window (as in https://github.com/bevyengine/bevy/issues/4876) this is a bit problematic.

I don't think there's any current workaround that doesn't include hardcoding the position (which isn't desirable considering different screen resolutions). `winit` does allow centering the window rather easily

```rust
if let Some(monitor) = window.current_monitor() {
let screen_size = monitor.size();
let window_size = window.outer_size();

window.set_outer_position(winit::dpi::PhysicalPosition {
x: screen_size.width.saturating_sub(window_size.width) as f64 / 2.
+ monitor.position().x as f64,
y: screen_size.height.saturating_sub(window_size.height) as f64 / 2.
+ monitor.position().y as f64,
});
}```

The problem is that even with `winit`, the `monitor.size()` API can only be accessed via a `window`, which isn't available at the time `WindowDescriptor` is created.

Contributor guide

Open the contributing guide

Research direction

Start with WindowDescriptor creation and the winit current_monitor(), size(), outer_size(), and set_outer_position() APIs mentioned in the report. Trace how window placement is handled before a window exists, then verify that a 1920x1080 window is centered and fully visible on a 3440x1440 Windows display. Done means the behavior works without hardcoded monitor coordinates.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
desktop, game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.