From edee7d0d3ed7aae7ed3c72060fade18cf52feed5 Mon Sep 17 00:00:00 2001 From: t-sin Date: Thu, 7 Apr 2022 06:37:51 +0900 Subject: [PATCH 01/16] Add an attribute to store its parent window to Unix WindowBuilder --- src/platform/x11.rs | 10 ++++++++++ src/platform_impl/linux/mod.rs | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/src/platform/x11.rs b/src/platform/x11.rs index 655d628176..1a67203ef0 100644 --- a/src/platform/x11.rs +++ b/src/platform/x11.rs @@ -171,6 +171,9 @@ pub trait WindowBuilderExtX11 { fn with_x11_visual(self, visual_infos: *const T) -> Self; fn with_x11_screen(self, screen_id: i32) -> Self; + #[cfg(feature = "x11")] + /// Build window with X11's parent window. Only relevant on X11. + fn with_x11_parent(self, parent_id: usize) -> Self; /// Build window with the given `general` and `instance` names. /// @@ -227,6 +230,13 @@ impl WindowBuilderExtX11 for WindowBuilder { self } + #[inline] + #[cfg(feature = "x11")] + fn with_x11_parent(mut self, parent_id: usize) -> Self { + self.platform_specific.parent_id = Some(parent_id); + self + } + #[inline] fn with_override_redirect(mut self, override_redirect: bool) -> Self { self.platform_specific.override_redirect = override_redirect; diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 0b075086e6..0aa3d8806d 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -95,6 +95,8 @@ pub struct PlatformSpecificWindowBuilderAttributes { #[cfg(feature = "x11")] pub screen_id: Option, #[cfg(feature = "x11")] + pub parent_id: Option, + #[cfg(feature = "x11")] pub base_size: Option, #[cfg(feature = "x11")] pub override_redirect: bool, @@ -115,6 +117,8 @@ impl Default for PlatformSpecificWindowBuilderAttributes { #[cfg(feature = "x11")] screen_id: None, #[cfg(feature = "x11")] + parent_id: None, + #[cfg(feature = "x11")] base_size: None, #[cfg(feature = "x11")] override_redirect: false, From aaeef3cdd2c90d3b3380370a9ea85d0b907e7053 Mon Sep 17 00:00:00 2001 From: t-sin Date: Thu, 7 Apr 2022 06:40:22 +0900 Subject: [PATCH 02/16] Use parent ID when creating a new X11 window --- src/platform_impl/linux/x11/window.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index cd66ebe784..c07cce67f3 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -120,7 +120,13 @@ impl UnownedWindow { pl_attribs: PlatformSpecificWindowBuilderAttributes, ) -> Result { let xconn = &event_loop.xconn; - let root = event_loop.root; + // root should be a type ffi::Window and it is finally c_ulong. + // cf. https://docs.rs/x11-dl/2.19.1/x11_dl/xlib/type.Window.html + let root = if let Some(id) = pl_attribs.parent_id { + id as ffi::Window + } else { + event_loop.root + }; let mut monitors = xconn.available_monitors(); let guessed_monitor = if monitors.is_empty() { From 182250fa1b6280911a6203116204f643b27c60c1 Mon Sep 17 00:00:00 2001 From: t-sin Date: Thu, 7 Apr 2022 07:58:02 +0900 Subject: [PATCH 03/16] Add test/example code for child windows --- examples/child_window.rs | 83 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 examples/child_window.rs diff --git a/examples/child_window.rs b/examples/child_window.rs new file mode 100644 index 0000000000..c37638f104 --- /dev/null +++ b/examples/child_window.rs @@ -0,0 +1,83 @@ +#[cfg(all(target_os = "linux", feature = "x11"))] +use std::collections::HashMap; + +#[cfg(all(target_os = "linux", feature = "x11"))] +use winit::{ + dpi::{LogicalPosition, LogicalSize, Position}, + event::{ElementState, Event, KeyboardInput, WindowEvent}, + event_loop::{ControlFlow, EventLoop, EventLoopWindowTarget}, + platform::unix::{WindowBuilderExtUnix, WindowExtUnix}, + window::{Window, WindowBuilder}, +}; + +#[cfg(all(target_os = "linux", feature = "x11"))] +fn spawn_child_window( + parent: usize, + event_loop: &EventLoopWindowTarget<()>, + windows: &mut HashMap, +) { + let child_window = WindowBuilder::new() + .with_x11_parent(parent) + .with_title("child window") + .with_inner_size(LogicalSize::new(200.0f32, 200.0f32)) + .with_position(Position::Logical(LogicalPosition::new(0.0, 0.0))) + .with_visible(true) + .build(&event_loop) + .unwrap(); + + let id: usize = child_window.xlib_window().unwrap().try_into().unwrap(); + windows.insert(id, child_window); + println!("child window created with id: {}", id); +} + +#[cfg(all(target_os = "linux", feature = "x11"))] +fn main() { + let mut windows = HashMap::new(); + + let event_loop: EventLoop<()> = EventLoop::new(); + let parent_window = WindowBuilder::new() + .with_title("parent window") + .with_position(Position::Logical(LogicalPosition::new(0.0, 0.0))) + .with_inner_size(LogicalSize::new(640.0f32, 480.0f32)) + .build(&event_loop) + .unwrap(); + let root: usize = parent_window.xlib_window().unwrap().try_into().unwrap(); + println!("parent window id: {})", root); + + event_loop.run(move |event: Event<'_, ()>, event_loop, control_flow| { + *control_flow = ControlFlow::Wait; + + match event { + Event::WindowEvent { event, window_id } => match event { + WindowEvent::CloseRequested => { + windows.clear(); + *control_flow = ControlFlow::Exit; + } + WindowEvent::CursorEntered { device_id: _ } => { + // println when the cursor entered in a window even if the child window is created + // by some key inputs. + // the child windows are always placed at (0, 0) with size (200, 200) in the parent window, + // so we also can see this log when we move the cursor arround (200, 200) in parent window. + println!("cursor entered in the window {:?}", window_id); + } + WindowEvent::KeyboardInput { + input: + KeyboardInput { + state: ElementState::Pressed, + .. + }, + .. + } => { + spawn_child_window(root, event_loop, &mut windows); + } + _ => (), + }, + _ => (), + } + }) +} + +#[cfg(not(all(target_os = "linux", feature = "x11")))] +fn main() { + panic!("This example is supported only on x11."); +} From 9dd97229667c513009005056eff2bb22ad638e95 Mon Sep 17 00:00:00 2001 From: t-sin Date: Wed, 6 Jul 2022 00:10:16 +0900 Subject: [PATCH 04/16] Use platform_impl::WindowId to specify the parent window on X11 --- examples/child_window.rs | 6 +++--- src/platform/x11.rs | 8 ++++---- src/platform_impl/linux/mod.rs | 2 +- src/platform_impl/linux/x11/window.rs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/child_window.rs b/examples/child_window.rs index c37638f104..a59828a2ed 100644 --- a/examples/child_window.rs +++ b/examples/child_window.rs @@ -12,12 +12,12 @@ use winit::{ #[cfg(all(target_os = "linux", feature = "x11"))] fn spawn_child_window( - parent: usize, + parent: u64, event_loop: &EventLoopWindowTarget<()>, windows: &mut HashMap, ) { let child_window = WindowBuilder::new() - .with_x11_parent(parent) + .with_x11_parent(parent.try_into().unwrap()) .with_title("child window") .with_inner_size(LogicalSize::new(200.0f32, 200.0f32)) .with_position(Position::Logical(LogicalPosition::new(0.0, 0.0))) @@ -41,7 +41,7 @@ fn main() { .with_inner_size(LogicalSize::new(640.0f32, 480.0f32)) .build(&event_loop) .unwrap(); - let root: usize = parent_window.xlib_window().unwrap().try_into().unwrap(); + let root: u64 = parent_window.xlib_window().unwrap().try_into().unwrap(); println!("parent window id: {})", root); event_loop.run(move |event: Event<'_, ()>, event_loop, control_flow| { diff --git a/src/platform/x11.rs b/src/platform/x11.rs index 1a67203ef0..affaeb853e 100644 --- a/src/platform/x11.rs +++ b/src/platform/x11.rs @@ -4,7 +4,7 @@ use std::{ptr, sync::Arc}; use crate::{ event_loop::{EventLoopBuilder, EventLoopWindowTarget}, monitor::MonitorHandle, - window::{Window, WindowBuilder}, + window::{Window, WindowBuilder, WindowId}, }; use crate::dpi::Size; @@ -173,7 +173,7 @@ pub trait WindowBuilderExtX11 { fn with_x11_screen(self, screen_id: i32) -> Self; #[cfg(feature = "x11")] /// Build window with X11's parent window. Only relevant on X11. - fn with_x11_parent(self, parent_id: usize) -> Self; + fn with_x11_parent(self, parent_id: WindowId) -> Self; /// Build window with the given `general` and `instance` names. /// @@ -232,8 +232,8 @@ impl WindowBuilderExtX11 for WindowBuilder { #[inline] #[cfg(feature = "x11")] - fn with_x11_parent(mut self, parent_id: usize) -> Self { - self.platform_specific.parent_id = Some(parent_id); + fn with_x11_parent(mut self, parent_id: WindowId) -> Self { + self.platform_specific.parent_id = Some(parent_id.0); self } diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 0aa3d8806d..533f3d4079 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -95,7 +95,7 @@ pub struct PlatformSpecificWindowBuilderAttributes { #[cfg(feature = "x11")] pub screen_id: Option, #[cfg(feature = "x11")] - pub parent_id: Option, + pub parent_id: Option, #[cfg(feature = "x11")] pub base_size: Option, #[cfg(feature = "x11")] diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index c07cce67f3..b03317ae3f 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -123,7 +123,7 @@ impl UnownedWindow { // root should be a type ffi::Window and it is finally c_ulong. // cf. https://docs.rs/x11-dl/2.19.1/x11_dl/xlib/type.Window.html let root = if let Some(id) = pl_attribs.parent_id { - id as ffi::Window + id.into() } else { event_loop.root }; From b9190a2b043d288f3c6f42bc61de3e46ccef4053 Mon Sep 17 00:00:00 2001 From: t-sin Date: Thu, 7 Jul 2022 08:51:56 +0900 Subject: [PATCH 05/16] Support 32-bit archtecture --- src/platform_impl/linux/x11/window.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index b03317ae3f..08396918c7 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -123,7 +123,7 @@ impl UnownedWindow { // root should be a type ffi::Window and it is finally c_ulong. // cf. https://docs.rs/x11-dl/2.19.1/x11_dl/xlib/type.Window.html let root = if let Some(id) = pl_attribs.parent_id { - id.into() + u64::from(id).try_into().unwrap() } else { event_loop.root }; From 83f1d9f4f08b2d354ee6e09d9c1e0678ddf21538 Mon Sep 17 00:00:00 2001 From: t-sin Date: Tue, 19 Jul 2022 19:00:40 +0900 Subject: [PATCH 06/16] Archtecture specific conversion by its pointer width --- examples/child_window.rs | 13 ++++++++++--- src/platform_impl/linux/x11/window.rs | 7 ++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/examples/child_window.rs b/examples/child_window.rs index a59828a2ed..8897a9416f 100644 --- a/examples/child_window.rs +++ b/examples/child_window.rs @@ -14,7 +14,7 @@ use winit::{ fn spawn_child_window( parent: u64, event_loop: &EventLoopWindowTarget<()>, - windows: &mut HashMap, + windows: &mut HashMap, ) { let child_window = WindowBuilder::new() .with_x11_parent(parent.try_into().unwrap()) @@ -25,7 +25,10 @@ fn spawn_child_window( .build(&event_loop) .unwrap(); - let id: usize = child_window.xlib_window().unwrap().try_into().unwrap(); + #[cfg(target_pointer_width = "64")] + let id = child_window.xlib_window().unwrap(); + #[cfg(not(target_pointer_width = "64"))] + let id = child_window.xlib_window().unwrap().try_into().unwrap(); windows.insert(id, child_window); println!("child window created with id: {}", id); } @@ -41,7 +44,11 @@ fn main() { .with_inner_size(LogicalSize::new(640.0f32, 480.0f32)) .build(&event_loop) .unwrap(); - let root: u64 = parent_window.xlib_window().unwrap().try_into().unwrap(); + + #[cfg(target_pointer_width = "64")] + let root = parent_window.xlib_window().unwrap(); + #[cfg(not(target_pointer_width = "64"))] + let root = parent_window.xlib_window().unwrap().try_into().unwrap(); println!("parent window id: {})", root); event_loop.run(move |event: Event<'_, ()>, event_loop, control_flow| { diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 08396918c7..d2a7d10449 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -123,7 +123,12 @@ impl UnownedWindow { // root should be a type ffi::Window and it is finally c_ulong. // cf. https://docs.rs/x11-dl/2.19.1/x11_dl/xlib/type.Window.html let root = if let Some(id) = pl_attribs.parent_id { - u64::from(id).try_into().unwrap() + #[cfg(target_pointer_width = "64")] + let root = u64::from(id); + #[cfg(not(target_pointer_width = "64"))] + let root = u64::from(id).try_into().unwrap(); + + root } else { event_loop.root }; From 2ba6432ef40fac97e7886be44ffe937868f4e3a4 Mon Sep 17 00:00:00 2001 From: t-sin Date: Sat, 23 Jul 2022 10:58:40 +0900 Subject: [PATCH 07/16] Fix errors by `cargo clippy --example child_window --- examples/child_window.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/examples/child_window.rs b/examples/child_window.rs index 8897a9416f..69759287f4 100644 --- a/examples/child_window.rs +++ b/examples/child_window.rs @@ -22,7 +22,7 @@ fn spawn_child_window( .with_inner_size(LogicalSize::new(200.0f32, 200.0f32)) .with_position(Position::Logical(LogicalPosition::new(0.0, 0.0))) .with_visible(true) - .build(&event_loop) + .build(event_loop) .unwrap(); #[cfg(target_pointer_width = "64")] @@ -54,8 +54,8 @@ fn main() { event_loop.run(move |event: Event<'_, ()>, event_loop, control_flow| { *control_flow = ControlFlow::Wait; - match event { - Event::WindowEvent { event, window_id } => match event { + if let Event::WindowEvent { event, window_id } = event { + match event { WindowEvent::CloseRequested => { windows.clear(); *control_flow = ControlFlow::Exit; @@ -78,8 +78,7 @@ fn main() { spawn_child_window(root, event_loop, &mut windows); } _ => (), - }, - _ => (), + } } }) } From 08a3c710b995b8875b5cf8b504db787f61d6e02c Mon Sep 17 00:00:00 2001 From: t-sin Date: Sat, 23 Jul 2022 11:05:21 +0900 Subject: [PATCH 08/16] Don't import WindowId with the feature wayland --- src/platform/x11.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/platform/x11.rs b/src/platform/x11.rs index affaeb853e..0d0ab4c6e0 100644 --- a/src/platform/x11.rs +++ b/src/platform/x11.rs @@ -1,10 +1,12 @@ use std::os::raw; use std::{ptr, sync::Arc}; +#[cfg(feature = "x11")] +use crate::window::WindowId; use crate::{ event_loop::{EventLoopBuilder, EventLoopWindowTarget}, monitor::MonitorHandle, - window::{Window, WindowBuilder, WindowId}, + window::{Window, WindowBuilder}, }; use crate::dpi::Size; From 522de7c5a61e7df0053309b939b243ee054f4e03 Mon Sep 17 00:00:00 2001 From: t-sin Date: Sat, 23 Jul 2022 12:39:02 +0900 Subject: [PATCH 09/16] Use casting with higher bits truncation instead of `try_into()` --- examples/child_window.rs | 18 ++++++------------ src/platform_impl/linux/x11/window.rs | 6 +++++- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/examples/child_window.rs b/examples/child_window.rs index 69759287f4..7bd1908d1d 100644 --- a/examples/child_window.rs +++ b/examples/child_window.rs @@ -7,17 +7,17 @@ use winit::{ event::{ElementState, Event, KeyboardInput, WindowEvent}, event_loop::{ControlFlow, EventLoop, EventLoopWindowTarget}, platform::unix::{WindowBuilderExtUnix, WindowExtUnix}, - window::{Window, WindowBuilder}, + window::{Window, WindowBuilder, WindowId}, }; #[cfg(all(target_os = "linux", feature = "x11"))] fn spawn_child_window( - parent: u64, + parent: u32, event_loop: &EventLoopWindowTarget<()>, - windows: &mut HashMap, + windows: &mut HashMap, ) { let child_window = WindowBuilder::new() - .with_x11_parent(parent.try_into().unwrap()) + .with_x11_parent(WindowId::from(parent as u64)) .with_title("child window") .with_inner_size(LogicalSize::new(200.0f32, 200.0f32)) .with_position(Position::Logical(LogicalPosition::new(0.0, 0.0))) @@ -25,10 +25,7 @@ fn spawn_child_window( .build(event_loop) .unwrap(); - #[cfg(target_pointer_width = "64")] - let id = child_window.xlib_window().unwrap(); - #[cfg(not(target_pointer_width = "64"))] - let id = child_window.xlib_window().unwrap().try_into().unwrap(); + let id = child_window.xlib_window().unwrap() as u32; windows.insert(id, child_window); println!("child window created with id: {}", id); } @@ -45,10 +42,7 @@ fn main() { .build(&event_loop) .unwrap(); - #[cfg(target_pointer_width = "64")] - let root = parent_window.xlib_window().unwrap(); - #[cfg(not(target_pointer_width = "64"))] - let root = parent_window.xlib_window().unwrap().try_into().unwrap(); + let root = parent_window.xlib_window().unwrap() as u32; println!("parent window id: {})", root); event_loop.run(move |event: Event<'_, ()>, event_loop, control_flow| { diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index d2a7d10449..b49e7fd57b 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -125,8 +125,12 @@ impl UnownedWindow { let root = if let Some(id) = pl_attribs.parent_id { #[cfg(target_pointer_width = "64")] let root = u64::from(id); + #[cfg(not(target_pointer_width = "64"))] - let root = u64::from(id).try_into().unwrap(); + // XID is defined as 32-bit value in the X11 protocol so + // there's no problem about higher bits truncation. + // cf. https://www.x.org/docs/XProtocol/proto.pdf + let root = u64::from(id) as u32; root } else { From 5a780c3246566ff8817959c894757b8c01c81f94 Mon Sep 17 00:00:00 2001 From: t-sin Date: Wed, 3 Aug 2022 11:20:14 +0900 Subject: [PATCH 10/16] Remove unneccesary pointer-width conditional --- src/platform_impl/linux/x11/window.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index b49e7fd57b..8c0283c8a1 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -123,16 +123,10 @@ impl UnownedWindow { // root should be a type ffi::Window and it is finally c_ulong. // cf. https://docs.rs/x11-dl/2.19.1/x11_dl/xlib/type.Window.html let root = if let Some(id) = pl_attribs.parent_id { - #[cfg(target_pointer_width = "64")] - let root = u64::from(id); - - #[cfg(not(target_pointer_width = "64"))] // XID is defined as 32-bit value in the X11 protocol so // there's no problem about higher bits truncation. // cf. https://www.x.org/docs/XProtocol/proto.pdf - let root = u64::from(id) as u32; - - root + u64::from(id) as _ } else { event_loop.root }; From a7b69f24067917a9489ccfc36916b28860edc4d9 Mon Sep 17 00:00:00 2001 From: t-sin Date: Fri, 2 Sep 2022 02:56:17 +0900 Subject: [PATCH 11/16] Rename with_x11_parent() -> with_parent() Because of X11/Wayland module separation --- src/platform/x11.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/platform/x11.rs b/src/platform/x11.rs index 0d0ab4c6e0..633b4ce0a7 100644 --- a/src/platform/x11.rs +++ b/src/platform/x11.rs @@ -1,7 +1,6 @@ use std::os::raw; use std::{ptr, sync::Arc}; -#[cfg(feature = "x11")] use crate::window::WindowId; use crate::{ event_loop::{EventLoopBuilder, EventLoopWindowTarget}, @@ -175,7 +174,7 @@ pub trait WindowBuilderExtX11 { fn with_x11_screen(self, screen_id: i32) -> Self; #[cfg(feature = "x11")] /// Build window with X11's parent window. Only relevant on X11. - fn with_x11_parent(self, parent_id: WindowId) -> Self; + fn with_parent(self, parent_id: WindowId) -> Self; /// Build window with the given `general` and `instance` names. /// @@ -233,8 +232,7 @@ impl WindowBuilderExtX11 for WindowBuilder { } #[inline] - #[cfg(feature = "x11")] - fn with_x11_parent(mut self, parent_id: WindowId) -> Self { + fn with_parent(mut self, parent_id: WindowId) -> Self { self.platform_specific.parent_id = Some(parent_id.0); self } From 40ab6b16004de738e021a60578ec1de62f968f5a Mon Sep 17 00:00:00 2001 From: t-sin Date: Thu, 1 Sep 2022 18:59:29 +0900 Subject: [PATCH 12/16] The child window example follows the new platform module structure --- examples/child_window.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/child_window.rs b/examples/child_window.rs index 7bd1908d1d..38c4d86188 100644 --- a/examples/child_window.rs +++ b/examples/child_window.rs @@ -6,7 +6,7 @@ use winit::{ dpi::{LogicalPosition, LogicalSize, Position}, event::{ElementState, Event, KeyboardInput, WindowEvent}, event_loop::{ControlFlow, EventLoop, EventLoopWindowTarget}, - platform::unix::{WindowBuilderExtUnix, WindowExtUnix}, + platform::x11::{WindowBuilderExtX11, WindowExtX11}, window::{Window, WindowBuilder, WindowId}, }; @@ -17,7 +17,7 @@ fn spawn_child_window( windows: &mut HashMap, ) { let child_window = WindowBuilder::new() - .with_x11_parent(WindowId::from(parent as u64)) + .with_parent(WindowId::from(parent as u64)) .with_title("child window") .with_inner_size(LogicalSize::new(200.0f32, 200.0f32)) .with_position(Position::Logical(LogicalPosition::new(0.0, 0.0))) From 4577d0fdf35f7106118b34df142c2af1f9765747 Mon Sep 17 00:00:00 2001 From: t-sin Date: Thu, 7 Apr 2022 08:10:16 +0900 Subject: [PATCH 13/16] Update FEATURES.md --- FEATURES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/FEATURES.md b/FEATURES.md index 7e88997030..4890db8c34 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -137,6 +137,7 @@ If your PR makes notable changes to Winit's features, please update this section * X11 Override Redirect Flag * GTK Theme Variant * Base window size +* Setting the X11 parent window ### iOS * `winit` has a minimum OS requirement of iOS 8 From 3b44e0259370bd9c1bf5ce4166d24e831fb61eb6 Mon Sep 17 00:00:00 2001 From: t-sin Date: Thu, 7 Apr 2022 08:08:16 +0900 Subject: [PATCH 14/16] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d6990eac7..68a0342d24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ And please only add new entries to the top of this list, right below the `# Unre - On Wayland, `wayland-csd-adwaita` now uses `ab_glyph` instead of `crossfont` to render the title for decorations. - On Wayland, a new `wayland-csd-adwaita-crossfont` feature was added to use `crossfont` instead of `ab_glyph` for decorations. - On Wayland, if not otherwise specified use upstream automatic CSD theme selection. +- On X11, added `WindowExtX11::with_parent` to create child windows. # 0.27.3 From 87dad508b518bdae00b8a3c480b8b56b42a16a9c Mon Sep 17 00:00:00 2001 From: t-sin Date: Sun, 18 Sep 2022 09:57:04 +0900 Subject: [PATCH 15/16] Remove `#[cfg(feature = "x11")]` because this file is X11 specific --- src/platform/x11.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/platform/x11.rs b/src/platform/x11.rs index 633b4ce0a7..37c524241f 100644 --- a/src/platform/x11.rs +++ b/src/platform/x11.rs @@ -172,8 +172,7 @@ pub trait WindowBuilderExtX11 { fn with_x11_visual(self, visual_infos: *const T) -> Self; fn with_x11_screen(self, screen_id: i32) -> Self; - #[cfg(feature = "x11")] - /// Build window with X11's parent window. Only relevant on X11. + /// Build window with parent window. fn with_parent(self, parent_id: WindowId) -> Self; /// Build window with the given `general` and `instance` names. From c920d89f4acad94e28373f86b7e7764fd283302d Mon Sep 17 00:00:00 2001 From: t-sin Date: Sun, 18 Sep 2022 09:57:50 +0900 Subject: [PATCH 16/16] Rewrite some comments for WindowID conversions --- src/platform_impl/linux/x11/window.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 8c0283c8a1..3132a2baad 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -120,12 +120,8 @@ impl UnownedWindow { pl_attribs: PlatformSpecificWindowBuilderAttributes, ) -> Result { let xconn = &event_loop.xconn; - // root should be a type ffi::Window and it is finally c_ulong. - // cf. https://docs.rs/x11-dl/2.19.1/x11_dl/xlib/type.Window.html let root = if let Some(id) = pl_attribs.parent_id { - // XID is defined as 32-bit value in the X11 protocol so - // there's no problem about higher bits truncation. - // cf. https://www.x.org/docs/XProtocol/proto.pdf + // WindowId is XID under the hood which doesn't exceed u32, so this conversion is lossless u64::from(id) as _ } else { event_loop.root