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

Unify behavior of resizable across platforms #2252

Merged
merged 1 commit into from
Apr 24, 2022

Conversation

kchibisov
Copy link
Member

This makes X11 and Wayland follow Windows and macOS, so the size of the
window could be set even though it has resizable attribute set to false.

Fixes #2242.

@kchibisov kchibisov requested a review from maroider April 9, 2022 23:14
@kchibisov
Copy link
Member Author

kchibisov commented Apr 9, 2022

@sourcebox would you mind testing this PR and tell whether it resolves your issue? I think it should resize the window now with set_inner_size.

Also, if you could send me a client to use for testing, I can test Wayland part, since I think you have something working already?

@sourcebox
Copy link

@kchibisov I just tested your PR and it works as expected so far. I'm typically not using winit directly but via egui. For testing I just modified the min_max_size example. Here's the full code:

use simple_logger::SimpleLogger;
use winit::{
    dpi::LogicalSize,
    event::{Event, WindowEvent},
    event_loop::{ControlFlow, EventLoop},
    window::WindowBuilder,
};

fn main() {
    SimpleLogger::new().init().unwrap();
    let event_loop = EventLoop::new();

    let window = WindowBuilder::new().build(&event_loop).unwrap();

    window.set_resizable(false);
    window.set_inner_size(LogicalSize::new(200.0, 200.0));

    event_loop.run(move |event, _, control_flow| {
        *control_flow = ControlFlow::Wait;
        println!("{:?}", event);

        match event {
            Event::WindowEvent {
                event: WindowEvent::CloseRequested,
                ..
            } => *control_flow = ControlFlow::Exit,
            Event::WindowEvent {
                event: WindowEvent::KeyboardInput { .. },
                ..
            } => {
                window.set_inner_size(LogicalSize::new(550.0, 550.0));
            }
            _ => (),
        }
    });
}

With your patch, window.set_inner_size() changes the dimensions accordingly, both on initialization and within the event loop when pressing a key.

This makes X11 and Wayland follow Windows and macOS, so the size of the
window could be set even though it has resizable attribute set to false.

Fixes rust-windowing#2242.
@kchibisov kchibisov merged commit ce890c3 into rust-windowing:master Apr 24, 2022
@kchibisov kchibisov deleted the min-max-size branch April 24, 2022 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Behaviour of resizable is different across platforms
3 participants