Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add monitor_selection to window #8178

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jakobhellermann
Copy link
Contributor

Objective

make

    commands.spawn(Window {
        monitor_selection: MonitorSelection::Index(1),
        mode: WindowMode::BorderlessFullscreen,
        ..default()
    });

work

Solution

  • add monitor_selection field to Window
  • respect that solution for non-Windowed modes

Open questions

  • should WindowPosition::Centered(MonitorSelection) change? we could
    1. remove the MonitorSelection and always use the MonitorSelection from the window itself
    2. keep MonitorSelection so that you can spawn on Primary, then later move to Centered(MonitorSelection::At(1)).
  • should we try to make changing the selection work after the window is spawned by moving it to another monitor? I don't know how to do this with winit.

Changelog

  • add monitor_selection to Window. Windows can now specify which monitor they want to be spawned on.

Migration Guide

  • nnothing if we keep WindowPosition::Centered(MonitorSelection)

@jakobhellermann jakobhellermann added C-Enhancement A new feature A-Windowing Platform-agnostic interface layer to run your app in labels Mar 23, 2023
Copy link
Contributor

@paul-hansen paul-hansen left a comment

Choose a reason for hiding this comment

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

I think I would prefer putting MonitorSelection on the WindowMode variants that it applies to instead of having it be top level.

E.g.

pub enum WindowMode {
    Windowed,
    BorderlessFullscreen(MonitorSelection),
    SizedFullscreen(MonitorSelection),
    Fullscreen(MonitorSelection),
}

This makes it more clear what it affects. For example, if the monitor selection is a top level field, does it affect WindowPosition::at too? What about WindowPosition::Automatic ? It seems like it would make sense that automatic would automatically position the window on the selected window, but currently in this PR it still positions it on the main monitor, and WindowPosition::at is also relative to the primary monitor.

I also think we really need to support being able to change which monitor fullscreen is using at runtime, this is something we need the user to be able to configure, we have no idea which monitor they want to use if they don't want to use the primary. Could do this in a PR later if that's easier though.

Comment on lines +3 to +17
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, bevy::window::close_on_esc)
.add_systems(Startup, spawn_window)
.run();
}

fn spawn_window(mut commands: Commands) {
commands.spawn(Window {
monitor_selection: MonitorSelection::Index(1),
mode: WindowMode::BorderlessFullscreen,
..default()
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Two suggestions for the example:

  • Set the monitor of the primary window instead of creating a second window
  • Add our standard bevy logo scene. Having something shown makes it clear that the example is working as intended.

Honestly my brain thought my second monitor randomly turned off when I ran this example the first time since the first bevy window showed up on the main screen windowed (thought this was the example) and the full-screen window covered my secondary monitor with black.

Suggested change
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, bevy::window::close_on_esc)
.add_systems(Startup, spawn_window)
.run();
}
fn spawn_window(mut commands: Commands) {
commands.spawn(Window {
monitor_selection: MonitorSelection::Index(1),
mode: WindowMode::BorderlessFullscreen,
..default()
});
}
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
monitor_selection: MonitorSelection::Index(1),
mode: WindowMode::BorderlessFullscreen,
..default()
}),
..default()
}))
.add_systems(Update, bevy::window::close_on_esc)
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
commands.spawn(SpriteBundle {
texture: asset_server.load("branding/icon.png"),
..default()
});
}

@irate-devil
Copy link
Contributor

irate-devil commented Mar 23, 2023

This was added before but was yoten by windows-as-entities. For reference: #5878

Things are trickier this time around with how Window is supposed to represent the active state of the window.

Monitor selection 2: electric boogaloo

@paul-hansen
Copy link
Contributor

paul-hansen commented Mar 23, 2023

Ah yeah that PR has more changes that would make this more of a complete solution. E.g. WindowPosition::at becomes relative to the monitor. I could be okay with that. I still think setting it on variants like WindowMode::Fullscreen(monitor) could make it more clear what it applies to and when though.

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-Enhancement A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants