From 2f7f177be8c039352ce9aa351cb55aa7ed624e1e Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Mon, 7 Feb 2022 21:51:54 +0100 Subject: [PATCH] Move RawWindowHandleWrapper to a shared module We're going to need this for the other platforms as well. --- src/window.rs | 12 ++++++++++++ src/x11/window.rs | 13 +------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/window.rs b/src/window.rs index 091a594..a0d91f6 100644 --- a/src/window.rs +++ b/src/window.rs @@ -18,6 +18,12 @@ pub struct WindowHandle { phantom: PhantomData<*mut ()>, } +/// Quick wrapper to satisfy [HasRawWindowHandle], because of course a raw window handle wouldn't +/// have a raw window handle, that would be silly. +pub(crate) struct RawWindowHandleWrapper { + pub handle: RawWindowHandle, +} + impl WindowHandle { fn new(window_handle: platform::WindowHandle) -> Self { Self { window_handle, phantom: PhantomData::default() } @@ -105,3 +111,9 @@ unsafe impl<'a> HasRawWindowHandle for Window<'a> { self.window.raw_window_handle() } } + +unsafe impl HasRawWindowHandle for RawWindowHandleWrapper { + fn raw_window_handle(&self) -> RawWindowHandle { + self.handle + } +} diff --git a/src/x11/window.rs b/src/x11/window.rs index ab56435..c1a81ac 100644 --- a/src/x11/window.rs +++ b/src/x11/window.rs @@ -11,6 +11,7 @@ use xcb::ffi::xcb_screen_t; use xcb::StructPtr; use super::XcbConnection; +use crate::window::RawWindowHandleWrapper; use crate::{ Event, MouseButton, MouseCursor, MouseEvent, PhyPoint, PhySize, ScrollDelta, WindowEvent, WindowHandler, WindowInfo, WindowOpenOptions, WindowScalePolicy, @@ -109,12 +110,6 @@ pub struct Window { // Hack to allow sending a RawWindowHandle between threads. Do not make public struct SendableRwh(RawWindowHandle); -/// Quick wrapper to satisfy [HasRawWindowHandle], because of course a raw window handle wouldn't -/// have a raw window handle, that would be silly. -struct RawWindowHandleWrapper { - handle: RawWindowHandle, -} - unsafe impl Send for SendableRwh {} type WindowOpenResult = Result; @@ -667,12 +662,6 @@ unsafe impl HasRawWindowHandle for Window { } } -unsafe impl HasRawWindowHandle for RawWindowHandleWrapper { - fn raw_window_handle(&self) -> RawWindowHandle { - self.handle - } -} - fn mouse_id(id: u8) -> MouseButton { match id { 1 => MouseButton::Left,