From dd7b08df153860741b53e91997619ba2a6fd371a Mon Sep 17 00:00:00 2001 From: Hal Gentz Date: Sun, 7 Apr 2019 23:07:47 -0600 Subject: [PATCH] Add ability to get wayland display from events loop. (#829) Signed-off-by: Hal Gentz --- CHANGELOG.md | 2 +- src/platform/unix.rs | 15 +++++++++++++++ src/platform_impl/linux/wayland/event_loop.rs | 4 ++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8460361027..e709197c13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,7 +37,7 @@ - `LoopDestroyed` is emitted when the `run` or `run_return` method is about to exit. - Rename `MonitorId` to `MonitorHandle`. - Removed `serde` implementations from `ControlFlow`. - +- On Wayland, added a `get_wayland_display` function to `EventsLoopExt`. - On Windows, fix `CursorMoved(0, 0)` getting dispatched on window focus. - On macOS, fix command key event left and right reverse. - On FreeBSD, NetBSD, and OpenBSD, fix build of X11 backend. diff --git a/src/platform/unix.rs b/src/platform/unix.rs index 5bde480d21..79a78d8480 100644 --- a/src/platform/unix.rs +++ b/src/platform/unix.rs @@ -111,6 +111,13 @@ pub trait EventLoopExtUnix { //#[doc(hidden)] //fn get_xlib_xconnection(&self) -> Option>; + + /// Returns a pointer to the `wl_display` object of wayland that is used by this `EventsLoop`. + /// + /// Returns `None` if the `EventsLoop` doesn't use wayland (if it uses xlib for example). + /// + /// The pointer will become invalid when the glutin `EventsLoop` is destroyed. + fn get_wayland_display(&self) -> Option<*mut raw::c_void>; } impl EventLoopExtUnix for EventLoop { @@ -150,6 +157,14 @@ impl EventLoopExtUnix for EventLoop { //fn get_xlib_xconnection(&self) -> Option> { // self.event_loop.x_connection().cloned() //} + + #[inline] + fn get_wayland_display(&self) -> Option<*mut raw::c_void> { + match self.events_loop { + LinuxEventsLoop::Wayland(ref e) => Some(e.get_display().c_ptr() as *mut _), + _ => None + } + } } /// Additional methods on `Window` that are specific to Unix. diff --git a/src/platform_impl/linux/wayland/event_loop.rs b/src/platform_impl/linux/wayland/event_loop.rs index 346d353640..297b5aead9 100644 --- a/src/platform_impl/linux/wayland/event_loop.rs +++ b/src/platform_impl/linux/wayland/event_loop.rs @@ -287,6 +287,10 @@ impl EventLoop { get_available_monitors(&self.outputs) } + pub fn get_display(&self) -> &Display { + &*self.display + } + pub fn window_target(&self) -> &RootELW { &self.window_target }