Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
add ability to set parent window when creating windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Blumenkrantz authored and paulrouget committed Aug 13, 2015
1 parent 5db9418 commit e4ed759
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/api/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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;
Expand All @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -381,7 +381,8 @@ pub struct BuilderAttribs<'a> {
srgb: Option<bool>,
transparent: bool,
decorations: bool,
multitouch: bool
multitouch: bool,
parent: *mut libc::c_void,
}

impl BuilderAttribs<'static> {
Expand All @@ -408,7 +409,8 @@ impl BuilderAttribs<'static> {
srgb: None,
transparent: false,
decorations: true,
multitouch: false
multitouch: false,
parent: std::ptr::null_mut(),
}
}
}
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -609,3 +615,7 @@ impl MonitorID {
id.get_dimensions()
}
}


/// Identifier for a display system window.
pub type WindowID = *mut libc::c_void;

0 comments on commit e4ed759

Please sign in to comment.