Skip to content

Introduce unix::WindowBuilderExt::with_xlib_parent #739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/api/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,21 @@ impl Window {
},
};

// getting the root window
let root = unsafe { (display.xlib.XDefaultRootWindow)(display.display) };
display.check_errors().expect("Failed to get root window");
// getting the parent window; root if None
let parent = match window_attrs.platform_specific.xlib_parent {
Some(ref w) => w.window as ffi::Window,
None => {
let root = unsafe {
(display.xlib.XDefaultRootWindow)(display.display)
};
display.check_errors().expect("Failed to get root window");
root
}
};

// 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);
display.check_errors().expect("Failed to call XCreateColormap");
Expand Down Expand Up @@ -443,7 +451,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);
Expand Down Expand Up @@ -564,7 +572,7 @@ impl Window {
unsafe {
(display.xlib.XSendEvent)(
display.display,
root,
parent,
0,
ffi::SubstructureRedirectMask | ffi::SubstructureNotifyMask,
&mut x_event as *mut _
Expand Down
7 changes: 6 additions & 1 deletion src/os/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ impl WindowExt for Window {

/// Additional methods on `WindowBuilder` that are specific to Unix.
pub trait WindowBuilderExt {

/// Sets the Xlib parent window.
fn with_xlib_parent(self, parent: Option<WindowId>) -> WindowBuilder<'a>;
}

impl<'a> WindowBuilderExt for WindowBuilder<'a> {
fn with_xlib_parent(mut self, parent: Option<WindowId>) -> WindowBuilder<'a> {
self.platform_specific.xlib_parent = parent;
self
}
}
4 changes: 3 additions & 1 deletion src/platform/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ pub use self::api_dispatch::PlatformSpecificWindowBuilderAttributes;
mod api_dispatch;

#[derive(Default)]
pub struct PlatformSpecificHeadlessBuilderAttributes;
pub struct PlatformSpecificHeadlessBuilderAttributes {
pub xlib_parent: Option<WindowID>,
}

pub struct HeadlessContext(OsMesaContext);

Expand Down