From c49c6bcd6ea7ab887a9ebeb547c4fff9b0f59406 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Sun, 8 May 2016 09:28:54 +0200 Subject: [PATCH] wayland: WindowExt implementations. --- src/api/wayland/window.rs | 12 ++++++++++++ src/os/unix.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/api/wayland/window.rs b/src/api/wayland/window.rs index 389f8da1..38f89bfe 100644 --- a/src/api/wayland/window.rs +++ b/src/api/wayland/window.rs @@ -286,6 +286,18 @@ impl Window { Err(()) } + #[inline] + pub fn get_wayland_display(&self) -> *mut libc::c_void { + WAYLAND_CONTEXT.as_ref().unwrap() // context exists if window was created + .display_ptr() as *mut libc::c_void + } + + #[inline] + pub fn get_wayland_surface(&self) -> *mut libc::c_void { + use wayland_client::Proxy; + self.surface.ptr() as *mut libc::c_void + } + #[inline] pub fn platform_display(&self) -> *mut libc::c_void { WAYLAND_CONTEXT.as_ref().unwrap() // context exists if window was created diff --git a/src/os/unix.rs b/src/os/unix.rs index 4c6237f4..195da77a 100644 --- a/src/os/unix.rs +++ b/src/os/unix.rs @@ -20,6 +20,20 @@ pub trait WindowExt { /// /// The pointer will become invalid when the glutin `Window` is destroyed. fn get_xlib_display(&self) -> Option<*mut libc::c_void>; + + /// Returns a pointer to the `wl_surface` object of wayland that is used by this window. + /// + /// Returns `None` if the window doesn't use wayland (if it uses xlib for example). + /// + /// The pointer will become invalid when the glutin `Window` is destroyed. + fn get_wayland_surface(&self) -> Option<*mut libc::c_void>; + + /// Returns a pointer to the `wl_display` object of wayland that is used by this window. + /// + /// Returns `None` if the window doesn't use wayland (if it uses xlib for example). + /// + /// The pointer will become invalid when the glutin `Window` is destroyed. + fn get_wayland_display(&self) -> Option<*mut libc::c_void>; } impl WindowExt for Window { @@ -38,6 +52,22 @@ impl WindowExt for Window { _ => None } } + + #[inline] + fn get_wayland_surface(&self) -> Option<*mut libc::c_void> { + match self.window { + LinuxWindow::Wayland(ref w) => Some(w.get_wayland_surface()), + _ => None + } + } + + #[inline] + fn get_wayland_display(&self) -> Option<*mut libc::c_void> { + match self.window { + LinuxWindow::Wayland(ref w) => Some(w.get_wayland_display()), + _ => None + } + } } /// Additional methods on `WindowBuilder` that are specific to Unix.