Skip to content

Commit 2061402

Browse files
author
Mike Blumenkrantz
committed
add ability to set parent window when creating windows
1 parent 11389c9 commit 2061402

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub use events::*;
5757
#[cfg(feature = "headless")]
5858
pub use headless::{HeadlessRendererBuilder, HeadlessContext};
5959
#[cfg(feature = "window")]
60-
pub use window::{WindowBuilder, Window, WindowProxy, PollEventsIterator, WaitEventsIterator};
60+
pub use window::{WindowBuilder, Window, WindowID, WindowProxy, PollEventsIterator, WaitEventsIterator};
6161
#[cfg(feature = "window")]
6262
pub use window::{AvailableMonitorsIter, MonitorID, get_available_monitors, get_primary_monitor};
6363
#[cfg(feature = "window")]
@@ -260,6 +260,7 @@ pub struct BuilderAttribs<'a> {
260260
alpha_bits: Option<u8>,
261261
stereoscopy: bool,
262262
srgb: Option<bool>,
263+
parent: *mut libc::c_void,
263264
}
264265

265266
impl BuilderAttribs<'static> {
@@ -282,6 +283,7 @@ impl BuilderAttribs<'static> {
282283
alpha_bits: None,
283284
stereoscopy: false,
284285
srgb: None,
286+
parent: std::ptr::null_mut(),
285287
}
286288
}
287289
}
@@ -308,6 +310,7 @@ impl<'a> BuilderAttribs<'a> {
308310
alpha_bits: self.alpha_bits,
309311
stereoscopy: self.stereoscopy,
310312
srgb: self.srgb,
313+
parent: self.parent,
311314
};
312315

313316
(new_attribs, sharing)

src/window.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ impl<'a> WindowBuilder<'a> {
129129
self
130130
}
131131

132+
/// Sets the parent window
133+
pub fn with_parent(mut self, parent: WindowID) -> WindowBuilder<'a> {
134+
self.attribs.parent = parent;
135+
self
136+
}
137+
132138
/// Builds the window.
133139
///
134140
/// Error should be very rare and only occur in case of permission denied, incompatible system,
@@ -528,3 +534,7 @@ impl MonitorID {
528534
id.get_dimensions()
529535
}
530536
}
537+
538+
539+
/// Identifier for a display system window.
540+
pub type WindowID = *mut libc::c_void;

src/x11/window/mod.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -414,21 +414,17 @@ impl Window {
414414
}
415415
};
416416

417-
// getting the root window
418-
let root = unsafe { ffi::XDefaultRootWindow(display) };
419-
420-
// creating the color map
421-
let cmap = unsafe {
422-
let cmap = ffi::XCreateColormap(display, root,
423-
visual_infos.visual as *mut _, ffi::AllocNone);
424-
// TODO: error checking?
425-
cmap
417+
// getting the parent window
418+
let parent = if builder.parent.is_null() {
419+
unsafe { ffi::XDefaultRootWindow(display) }
420+
} else {
421+
builder.parent as ffi::Window
426422
};
427423

428424
// creating
429425
let mut set_win_attr = {
430426
let mut swa: ffi::XSetWindowAttributes = unsafe { mem::zeroed() };
431-
swa.colormap = cmap;
427+
swa.colormap = 0;
432428
swa.event_mask = ffi::ExposureMask | ffi::StructureNotifyMask |
433429
ffi::VisibilityChangeMask | ffi::KeyPressMask | ffi::PointerMotionMask |
434430
ffi::KeyReleaseMask | ffi::ButtonPressMask |
@@ -450,7 +446,7 @@ impl Window {
450446

451447
// finally creating the window
452448
let window = unsafe {
453-
let win = ffi::XCreateWindow(display, root, 0, 0, dimensions.0 as libc::c_uint,
449+
let win = ffi::XCreateWindow(display, parent, 0, 0, dimensions.0 as libc::c_uint,
454450
dimensions.1 as libc::c_uint, 0, visual_infos.depth, ffi::InputOutput as libc::c_uint,
455451
visual_infos.visual as *mut _, window_attributes,
456452
&mut set_win_attr);

0 commit comments

Comments
 (0)