diff --git a/src/api/x11/window.rs b/src/api/x11/window.rs index f6f944d7fe..e1ecece8c7 100644 --- a/src/api/x11/window.rs +++ b/src/api/x11/window.rs @@ -392,12 +392,17 @@ impl Window { }, }; + // getting the parent window + let parent = if builder.parent.is_null() { + unsafe { (display.xlib.XDefaultRootWindow)(display.display) } + } else { + builder.parent as ffi::Window + }; // getting the root window - let root = unsafe { (display.xlib.XDefaultRootWindow)(display.display) }; // creating the color map let cmap = unsafe { - let cmap = (display.xlib.XCreateColormap)(display.display, root, + let cmap = (display.xlib.XCreateColormap)(display.display, parent, visual_infos.visual as *mut _, ffi::AllocNone); // TODO: error checking? @@ -420,7 +425,7 @@ impl Window { swa }; - let mut window_attributes = ffi::CWBorderPixel | ffi::CWColormap | ffi::CWEventMask; + let mut window_attributes = ffi::CWBorderPixel | ffi::CWEventMask | ffi::CWColormap; if builder.transparent { window_attributes |= ffi::CWBackPixel; @@ -438,7 +443,7 @@ impl Window { // finally creating the window let window = unsafe { - let win = (display.xlib.XCreateWindow)(display.display, root, 0, 0, dimensions.0 as libc::c_uint, + let win = (display.xlib.XCreateWindow)(display.display, parent, 0, 0, dimensions.0 as libc::c_uint, dimensions.1 as libc::c_uint, 0, visual_infos.depth, ffi::InputOutput as libc::c_uint, visual_infos.visual as *mut _, window_attributes, &mut set_win_attr); diff --git a/src/lib.rs b/src/lib.rs index 49b8d9ab82..be6e25027d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,7 +61,7 @@ extern crate x11_dl; pub use events::*; pub use headless::{HeadlessRendererBuilder, HeadlessContext}; #[cfg(feature = "window")] -pub use window::{WindowBuilder, Window, WindowProxy, PollEventsIterator, WaitEventsIterator}; +pub use window::{WindowBuilder, Window, WindowID, WindowProxy, PollEventsIterator, WaitEventsIterator}; #[cfg(feature = "window")] pub use window::{AvailableMonitorsIter, MonitorID, get_available_monitors, get_primary_monitor}; #[cfg(feature = "window")] @@ -381,7 +381,8 @@ pub struct BuilderAttribs<'a> { srgb: Option, transparent: bool, decorations: bool, - multitouch: bool + multitouch: bool, + parent: *mut libc::c_void, } impl BuilderAttribs<'static> { @@ -408,7 +409,8 @@ impl BuilderAttribs<'static> { srgb: None, transparent: false, decorations: true, - multitouch: false + multitouch: false, + parent: std::ptr::null_mut(), } } } @@ -440,7 +442,8 @@ impl<'a> BuilderAttribs<'a> { srgb: self.srgb, transparent: self.transparent, decorations: self.decorations, - multitouch: self.multitouch + multitouch: self.multitouch, + parent: self.parent, }; (new_attribs, sharing) diff --git a/src/window.rs b/src/window.rs index 00174d3d36..9982e2daaf 100644 --- a/src/window.rs +++ b/src/window.rs @@ -163,6 +163,12 @@ impl<'a> WindowBuilder<'a> { self } + /// Sets the parent window + pub fn with_parent(mut self, parent: WindowID) -> WindowBuilder<'a> { + self.attribs.parent = parent; + self + } + /// Builds the window. /// /// Error should be very rare and only occur in case of permission denied, incompatible system, @@ -609,3 +615,7 @@ impl MonitorID { id.get_dimensions() } } + + +/// Identifier for a display system window. +pub type WindowID = *mut libc::c_void;