rust-windowing / winit

Window handling library in pure Rust
https://docs.rs/winit/
Apache License 2.0
4.55k stars 876 forks source link

How to get primary monitor size with `EventLoop::primary_monitor` gone in winit 0.30 #3723

Closed alexheretic closed 3 weeks ago

alexheretic commented 3 weeks ago

I used the primary monitor size to inform setting up of WindowAttributes (previously WindowBuilder in 0.29). This no longer seems possible in 0.30 as these methods were moved out of EventLoop.

Is it possible to access this info before building the window with 0.30?

let primary_monitor = event_loop // EventLoop<()>
    .primary_monitor()
    .or_else(|| event_loop.available_monitors().next())
    .expect("No monitors found to render on");
let (win_width, win_height): (u32, _) = primary_monitor.size().into();

let mut window_attrs = Window::default_attributes();
// ... use win_width & win_height to setup

// build window

// run loop
kchibisov commented 3 weeks ago

Building window outside of event loop is deprecated. Inside of event loop everything is still there as before.

alexheretic commented 3 weeks ago

WindowAttributes::with_inner_size etc don't seem deprecated. It's just that I can no longer query the primary monitor info any more to use that dynamically.

I haven't migrated to the new trait yet. So I guess this can only be done now with that now. Just seems a bit of an odd limitation.

kchibisov commented 3 weeks ago

ActiveEventLoop has primary_monitor and that's the type you work with inside the loop. The limitation is because you need loop running to get such information in general.

The API was not that reliable before and primary monitor as a concept is not a great thing either.

alexheretic commented 3 weeks ago

Ok thanks for the info