|
| 1 | +use simple_logger::SimpleLogger; |
| 2 | +use winit::{ |
| 3 | + event::{ElementState, Event, KeyboardInput, WindowEvent}, |
| 4 | + event_loop::{ControlFlow, EventLoop}, |
| 5 | + window::Window, |
| 6 | +}; |
| 7 | + |
| 8 | +#[cfg(feature = "x11")] |
| 9 | +use winit::platform::unix::{EventLoopExtUnix, WindowExtUnix}; |
| 10 | + |
| 11 | +#[cfg(feature = "x11")] |
| 12 | +fn main() { |
| 13 | + SimpleLogger::new().init().unwrap(); |
| 14 | + let event_loop = EventLoop::new_x11_any_thread().unwrap(); |
| 15 | + let parent_window = Window::new(&event_loop).unwrap(); |
| 16 | + let root = parent_window.xlib_window().unwrap(); |
| 17 | + println!("root (id: {})", root); |
| 18 | + |
| 19 | + event_loop.run(move |event: Event<'_, ()>, _, control_flow| { |
| 20 | + *control_flow = ControlFlow::Wait; |
| 21 | + |
| 22 | + match event { |
| 23 | + Event::WindowEvent { |
| 24 | + event, |
| 25 | + window_id: _, |
| 26 | + } => match event { |
| 27 | + WindowEvent::CloseRequested => { |
| 28 | + *control_flow = ControlFlow::Exit; |
| 29 | + } |
| 30 | + WindowEvent::KeyboardInput { |
| 31 | + input: |
| 32 | + KeyboardInput { |
| 33 | + state: ElementState::Pressed, |
| 34 | + .. |
| 35 | + }, |
| 36 | + .. |
| 37 | + } => { |
| 38 | + let root = parent_window.xlib_window().unwrap() as u32; |
| 39 | + let child_event_loop: EventLoop<()> = |
| 40 | + EventLoop::new_x11_any_thread_with_root(root.into()).unwrap(); |
| 41 | + Window::new(&child_event_loop).unwrap(); |
| 42 | + } |
| 43 | + _ => (), |
| 44 | + }, |
| 45 | + _ => (), |
| 46 | + } |
| 47 | + }) |
| 48 | +} |
| 49 | + |
| 50 | +#[cfg(not(feature = "x11"))] |
| 51 | +fn main() { |
| 52 | + panic!("This example is supported only on x11."); |
| 53 | +} |
0 commit comments