From 6eff410e1eabd120f4f919661a035c3b58006b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Laitl?= Date: Sun, 3 Sep 2023 22:41:38 +0200 Subject: [PATCH 1/2] Fix WindowBuilderExtUnix::with_x11_screen() to pass correct root window --- examples/window.rs | 18 ++++++++++++------ src/platform_impl/linux/x11/window.rs | 5 ++++- 2 files changed, 16 insertions(+), 7 deletions(-) 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() { From c49f020c716adfd105e37cd91f5cb6c45c19eb14 Mon Sep 17 00:00:00 2001 From: Ryo Kawaguchi Date: Tue, 12 Sep 2023 17:09:56 +0900 Subject: [PATCH 2/2] Make platform_specific field public to access screen_id --- src/window.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 {