diff --git a/examples/window.rs b/examples/window.rs index 23a633d2ed..c9c87f8c19 100644 --- a/examples/window.rs +++ b/examples/window.rs @@ -4,22 +4,28 @@ use simple_logger::SimpleLogger; use winit::{ event::{Event, WindowEvent}, event_loop::EventLoop, + platform::unix::WindowBuilderExtUnix, window::WindowBuilder, }; fn main() { - SimpleLogger::new().init().unwrap(); + let screen_number = std::env::args() + .nth(1) + .expect("please specify screen number to run on as first commandline argument") + .parse() + .expect("could not parse first commandline argument as i32"); + + SimpleLogger::new().env().init().unwrap(); let event_loop = EventLoop::new(); - let window = WindowBuilder::new() + let window_builder = WindowBuilder::new() .with_title("A fantastic window!") - .with_inner_size(winit::dpi::LogicalSize::new(128.0, 128.0)) - .build(&event_loop) - .unwrap(); + .with_inner_size(winit::dpi::LogicalSize::new(500.0, 500.0)) + .with_x11_screen(screen_number); + let window = window_builder.build(&event_loop).unwrap(); event_loop.run(move |event, _, control_flow| { control_flow.set_wait(); - println!("{:?}", event); match event { Event::WindowEvent { diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index ab7cddfa42..5bf93deab9 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -120,7 +120,10 @@ impl UnownedWindow { pl_attribs: PlatformSpecificWindowBuilderAttributes, ) -> Result { let xconn = &event_loop.xconn; - let root = event_loop.root; + let root = match pl_attribs.screen_id { + Some(screen_id) => unsafe { (xconn.xlib.XRootWindow)(xconn.display, screen_id) }, + None => event_loop.root, + }; let mut monitors = xconn.available_monitors(); let guessed_monitor = if monitors.is_empty() { diff --git a/src/window.rs b/src/window.rs index dba514f90d..bb59e187e2 100644 --- a/src/window.rs +++ b/src/window.rs @@ -107,7 +107,7 @@ pub struct WindowBuilder { pub(crate) window: WindowAttributes, // Platform-specific configuration. - pub(crate) platform_specific: platform_impl::PlatformSpecificWindowBuilderAttributes, + pub platform_specific: platform_impl::PlatformSpecificWindowBuilderAttributes, } impl fmt::Debug for WindowBuilder {