bevy icon indicating copy to clipboard operation
bevy copied to clipboard

WindowMode::Windowed to WindowMode::Fullscreen when resizable is false (ubuntu x11)

Open LLNet opened this issue 3 years ago • 8 comments

Bevy version

0.7.0

Relevant system information

  • cargo 1.62.1
  • rustc 1.62.1 (stable) operating system: Ubuntu 22.04 LTS (X11)
winit::platform_impl::platform::x11::window: Guessed window scale factor: 1 
`AdapterInfo { name: "NVIDIA GeForce RTX 3080", vendor: 4318, device: 8714, device_type: DiscreteGpu, backend: Vulkan }`

What you did

work:

use bevy::prelude::*;
use bevy::window::WindowMode;

fn main() {
    App::new()
        .insert_resource(ClearColor(Color::rgb(0.4, 0.4, 0.4)))
        .insert_resource(WindowDescriptor {
            resizable: true,
            mode: WindowMode::Windowed,
            width: 0.0,
            height: 0.0,
            ..Default::default()
        })
        .add_plugins(DefaultPlugins)
        .add_system(fullscreeen)
        .run();
}

fn fullscreeen(
    input: Res<Input<KeyCode>>,
    mut windows: ResMut<Windows>,
) {
    let window = windows
        .get_primary_mut()
        .unwrap();

    if input.pressed(KeyCode::LAlt) && input.just_pressed(KeyCode::Return) {
        if window.mode() == WindowMode::Windowed {
            println!("Changing to fullscreen");
            window.set_mode(WindowMode::Fullscreen);
        } else {
            println!("Changing to windowed");
            window.set_mode(WindowMode::Windowed);
        }
    }
}

not working:

use bevy::prelude::*;
use bevy::window::WindowMode;

fn main() {
    App::new()
        .insert_resource(ClearColor(Color::rgb(0.4, 0.4, 0.4)))
        .insert_resource(WindowDescriptor {
            resizable: false,
            mode: WindowMode::Windowed,
            width: 0.0,
            height: 0.0,
            ..Default::default()
        })
        .add_plugins(DefaultPlugins)
        .add_system(fullscreeen)
        .run();
}

fn fullscreeen(
    input: Res<Input<KeyCode>>,
    mut windows: ResMut<Windows>,
) {
    let window = windows
        .get_primary_mut()
        .unwrap();

    if input.pressed(KeyCode::LAlt) && input.just_pressed(KeyCode::Return) {
        if window.mode() == WindowMode::Windowed {
            println!("Changing to fullscreen");
            window.set_mode(WindowMode::Fullscreen);
        } else {
            println!("Changing to windowed");
            window.set_mode(WindowMode::Windowed);
        }
    }
}

What went wrong

only change between them is resizable true or false. if false app will jump around between two places on my screen. (if you will see what i mean with jump https://www.youtube.com/watch?v=Lplo9Nq3WVw) if true fullscreen work fine

What you expected to happen

i expected app resizable icons and user not can resize app longer - if resizable is false. i expected app to easy change to fullscreen - not funny jumps ;-)

sorry if my english is bad.

LLNet avatar Jul 29 '22 17:07 LLNet

Ah, so when the app is configured to not be resizable, you're noticing that the position on the screen moves to an arbitrary location (and then back again) when toggling fullscreen.

I generally wouldn't expect to be able to properly fullscreen an app with a resolution other than the resolution of my monitor if it cannot be resized. What happens if you make the resolution of the app match the resolution of your monitor?

alice-i-cecile avatar Jul 29 '22 17:07 alice-i-cecile

@alice-i-cecile

I generally wouldn't expect to be able to properly fullscreen an app with a resolution other than the resolution of my monitor if it cannot be resized. What happens if you make the resolution of the app match the resolution of your monitor?

WindowDescriptor {
            resizable: false,
            mode: WindowMode::Windowed,
            width: 3440.0,
            height: 1440.0,
            ..Default::default()
        }

and go to fullscreen - it work.

