mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 06:41:31 +11:00
3d1c18ded9
* Don't use UNIX_BACKEND in Window2::new * Move get_available_monitors and get_primary_monitor to EventsLoop * Remove UNIX_BACKEND * Restore choosing the Linux backend * Return a XNotSupported for new_x11() * Fix fullscreen example
59 lines
1.9 KiB
Rust
59 lines
1.9 KiB
Rust
extern crate winit;
|
|
|
|
use std::io::{self, Write};
|
|
use winit::{ControlFlow, Event, WindowEvent, FullScreenState};
|
|
|
|
fn main() {
|
|
let mut events_loop = winit::EventsLoop::new();
|
|
|
|
// enumerating monitors
|
|
let monitor = {
|
|
for (num, monitor) in events_loop.get_available_monitors().enumerate() {
|
|
println!("Monitor #{}: {:?}", num, monitor.get_name());
|
|
}
|
|
|
|
print!("Please write the number of the monitor to use: ");
|
|
io::stdout().flush().unwrap();
|
|
|
|
let mut num = String::new();
|
|
io::stdin().read_line(&mut num).unwrap();
|
|
let num = num.trim().parse().ok().expect("Please enter a number");
|
|
let monitor = events_loop.get_available_monitors().nth(num).expect("Please enter a valid ID");
|
|
|
|
println!("Using {:?}", monitor.get_name());
|
|
|
|
monitor
|
|
};
|
|
|
|
let _window = winit::WindowBuilder::new()
|
|
.with_title("Hello world!")
|
|
.with_fullscreen(FullScreenState::Exclusive(monitor))
|
|
.build(&events_loop)
|
|
.unwrap();
|
|
|
|
if cfg!(target_os = "linux") {
|
|
println!("Running this example under wayland may not display a window at all.\n\
|
|
This is normal and because this example does not actually draw anything in the window,\
|
|
thus the compositor does not display it.");
|
|
}
|
|
|
|
events_loop.run_forever(|event| {
|
|
println!("{:?}", event);
|
|
|
|
match event {
|
|
Event::WindowEvent { event, .. } => {
|
|
match event {
|
|
WindowEvent::Closed => return ControlFlow::Break,
|
|
WindowEvent::KeyboardInput {
|
|
input: winit::KeyboardInput { virtual_keycode: Some(winit::VirtualKeyCode::Escape), .. }, ..
|
|
} => return ControlFlow::Break,
|
|
_ => ()
|
|
}
|
|
},
|
|
_ => {}
|
|
}
|
|
|
|
ControlFlow::Continue
|
|
});
|
|
}
|