aboutsummaryrefslogtreecommitdiffstats
path: root/src/platform
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-06-10 18:32:26 -0400
committerbnewbold <bnewbold@robocracy.org>2016-06-12 12:23:15 -0400
commitbea8daf5e49055bc72ab7f61d245463b1ef1f1bd (patch)
tree13b47f64316102b01e4c719c958f51a952ce7210 /src/platform
parent8c6a3cb1ac90cc8c625c735193c49489379940d8 (diff)
downloadglutin-bea8daf5e49055bc72ab7f61d245463b1ef1f1bd.tar.gz
glutin-bea8daf5e49055bc72ab7f61d245463b1ef1f1bd.zip
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.
Diffstat (limited to 'src/platform')
-rw-r--r--src/platform/linux/api_dispatch.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/platform/linux/api_dispatch.rs b/src/platform/linux/api_dispatch.rs
index 54e0186..3a2a1e8 100644
--- a/src/platform/linux/api_dispatch.rs
+++ b/src/platform/linux/api_dispatch.rs
@@ -21,9 +21,14 @@ use api::x11;
use api::x11::XConnection;
use api::x11::XError;
use api::x11::XNotSupported;
+use std::os::raw::c_ulong;
#[derive(Clone, Default)]
-pub struct PlatformSpecificWindowBuilderAttributes;
+pub struct PlatformSpecificWindowBuilderAttributes {
+ /// Optionally tells the WindowBuilder to re-use an existing X window with
+ /// the given Window id number
+ pub existing_x11_window_id: Option<c_ulong>,
+}
enum Backend {
X(Arc<XConnection>),
@@ -175,7 +180,7 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
impl Window {
#[inline]
pub fn new(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
- opengl: &GlAttributes<&Window>, _: &PlatformSpecificWindowBuilderAttributes)
+ opengl: &GlAttributes<&Window>, platform: &PlatformSpecificWindowBuilderAttributes)
-> Result<Window, CreationError>
{
match *BACKEND {
@@ -194,7 +199,10 @@ impl Window {
_ => panic!() // TODO: return an error
});
- x11::Window::new(connec, window, pf_reqs, &opengl).map(Window::X)
+ match platform.existing_x11_window_id {
+ None => x11::Window::new(connec, window, pf_reqs, &opengl).map(Window::X),
+ Some(window_id) => x11::Window::from_existing_window(connec, window, pf_reqs, &opengl, window_id).map(Window::X),
+ }
},
Backend::Error(ref error) => Err(CreationError::NoBackendAvailable(Box::new(error.clone())))