fn fullscreeen(
    input: Res<Input<KeyCode>>,
    mut windows: ResMut<Windows>,
) {
    let window = windows
        .get_primary_mut()
        .unwrap();

    if input.pressed(KeyCode::LAlt) && input.just_pressed(KeyCode::Return) {
        if window.mode() == WindowMode::Windowed {
            println!("Changing to fullscreen");
            window.set_resolution(3440.0, 1440.0);
            window.set_mode(WindowMode::Fullscreen);
        } else {
            println!("Changing to windowed");
            window.set_mode(WindowMode::Windowed);
            window.set_resolution(100.0, 200.0);
        }
    }
}

not sure it correct (set_resolution) but if it correct - it not working.

for me it more about logic - if you without width and height can make fullscreen if window is resizable = true. i expect same when it false.

but it maybe me.

LLNet avatar Jul 29 '22 17:07 LLNet

IMO no; if you can't resize the window you can't resize it, even to make it full screen. Maybe this needs more granular settings though, like "fixed aspect ratio"?

alice-i-cecile avatar Jul 29 '22 18:07 alice-i-cecile

@alice-i-cecile image i expect resizable:false to disable that ;-) not disable it for app itself. :smile:

but back to issue - when i add "set_resizable(true);" i can get full screen to work.

fn fullscreeen(
    input: Res<Input<KeyCode>>,
    mut windows: ResMut<Windows>,
) {
    let window = windows
        .get_primary_mut()
        .unwrap();

    if input.pressed(KeyCode::LAlt) && input.just_pressed(KeyCode::Return) {
        if window.mode() == WindowMode::Windowed {
            println!("Changing to fullscreen");
            window.set_resizable(true);
            window.set_resolution(3440.0, 1440.0);
            window.set_mode(WindowMode::Fullscreen);
        } else {
            println!("Changing to windowed");
            window.set_mode(WindowMode::Windowed);
            window.set_resolution(100.0, 200.0);
            window.set_resizable(false);
        }
    }
}

but i cannot get to go back to window size (100 x 200).

LLNet avatar Jul 29 '22 18:07 LLNet

update

fn fullscreeen(
    input: Res<Input<KeyCode>>,
    mut windows: ResMut<Windows>,
) {
    let window = windows
        .get_primary_mut()
        .unwrap();

    if input.pressed(KeyCode::LAlt) && input.just_pressed(KeyCode::Return) {
        if window.mode() == WindowMode::Windowed {
            println!("Changing to fullscreen");
            window.set_resizable(true);
            window.set_resolution(3440.0, 1440.0);
            window.set_mode(WindowMode::Fullscreen);
        } else {
            println!("Changing to windowed");
            window.set_mode(WindowMode::Windowed);
            window.set_resolution(100.0, 200.0);
        }
    }
}

if i do this it go fine back to correct screen size. but if i add "window.set_resizable(false);" after "set_resolution" - screen size not change back.

LLNet avatar Jul 29 '22 18:07 LLNet

i expect resizable:false to disable that ;-) not disable it for app itself. 😄

Ah, I see. Let me see about putting together an issue for winit for you; this is a sensible pattern.

EDIT: there already is one: https://github.com/rust-windowing/winit/issues/2306

alice-i-cecile avatar Jul 29 '22 19:07 alice-i-cecile

We should consider taking the approach used in https://github.com/rust-gamedev/rust-game-ports/pull/61/files, found via the linked issue.

@64kramsystem, does that sound right to you?

alice-i-cecile avatar Jul 29 '22 19:07 alice-i-cecile

We should consider taking the approach used in https://github.com/rust-gamedev/rust-game-ports/pull/61/files, found via the linked issue.

@64kramsystem, does that sound right to you?

Hi there! Yes, makes sense, and it's the same problem, with the same workaround.

@alice-i-cecile Unfortunately, I have the suspicion that users may face other fullscreen issues, caused by Winit; see this issue I've opened on ggez, for reference.

64kramsystem avatar Jul 29 '22 21:07 64kramsystem