Skip to content

Commit

Permalink
Introduce unix::WindowBuilderExt::with_xlib_parent
Browse files Browse the repository at this point in the history
Upstreamed from Servo's fork, fixes servo#71.
  • Loading branch information
nox committed Mar 12, 2016
1 parent 140fd1f commit 58b88fb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
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

0 comments on commit 58b88fb

Please sign in to comment.