From bea8daf5e49055bc72ab7f61d245463b1ef1f1bd Mon Sep 17 00:00:00 2001 From: bnewbold Date: Fri, 10 Jun 2016 18:32:26 -0400 Subject: x11: initial implementation of from_existing_window This adds the ability to create a glutin Window that wraps a pre-existing X Window. The proximal motivation for this is to allow writing of XScreensaver hacks in Rust, but it might also be useful for embedding 3D graphics in larger applications with full process separation, etc. This commit includes a bit of inline documentation, but no tests, and the details of what if any WindowAttributes or pixel information should be applied to the existing window aren't worked out. --- src/os/unix.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/os') diff --git a/src/os/unix.rs b/src/os/unix.rs index 61c89bc..0d89571 100644 --- a/src/os/unix.rs +++ b/src/os/unix.rs @@ -1,5 +1,7 @@ #![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] +use std::os::raw::c_ulong; + use libc; use Window; use platform::Window as LinuxWindow; @@ -41,9 +43,16 @@ impl WindowExt for Window { } /// Additional methods on `WindowBuilder` that are specific to Unix. -pub trait WindowBuilderExt { - +pub trait WindowBuilderExt<'a> { + fn from_existing_window(mut self, window_id: c_ulong) -> WindowBuilder<'a>; } -impl<'a> WindowBuilderExt for WindowBuilder<'a> { +impl<'a> WindowBuilderExt<'a> for WindowBuilder<'a> { + + /// Tells this (UNIX/X11) WindowBuilder to use an existing X window (eg, + /// one created by another application) instead of creating a new window. + fn from_existing_window(mut self, window_id: c_ulong) -> WindowBuilder<'a> { + self.platform_specific.existing_x11_window_id = Some(window_id); + self + } } -- cgit v1.2.3